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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <sch_render_settings.h>
22#include <scintilla_tricks.h>
23#include <netclass.h>
24#include <wx/log.h>
25#include <wx/menu.h>
26
27#include <advanced_config.h>
28#include <base_units.h>
29#include <common.h> // for ExpandTextVars
30#include <sch_edit_frame.h>
31#include <plotters/plotter.h>
32#include <bitmaps.h>
33#include <kiway.h>
35#include <string_utils.h>
37#include <trace_helpers.h>
38#include <tool/tool_manager.h>
40#include <font/glyph_types.h>
41#include <font/outline_font.h>
42#include "sim/sim_lib_mgr.h"
43#include <properties/property.h>
45#include <google/protobuf/any.pb.h>
46#include <api/api_utils.h>
47#include <api/schematic/schematic_types.pb.h>
48
49static const std::vector<KICAD_T> labelTypes = { SCH_LABEL_LOCATE_ANY_T };
50
51
61static const std::vector<wxString>& GetKnownNetclassFieldTranslations()
62{
63 static const std::vector<wxString> translations = {
64 wxString::FromUTF8( "Net Class" ),
65 wxString::FromUTF8( "صنف الشبكة" ), // ar
66 wxString::FromUTF8( "Верига Клас" ), // bg
67 wxString::FromUTF8( "Classe de xarxa" ), // ca
68 wxString::FromUTF8( "Třídy spojů" ), // cs
69 wxString::FromUTF8( "Netklasse" ), // da, nl
70 wxString::FromUTF8( "Netzklasse" ), // de
71 wxString::FromUTF8( "Κλάση Δικτύου" ), // el
72 wxString::FromUTF8( "Clase de red" ), // es, es_MX
73 wxString::FromUTF8( "Ühendusniidiklass" ), // et
74 wxString::FromUTF8( "Verkkoluokka" ), // fi
75 wxString::FromUTF8( "Classe d'Equipot" ), // fr
76 wxString::FromUTF8( "מחלקת רשת" ), // he
77 wxString::FromUTF8( "नेट क्लास" ), // hi
78 wxString::FromUTF8( "Hálózatosztály" ), // hu
79 wxString::FromUTF8( "Kelas Net" ), // id
80 wxString::FromUTF8( "Netclass" ), // it, ro (same as untranslated)
81 wxString::FromUTF8( "ネットクラス" ), // ja
82 wxString::FromUTF8( "ქსელის კლასი" ), // ka
83 wxString::FromUTF8( "네트 클래스" ), // ko
84 wxString::FromUTF8( "Grandinių klasė" ), // lt
85 wxString::FromUTF8( "Tīklu klase" ), // lv
86 wxString::FromUTF8( "Nettklasse" ), // no
87 wxString::FromUTF8( "Klasy sieci" ), // pl
88 wxString::FromUTF8( "Classes da rede" ), // pt_BR
89 wxString::FromUTF8( "Classe de Rede" ), // pt
90 wxString::FromUTF8( "Класс цепей" ), // ru
91 wxString::FromUTF8( "Triedy spojov" ), // sk
92 wxString::FromUTF8( "Razred vozlišča" ), // sl
93 wxString::FromUTF8( "Класа везе" ), // sr
94 wxString::FromUTF8( "Nätklass" ), // sv
95 wxString::FromUTF8( "நிகர வகுப்பு" ), // ta
96 wxString::FromUTF8( "నెట్ క్లాస్" ), // te
97 wxString::FromUTF8( "เน็ตคลาส" ), // th
98 wxString::FromUTF8( "Ağ Sınıfı" ), // tr
99 wxString::FromUTF8( "Клас зв'язків" ), // uk
100 wxString::FromUTF8( "Lớp mạng" ), // vi
101 wxString::FromUTF8( "网络类" ), // zh_CN
102 wxString::FromUTF8( "網路類" ) // zh_TW
103 };
104
105 return translations;
106}
107
108
109bool SCH_FIELD::IsNetclassLabelFieldName( const wxString& aName )
110{
111 if( aName == wxT( "Netclass" ) )
112 return true;
113
114 for( const wxString& candidate : GetKnownNetclassFieldTranslations() )
115 {
116 if( aName == candidate )
117 return true;
118 }
119
120 return false;
121}
122
123
125 SCH_ITEM( nullptr, SCH_FIELD_T ),
126 EDA_TEXT( schIUScale, wxEmptyString ),
127 m_id( FIELD_T::USER ),
128 m_ordinal( 0 ),
129 m_showName( false ),
130 m_allowAutoPlace( true ),
131 m_isGeneratedField( false ),
132 m_autoAdded( false ),
133 m_showInChooser( true ),
135{
136}
137
138
139SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, FIELD_T aFieldId, const wxString& aName ) :
140 SCH_FIELD()
141{
142 m_parent = aParent;
143
144 if( !aName.IsEmpty() )
145 SetName( aName );
146 else
147 SetName( GetDefaultFieldName( aFieldId, TRANSLATED ) );
148
149 setId( aFieldId ); // will also set the layer; call only AFTER SetName()
150 SetVisible( true );
151
152 if( aParent && aParent->Schematic() )
153 {
154 SCHEMATIC_SETTINGS& settings = aParent->Schematic()->Settings();
156 }
157
158 if( aFieldId == FIELD_T::USER && aParent )
159 {
160 wxASSERT_MSG( aParent->Type() != SCH_SHEET_T, wxT( "Sheets use FIELD_T::SHEET_USER, not FIELD_T::USER!" ) );
161
162 if( aParent->Type() == SCH_SYMBOL_T )
163 m_ordinal = static_cast<SCH_SYMBOL*>( aParent )->GetNextFieldOrdinal();
164 else if( aParent->Type() == LIB_SYMBOL_T )
165 m_ordinal = static_cast<LIB_SYMBOL*>( aParent )->GetNextFieldOrdinal();
166 else if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aParent ) )
167 m_ordinal = label->GetNextFieldOrdinal();
168 }
169 else if( aFieldId == FIELD_T::SHEET_USER && aParent )
170 {
171 if( aParent->Type() == SCH_SHEET_T )
172 m_ordinal = static_cast<SCH_SHEET*>( aParent )->GetNextFieldOrdinal();
173 }
174}
175
176
178 SCH_FIELD( aParent, FIELD_T::USER, wxEmptyString )
179{
180 SCH_ITEM::operator=( *aText );
181 EDA_TEXT::operator=( *aText );
182}
183
184
186 SCH_ITEM( aField ),
187 EDA_TEXT( aField )
188{
189 m_private = aField.m_private;
190 m_name = aField.m_name;
191 setId( aField.m_id ); // will also set the layer; call only AFTER setting m_name
192 m_ordinal = aField.m_ordinal;
193 m_showName = aField.m_showName;
196 m_autoAdded = aField.m_autoAdded;
199
200 m_renderCache.reset();
201}
202
203
204void SCH_FIELD::Serialize( kiapi::schematic::types::SchematicField& field, const EDA_IU_SCALE& aScale ) const
205{
206 field.set_name( GetName( false ).ToUTF8() );
207 field.set_visible( IsVisible() );
208 field.set_show_name( IsNameShown() );
209 field.set_allow_auto_place( CanAutoplace() );
210 field.set_is_private( IsPrivate() );
211
212 EDA_TEXT::Serialize( *field.mutable_text(), aScale );
213
214 // Override the position from the above for symbols so that they are in the right reference frame
215 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
216 kiapi::common::PackVector2( *field.mutable_text()->mutable_position(), GetPosition(), aScale );
217
218 kiapi::common::PackCustomProperties( field.mutable_custom_properties(), *this );
219}
220
221
222void SCH_FIELD::Serialize( google::protobuf::Any& aContainer ) const
223{
224 kiapi::schematic::types::SchematicField field;
225 Serialize( field, schIUScale );
226
227 if( !aContainer.PackFrom( field ) )
228 wxFAIL_MSG( wxT( "Failed to pack SCH_FIELD" ) );
229}
230
231
232bool SCH_FIELD::Deserialize( const kiapi::schematic::types::SchematicField& field, const EDA_IU_SCALE& aScale )
233{
234 SetName( wxString::FromUTF8( field.name() ) );
235 SetVisible( field.visible() );
236 SetNameShown( field.show_name() );
237 SetCanAutoplace( field.allow_auto_place() );
238 SetPrivate( field.is_private() );
239
240 bool result = EDA_TEXT::Deserialize( field.text(), aScale );
241
242 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
243 SetPosition( kiapi::common::UnpackVector2( field.text().position(), aScale ) );
244
245 kiapi::common::UnpackCustomProperties( field.custom_properties(), *this );
246 return result;
247}
248
249
250bool SCH_FIELD::Deserialize( const google::protobuf::Any& aContainer )
251{
252 kiapi::schematic::types::SchematicField field;
253
254 if( !aContainer.UnpackTo( &field ) )
255 return false;
256
257 return Deserialize( field, schIUScale );
258}
259
260
262{
263 EDA_TEXT::operator=( aField );
264
265 m_private = aField.m_private;
266 m_name = aField.m_name;
267 setId( aField.m_id ); // will also set the layer; call only AFTER setting m_name
268 m_ordinal = aField.m_ordinal;
269 m_showName = aField.m_showName;
273
274 m_renderCache.reset();
276
277 return *this;
278}
279
280
282{
283 return new SCH_FIELD( *this );
284}
285
286
287void SCH_FIELD::Copy( SCH_FIELD* aTarget ) const
288{
289 *aTarget = *this;
290}
291
292
294static FIELD_T sheetFieldId( FIELD_T aId, const wxString& aName )
295{
297 return aId;
298
301
302 return FIELD_T::SHEET_USER;
303}
304
305
307{
308 m_id = sheetFieldId( aId, m_name );
310}
311
312
313void SCH_FIELD::SetOrdinal( int aOrdinal, FIELD_T aType )
314{
315 m_id = sheetFieldId( aType, m_name );
316 m_ordinal = aOrdinal;
317}
318
319
324
325
327 const wxString& aVariantName, int aDepth ) const
328{
329 bool hasTextVars = HasTextVars();
330 wxString text = getUnescapedText( aPath, aVariantName );
331
332 if( !aVariantName.IsEmpty() )
333 hasTextVars = text.Contains( wxT( "${" ) ) || text.Contains( wxT( "@{" ) );
334
335 if( IsNameShown() && aContext == FOR_CANVAS )
336 text = GetShownName() << wxS( ": " ) << text;
337
338 if( hasTextVars && aContext != RAW_VALUE )
339 {
340 text = ResolveText( text, aPath, aDepth, aVariantName );
341 FinalizeTextVarExpansion( text, aContext );
342 }
343
344 return text;
345}
346
347
348wxString SCH_FIELD::GetShownText( RESOLUTION_CONTEXT aContext, int aDepth ) const
349{
350 if( SCHEMATIC* schematic = Schematic() )
351 {
352 const SCH_SHEET_PATH& currentSheet = schematic->CurrentSheet();
353 wxString variantName = schematic->GetCurrentVariant();
354
355 // Path() builds a KIID_PATH, so keep it off the render path unless the trace is on
356 if( wxLog::IsAllowedTraceMask( traceSchFieldRendering ) )
357 {
358 wxLogTrace( traceSchFieldRendering,
359 "GetShownText (no path arg): field=%s, current sheet path='%s', variant='%s', "
360 "size=%zu, empty=%d",
361 GetName(), currentSheet.Path().AsString(), variantName, currentSheet.size(),
362 currentSheet.empty() ? 1 : 0 );
363 }
364
365 return GetShownText( &currentSheet, aContext, variantName, aDepth );
366 }
367 else
368 {
369 return GetShownText( nullptr, aContext, wxEmptyString, aDepth );
370 }
371}
372
373
374wxString SCH_FIELD::GetFullText( int unit ) const
375{
376 if( GetId() != FIELD_T::REFERENCE )
377 return GetText();
378
379 wxString text = GetText();
380 text << wxT( "?" );
381
382 if( GetParentSymbol() && GetParentSymbol()->IsMultiUnit() )
383 text << GetParentSymbol()->GetUnitDisplayName( unit, false );
384
385 return text;
386}
387
388
390{
392}
393
394
396{
398
399 if( !font )
400 font = KIFONT::FONT::GetFont( GetDefaultFont( aSettings ), IsBold(), IsItalic() );
401
402 return font;
403}
404
405
411
412
418
419
420std::vector<std::unique_ptr<KIFONT::GLYPH>>*
421SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition, TEXT_ATTRIBUTES& aAttrs ) const
422{
423 KIFONT::FONT* font = GetDrawFont( nullptr );
424
425 if( font->IsOutline() )
426 {
427 KIFONT::OUTLINE_FONT* outlineFont = static_cast<KIFONT::OUTLINE_FONT*>( font );
428
429 if( !m_renderCache )
430 m_renderCache = std::make_unique<SCH_FIELD_RENDER_CACHE_DATA>();
431
432 if( m_renderCache->glyphs.empty() )
433 {
434 m_renderCache->glyphs.clear();
435
436 outlineFont->GetLinesAsGlyphs( &m_renderCache->glyphs, forResolvedText, forPosition, aAttrs,
437 GetFontMetrics() );
438
439 m_renderCache->pos = forPosition;
440 }
441
442 if( m_renderCache->pos != forPosition )
443 {
444 VECTOR2I delta = forPosition - m_renderCache->pos;
445
446 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_renderCache->glyphs )
447 {
448 if( glyph->IsOutline() )
449 static_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() )->Move( delta );
450 else
451 static_cast<KIFONT::STROKE_GLYPH*>( glyph.get() )->Move( delta );
452 }
453
454 m_renderCache->pos = forPosition;
455 }
456
457 return &m_renderCache->glyphs;
458 }
459
460 return nullptr;
461}
462
463
464void SCH_FIELD::ImportValues( const SCH_FIELD& aSource )
465{
466 SetAttributes( aSource );
467 SetVisible( aSource.IsVisible() );
468 SetNameShown( aSource.IsNameShown() );
469 SetCanAutoplace( aSource.CanAutoplace() );
470}
471
472
474{
475 wxCHECK_RET( aItem && aItem->Type() == SCH_FIELD_T, wxT( "Cannot swap with invalid item." ) );
476
477 SCH_FIELD* item = static_cast<SCH_FIELD*>( aItem );
478
479 std::swap( m_showName, item->m_showName );
480 std::swap( m_allowAutoPlace, item->m_allowAutoPlace );
481 std::swap( m_isGeneratedField, item->m_isGeneratedField );
482 SwapText( *item );
483 SwapAttributes( *item );
484
485 std::swap( m_lastResolvedColor, item->m_lastResolvedColor );
486}
487
488
490{
492 {
494 }
495 else
496 {
497 SCH_LABEL_BASE* parentLabel = dynamic_cast<SCH_LABEL_BASE*>( GetParent() );
498
499 if( parentLabel && !parentLabel->IsConnectivityDirty() )
501 else
503 }
504
505 return m_lastResolvedColor;
506}
507
508
509std::vector<int> SCH_FIELD::ViewGetLayers() const
510{
512}
513
514
516{
517 if( m_parent && m_parent->Type() == SCH_LABEL_T )
518 {
519 if( GetUntranslatedName() == wxT( "Netclass" ) || GetUntranslatedName() == wxT( "Component Class" ) )
520 {
521 return LAYER_NETCLASS_REFS;
522 }
523 }
524
525 switch( m_id )
526 {
528 case FIELD_T::VALUE: return LAYER_VALUEPART;
534 default: return LAYER_FIELDS;
535 }
536}
537
538
540{
541 // Calculate the text orientation according to the symbol orientation.
542 EDA_ANGLE orient = GetTextAngle();
543
544 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
545 {
546 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
547
548 if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
549 {
550 if( orient.IsHorizontal() )
551 orient = ANGLE_VERTICAL;
552 else
553 orient = ANGLE_HORIZONTAL;
554 }
555 }
556
557 return orient;
558}
559
560
562{
563 BOX2I bbox = GetTextBox( nullptr );
564
565 // Calculate the bounding box position relative to the parent:
566 VECTOR2I origin = GetParentPosition();
567 VECTOR2I pos = GetTextPos() - origin;
568 VECTOR2I begin = bbox.GetOrigin() - origin;
569 VECTOR2I end = bbox.GetEnd() - origin;
570 RotatePoint( begin, pos, GetTextAngle() );
571 RotatePoint( end, pos, GetTextAngle() );
572
573 // Now, apply the symbol transform (mirror/rot)
574 TRANSFORM transform;
575
576 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
577 transform = static_cast<SCH_SYMBOL*>( m_parent )->GetTransform();
578
579 bbox.SetOrigin( transform.TransformCoordinate( begin ) );
580 bbox.SetEnd( transform.TransformCoordinate( end ) );
581
582 bbox.Move( origin );
583 bbox.Normalize();
584
585 return bbox;
586}
587
588
590{
591 VECTOR2I render_center = GetBoundingBox().Centre();
592 VECTOR2I pos = GetPosition();
593
594 switch( GetHorizJustify() )
595 {
597 if( GetDrawRotation().IsVertical() )
598 return render_center.y > pos.y;
599 else
600 return render_center.x < pos.x;
601
603 if( GetDrawRotation().IsVertical() )
604 return render_center.y < pos.y;
605 else
606 return render_center.x > pos.x;
607
608 default:
609 return false;
610 }
611}
612
613
615{
616 // The justification must be stored before asking whether it is flipped, as a center
617 // justification has no side to report.
618 SetHorizJustify( aJustify );
619
621 SetHorizJustify( MapHorizJustify( -aJustify ) );
622}
623
624
634
635
637{
638 VECTOR2I render_center = GetBoundingBox().Centre();
639 VECTOR2I pos = GetPosition();
640
641 switch( GetVertJustify() )
642 {
644 if( GetDrawRotation().IsVertical() )
645 return render_center.x < pos.x;
646 else
647 return render_center.y < pos.y;
648
650 if( GetDrawRotation().IsVertical() )
651 return render_center.x > pos.x;
652 else
653 return render_center.y > pos.y;
654
655 default:
656 return false;
657 }
658}
659
660
662{
663 SetVertJustify( aJustify );
664
666 SetVertJustify( MapVertJustify( -aJustify ) );
667}
668
669
679
680
681bool SCH_FIELD::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
682{
683 bool searchHiddenFields = aSearchData.searchAllFields;
684 bool searchAndReplace = aSearchData.searchAndReplace;
685 bool replaceReferences = false;
686
687 try
688 {
689 // downcast
690 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
691 replaceReferences = schSearchData.replaceReferences;
692 }
693 catch( const std::bad_cast& )
694 {
695 }
696
697 wxString text = UnescapeString( GetText() );
698
699 if( !IsVisible() && !searchHiddenFields )
700 return false;
701
702 if( m_id == FIELD_T::REFERENCE )
703 {
704 if( searchAndReplace && !replaceReferences )
705 return false;
706
707 SCH_SYMBOL* parentSymbol = dyn_cast<SCH_SYMBOL*>( m_parent );
708
709 // The parent might be a LIB_SYMBOL, in which case, we don't
710 // have a sheet path to resolve the reference.
711 if( !parentSymbol )
712 return false;
713
714 // the search pane surfaces metadata hits through the reference field
715 if( aSearchData.searchMetadata && parentSymbol->Matches( aSearchData, aAuxData ) )
716 return true;
717
718 wxASSERT( aAuxData );
719
720 // Take sheet path into account which effects the reference field and the unit for
721 // symbols with multiple parts.
722 if( aAuxData )
723 {
724 SCH_SHEET_PATH* sheet = (SCH_SHEET_PATH*) aAuxData;
725 text = parentSymbol->GetRef( sheet );
726
727 if( SCH_ITEM::Matches( text, aSearchData ) )
728 return true;
729
730 if( parentSymbol->GetUnitCount() > 1 )
731 text = parentSymbol->GetRef( sheet, true );
732 }
733 }
734
735 return SCH_ITEM::Matches( text, aSearchData );
736}
737
738
739void SCH_FIELD::OnScintillaCharAdded( SCINTILLA_TRICKS* aScintillaTricks, wxStyledTextEvent& aEvent ) const
740{
741 SCH_ITEM* parent = dynamic_cast<SCH_ITEM*>( GetParent() );
742 SCHEMATIC* schematic = parent ? parent->Schematic() : nullptr;
743
744 if( !schematic )
745 return;
746
747 wxStyledTextCtrl* scintilla = aScintillaTricks->Scintilla();
748 int key = aEvent.GetKey();
749
750 wxArrayString autocompleteTokens;
751 int pos = scintilla->GetCurrentPos();
752 int start = scintilla->WordStartPosition( pos, true );
753 wxString partial;
754
755 // Multi-line fields are not allowed. So remove '\n' if entered.
756 if( key == '\n' )
757 {
758 wxString text = scintilla->GetText();
759 int currpos = scintilla->GetCurrentPos();
760 text.Replace( wxS( "\n" ), wxS( "" ) );
761 scintilla->SetText( text );
762 scintilla->GotoPos( currpos - 1 );
763 return;
764 }
765
766 auto textVarRef =
767 [&]( int pt )
768 {
769 return pt >= 2 && scintilla->GetCharAt( pt - 2 ) == '$' && scintilla->GetCharAt( pt - 1 ) == '{';
770 };
771
772 // Check for cross-reference
773 if( start > 1 && scintilla->GetCharAt( start - 1 ) == ':' )
774 {
775 int refStart = scintilla->WordStartPosition( start - 1, true );
776
777 if( textVarRef( refStart ) )
778 {
779 partial = scintilla->GetRange( start, pos );
780
781 wxString ref = scintilla->GetRange( refStart, start - 1 );
782
783 if( ref == wxS( "OP" ) )
784 {
785 // SPICE operating points use ':' syntax for ports
786 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent ) )
787 {
788 NULL_REPORTER devnull;
789 SCH_SHEET_PATH& sheet = schematic->CurrentSheet();
790 wxString variant = schematic->GetCurrentVariant();
791 SIM_LIB_MGR mgr( &schematic->Project() );
792
793 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
794 embeddedFilesStack.push_back( schematic->GetEmbeddedFiles() );
795
796 if( symbol->GetLibSymbolRef() )
797 symbol->GetLibSymbolRef()->AppendParentEmbeddedFiles( embeddedFilesStack );
798
799 if( EMBEDDED_FILES* symbolEmbeddedFiles = symbol->GetEmbeddedFiles() )
800 embeddedFilesStack.push_back( symbolEmbeddedFiles );
801
802 mgr.SetFilesStack( std::move( embeddedFilesStack ) );
803
804 SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, true, 0, variant, devnull ).model;
805
806 for( wxString pin : model.GetPinNames() )
807 {
808 if( pin.StartsWith( '<' ) && pin.EndsWith( '>' ) )
809 autocompleteTokens.push_back( pin.Mid( 1, pin.Length() - 2 ) );
810 else
811 autocompleteTokens.push_back( pin );
812 }
813
814 // add the synthetic port for power measurements
815 autocompleteTokens.push_back( wxT( "power" ) );
816 }
817 }
818 else
819 {
821 SCH_SYMBOL* refSymbol = nullptr;
822
823 schematic->Hierarchy().GetSymbols( refs, SYMBOL_FILTER_NON_POWER );
824
825 for( size_t jj = 0; jj < refs.GetCount(); jj++ )
826 {
827 if( refs[jj].GetSymbol()->GetRef( &refs[jj].GetSheetPath(), true ) == ref )
828 {
829 refSymbol = refs[jj].GetSymbol();
830 break;
831 }
832 }
833
834 if( refSymbol )
835 refSymbol->GetContextualTextVars( &autocompleteTokens );
836 }
837 }
838 }
839 else if( textVarRef( start ) )
840 {
841 partial = scintilla->GetTextRange( start, pos );
842
843 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent );
844 SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( parent );
845 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( parent );
846
847 if( symbol )
848 {
849 symbol->GetContextualTextVars( &autocompleteTokens );
850
851 if( schematic->CurrentSheet().Last() )
852 schematic->CurrentSheet().Last()->GetContextualTextVars( &autocompleteTokens );
853 }
854
855 if( sheet )
856 sheet->GetContextualTextVars( &autocompleteTokens );
857
858 if( label )
859 label->GetContextualTextVars( &autocompleteTokens );
860
861 for( std::pair<wxString, wxString> entry : schematic->Project().GetTextVars() )
862 autocompleteTokens.push_back( entry.first );
863 }
864
865 aScintillaTricks->DoAutocomplete( partial, autocompleteTokens );
866 scintilla->SetFocus();
867}
868
869
871{
872 // See comments in SCH_FIELD::Replace(), below.
874 return false;
875
876 return true;
877}
878
879
881{
882 if( const SYMBOL* parentSymbol = GetParentSymbol() )
883 {
884 if( parentSymbol->IsLocked() )
885 return true;
886 }
887
888 if( const SCH_SHEET* parentSheet = dynamic_cast<const SCH_SHEET*>( m_parent ) )
889 {
890 if( parentSheet->IsLocked() )
891 return true;
892 }
893
894 if( const SCH_LABEL_BASE* parentLabel = dynamic_cast<const SCH_LABEL_BASE*>( m_parent ) )
895 {
896 if( parentLabel->IsLocked() )
897 return true;
898 }
899
900 return SCH_ITEM::IsLocked();
901}
902
903
904bool SCH_FIELD::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
905{
907 return false;
908
909 bool replaceReferences = false;
910
911 try
912 {
913 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
914 replaceReferences = schSearchData.replaceReferences;
915 }
916 catch( const std::bad_cast& )
917 {
918 }
919
920 wxString text;
921 bool isReplaced = false;
922
923 if( m_id == FIELD_T::REFERENCE && m_parent && m_parent->Type() == SCH_SYMBOL_T )
924 {
925 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
926
927 if( !replaceReferences )
928 return false;
929
930 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in refdes." ) );
931
932 const SCH_SHEET_PATH* sheet = static_cast<const SCH_SHEET_PATH*>( aAuxData );
933
934 text = parentSymbol->GetRef( sheet );
935
936 // Only the base is stored, and the sheet suffix must survive the replacement
937 const wxString suffix = text.Mid( parentSymbol->GetBaseRef( sheet ).length() );
938
939 isReplaced = EDA_ITEM::Replace( aSearchData, text )
940 && ( suffix.IsEmpty() || ( text.EndsWith( suffix ) && text.length() > suffix.length() ) );
941
942 if( isReplaced )
943 parentSymbol->SetUserRef( *sheet, text.Left( text.length() - suffix.length() ) );
944 }
945 else
946 {
947 isReplaced = EDA_TEXT::Replace( aSearchData );
948
949 if( m_id == FIELD_T::SHEET_FILENAME && isReplaced )
950 {
951 // If we allowed this we'd have a bunch of work to do here, including warning
952 // about it not being undoable, checking for recursive hierarchies, reloading
953 // sheets, etc. See DIALOG_SHEET_PROPERTIES::TransferDataFromWindow().
954 }
955 }
956
957 return isReplaced;
958}
959
960
961void SCH_FIELD::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
962{
964
965 if( GetTextAngle().IsVertical() )
966 {
967 switch( horizJustify )
968 {
970 if( aRotateCCW )
972
973 break;
974
976 if( aRotateCCW )
978
979 break;
980
983 break;
984 }
985
987 }
988 else if( GetTextAngle().IsHorizontal() )
989 {
990 switch( horizJustify )
991 {
993 if( !aRotateCCW )
995
996 break;
997
999 if( !aRotateCCW )
1001
1002 break;
1003
1006 break;
1007 }
1008
1010 }
1011 else
1012 {
1013 wxFAIL_MSG( wxString::Format( wxT( "SCH_FIELD text angle is not horizontal or vertical: %f" ),
1014 GetTextAngle().AsDegrees() ) );
1015 }
1016
1017 VECTOR2I pt = GetPosition();
1018 RotatePoint( pt, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
1019 SetPosition( pt );
1020}
1021
1022
1024{
1025 int x = GetTextPos().x;
1026
1027 x -= aCenter;
1028 x *= -1;
1029 x += aCenter;
1030
1031 SetTextX( x );
1032}
1033
1034
1036{
1037 int y = GetTextPos().y;
1038
1039 y -= aCenter;
1040 y *= -1;
1041 y += aCenter;
1042
1043 SetTextY( y );
1044}
1045
1046
1047void SCH_FIELD::BeginEdit( const VECTOR2I& aPosition )
1048{
1049 SetTextPos( aPosition );
1050}
1051
1052
1053void SCH_FIELD::CalcEdit( const VECTOR2I& aPosition )
1054{
1055 SetTextPos( aPosition );
1056}
1057
1058
1059wxString SCH_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
1060{
1061 wxString content = aFull ? GetShownText( FOR_GUI ) : KIUI::EllipsizeMenuText( GetText() );
1062
1063 if( content.IsEmpty() )
1064 return wxString::Format( _( "Field %s (empty)" ), UnescapeString( GetName() ) );
1065 else
1066 return wxString::Format( _( "Field %s '%s'" ), UnescapeString( GetName() ), content );
1067}
1068
1069
1070void SCH_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1071{
1072 wxString msg;
1073
1074 aList.emplace_back( _( "Symbol Field" ), UnescapeString( GetName() ) );
1075
1076 // Don't use GetShownText() here; we want to show the user the variable references
1077 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
1078
1079 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
1080
1081 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
1082
1083 aList.emplace_back( _( "Style" ), GetTextStyleName() );
1084
1085 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
1086
1087 switch( GetHorizJustify() )
1088 {
1089 case GR_TEXT_H_ALIGN_LEFT: msg = _( "Left" ); break;
1090 case GR_TEXT_H_ALIGN_CENTER: msg = _( "Center" ); break;
1091 case GR_TEXT_H_ALIGN_RIGHT: msg = _( "Right" ); break;
1093 }
1094
1095 aList.emplace_back( _( "H Justification" ), msg );
1096
1097 switch( GetVertJustify() )
1098 {
1099 case GR_TEXT_V_ALIGN_TOP: msg = _( "Top" ); break;
1100 case GR_TEXT_V_ALIGN_CENTER: msg = _( "Center" ); break;
1101 case GR_TEXT_V_ALIGN_BOTTOM: msg = _( "Bottom" ); break;
1103 }
1104
1105 aList.emplace_back( _( "V Justification" ), msg );
1106}
1107
1108
1110{
1112 return true;
1113
1114 return IsURL( GetShownText( FOR_GUI ) );
1115}
1116
1117
1118void SCH_FIELD::DoHypertextAction( EDA_DRAW_FRAME* aFrame, const VECTOR2I& aMousePos ) const
1119{
1120 constexpr int START_ID = 1;
1121
1122 wxString href;
1123
1125 {
1126 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
1127 SCH_SHEET_PATH* sheet = &label->Schematic()->CurrentSheet();
1128 wxMenu menu;
1129
1130 std::vector<std::pair<wxString, wxString>> pages;
1131
1132 label->GetIntersheetRefs( sheet, &pages );
1133
1134 for( int i = 0; i < (int) pages.size(); ++i )
1135 {
1136 menu.Append( i + START_ID,
1137 wxString::Format( _( "Go to Page %s (%s)" ), pages[i].first, pages[i].second ) );
1138 }
1139
1140 menu.AppendSeparator();
1141 menu.Append( 999 + START_ID, _( "Back to Previous Selected Sheet" ) );
1142
1143 int sel = aFrame->GetPopupMenuSelectionFromUser( menu ) - START_ID;
1144
1145 if( sel >= 0 && sel < (int) pages.size() )
1146 href = wxT( "#" ) + pages[sel].first;
1147 else if( sel == 999 )
1149 }
1151 {
1152 href = GetShownText( FOR_GUI );
1153 }
1154
1155 if( !href.IsEmpty() )
1156 {
1158 navTool->HypertextCommand( href );
1159 }
1160}
1161
1162
1163void SCH_FIELD::SetName( const wxString& aName )
1164{
1165 const bool generated = ::IsGeneratedField( aName );
1166 const bool changed = m_name != aName || ( generated && EDA_TEXT::GetText() != aName );
1167 m_name = aName;
1168 m_isGeneratedField = generated;
1169
1170 if( m_isGeneratedField )
1171 EDA_TEXT::SetText( aName );
1172
1173 if( sheetFieldId( m_id, m_name ) != m_id )
1174 setId( m_id );
1175
1176 if( changed )
1178}
1179
1180
1181void SCH_FIELD::SetText( const wxString& aText )
1182{
1183 // Don't allow modification of text value of generated fields.
1184 if( m_isGeneratedField )
1185 return;
1186
1187 // Mandatory fields should not have leading or trailing whitespace.
1188 const wxString text = IsMandatory() ? aText.Strip( wxString::both ) : aText;
1189 const bool changed = EDA_TEXT::GetText() != text;
1191
1192 if( changed )
1194}
1195
1196
1197void SCH_FIELD::SetText( const wxString& aText, const SCH_SHEET_PATH* aPath, const wxString& aVariantName )
1198{
1199 wxCHECK( m_parent, /* void */ );
1200
1201 if( m_isGeneratedField )
1202 return;
1203
1204 const wxString text = IsMandatory() ? aText.Strip( wxString::both ) : aText;
1205
1206 switch( m_parent->Type() )
1207 {
1208 case SCH_SYMBOL_T:
1209 {
1210 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( m_parent );
1211 wxCHECK( symbol, /* void */ );
1212
1213 // Just because we _have_ a parent, doesn't mean we've been added to it yet. Make sure to
1214 // use the version of SetFieldText() which gives our parent a pointer to us.
1215 symbol->SetFieldText( this, GetName( false ), text, aPath, aVariantName );
1216
1217 break;
1218 }
1219
1220 case SCH_SHEET_T:
1221 {
1222 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
1223 wxCHECK( sheet, /* void */ );
1224
1225 // Just because we _have_ a parent, doesn't mean we've been added to it yet. Make sure to
1226 // use the version of SetFieldText() which gives our parent a pointer to us.
1227 sheet->SetFieldText( this, GetName( false ), text, aPath, aVariantName );
1228
1229 break;
1230 }
1231
1232 default:
1234 break;
1235 }
1236}
1237
1238
1239wxString SCH_FIELD::GetText( const SCH_SHEET_PATH* aPath, const wxString& aVariantName ) const
1240{
1241 wxString retv;
1242
1243 wxCHECK( aPath && m_parent, retv );
1244
1245 switch( m_parent->Type() )
1246 {
1247 case SCH_SYMBOL_T:
1248 {
1249 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( m_parent );
1250 wxCHECK( symbol, retv );
1251
1252 // Just because we _have_ a parent, doesn't mean we've been added to it yet. Make sure to
1253 // use the version of SetFieldText() which gives our parent a pointer to us.
1254 retv = symbol->GetFieldText( this, GetName( false ), aPath, aVariantName );
1255
1256 break;
1257 }
1258
1259 case SCH_SHEET_T:
1260 {
1261 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
1262 wxCHECK( sheet, retv );
1263
1264 // Just because we _have_ a parent, doesn't mean we've been added to it yet. Make sure to
1265 // use the version of SetFieldText() which gives our parent a pointer to us.
1266 retv = sheet->GetFieldText( this, GetName( false ), aPath, aVariantName );
1267
1268 break;
1269 }
1270
1271 default:
1272 retv = GetText();
1273 break;
1274 }
1275
1276 return retv;
1277}
1278
1279
1280wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
1281{
1282 if( m_parent && m_parent->IsType( labelTypes ) )
1283 return SCH_LABEL_BASE::GetDefaultFieldName( m_name, aUseDefaultName );
1284
1285 if( IsMandatory() )
1287 else if( m_name.IsEmpty() && aUseDefaultName )
1289 else
1290 return m_name;
1291}
1292
1293
1295{
1296 if( m_parent && m_parent->IsType( labelTypes ) )
1297 {
1298 // These should be stored untranslated, but recover translated forms written by
1299 // older versions or by cross-language collaboration via Git.
1301 return wxT( "Netclass" );
1302 }
1303
1304 if( IsMandatory() )
1306
1307 return m_name;
1308}
1309
1310
1312{
1313 if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
1314 {
1315 switch( m_id )
1316 {
1320 default: return BITMAPS::text;
1321 }
1322 }
1323
1324 return BITMAPS::text;
1325}
1326
1327
1328bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
1329{
1331 return false;
1332
1334
1335 // Text in symbol editor can have additional chars (ie: reference designators U? or U?A)
1336 if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
1337 {
1338 SCH_FIELD temp( *this );
1339 temp.SetText( GetFullText() );
1340 rect = temp.GetBoundingBox();
1341 }
1342
1343 rect.Inflate( aAccuracy );
1344
1345 if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
1346 {
1347 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
1348 rect.Offset( label->GetSchematicTextOffset( nullptr ) );
1349 }
1350
1351 return rect.Contains( aPosition );
1352}
1353
1354
1355bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
1356{
1358 return false;
1359
1360 if( m_flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
1361 return false;
1362
1363 BOX2I rect = aRect;
1364
1365 rect.Inflate( aAccuracy );
1366
1367 if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
1368 {
1369 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
1370 rect.Offset( label->GetSchematicTextOffset( nullptr ) );
1371 }
1372
1373 if( aContained )
1374 return rect.Contains( GetBoundingBox() );
1375
1376 return rect.Intersects( GetBoundingBox() );
1377}
1378
1379
1380bool SCH_FIELD::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
1381{
1383 return false;
1384
1385 if( m_flags & ( STRUCT_DELETED | SKIP_STRUCT ) )
1386 return false;
1387
1388 BOX2I bbox = GetBoundingBox();
1389
1390 if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
1391 {
1392 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
1393 bbox.Offset( label->GetSchematicTextOffset( nullptr ) );
1394 }
1395
1396 return KIGEOM::BoxHitTest( aPoly, bbox, aContained );
1397}
1398
1399
1400void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts, int aUnit, int aBodyStyle,
1401 const VECTOR2I& aOffset, bool aDimmed )
1402{
1403 wxString text;
1404
1405 if( Schematic() )
1406 text = GetShownText( &Schematic()->CurrentSheet(), FOR_CANVAS, Schematic()->GetCurrentVariant() );
1407 else
1409
1410 if( ( !IsVisible() && !IsForceVisible() ) || text.IsEmpty() || aBackground )
1411 return;
1412
1413 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1414 COLOR4D color = renderSettings->GetLayerColor( GetLayer() );
1415 int penWidth = GetEffectiveTextPenWidth( renderSettings->GetDefaultPenWidth() );
1416
1417 COLOR4D bg = renderSettings->GetBackgroundColor();
1418
1419 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
1420 bg = COLOR4D::WHITE;
1421
1422 if( aPlotter->GetColorMode() && GetTextColor() != COLOR4D::UNSPECIFIED )
1423 color = GetTextColor();
1424
1425 if( color.m_text && Schematic() )
1426 color = COLOR4D( ResolveText( *color.m_text, &Schematic()->CurrentSheet() ) );
1427
1428 if( aDimmed )
1429 {
1430 color.Desaturate();
1431 color = color.Mix( bg, 0.5f );
1432 }
1433
1434 penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
1435
1436 // clamp the pen width to be sure the text is readable
1437 penWidth = std::min( penWidth, std::min( GetTextSize().x, GetTextSize().y ) / 4 );
1438
1439 if( !IsVisible() && !renderSettings->m_ShowHiddenFields )
1440 return;
1441
1442 // Calculate the text orientation, according to the symbol orientation/mirror
1443 EDA_ANGLE orient = GetTextAngle();
1444 VECTOR2I textpos = GetTextPos();
1446 GR_TEXT_V_ALIGN_T vjustify = GetVertJustify();
1447
1448 if( renderSettings->m_Transform.y1 ) // Rotate symbol 90 deg.
1449 {
1450 if( orient.IsHorizontal() )
1451 orient = ANGLE_VERTICAL;
1452 else
1453 orient = ANGLE_HORIZONTAL;
1454 }
1455
1456 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1457 {
1458 /*
1459 * Calculate the text justification, according to the symbol orientation/mirror. This is
1460 * a bit complicated due to cumulative calculations:
1461 * - numerous cases (mirrored or not, rotation)
1462 * - the plotter's Text() function will also recalculate H and V justifications according
1463 * to the text orientation
1464 * - when a symbol is mirrored the text is not, and justifications become a nightmare
1465 *
1466 * So the easier way is to use no justifications (centered text) and use GetBoundingBox
1467 * to know the text coordinate considered as centered.
1468 */
1469 hjustify = GR_TEXT_H_ALIGN_CENTER;
1470 vjustify = GR_TEXT_V_ALIGN_CENTER;
1471 textpos = GetBoundingBox().Centre();
1472 }
1473 else if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
1474 {
1475 // Library-symbol exports (CLI/symbol editor) provide an item offset in the same coordinate
1476 // frame as body graphics/pins. Apply the same transform+offset pipeline to field text.
1477 textpos = renderSettings->TransformCoordinate( textpos ) + aOffset;
1478 }
1479 else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
1480 {
1481 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( m_parent );
1482 textpos += label->GetSchematicTextOffset( renderSettings );
1483 }
1484 else if( m_parent && m_parent->Type() == SCH_DIRECTIVE_LABEL_T )
1485 {
1486 SCH_DIRECTIVE_LABEL* label = static_cast<SCH_DIRECTIVE_LABEL*>( m_parent );
1487 std::shared_ptr<NETCLASS> nc = label->GetEffectiveNetClass();
1488
1489 if( nc && ( nc->GetSchematicColor() != COLOR4D::UNSPECIFIED ) && aPlotter->GetColorMode() )
1490 color = nc->GetSchematicColor();
1491 }
1492
1493 KIFONT::FONT* font = GetDrawFont( renderSettings );
1495 attrs.m_StrokeWidth = penWidth;
1496 attrs.m_Halign = hjustify;
1497 attrs.m_Valign = vjustify;
1498 attrs.m_Angle = orient;
1499 attrs.m_Multiline = false;
1500
1501 aPlotter->PlotText( textpos, color, text, attrs, font, GetFontMetrics() );
1502
1504 {
1505 if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( m_parent ) )
1506 {
1507 std::vector<std::pair<wxString, wxString>> pages;
1508 std::vector<wxString> pageHrefs;
1509
1510 label->GetIntersheetRefs( &Schematic()->CurrentSheet(), &pages );
1511
1512 for( const auto& [pageNumber, sheetName] : pages )
1513 pageHrefs.push_back( wxT( "#" ) + pageNumber );
1514
1515 BOX2I bbox = GetBoundingBox();
1516 bbox.Offset( label->GetSchematicTextOffset( renderSettings ) );
1517
1518 aPlotter->HyperlinkMenu( bbox, pageHrefs );
1519 }
1520 }
1521}
1522
1523
1524void SCH_FIELD::SetPosition( const VECTOR2I& aPosition )
1525{
1526 // Actual positions are calculated by the rotation/mirror transform of the parent symbol
1527 // of the field. The inverse transform is used to calculate the position relative to the
1528 // parent symbol.
1529 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1530 {
1531 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1532 VECTOR2I relPos = aPosition - parentSymbol->GetPosition();
1533
1534 relPos = parentSymbol->GetTransform().InverseTransform().TransformCoordinate( relPos );
1535
1536 SetTextPos( relPos + parentSymbol->GetPosition() );
1537 return;
1538 }
1539
1540 SetTextPos( aPosition );
1541}
1542
1543
1545{
1546 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1547 {
1548 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1549 VECTOR2I relativePos = GetTextPos() - parentSymbol->GetPosition();
1550
1551 relativePos = parentSymbol->GetTransform().TransformCoordinate( relativePos );
1552
1553 return relativePos + parentSymbol->GetPosition();
1554 }
1555
1556 return GetTextPos();
1557}
1558
1559
1561{
1562 return m_parent ? m_parent->GetPosition() : VECTOR2I( 0, 0 );
1563}
1564
1565
1572
1573
1574bool SCH_FIELD::operator<( const SCH_ITEM& aItem ) const
1575{
1576 if( Type() != aItem.Type() )
1577 return Type() < aItem.Type();
1578
1579 auto field = static_cast<const SCH_FIELD*>( &aItem );
1580
1581 if( GetId() != field->GetId() )
1582 return GetId() < field->GetId();
1583
1584 if( GetText() != field->GetText() )
1585 return GetText() < field->GetText();
1586
1587 if( GetLibPosition().x != field->GetLibPosition().x )
1588 return GetLibPosition().x < field->GetLibPosition().x;
1589
1590 if( GetLibPosition().y != field->GetLibPosition().y )
1591 return GetLibPosition().y < field->GetLibPosition().y;
1592
1593 return GetName() < field->GetName();
1594}
1595
1596
1597bool SCH_FIELD::operator==( const SCH_ITEM& aOther ) const
1598{
1599 if( Type() != aOther.Type() )
1600 return false;
1601
1602 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
1603
1604 return *this == field;
1605}
1606
1607
1608bool SCH_FIELD::operator==( const SCH_FIELD& aOther ) const
1609{
1610 // Identical fields owned by different items are not equal.
1611 if( m_parent || aOther.m_parent )
1612 {
1613 if( !m_parent || !aOther.m_parent )
1614 return false;
1615
1616 if( m_parent->Type() != aOther.m_parent->Type() )
1617 return false;
1618
1619 if( m_parent->m_Uuid != aOther.m_parent->m_Uuid )
1620 return false;
1621 }
1622
1623 if( IsMandatory() != aOther.IsMandatory() )
1624 return false;
1625
1626 if( IsMandatory() )
1627 {
1628 if( GetId() != aOther.GetId() )
1629 return false;
1630 }
1631 else
1632 {
1633 if( GetOrdinal() != aOther.GetOrdinal() )
1634 return false;
1635 }
1636
1637 if( GetPosition() != aOther.GetPosition() )
1638 return false;
1639
1640 if( IsGeneratedField() != aOther.IsGeneratedField() )
1641 return false;
1642
1643 if( IsNameShown() != aOther.IsNameShown() )
1644 return false;
1645
1646 if( CanAutoplace() != aOther.CanAutoplace() )
1647 return false;
1648
1649 return EDA_TEXT::operator==( aOther );
1650}
1651
1652
1653bool SCH_FIELD::HasSameContent( const SCH_FIELD& aOther ) const
1654{
1655 if( GetUntranslatedName() != aOther.GetUntranslatedName() )
1656 return false;
1657
1658 if( GetPosition() != aOther.GetPosition() )
1659 return false;
1660
1661 if( IsVisible() != aOther.IsVisible() )
1662 return false;
1663
1664 if( IsPrivate() != aOther.IsPrivate() )
1665 return false;
1666
1667 if( IsGeneratedField() != aOther.IsGeneratedField() )
1668 return false;
1669
1670 if( IsNameShown() != aOther.IsNameShown() )
1671 return false;
1672
1673 if( CanAutoplace() != aOther.CanAutoplace() )
1674 return false;
1675
1676 return EDA_TEXT::operator==( aOther );
1677}
1678
1679
1680double SCH_FIELD::Similarity( const SCH_ITEM& aOther ) const
1681{
1682 if( Type() != aOther.Type() )
1683 return 0.0;
1684
1685 if( m_Uuid == aOther.m_Uuid )
1686 return 1.0;
1687
1688 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
1689
1690 double similarity = 0.99; // The UUIDs are different, so we start with non-identity
1691
1692 if( GetId() != field.GetId() )
1693 {
1694 // We don't allow swapping of mandatory fields, so these cannot be the same item
1695 if( IsMandatory() || field.IsMandatory() )
1696 return 0.0;
1697 else
1698 similarity *= 0.5;
1699 }
1700
1701 similarity *= SimilarityBase( aOther );
1702
1703 similarity *= EDA_TEXT::Similarity( field );
1704
1705 if( GetPosition() != field.GetPosition() )
1706 similarity *= 0.5;
1707
1708 if( IsGeneratedField() != field.IsGeneratedField() )
1709 similarity *= 0.5;
1710
1711 if( IsNameShown() != field.IsNameShown() )
1712 similarity *= 0.5;
1713
1714 if( CanAutoplace() != field.CanAutoplace() )
1715 similarity *= 0.5;
1716
1717 return similarity;
1718}
1719
1720
1721int SCH_FIELD::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1722{
1723 wxASSERT( aOther.Type() == SCH_FIELD_T );
1724
1725 int retv = SCH_ITEM::compare( aOther, aCompareFlags );
1726
1727 if( retv )
1728 return retv;
1729
1730 const SCH_FIELD* tmp = static_cast<const SCH_FIELD*>( &aOther );
1731
1732 // If we're not testing the UUID then we're looking for an equivalence test
1733 if( !( aCompareFlags & COMPARE_FLAGS::UUID ) )
1734 {
1735 // Mandatory fields have fixed ordinals and their names can vary due to translated field
1736 // names. Optional fields have fixed names and their ordinals can vary.
1737 if( IsMandatory() )
1738 {
1739 if( m_id != tmp->m_id )
1740 return (int) m_id - (int) tmp->m_id;
1741 }
1742 else
1743 {
1744 retv = m_name.Cmp( tmp->m_name );
1745
1746 if( retv )
1747 return retv;
1748 }
1749 }
1750 else // assume we're sorting for stable file order
1751 {
1752 if( m_id != tmp->m_id )
1753 return (int) m_id - (int) tmp->m_id;
1754 }
1755
1756 if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::FIELD_TEXT )
1757 {
1758 retv = GetText().CmpNoCase( tmp->GetText() );
1759
1760 if( retv != 0 )
1761 return retv;
1762 }
1763
1764 if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::FIELD_POSITIONS )
1765 {
1766 if( GetTextPos().x != tmp->GetTextPos().x )
1767 return GetTextPos().x - tmp->GetTextPos().x;
1768
1769 if( GetTextPos().y != tmp->GetTextPos().y )
1770 return GetTextPos().y - tmp->GetTextPos().y;
1771 }
1772
1773 if( aCompareFlags & COMPARE_FLAGS::FIELD_SIZE_AND_STYLE )
1774 {
1775 retv = GetAttributes().Compare( tmp->GetAttributes() );
1776
1777 if( retv )
1778 return retv;
1779 }
1780
1781 return 0;
1782}
1783
1784
1785wxString SCH_FIELD::getUnescapedText( const SCH_SHEET_PATH* aPath, const wxString& aVariantName ) const
1786{
1787 // This is the default variant field text for all fields except the reference field.
1788 wxString retv = EDA_TEXT::GetShownText( INTERNAL );
1789
1790 // Special handling for parent object field instance and variant information.
1791 // Only use the path if it's non-empty; an empty path can't match any instances
1792 if( m_parent && aPath && !aPath->empty() )
1793 {
1794 const bool trace = wxLog::IsAllowedTraceMask( traceSchFieldRendering );
1795
1796 if( trace )
1797 wxLogTrace( traceSchFieldRendering, " Path is valid and non-empty, parent type=%d", m_parent->Type() );
1798
1799 switch( m_parent->Type() )
1800 {
1801 case SCH_SYMBOL_T:
1802 if( const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( m_parent ) )
1803 {
1804 if( m_id == FIELD_T::REFERENCE )
1805 {
1806 if( trace )
1807 {
1808 wxLogTrace( traceSchFieldRendering, " Calling GetRef for symbol %s on path %s",
1809 symbol->m_Uuid.AsString(), aPath->Path().AsString() );
1810 }
1811
1812 retv = symbol->GetRef( aPath, true );
1813
1814 if( trace )
1815 wxLogTrace( traceSchFieldRendering, " GetRef returned: '%s'", retv );
1816 }
1817 else if( !aVariantName.IsEmpty() )
1818 {
1819 // If the variant is not found, fall back to default variant above.
1820 if( std::optional<SCH_SYMBOL_VARIANT> variant = symbol->GetVariant( *aPath, aVariantName ) )
1821 {
1822 // An explicit override wins; otherwise resolve through the alternate
1823 // library symbol so the canvas matches the fields table and netlist.
1824 if( variant->m_Fields.contains( GetName() ) )
1825 {
1826 retv = variant->m_Fields[GetName()];
1827 }
1828 else if( LIB_SYMBOL* altSymbol = symbol->GetVariantLibSymbol( aVariantName, *aPath ) )
1829 {
1830 const SCH_FIELD* altField = altSymbol->GetField( GetName() );
1831
1832 if( altField && !altField->GetText().IsEmpty() )
1833 retv = altField->GetText();
1834 }
1835 }
1836 }
1837 }
1838
1839 break;
1840
1841 case SCH_SHEET_T:
1842 if( const SCH_SHEET* sheet = static_cast<const SCH_SHEET*>( m_parent ) )
1843 {
1844 if( !aVariantName.IsEmpty() && m_id != FIELD_T::SHEET_REF_SUFFIX )
1845 {
1846 const SCH_SHEET_INSTANCE* instance = sheet->GetInstance( aPath->Path() );
1847
1848 if( instance
1849 && instance->m_Variants.contains( aVariantName )
1850 && instance->m_Variants.at( aVariantName ).m_Fields.contains( GetName() ) )
1851 {
1852 return instance->m_Variants.at( aVariantName ).m_Fields.at( GetName() );
1853 }
1854 }
1855 }
1856
1857 break;
1858
1859 default:
1860 break;
1861 }
1862 }
1863
1864 return retv;
1865}
1866
1867
1868static struct SCH_FIELD_DESC
1869{
1871 {
1872 // These are defined in EDA_TEXT as well but initialization order is
1873 // not defined, so this needs to be conditional. Defining in both
1874 // places leads to duplicate symbols.
1876
1877 if( h_inst.Choices().GetCount() == 0 )
1878 {
1879 h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _HKI( "Left" ) );
1880 h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _HKI( "Center" ) );
1881 h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _HKI( "Right" ) );
1882 }
1883
1885
1886 if( v_inst.Choices().GetCount() == 0 )
1887 {
1888 v_inst.Map( GR_TEXT_V_ALIGN_TOP, _HKI( "Top" ) );
1889 v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _HKI( "Center" ) );
1890 v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _HKI( "Bottom" ) );
1891 }
1892
1899
1900 // Lock state is inherited from parent symbol (no independent locking of child items)
1901 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( SCH_ITEM ), _HKI( "Locked" ) );
1902
1903 // Library fields are written at symbol scope rather than inside a unit body, so a
1904 // per-unit or per-body-style assignment is silently dropped by the next save
1905 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( SCH_ITEM ), _HKI( "Unit" ) );
1906 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( SCH_ITEM ), _HKI( "Body Style" ) );
1907
1908 const wxString textProps = _HKI( "Text Properties" );
1909
1910 propMgr.ReplaceProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Horizontal Justification" ),
1911 new PROPERTY_ENUM<SCH_FIELD, GR_TEXT_H_ALIGN_T>( _HKI( "Horizontal Justification" ),
1913 textProps );
1914
1915 propMgr.ReplaceProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Vertical Justification" ),
1916 new PROPERTY_ENUM<SCH_FIELD, GR_TEXT_V_ALIGN_T>( _HKI( "Vertical Justification" ),
1918 textProps );
1919
1920 propMgr.AddProperty( new PROPERTY<SCH_FIELD, bool>( _HKI( "Show Field Name" ),
1922
1923 propMgr.AddProperty( new PROPERTY<SCH_FIELD, bool>( _HKI( "Allow Autoplacement" ),
1925
1926 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
1927 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
1928 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Mirrored" ) );
1929 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
1930 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
1931
1932
1933 propMgr.AddProperty( new PROPERTY<SCH_FIELD, int>( _HKI( "Text Size" ),
1935 _HKI( "Text Properties" ) );
1936
1937 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
1938
1940 []( INSPECTABLE* aItem ) -> bool
1941 {
1942 if( SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( aItem ) )
1943 return !field->IsGeneratedField();
1944
1945 return true;
1946 } );
1947
1948
1949 propMgr.OverrideAvailability( TYPE_HASH( SCH_FIELD ), TYPE_HASH( SCH_ITEM ), _HKI( "Private" ),
1950 []( INSPECTABLE* aItem ) -> bool
1951 {
1952 if( SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( aItem ) )
1953 return !field->IsMandatory();
1954
1955 return false;
1956 } );
1957 }
1959
1960
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
BITMAPS
A list of all bitmap identifiers.
@ edit_comp_value
@ edit_comp_footprint
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr const Vec GetEnd() const
Definition box2.h:215
constexpr void SetOrigin(const Vec &pos)
Definition box2.h:240
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:149
constexpr Vec Centre() const
Definition box2.h:100
constexpr void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
Definition box2.h:141
constexpr const Vec & GetOrigin() const
Definition box2.h:213
constexpr void SetEnd(coord_type x, coord_type y)
Definition box2.h:300
constexpr void Offset(coord_type dx, coord_type dy)
Definition box2.h:262
static const COLOR4D WHITE
Definition color4d.h:403
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
bool IsHorizontal() const
Definition eda_angle.h:141
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:608
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:484
EDA_ITEM * GetParent() const
Definition eda_item.h:112
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:609
bool IsForceVisible() const
Definition eda_item.h:233
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:406
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition eda_text.cpp:170
virtual VECTOR2I GetTextSize() const
Definition eda_text.h:301
COLOR4D GetTextColor() const
Definition eda_text.h:310
wxString GetTextStyleName() const
virtual VECTOR2I GetTextPos() const
Definition eda_text.h:313
bool IsItalic() const
Definition eda_text.h:200
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition eda_text.cpp:513
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
virtual bool IsVisible() const
Definition eda_text.h:226
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:557
virtual void SetTextX(int aX)
Definition eda_text.cpp:564
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition eda_text.cpp:201
KIFONT::FONT * GetFont() const
Definition eda_text.h:286
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition eda_text.cpp:395
virtual void SetTextY(int aY)
Definition eda_text.cpp:570
EDA_TEXT & operator=(const EDA_TEXT &aItem)
Definition eda_text.cpp:140
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:755
virtual wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition eda_text.h:128
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:379
virtual int GetTextWidth() const
Definition eda_text.h:304
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:239
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition eda_text.cpp:451
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition eda_text.h:139
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition eda_text.cpp:98
virtual void ClearBoundingBoxCache()
Definition eda_text.cpp:676
double Similarity(const EDA_TEXT &aOther) const
static GR_TEXT_H_ALIGN_T MapHorizJustify(int aHorizJustify)
Definition eda_text.cpp:70
virtual void ClearRenderCache()
Definition eda_text.cpp:670
virtual EDA_ANGLE GetTextAngle() const
Definition eda_text.h:178
const TEXT_ATTRIBUTES & GetAttributes() const
Definition eda_text.h:270
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition eda_text.cpp:428
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition eda_text.cpp:415
bool IsBold() const
Definition eda_text.h:215
static GR_TEXT_V_ALIGN_T MapVertJustify(int aVertJustify)
Definition eda_text.cpp:84
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:242
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:269
void SwapText(EDA_TEXT &aTradingPartner)
Definition eda_text.cpp:407
bool operator==(const EDA_TEXT &aRhs) const
Definition eda_text.h:444
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:371
static ENUM_MAP< T > & Instance()
Definition property.h:811
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:39
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:94
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition font.cpp:144
virtual bool IsOutline() const
Definition font.h:102
Implement 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:115
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
std::shared_ptr< wxString > m_text
Definition color4d.h:397
COLOR4D & Desaturate()
Removes color (in HSL model)
Definition color4d.cpp:530
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition color4d.h:293
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:423
COLOR4D GetSchematicColor(bool aIsForSave=false) const
Definition netclass.h:244
A singleton reporter that reports to nowhere.
Definition reporter.h:267
Base plotter engine class.
Definition plotter.h:138
bool GetColorMode() const
Definition plotter.h:166
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:618
virtual void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs)
Create a clickable hyperlink menu with a rectangular click area.
Definition plotter.h:538
virtual std::map< wxString, wxString > & GetTextVars() const
Definition project.cpp:223
Provide class metadata.
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:155
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:177
wxString GetCurrentVariant() const
Return the current variant being edited.
EMBEDDED_FILES * GetEmbeddedFiles() override
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:399
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:375
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.
bool HasSameContent(const SCH_FIELD &aOther) const
Test if this field has the same name, content and presentation as another field, ignoring the owning ...
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.
bool IsLocked() const override
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:186
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:365
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:225
bool m_autoAdded
Was this field automatically added to a LIB_SYMBOL?
Definition sch_field.h:370
double Similarity(const SCH_ITEM &aItem) const override
Return a measure of how likely the other object is to represent the same object.
std::unique_ptr< SCH_FIELD_RENDER_CACHE_DATA > m_renderCache
Definition sch_field.h:373
bool IsGeneratedField() const
Generated fields are fields whose names are variables like ${VAR}.
Definition sch_field.h:234
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 HasHypertext() const override
Indicates that the item has at least one hypertext action.
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.
void SetOrdinal(int aOrdinal, FIELD_T aType)
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
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:143
void SetCanAutoplace(bool aCanPlace)
Definition sch_field.h:237
int GetPenWidth() const override
bool m_isGeneratedField
If the field name is a variable name (e.g.
Definition sch_field.h:367
int m_ordinal
Sort order for non-mandatory fields.
Definition sch_field.h:362
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.
wxString GetUntranslatedName() const
Get the untranslated field name for storage, variable look-up, etc.
bool operator<(const SCH_ITEM &aItem) const override
FIELD_T m_id
Field id,.
Definition sch_field.h:361
void DoHypertextAction(EDA_DRAW_FRAME *aFrame, const VECTOR2I &aMousePos) const override
wxString GetShownName() const
Get the field's name as displayed on the schematic or in the symbol fields table.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
VECTOR2I GetLibPosition() const
Definition sch_field.h:283
void setId(FIELD_T aId)
int GetOrdinal() const
Definition sch_field.h:145
bool IsEmpty()
Return true if both the name and value of the field are empty.
Definition sch_field.h:178
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:187
wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString, int aDepth=0) const
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)
bool CanAutoplace() const
Definition sch_field.h:236
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:371
void OnScintillaCharAdded(SCINTILLA_TRICKS *aScintillaTricks, wxStyledTextEvent &aEvent) const
wxString m_name
Definition sch_field.h:363
void SetNameShown(bool aShown=true)
Definition sch_field.h:226
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
static bool IsNetclassLabelFieldName(const wxString &aName)
Test whether aName is one of the known translations of the directive-label net class field name (used...
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:366
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:170
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition sch_item.cpp:91
const wxString & GetDefaultFont(const KIGFX::RENDER_SETTINGS *aSettings) const
void invalidateConnectivity(KICAD_T aChangedType=TYPE_NOT_INIT)
Bump the parent screen's connectivity revision when this item, or the item owning it as a child,...
Definition sch_item.cpp:323
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition sch_item.cpp:46
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:350
void SetPrivate(bool aPrivate)
Definition sch_item.h:258
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:302
virtual wxString GetUnitDisplayName(int aUnit, bool aLabel) const
Definition sch_item.cpp:225
bool IsLocked() const override
Definition sch_item.cpp:179
friend class LIB_SYMBOL
Definition sch_item.h:822
@ FIELD_SIZE_AND_STYLE
Definition sch_item.h:757
@ FIELD_TEXT
Definition sch_item.h:755
@ FIELD_POSITIONS
Definition sch_item.h:758
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition sch_item.cpp:733
bool IsPrivate() const
Definition sch_item.h:259
void SetLayer(SCH_LAYER_ID aLayer)
Definition sch_item.h:354
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition sch_item.h:353
bool IsConnectivityDirty() const
Definition sch_item.h:635
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:65
bool m_private
Definition sch_item.h:846
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:464
virtual int compare(const SCH_ITEM &aOther, int aCompareFlags=~COMPARE_FLAGS::UNIT) const
Provide the draw object specific comparison called by the == and < operators.
Definition sch_item.cpp:935
const KIFONT::METRICS & GetFontMetrics() const
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:403
void GetIntersheetRefs(const SCH_SHEET_PATH *aPath, std::vector< std::pair< wxString, wxString > > *pages)
Build an array of { pageNumber, pageName } pairs.
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 ...
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, 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:50
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
wxString GetFieldText(const SCH_FIELD *aField, const wxString &aFieldName, const SCH_SHEET_PATH *aPath, const wxString &aVariantName) const
void SetFieldText(SCH_FIELD *aField, const wxString &aFieldName, const wxString &aFieldText, const SCH_SHEET_PATH *aPath, const wxString &aVariantName)
Schematic symbol object.
Definition sch_symbol.h:76
void SetFieldText(SCH_FIELD *aField, const wxString &aFieldName, const wxString &aFieldText, const SCH_SHEET_PATH *aPath, const wxString &aVariantName)
wxString GetBaseRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
VECTOR2I GetPosition() const override
Definition sch_symbol.h:958
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this symbol.
void SetUserRef(const SCH_SHEET_PATH &aSheet, const wxString &aBase)
Set a base reference chosen by the user on aSheet.
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
wxString GetFieldText(const SCH_FIELD *aField, const wxString &aFieldName, const SCH_SHEET_PATH *aPath, const wxString &aVariantName) const
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:31
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, std::span< const wxString > aPins, REPORTER &aReporter)
void SetFilesStack(std::vector< EMBEDDED_FILES * > aFilesStack)
Definition sim_lib_mgr.h:45
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:60
const TRANSFORM & GetTransform() const
Definition symbol.h:247
EDA_ORIENTATION m_Angle
int Compare(const TEXT_ATTRIBUTES &aRhs) const
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
for transforming drawing coordinates for a wxDC device context.
Definition transform.h:42
TRANSFORM InverseTransform() const
Calculate the Inverse mirror/rotation transform.
Definition transform.cpp:55
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition transform.cpp:40
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
void FinalizeTextVarExpansion(wxString &aText, RESOLUTION_CONTEXT aContext)
Definition common.cpp:88
wxString GetGeneratedFieldDisplayName(const wxString &aSource)
Returns any variables unexpanded, e.g.
Definition common.cpp:481
RESOLUTION_CONTEXT
Definition common.h:91
@ FOR_GUI
Definition common.h:93
@ FOR_CANVAS
Definition common.h:92
@ RAW_VALUE
Definition common.h:98
@ INTERNAL
Definition common.h:96
#define UNSPECIFIED
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:469
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:468
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:477
#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:480
@ LAYER_SHEETNAME
Definition layer_ids.h:503
@ LAYER_VALUEPART
Definition layer_ids.h:492
@ LAYER_FIELDS
Definition layer_ids.h:493
@ LAYER_SHEETFIELDS
Definition layer_ids.h:505
@ LAYER_REFERENCEPART
Definition layer_ids.h:491
@ LAYER_NETCLASS_REFS
Definition layer_ids.h:495
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:526
@ LAYER_INTERSHEET_REFS
Definition layer_ids.h:494
@ LAYER_SHEETFILENAME
Definition layer_ids.h:504
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
#define _HKI(x)
Definition page_info.cpp:40
static GR_TEXT_H_ALIGN_T horizJustify(const char *horizontal)
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
#define DECLARE_ENUM_TO_WXANY(type)
Definition property.h:879
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
static const std::vector< wxString > & GetKnownNetclassFieldTranslations()
Translations of "Net Class" extracted from KiCad's .po catalogs.
Definition sch_field.cpp:61
static const std::vector< KICAD_T > labelTypes
Definition sch_field.cpp:49
static struct SCH_FIELD_DESC _SCH_FIELD_DESC
static FIELD_T sheetFieldId(FIELD_T aId, const wxString &aName)
A sheet field takes its type from its name, so every path that creates or renames one agrees.
@ SYMBOL_FILTER_NON_POWER
wxString UnescapeString(const wxString &aSource)
bool IsURL(wxString aStr)
Performs a URL sniff-test on a string.
A simple container for sheet instance information.
std::map< wxString, SCH_SHEET_VARIANT > m_Variants
A list of sheet variants.
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
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".
@ SHEET_REF_SUFFIX
Optional sheet field appended to the references of the sheet's symbols.
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
@ UNTRANSLATED
@ TRANSLATED
KIBIS_MODEL * model
KIBIS_PIN * pin
VECTOR2I end
wxString result
Test unit parsing edge cases and error handling.
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:227
@ LIB_SYMBOL_T
Definition typeinfo.h:144
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_FIELD_T
Definition typeinfo.h:146
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:167
@ SCH_LABEL_T
Definition typeinfo.h:163
@ SCH_SHEET_T
Definition typeinfo.h:171
@ SCH_LABEL_LOCATE_ANY_T
Definition typeinfo.h:187
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:164
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:55
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition ui_common.h:48
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)