KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_field.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2004-2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25/*
26 * Fields are texts attached to a symbol, some of which have a special meaning.
27 * Fields 0 and 1 are very important: reference and value.
28 * Field 2 is used as default footprint name.
29 * Field 3 is used to point to a datasheet (usually a URL).
30 * Fields 4+ are user fields. They can be renamed and can appear in reports.
31 */
32
33#include <wx/log.h>
34#include <wx/menu.h>
35
36#include <advanced_config.h>
37#include <base_units.h>
38#include <common.h> // for ExpandTextVars
39#include <sch_edit_frame.h>
40#include <plotters/plotter.h>
41#include <bitmaps.h>
42#include <core/mirror.h>
43#include <kiway.h>
44#include <symbol_library.h>
45#include <sch_symbol.h>
46#include <sch_field.h>
47#include <sch_label.h>
48#include <schematic.h>
50#include <string_utils.h>
51#include <trace_helpers.h>
52#include <tool/tool_manager.h>
54#include <font/outline_font.h>
55#include "sim/sim_lib_mgr.h"
56
57static const std::vector<KICAD_T> labelTypes = { SCH_LABEL_LOCATE_ANY_T };
58
59
60SCH_FIELD::SCH_FIELD( const VECTOR2I& aPos, int aFieldId, SCH_ITEM* aParent,
61 const wxString& aName ) :
62 SCH_ITEM( aParent, SCH_FIELD_T ),
63 EDA_TEXT( schIUScale, wxEmptyString ),
64 m_id( 0 ),
65 m_showName( false ),
66 m_allowAutoPlace( true ),
67 m_autoAdded( false ),
68 m_showInChooser( true ),
69 m_renderCacheValid( false ),
70 m_lastResolvedColor( COLOR4D::UNSPECIFIED )
71{
72 if( aName.IsEmpty() )
74 else
75 SetName( aName );
76
77 SetTextPos( aPos );
78 SetId( aFieldId ); // will also set the layer
79 SetVisible( true );
80}
81
82
83SCH_FIELD::SCH_FIELD( SCH_ITEM* aParent, int aFieldId, const wxString& aName) :
84 SCH_FIELD( VECTOR2I(), aFieldId, aParent, aName )
85{
86}
87
88
90 SCH_ITEM( aField ),
91 EDA_TEXT( aField )
92{
93 m_id = aField.m_id;
94 m_name = aField.m_name;
95 m_showName = aField.m_showName;
98 m_autoAdded = aField.m_autoAdded;
100
101 m_renderCache.clear();
102
103 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aField.m_renderCache )
104 {
105 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
106 m_renderCache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
107 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
108 m_renderCache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
109 }
110
113
115}
116
117
119{
120 EDA_TEXT::operator=( aField );
121
122 m_id = aField.m_id;
123 m_name = aField.m_name;
124 m_showName = aField.m_showName;
127
128 m_renderCache.clear();
129
130 for( const std::unique_ptr<KIFONT::GLYPH>& glyph : aField.m_renderCache )
131 {
132 if( KIFONT::OUTLINE_GLYPH* outline = dynamic_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() ) )
133 m_renderCache.emplace_back( std::make_unique<KIFONT::OUTLINE_GLYPH>( *outline ) );
134 else if( KIFONT::STROKE_GLYPH* stroke = dynamic_cast<KIFONT::STROKE_GLYPH*>( glyph.get() ) )
135 m_renderCache.emplace_back( std::make_unique<KIFONT::STROKE_GLYPH>( *stroke ) );
136 }
137
140
142
143 return *this;
144}
145
146
148{
149 return new SCH_FIELD( *this );
150}
151
152
153void SCH_FIELD::Copy( SCH_FIELD* aTarget ) const
154{
155 *aTarget = *this;
156}
157
158
159void SCH_FIELD::SetId( int aId )
160{
161 m_id = aId;
162
163 if( m_parent && m_parent->Type() == SCH_SHEET_T )
164 {
165 switch( m_id )
166 {
167 case SHEETNAME: SetLayer( LAYER_SHEETNAME ); break;
169 default: SetLayer( LAYER_SHEETFIELDS ); break;
170 }
171 }
172 else if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
173 {
174 switch( m_id )
175 {
177 case VALUE_FIELD: SetLayer( LAYER_VALUEPART ); break;
178 default: SetLayer( LAYER_FIELDS ); break;
179 }
180 }
181 else if( m_parent && m_parent->IsType( labelTypes ) )
182 {
183 // We can't use defined IDs for labels because there can be multiple net class
184 // assignments.
185
186 if( GetCanonicalName() == wxT( "Netclass" ) )
188 else if( GetCanonicalName() == wxT( "Intersheetrefs" ) )
190 else
192 }
193}
194
195
197{
199}
200
201
202wxString SCH_FIELD::GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
203 int aDepth ) const
204{
205 std::function<bool( wxString* )> libSymbolResolver =
206 [&]( wxString* token ) -> bool
207 {
208 LIB_SYMBOL* symbol = static_cast<LIB_SYMBOL*>( m_parent );
209 return symbol->ResolveTextVar( token, aDepth + 1 );
210 };
211
212 std::function<bool( wxString* )> symbolResolver =
213 [&]( wxString* token ) -> bool
214 {
215 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( m_parent );
216 return symbol->ResolveTextVar( aPath, token, aDepth + 1 );
217 };
218
219 std::function<bool( wxString* )> schematicResolver =
220 [&]( wxString* token ) -> bool
221 {
222 if( !aPath )
223 return false;
224
225 if( SCHEMATIC* schematic = Schematic() )
226 return schematic->ResolveTextVar( aPath, token, aDepth + 1 );
227
228 return false;
229 };
230
231 std::function<bool( wxString* )> sheetResolver =
232 [&]( wxString* token ) -> bool
233 {
234 if( !aPath )
235 return false;
236
237 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
238
239 SCHEMATIC* schematic = Schematic();
240 SCH_SHEET_PATH path = *aPath;
241 path.push_back( sheet );
242
243 bool retval = sheet->ResolveTextVar( &path, token, aDepth + 1 );
244
245 if( schematic )
246 retval |= schematic->ResolveTextVar( &path, token, aDepth + 1 );
247
248 return retval;
249 };
250
251 std::function<bool( wxString* )> labelResolver =
252 [&]( wxString* token ) -> bool
253 {
254 if( !aPath )
255 return false;
256
257 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
258 return label->ResolveTextVar( aPath, token, aDepth + 1 );
259 };
260
261 wxString text = EDA_TEXT::GetShownText( aAllowExtraText, aDepth );
262
263 if( IsNameShown() && aAllowExtraText )
264 text = GetShownName() << wxS( ": " ) << text;
265
266 if( text == wxS( "~" ) ) // Legacy placeholder for empty string
267 text = wxS( "" );
268
269 // The iteration here it to allow for nested variables in the
270 // text strings (e.g. ${${VAR}}). Although the symbols and sheets
271 // and labels recurse, text that is none of those types such as text
272 // boxes and labels do not. This only loops if there is still a
273 // variable to resolve.
274 for( int ii = 0; ii < 10 && text.Contains( wxT( "${" ) ); ++ii )
275 {
276 if( aDepth < ADVANCED_CFG::GetCfg().m_ResolveTextRecursionDepth )
277 {
278 if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
279 text = ExpandTextVars( text, &libSymbolResolver );
280 else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
281 text = ExpandTextVars( text, &symbolResolver );
282 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
283 text = ExpandTextVars( text, &sheetResolver );
284 else if( m_parent && m_parent->IsType( labelTypes ) )
285 text = ExpandTextVars( text, &labelResolver );
286 else if( Schematic() )
287 {
289 text = ExpandTextVars( text, &schematicResolver );
290 }
291 }
292 }
293
294 // WARNING: the IDs of FIELDS and SHEETS overlap, so one must check *both* the
295 // id and the parent's type.
296
297 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
298 {
299 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
300
301 if( m_id == REFERENCE_FIELD && aPath )
302 {
303 // For more than one part per package, we must add the part selection
304 // A, B, ... or 1, 2, .. to the reference.
305 if( parentSymbol->GetUnitCount() > 1 )
306 text << parentSymbol->SubReference( parentSymbol->GetUnitSelection( aPath ) );
307 }
308 }
309 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
310 {
311 if( m_id == SHEETFILENAME && aAllowExtraText && !IsNameShown() )
312 text = _( "File:" ) + wxS( " " ) + text;
313 }
314
315 return text;
316}
317
318
319wxString SCH_FIELD::GetShownText( bool aAllowExtraText, int aDepth ) const
320{
321 if( SCHEMATIC* schematic = Schematic() )
322 return GetShownText( &schematic->CurrentSheet(), aAllowExtraText, aDepth );
323 else
324 return GetShownText( nullptr, aAllowExtraText, aDepth );
325}
326
327
328wxString SCH_FIELD::GetFullText( int unit ) const
329{
330 if( GetId() != REFERENCE_FIELD )
331 return GetText();
332
333 wxString text = GetText();
334 text << wxT( "?" );
335
336 if( GetParentSymbol() && GetParentSymbol()->IsMulti() )
337 text << LIB_SYMBOL::LetterSubReference( unit, 'A' );
338
339 return text;
340}
341
342
344{
346}
347
348
350{
352
353 if( !font )
355
356 return font;
357}
358
359
361{
364}
365
366
368{
370 m_renderCacheValid = false;
371}
372
373
374std::vector<std::unique_ptr<KIFONT::GLYPH>>*
375SCH_FIELD::GetRenderCache( const wxString& forResolvedText, const VECTOR2I& forPosition,
376 TEXT_ATTRIBUTES& aAttrs ) const
377{
378 KIFONT::FONT* font = GetFont();
379
380 if( !font )
382
383 if( font->IsOutline() )
384 {
385 KIFONT::OUTLINE_FONT* outlineFont = static_cast<KIFONT::OUTLINE_FONT*>( font );
386
387 if( m_renderCache.empty() || !m_renderCacheValid )
388 {
389 m_renderCache.clear();
390
391 outlineFont->GetLinesAsGlyphs( &m_renderCache, forResolvedText, forPosition, aAttrs,
392 GetFontMetrics() );
393
394 m_renderCachePos = forPosition;
395 m_renderCacheValid = true;
396 }
397
398 if( m_renderCachePos != forPosition )
399 {
400 VECTOR2I delta = forPosition - m_renderCachePos;
401
402 for( std::unique_ptr<KIFONT::GLYPH>& glyph : m_renderCache )
403 {
404 if( glyph->IsOutline() )
405 static_cast<KIFONT::OUTLINE_GLYPH*>( glyph.get() )->Move( delta );
406 else
407 static_cast<KIFONT::STROKE_GLYPH*>( glyph.get() )->Move( delta );
408 }
409
410 m_renderCachePos = forPosition;
411 }
412
413 return &m_renderCache;
414 }
415
416 return nullptr;
417}
418
419
420void SCH_FIELD::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
421 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
422{
423 wxString text;
424
425 if( Schematic() )
426 text = GetShownText( &Schematic()->CurrentSheet(), true );
427 else
428 text = GetShownText( true );
429
430 if( ( !IsVisible() && !IsForceVisible() ) || text.IsEmpty() )
431 return;
432
433 wxDC* DC = aSettings->GetPrintDC();
435 bool blackAndWhiteMode = GetGRForceBlackPenState();
436 int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
437
438 COLOR4D bg = aSettings->GetBackgroundColor();
439
440 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
441 bg = COLOR4D::WHITE;
442
443 if( IsForceVisible() )
444 bg = aSettings->GetLayerColor( LAYER_HIDDEN );
445
446 if( !blackAndWhiteMode && GetTextColor() != COLOR4D::UNSPECIFIED )
448
449 if( aDimmed )
450 {
451 color.Desaturate( );
452 color = color.Mix( bg, 0.5f );
453 }
454
455 // Calculate the text orientation according to the symbol orientation.
456 EDA_ANGLE orient = GetTextAngle();
457 VECTOR2I textpos = GetTextPos();
460 KIFONT::FONT* font = GetFont();
461
462 if( !font )
463 font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), IsBold(), IsItalic() );
464
465 if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
466 {
467 textpos = aSettings->TransformCoordinate( GetTextPos() ) + aOffset;
468 }
469 else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
470 {
471 /*
472 * Calculate the text justification, according to the symbol orientation/mirror.
473 * This is a bit complicated due to cumulative calculations:
474 * - numerous cases (mirrored or not, rotation)
475 * - the GRText function will also recalculate H and V justifications according to the
476 * text orientation.
477 * - when symbol is mirrored, the text is not mirrored and justifications are complicated
478 * to calculate so the easier way is to use no justifications (centered text) and use
479 * GetBoundingBox to know the text coordinate considered as centered
480 */
481 hjustify = GR_TEXT_H_ALIGN_CENTER;
482 vjustify = GR_TEXT_V_ALIGN_CENTER;
483 textpos = GetBoundingBox().Centre() + aOffset;
484
485 if( aSettings->m_Transform.y1 ) // Rotate symbol 90 degrees.
486 {
487 if( orient == ANGLE_HORIZONTAL )
488 orient = ANGLE_VERTICAL;
489 else
490 orient = ANGLE_HORIZONTAL;
491 }
492 }
493 else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
494 {
495 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
496 textpos += label->GetSchematicTextOffset( aSettings );
497 }
498
499 GRPrintText( DC, textpos, color, text, orient, GetTextSize(), hjustify, vjustify, penWidth,
500 IsItalic(), IsBold(), font, GetFontMetrics() );
501}
502
503
504void SCH_FIELD::ImportValues( const SCH_FIELD& aSource )
505{
506 SetAttributes( aSource );
507 SetNameShown( aSource.IsNameShown() );
508 SetCanAutoplace( aSource.CanAutoplace() );
509}
510
511
513{
514 wxCHECK_RET( aItem && aItem->Type() == SCH_FIELD_T, wxT( "Cannot swap with invalid item." ) );
515
516 SCH_ITEM::SwapFlags( aItem );
517
518 SCH_FIELD* item = static_cast<SCH_FIELD*>( aItem );
519
520 std::swap( m_layer, item->m_layer );
521 std::swap( m_showName, item->m_showName );
522 std::swap( m_allowAutoPlace, item->m_allowAutoPlace );
523 std::swap( m_isNamedVariable, item->m_isNamedVariable );
524 SwapText( *item );
525 SwapAttributes( *item );
526
527 std::swap( m_lastResolvedColor, item->m_lastResolvedColor );
528}
529
530
532{
533 if( GetTextColor() != COLOR4D::UNSPECIFIED )
534 {
536 }
537 else
538 {
539 SCH_LABEL_BASE* parentLabel = dynamic_cast<SCH_LABEL_BASE*>( GetParent() );
540
541 if( parentLabel && !parentLabel->IsConnectivityDirty() )
542 m_lastResolvedColor = parentLabel->GetEffectiveNetClass()->GetSchematicColor();
543 else
545 }
546
547 return m_lastResolvedColor;
548}
549
550
551void SCH_FIELD::ViewGetLayers( int aLayers[], int& aCount ) const
552{
553 aCount = 2;
554 aLayers[0] = GetDefaultLayer();
555 aLayers[1] = LAYER_SELECTION_SHADOWS;
556}
557
558
560{
561 if( m_parent && ( m_parent->Type() == LIB_SYMBOL_T || m_parent->Type() == SCH_SYMBOL_T ) )
562 {
563 if( m_id == REFERENCE_FIELD )
564 return LAYER_REFERENCEPART;
565 else if( m_id == VALUE_FIELD )
566 return LAYER_VALUEPART;
567 }
568 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
569 {
570 if( m_id == SHEETNAME )
571 return LAYER_SHEETNAME;
572 else if( m_id == SHEETFILENAME )
573 return LAYER_SHEETFILENAME;
574 else
575 return LAYER_SHEETFIELDS;
576 }
577 else if( m_parent && m_parent->Type() == SCH_LABEL_T )
578 {
579 if( GetCanonicalName() == wxT( "Netclass" ) )
580 return LAYER_NETCLASS_REFS;
581 }
582
583 return LAYER_FIELDS;
584}
585
586
588{
589 // Calculate the text orientation according to the symbol orientation.
590 EDA_ANGLE orient = GetTextAngle();
591
592 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
593 {
594 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
595
596 if( parentSymbol && parentSymbol->GetTransform().y1 ) // Rotate symbol 90 degrees.
597 {
598 if( orient.IsHorizontal() )
599 orient = ANGLE_VERTICAL;
600 else
601 orient = ANGLE_HORIZONTAL;
602 }
603 }
604
605 return orient;
606}
607
608
610{
611 BOX2I bbox = GetTextBox();
612
613 // Calculate the bounding box position relative to the parent:
614 VECTOR2I origin = GetParentPosition();
615 VECTOR2I pos = GetTextPos() - origin;
616 VECTOR2I begin = bbox.GetOrigin() - origin;
617 VECTOR2I end = bbox.GetEnd() - origin;
618 RotatePoint( begin, pos, GetTextAngle() );
619 RotatePoint( end, pos, GetTextAngle() );
620
621 // Now, apply the symbol transform (mirror/rot)
622 TRANSFORM transform;
623
624 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
625 transform = static_cast<SCH_SYMBOL*>( m_parent )->GetTransform();
626
627 bbox.SetOrigin( transform.TransformCoordinate( begin ) );
628 bbox.SetEnd( transform.TransformCoordinate( end ) );
629
630 bbox.Move( origin );
631 bbox.Normalize();
632
633 return bbox;
634}
635
636
638{
639 VECTOR2I render_center = GetBoundingBox().Centre();
640 VECTOR2I pos = GetPosition();
641
642 switch( GetHorizJustify() )
643 {
645 if( GetDrawRotation().IsVertical() )
646 return render_center.y > pos.y;
647 else
648 return render_center.x < pos.x;
650 if( GetDrawRotation().IsVertical() )
651 return render_center.y < pos.y;
652 else
653 return render_center.x > pos.x;
654 default:
655 return false;
656 }
657}
658
659
661{
662 GR_TEXT_H_ALIGN_T actualJustify;
663
664 switch( aJustify )
665 {
668 break;
671 break;
672 default:
673 actualJustify = aJustify;
674 }
675
676 SetHorizJustify( actualJustify );
677}
678
679
681{
682 switch( GetHorizJustify() )
683 {
688 default:
690 }
691}
692
693
695{
696 VECTOR2I render_center = GetBoundingBox().Centre();
697 VECTOR2I pos = GetPosition();
698
699 switch( GetVertJustify() )
700 {
702 if( GetDrawRotation().IsVertical() )
703 return render_center.x < pos.x;
704 else
705 return render_center.y < pos.y;
707 if( GetDrawRotation().IsVertical() )
708 return render_center.x > pos.x;
709 else
710 return render_center.y > pos.y;
711 default:
712 return false;
713 }
714}
715
716
718{
719 GR_TEXT_V_ALIGN_T actualJustify;
720
721 switch( aJustify )
722 {
725 break;
728 break;
729 default:
730 actualJustify = aJustify;
731 }
732
733 SetVertJustify( actualJustify );
734}
735
736
738{
739 switch( GetVertJustify() )
740 {
745 default:
747 }
748}
749
750
751bool SCH_FIELD::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
752{
753 bool searchHiddenFields = false;
754 bool searchAndReplace = false;
755 bool replaceReferences = false;
756
757 try
758 {
759 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData ); // downcast
760 searchHiddenFields = schSearchData.searchAllFields;
761 searchAndReplace = schSearchData.searchAndReplace;
762 replaceReferences = schSearchData.replaceReferences;
763 }
764 catch( const std::bad_cast& )
765 {
766 }
767
768 wxString text = UnescapeString( GetText() );
769
770 if( !IsVisible() && !searchHiddenFields )
771 return false;
772
774 {
775 if( searchAndReplace && !replaceReferences )
776 return false;
777
778 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
779 wxASSERT( aAuxData );
780
781 // Take sheet path into account which effects the reference field and the unit for
782 // symbols with multiple parts.
783 if( aAuxData )
784 {
785 SCH_SHEET_PATH* sheet = (SCH_SHEET_PATH*) aAuxData;
786 text = parentSymbol->GetRef( sheet );
787
788 if( SCH_ITEM::Matches( text, aSearchData ) )
789 return true;
790
791 if( parentSymbol->GetUnitCount() > 1 )
792 text << parentSymbol->SubReference( parentSymbol->GetUnitSelection( sheet ) );
793 }
794 }
795
796 return SCH_ITEM::Matches( text, aSearchData );
797}
798
799
801 wxStyledTextEvent &aEvent ) const
802{
803 SCH_ITEM* parent = dynamic_cast<SCH_ITEM*>( GetParent() );
804 SCHEMATIC* schematic = parent ? parent->Schematic() : nullptr;
805
806 if( !schematic )
807 return;
808
809 wxStyledTextCtrl* scintilla = aScintillaTricks->Scintilla();
810 int key = aEvent.GetKey();
811
812 wxArrayString autocompleteTokens;
813 int pos = scintilla->GetCurrentPos();
814 int start = scintilla->WordStartPosition( pos, true );
815 wxString partial;
816
817 // Multi-line fields are not allowed. So remove '\n' if entered.
818 if( key == '\n' )
819 {
820 wxString text = scintilla->GetText();
821 int currpos = scintilla->GetCurrentPos();
822 text.Replace( wxS( "\n" ), wxS( "" ) );
823 scintilla->SetText( text );
824 scintilla->GotoPos( currpos-1 );
825 return;
826 }
827
828 auto textVarRef =
829 [&]( int pt )
830 {
831 return pt >= 2
832 && scintilla->GetCharAt( pt - 2 ) == '$'
833 && scintilla->GetCharAt( pt - 1 ) == '{';
834 };
835
836 // Check for cross-reference
837 if( start > 1 && scintilla->GetCharAt( start - 1 ) == ':' )
838 {
839 int refStart = scintilla->WordStartPosition( start - 1, true );
840
841 if( textVarRef( refStart ) )
842 {
843 partial = scintilla->GetRange( start, pos );
844
845 wxString ref = scintilla->GetRange( refStart, start - 1 );
846
847 if( ref == wxS( "OP" ) )
848 {
849 // SPICE operating points use ':' syntax for ports
850 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent ) )
851 {
852 NULL_REPORTER devnull;
853 SCH_SHEET_PATH& sheet = schematic->CurrentSheet();
854 SIM_LIB_MGR mgr( &schematic->Prj() );
855 SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, devnull ).model;
856
857 for( wxString pin : model.GetPinNames() )
858 {
859 if( pin.StartsWith( '<' ) && pin.EndsWith( '>' ) )
860 autocompleteTokens.push_back( pin.Mid( 1, pin.Length() - 2 ) );
861 else
862 autocompleteTokens.push_back( pin );
863 }
864 }
865 }
866 else
867 {
869 SCH_SYMBOL* refSymbol = nullptr;
870
871 schematic->BuildUnorderedSheetList().GetSymbols( refs );
872
873 for( size_t jj = 0; jj < refs.GetCount(); jj++ )
874 {
875 if( refs[ jj ].GetSymbol()->GetRef( &refs[ jj ].GetSheetPath(), true ) == ref )
876 {
877 refSymbol = refs[ jj ].GetSymbol();
878 break;
879 }
880 }
881
882 if( refSymbol )
883 refSymbol->GetContextualTextVars( &autocompleteTokens );
884 }
885 }
886 }
887 else if( textVarRef( start ) )
888 {
889 partial = scintilla->GetTextRange( start, pos );
890
891 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent );
892 SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( parent );
893 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( parent );
894
895 if( symbol )
896 {
897 symbol->GetContextualTextVars( &autocompleteTokens );
898
899 if( schematic->CurrentSheet().Last() )
900 schematic->CurrentSheet().Last()->GetContextualTextVars( &autocompleteTokens );
901 }
902
903 if( sheet )
904 sheet->GetContextualTextVars( &autocompleteTokens );
905
906 if( label )
907 label->GetContextualTextVars( &autocompleteTokens );
908
909 for( std::pair<wxString, wxString> entry : schematic->Prj().GetTextVars() )
910 autocompleteTokens.push_back( entry.first );
911 }
912
913 aScintillaTricks->DoAutocomplete( partial, autocompleteTokens );
914 scintilla->SetFocus();
915}
916
917
919{
920 if( m_parent && m_parent->Type() == SCH_SHEET_T )
921 {
922 // See comments in SCH_FIELD::Replace(), below.
923 if( m_id == SHEETFILENAME )
924 return false;
925 }
926 else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
927 {
928 if( m_id == 0 /* IntersheetRefs */ )
929 return false;
930 }
931
932 return true;
933}
934
935
936bool SCH_FIELD::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
937{
938 bool replaceReferences = false;
939
940 try
941 {
942 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
943 replaceReferences = schSearchData.replaceReferences;
944 }
945 catch( const std::bad_cast& )
946 {
947 }
948
949 wxString text;
950 bool isReplaced = false;
951
952 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
953 {
954 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
955
956 switch( m_id )
957 {
958 case REFERENCE_FIELD:
959 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in refdes." ) );
960
961 if( !replaceReferences )
962 return false;
963
964 text = parentSymbol->GetRef( (SCH_SHEET_PATH*) aAuxData );
965 isReplaced = EDA_ITEM::Replace( aSearchData, text );
966
967 if( isReplaced )
968 parentSymbol->SetRef( (SCH_SHEET_PATH*) aAuxData, text );
969
970 break;
971
972 case VALUE_FIELD:
973 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in value field." ) );
974
975 text = parentSymbol->GetField( VALUE_FIELD )->GetText();
976 isReplaced = EDA_ITEM::Replace( aSearchData, text );
977
978 if( isReplaced )
979 parentSymbol->SetValueFieldText( text );
980
981 break;
982
983 case FOOTPRINT_FIELD:
984 wxCHECK_MSG( aAuxData, false, wxT( "Need sheetpath to replace in footprint field." ) );
985
986 text = parentSymbol->GetField( FOOTPRINT_FIELD )->GetText();
987 isReplaced = EDA_ITEM::Replace( aSearchData, text );
988
989 if( isReplaced )
990 parentSymbol->SetFootprintFieldText( text );
991
992 break;
993
994 default:
995 isReplaced = EDA_TEXT::Replace( aSearchData );
996 }
997 }
998 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
999 {
1000 isReplaced = EDA_TEXT::Replace( aSearchData );
1001
1002 if( m_id == SHEETFILENAME && isReplaced )
1003 {
1004 // If we allowed this we'd have a bunch of work to do here, including warning
1005 // about it not being undoable, checking for recursive hierarchies, reloading
1006 // sheets, etc. See DIALOG_SHEET_PROPERTIES::TransferDataFromWindow().
1007 }
1008 }
1009 else
1010 {
1011 isReplaced = EDA_TEXT::Replace( aSearchData );
1012 }
1013
1014 return isReplaced;
1015}
1016
1017
1018void SCH_FIELD::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
1019{
1020 if( GetTextAngle().IsVertical() && GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
1021 {
1022 if( aRotateCCW )
1024
1026 }
1027 else if( GetTextAngle().IsVertical() && GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
1028 {
1029 if( aRotateCCW )
1031
1033 }
1034 else if( GetTextAngle().IsHorizontal() && GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
1035 {
1036 if( !aRotateCCW )
1038
1040 }
1041 else if( GetTextAngle().IsHorizontal() && GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
1042 {
1043 if( !aRotateCCW )
1045
1047 }
1048
1049 VECTOR2I pt = GetPosition();
1050 RotatePoint( pt, aCenter, aRotateCCW ? ANGLE_90 : ANGLE_270 );
1051 SetPosition( pt );
1052}
1053
1054
1056{
1057 int x = GetTextPos().x;
1058
1059 x -= aCenter;
1060 x *= -1;
1061 x += aCenter;
1062
1063 SetTextX( x );
1064}
1065
1066
1068{
1069 int y = GetTextPos().y;
1070
1071 y -= aCenter;
1072 y *= -1;
1073 y += aCenter;
1074
1075 SetTextY( y );
1076}
1077
1078
1079void SCH_FIELD::BeginEdit( const VECTOR2I& aPosition )
1080{
1081 SetTextPos( aPosition );
1082}
1083
1084
1085void SCH_FIELD::CalcEdit( const VECTOR2I& aPosition )
1086{
1087 SetTextPos( aPosition );
1088}
1089
1090
1091wxString SCH_FIELD::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
1092{
1093 return wxString::Format( _( "Field %s '%s'" ),
1095 aFull ? GetShownText( false ) : KIUI::EllipsizeMenuText( GetText() ) );
1096}
1097
1098
1099void SCH_FIELD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1100{
1101 wxString msg;
1102
1103 aList.emplace_back( _( "Symbol Field" ), UnescapeString( GetName() ) );
1104
1105 // Don't use GetShownText() here; we want to show the user the variable references
1106 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
1107
1108 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
1109
1110 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
1111
1112 aList.emplace_back( _( "Style" ), GetTextStyleName() );
1113
1114 aList.emplace_back( _( "Text Size" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
1115
1116 switch ( GetHorizJustify() )
1117 {
1118 case GR_TEXT_H_ALIGN_LEFT: msg = _( "Left" ); break;
1119 case GR_TEXT_H_ALIGN_CENTER: msg = _( "Center" ); break;
1120 case GR_TEXT_H_ALIGN_RIGHT: msg = _( "Right" ); break;
1122 }
1123
1124 aList.emplace_back( _( "H Justification" ), msg );
1125
1126 switch ( GetVertJustify() )
1127 {
1128 case GR_TEXT_V_ALIGN_TOP: msg = _( "Top" ); break;
1129 case GR_TEXT_V_ALIGN_CENTER: msg = _( "Center" ); break;
1130 case GR_TEXT_V_ALIGN_BOTTOM: msg = _( "Bottom" ); break;
1132 }
1133
1134 aList.emplace_back( _( "V Justification" ), msg );
1135}
1136
1137
1139{
1140 constexpr int START_ID = 1;
1141
1142 if( IsHypertext() )
1143 {
1144 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
1145 SCH_SHEET_PATH* sheet = &label->Schematic()->CurrentSheet();
1146 wxMenu menu;
1147 wxString href;
1148
1149 std::vector<std::pair<wxString, wxString>> pages;
1150
1151 label->GetIntersheetRefs( sheet, &pages );
1152
1153 for( int i = 0; i < (int) pages.size(); ++i )
1154 {
1155 menu.Append( i + START_ID, wxString::Format( _( "Go to Page %s (%s)" ),
1156 pages[i].first,
1157 pages[i].second ) );
1158 }
1159
1160 menu.AppendSeparator();
1161 menu.Append( 999 + START_ID, _( "Back to Previous Selected Sheet" ) );
1162
1163 int sel = aFrame->GetPopupMenuSelectionFromUser( menu ) - START_ID;
1164
1165 if( sel >= 0 && sel < (int) pages.size() )
1166 href = wxT( "#" ) + pages[ sel ].first;
1167 else if( sel == 999 )
1169
1170 if( !href.IsEmpty() )
1171 {
1173 navTool->HypertextCommand( href );
1174 }
1175 }
1176}
1177
1178
1179void SCH_FIELD::SetName( const wxString& aName )
1180{
1181 m_name = aName;
1182 m_isNamedVariable = m_name.StartsWith( wxT( "${" ) );
1183
1184 if( m_isNamedVariable )
1185 EDA_TEXT::SetText( aName );
1186}
1187
1188
1189void SCH_FIELD::SetText( const wxString& aText )
1190{
1191 // Don't allow modification of text value when using named variables
1192 // as field name.
1193 if( m_isNamedVariable )
1194 return;
1195
1196 // Mandatory fields should not have leading or trailing whitespace.
1197 if( IsMandatory() )
1198 EDA_TEXT::SetText( aText.Strip( wxString::both ) );
1199 else
1200 EDA_TEXT::SetText( aText );
1201}
1202
1203
1204wxString SCH_FIELD::GetName( bool aUseDefaultName ) const
1205{
1206 if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
1207 {
1208 if( IsMandatory() )
1209 return GetCanonicalFieldName( m_id );
1210 else if( m_name.IsEmpty() && aUseDefaultName )
1212 }
1213 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
1214 {
1215 if( IsMandatory() )
1217 else if( m_name.IsEmpty() && aUseDefaultName )
1219 }
1220 else if( m_parent && m_parent->IsType( labelTypes ) )
1221 {
1222 return SCH_LABEL_BASE::GetDefaultFieldName( m_name, aUseDefaultName );
1223 }
1224
1225 return m_name;
1226}
1227
1228
1230{
1231 if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
1232 {
1233 if( IsMandatory() )
1234 return GetCanonicalFieldName( m_id );
1235 }
1236 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
1237 {
1238 if( m_id == SHEETNAME )
1239 return wxT( "Sheetname" );
1240 else if( m_id == SHEETFILENAME )
1241 return wxT( "Sheetfile" );
1242 }
1243 else if( m_parent && m_parent->IsType( labelTypes ) )
1244 {
1245 // These should be stored in canonical format, but just in case:
1246 if( m_name == _( "Net Class" ) || m_name == wxT( "Net Class" ) )
1247 {
1248 return wxT( "Netclass" );
1249 }
1250 else if( m_name == _( "Sheet References" )
1251 || m_name == wxT( "Sheet References" )
1252 || m_name == wxT( "Intersheet References" ) )
1253 {
1254 return wxT( "Intersheetrefs" );
1255 }
1256 }
1257
1258 return m_name;
1259}
1260
1261
1263{
1264 if( m_parent && ( m_parent->Type() == SCH_SYMBOL_T || m_parent->Type() == LIB_SYMBOL_T ) )
1265 {
1266 switch( m_id )
1267 {
1268 case REFERENCE_FIELD: return BITMAPS::edit_comp_ref;
1269 case VALUE_FIELD: return BITMAPS::edit_comp_value;
1270 case FOOTPRINT_FIELD: return BITMAPS::edit_comp_footprint;
1271 default: return BITMAPS::text;
1272 }
1273 }
1274
1275 return BITMAPS::text;
1276}
1277
1278
1279bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
1280{
1281 if( GetShownText( true ).IsEmpty() )
1282 return false;
1283
1284 BOX2I rect = GetBoundingBox();
1285
1286 // Text in symbol editor can have additional chars (ie: reference designators U? or U?A)
1287 if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
1288 {
1289 SCH_FIELD temp( *this );
1290 temp.SetText( GetFullText() );
1291 rect = temp.GetBoundingBox();
1292 }
1293
1294 rect.Inflate( aAccuracy );
1295
1297 {
1298 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
1299 rect.Offset( label->GetSchematicTextOffset( nullptr ) );
1300 }
1301
1302 return rect.Contains( aPosition );
1303}
1304
1305
1306bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
1307{
1308 if( GetShownText( true ).IsEmpty() )
1309 return false;
1310
1312 return false;
1313
1314 BOX2I rect = aRect;
1315
1316 rect.Inflate( aAccuracy );
1317
1318 if( GetParent() && GetParent()->Type() == SCH_GLOBAL_LABEL_T )
1319 {
1320 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( GetParent() );
1321 rect.Offset( label->GetSchematicTextOffset( nullptr ) );
1322 }
1323
1324 if( aContained )
1325 return rect.Contains( GetBoundingBox() );
1326
1327 return rect.Intersects( GetBoundingBox() );
1328}
1329
1330
1331void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
1332 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
1333{
1334 wxString text;
1335
1336 if( Schematic() )
1337 text = GetShownText( &Schematic()->CurrentSheet(), true );
1338 else
1339 text = GetShownText( true );
1340
1341 if( ( !IsVisible() && !IsForceVisible() ) || text.IsEmpty() || aBackground )
1342 return;
1343
1344 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1345 COLOR4D color = renderSettings->GetLayerColor( GetLayer() );
1346 int penWidth = GetEffectiveTextPenWidth( renderSettings->GetDefaultPenWidth() );
1347
1348 COLOR4D bg = renderSettings->GetBackgroundColor();;
1349
1350 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
1351 bg = COLOR4D::WHITE;
1352
1353 if( aPlotter->GetColorMode() && GetTextColor() != COLOR4D::UNSPECIFIED )
1354 color = GetTextColor();
1355
1356 if( aDimmed )
1357 {
1358 color.Desaturate( );
1359 color = color.Mix( bg, 0.5f );
1360 }
1361
1362 penWidth = std::max( penWidth, renderSettings->GetMinPenWidth() );
1363
1364 // clamp the pen width to be sure the text is readable
1365 penWidth = std::min( penWidth, std::min( GetTextSize().x, GetTextSize().y ) / 4 );
1366
1367 if( !IsVisible() && !renderSettings->m_ShowHiddenFields )
1368 return;
1369
1370 // Calculate the text orientation, according to the symbol orientation/mirror
1371 EDA_ANGLE orient = GetTextAngle();
1372 VECTOR2I textpos = GetTextPos();
1374 GR_TEXT_V_ALIGN_T vjustify = GetVertJustify();
1375
1376 if( renderSettings->m_Transform.y1 ) // Rotate symbol 90 deg.
1377 {
1378 if( orient.IsHorizontal() )
1379 orient = ANGLE_VERTICAL;
1380 else
1381 orient = ANGLE_HORIZONTAL;
1382 }
1383
1384 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1385 {
1386 /*
1387 * Calculate the text justification, according to the symbol orientation/mirror. This is
1388 * a bit complicated due to cumulative calculations:
1389 * - numerous cases (mirrored or not, rotation)
1390 * - the plotter's Text() function will also recalculate H and V justifications according
1391 * to the text orientation
1392 * - when a symbol is mirrored the text is not, and justifications become a nightmare
1393 *
1394 * So the easier way is to use no justifications (centered text) and use GetBoundingBox
1395 * to know the text coordinate considered as centered.
1396 */
1397 hjustify = GR_TEXT_H_ALIGN_CENTER;
1398 vjustify = GR_TEXT_V_ALIGN_CENTER;
1399 textpos = GetBoundingBox().Centre();
1400 }
1401 else if( m_parent && m_parent->Type() == SCH_GLOBAL_LABEL_T )
1402 {
1403 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( m_parent );
1404 textpos += label->GetSchematicTextOffset( renderSettings );
1405 }
1406
1407 KIFONT::FONT* font = GetFont();
1408
1409 if( !font )
1410 font = KIFONT::FONT::GetFont( renderSettings->GetDefaultFont(), IsBold(), IsItalic() );
1411
1413 attrs.m_StrokeWidth = penWidth;
1414 attrs.m_Halign = hjustify;
1415 attrs.m_Valign = vjustify;
1416 attrs.m_Angle = orient;
1417 attrs.m_Multiline = false;
1418
1419 aPlotter->PlotText( textpos, color, text, attrs, font, GetFontMetrics() );
1420
1421 if( IsHypertext() && Schematic() )
1422 {
1423 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
1424 std::vector<std::pair<wxString, wxString>> pages;
1425 std::vector<wxString> pageHrefs;
1426 BOX2I bbox = GetBoundingBox();
1427
1428 wxCHECK( label, /* void */ );
1429
1430 label->GetIntersheetRefs( &Schematic()->CurrentSheet(), &pages );
1431
1432 for( const auto& [ pageNumber, sheetName ] : pages )
1433 pageHrefs.push_back( wxT( "#" ) + pageNumber );
1434
1435 bbox.Offset( label->GetSchematicTextOffset( renderSettings ) );
1436
1437 aPlotter->HyperlinkMenu( bbox, pageHrefs );
1438 }
1439}
1440
1441
1442void SCH_FIELD::SetPosition( const VECTOR2I& aPosition )
1443{
1444 // Actual positions are calculated by the rotation/mirror transform of the parent symbol
1445 // of the field. The inverse transform is used to calculate the position relative to the
1446 // parent symbol.
1447 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1448 {
1449 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1450 VECTOR2I relPos = aPosition - parentSymbol->GetPosition();
1451
1452 relPos = parentSymbol->GetTransform().InverseTransform().TransformCoordinate( relPos );
1453
1454 SetTextPos( relPos + parentSymbol->GetPosition() );
1455 return;
1456 }
1457
1458 SetTextPos( aPosition );
1459}
1460
1461
1463{
1464 if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
1465 {
1466 SCH_SYMBOL* parentSymbol = static_cast<SCH_SYMBOL*>( m_parent );
1467 VECTOR2I relativePos = GetTextPos() - parentSymbol->GetPosition();
1468
1469 relativePos = parentSymbol->GetTransform().TransformCoordinate( relativePos );
1470
1471 return relativePos + parentSymbol->GetPosition();
1472 }
1473
1474 return GetTextPos();
1475}
1476
1477
1479{
1480 return m_parent ? m_parent->GetPosition() : VECTOR2I( 0, 0 );
1481}
1482
1483
1485{
1486 if( m_parent && m_parent->Type() == SCH_SHEET_T )
1487 return m_id >= 0 && m_id < SHEET_MANDATORY_FIELDS;
1488 else
1489 return m_id >= 0 && m_id < MANDATORY_FIELDS;
1490}
1491
1492
1493bool SCH_FIELD::operator<( const SCH_ITEM& aItem ) const
1494{
1495 if( Type() != aItem.Type() )
1496 return Type() < aItem.Type();
1497
1498 auto field = static_cast<const SCH_FIELD*>( &aItem );
1499
1500 if( GetId() != field->GetId() )
1501 return GetId() < field->GetId();
1502
1503 if( GetText() != field->GetText() )
1504 return GetText() < field->GetText();
1505
1506 if( GetLibPosition().x != field->GetLibPosition().x )
1507 return GetLibPosition().x < field->GetLibPosition().x;
1508
1509 if( GetLibPosition().y != field->GetLibPosition().y )
1510 return GetLibPosition().y < field->GetLibPosition().y;
1511
1512 return GetName() < field->GetName();
1513}
1514
1515
1516bool SCH_FIELD::operator==(const SCH_ITEM& aOther) const
1517{
1518 if( Type() != aOther.Type() )
1519 return false;
1520
1521 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
1522
1523 return *this == field;
1524}
1525
1526
1527bool SCH_FIELD::operator==( const SCH_FIELD& aOther ) const
1528{
1529 // Identical fields of different symbols are not equal.
1530 if( !GetParentSymbol() || !aOther.GetParentSymbol()
1531 || GetParentSymbol()->m_Uuid != aOther.GetParentSymbol()->m_Uuid )
1532 {
1533 return false;
1534 }
1535
1536 if( GetId() != aOther.GetId() )
1537 return false;
1538
1539 if( GetPosition() != aOther.GetPosition() )
1540 return false;
1541
1542 if( IsNamedVariable() != aOther.IsNamedVariable() )
1543 return false;
1544
1545 if( IsNameShown() != aOther.IsNameShown() )
1546 return false;
1547
1548 if( CanAutoplace() != aOther.CanAutoplace() )
1549 return false;
1550
1551 return EDA_TEXT::operator==( aOther );
1552}
1553
1554
1555double SCH_FIELD::Similarity( const SCH_ITEM& aOther ) const
1556{
1557 if( Type() != aOther.Type() )
1558 return 0.0;
1559
1560 if( m_Uuid == aOther.m_Uuid )
1561 return 1.0;
1562
1563 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aOther );
1564
1565 double similarity = 0.99; // The UUIDs are different, so we start with non-identity
1566
1567 if( GetId() != field.GetId() )
1568 {
1569 // We don't allow swapping of mandatory fields, so these cannot be the same item
1570 if( GetId() < MANDATORY_FIELDS || field.GetId() < MANDATORY_FIELDS )
1571 return 0.0;
1572 else
1573 similarity *= 0.5;
1574 }
1575
1576 similarity *= SimilarityBase( aOther );
1577
1578 similarity *= EDA_TEXT::Similarity( field );
1579
1580 if( GetPosition() != field.GetPosition() )
1581 similarity *= 0.5;
1582
1583 if( IsNamedVariable() != field.IsNamedVariable() )
1584 similarity *= 0.5;
1585
1586 if( IsNameShown() != field.IsNameShown() )
1587 similarity *= 0.5;
1588
1589 if( CanAutoplace() != field.CanAutoplace() )
1590 similarity *= 0.5;
1591
1592 return similarity;
1593}
1594
1595
1596int SCH_FIELD::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1597{
1598 wxASSERT( aOther.Type() == SCH_FIELD_T );
1599
1600 int compareFlags = aCompareFlags;
1601
1602 // For ERC tests, the field position has no matter, so do not test it
1603 if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC )
1605
1606 int retv = SCH_ITEM::compare( aOther, compareFlags );
1607
1608 if( retv )
1609 return retv;
1610
1611 const SCH_FIELD* tmp = static_cast<const SCH_FIELD*>( &aOther );
1612
1613 // Equality test will vary depending whether or not the field is mandatory. Otherwise,
1614 // sorting is done by ordinal.
1615 if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
1616 {
1617 // Mandatory fields have fixed ordinals and their names can vary due to translated field
1618 // names. Optional fields have fixed names and their ordinals can vary.
1619 if( IsMandatory() )
1620 {
1621 if( m_id != tmp->m_id )
1622 return m_id - tmp->m_id;
1623 }
1624 else
1625 {
1626 retv = m_name.Cmp( tmp->m_name );
1627
1628 if( retv )
1629 return retv;
1630 }
1631 }
1632 else // assume we're sorting
1633 {
1634 if( m_id != tmp->m_id )
1635 return m_id - tmp->m_id;
1636 }
1637
1638 bool ignoreFieldText = false;
1639
1640 if( m_id == REFERENCE_FIELD && !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY ) )
1641 ignoreFieldText = true;
1642
1643 if( m_id == VALUE_FIELD && ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) )
1644 ignoreFieldText = true;
1645
1646 if( !ignoreFieldText )
1647 {
1648 retv = GetText().CmpNoCase( tmp->GetText() );
1649
1650 if( retv != 0 )
1651 return retv;
1652 }
1653
1654 if( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
1655 {
1656 if( GetTextPos().x != tmp->GetTextPos().x )
1657 return GetTextPos().x - tmp->GetTextPos().x;
1658
1659 if( GetTextPos().y != tmp->GetTextPos().y )
1660 return GetTextPos().y - tmp->GetTextPos().y;
1661 }
1662
1663 // For ERC tests, the field size has no matter, so do not test it
1664 if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) )
1665 {
1666 if( GetTextWidth() != tmp->GetTextWidth() )
1667 return GetTextWidth() - tmp->GetTextWidth();
1668
1669 if( GetTextHeight() != tmp->GetTextHeight() )
1670 return GetTextHeight() - tmp->GetTextHeight();
1671 }
1672
1673 return 0;
1674}
1675
1676
1677static struct SCH_FIELD_DESC
1678{
1680 {
1681 // These are defined in EDA_TEXT as well but initialization order is
1682 // not defined, so this needs to be conditional. Defining in both
1683 // places leads to duplicate symbols.
1685
1686 if( h_inst.Choices().GetCount() == 0)
1687 {
1688 h_inst.Map( GR_TEXT_H_ALIGN_LEFT, _( "Left" ) );
1689 h_inst.Map( GR_TEXT_H_ALIGN_CENTER, _( "Center" ) );
1690 h_inst.Map( GR_TEXT_H_ALIGN_RIGHT, _( "Right" ) );
1691 }
1692
1694
1695 if( v_inst.Choices().GetCount() == 0)
1696 {
1697 v_inst.Map( GR_TEXT_V_ALIGN_TOP, _( "Top" ) );
1698 v_inst.Map( GR_TEXT_V_ALIGN_CENTER, _( "Center" ) );
1699 v_inst.Map( GR_TEXT_V_ALIGN_BOTTOM, _( "Bottom" ) );
1700 }
1701
1708
1709 const wxString textProps = _HKI( "Text Properties" );
1710
1711 auto horiz = new PROPERTY_ENUM<SCH_FIELD, GR_TEXT_H_ALIGN_T>( _HKI( "Horizontal Justification" ),
1713
1714 propMgr.ReplaceProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Horizontal Justification" ), horiz, textProps );
1715
1716 auto vert = new PROPERTY_ENUM<SCH_FIELD, GR_TEXT_V_ALIGN_T>( _HKI( "Vertical Justification" ),
1718
1719 propMgr.ReplaceProperty( TYPE_HASH( EDA_TEXT ), _HKI( "Vertical Justification" ), vert, textProps );
1720
1721 propMgr.AddProperty( new PROPERTY<SCH_FIELD, bool>( _HKI( "Show Field Name" ),
1723
1724 propMgr.AddProperty( new PROPERTY<SCH_FIELD, bool>( _HKI( "Allow Autoplacement" ),
1726
1727 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
1728 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Thickness" ) );
1729 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Mirrored" ) );
1730 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Width" ) );
1731 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Height" ) );
1732
1733
1734 propMgr.AddProperty( new PROPERTY<SCH_FIELD, int>( _HKI( "Text Size" ),
1735 &SCH_FIELD::SetSchTextSize, &SCH_FIELD::GetSchTextSize, PROPERTY_DISPLAY::PT_SIZE ),
1736 _HKI( "Text Properties" ) );
1737
1738 propMgr.Mask( TYPE_HASH( SCH_FIELD ), TYPE_HASH( EDA_TEXT ), _HKI( "Orientation" ) );
1739
1740 auto isNotNamedVariable =
1741 []( INSPECTABLE* aItem ) -> bool
1742 {
1743 if( SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( aItem ) )
1744 return !field->IsNamedVariable();
1745
1746 return true;
1747 };
1748
1750 isNotNamedVariable );
1751 }
1753
1754
int color
Definition: DXF_plotter.cpp:58
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void SetOrigin(const Vec &pos)
Definition: box2.h:227
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:136
const Vec & GetOrigin() const
Definition: box2.h:200
void Offset(coord_type dx, coord_type dy)
Definition: box2.h:249
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:294
const Vec GetEnd() const
Definition: box2.h:202
void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
Definition: box2.h:128
bool Contains(const Vec &aPoint) const
Definition: box2.h:158
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:541
Vec Centre() const
Definition: box2.h:87
void SetEnd(coord_type x, coord_type y)
Definition: box2.h:280
bool IsHorizontal() const
Definition: eda_angle.h:138
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:243
const KIID m_Uuid
Definition: eda_item.h:489
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:499
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:377
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:176
EDA_ITEM * GetParent() const
Definition: eda_item.h:103
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:500
bool IsForceVisible() const
Definition: eda_item.h:195
static bool Replace(const EDA_SEARCH_DATA &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
Definition: eda_item.cpp:186
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:79
int GetTextHeight() const
Definition: eda_text.h:224
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:230
COLOR4D GetTextColor() const
Definition: eda_text.h:227
wxString GetTextStyleName() const
Definition: eda_text.cpp:822
bool IsItalic() const
Definition: eda_text.h:140
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:130
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:94
virtual bool IsVisible() const
Definition: eda_text.h:147
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:418
void SetTextX(int aX)
Definition: eda_text.cpp:424
KIFONT::FONT * GetFont() const
Definition: eda_text.h:207
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition: eda_text.cpp:291
BOX2I GetTextBox(int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition: eda_text.cpp:570
void SetTextY(int aY)
Definition: eda_text.cpp:430
EDA_TEXT & operator=(const EDA_TEXT &aItem)
Definition: eda_text.cpp:151
int GetTextWidth() const
Definition: eda_text.h:221
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:275
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:160
bool Replace(const EDA_SEARCH_DATA &aSearchData)
Helper function used in search and replace dialog.
Definition: eda_text.cpp:344
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:244
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:504
double Similarity(const EDA_TEXT &aOther) const
Definition: eda_text.cpp:1142
virtual void ClearRenderCache()
Definition: eda_text.cpp:498
const TEXT_ATTRIBUTES & GetAttributes() const
Definition: eda_text.h:191
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition: eda_text.cpp:323
void SwapAttributes(EDA_TEXT &aTradingPartner)
Swap the text attributes of the two involved instances.
Definition: eda_text.cpp:310
bool IsBold() const
Definition: eda_text.h:144
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:163
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:105
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:182
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:204
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:303
bool operator==(const EDA_TEXT &aRhs) const
Definition: eda_text.h:353
VECTOR2I GetTextSize() const
Definition: eda_text.h:218
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:267
static ENUM_MAP< T > & Instance()
Definition: property.h:663
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:36
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr)
Definition: font.cpp:146
virtual bool IsOutline() const
Definition: font.h:139
Class OUTLINE_FONT implements outline font drawing.
Definition: outline_font.h:53
void GetLinesAsGlyphs(std::vector< std::unique_ptr< GLYPH > > *aGlyphs, const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs, const METRICS &aFontMetrics) const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
int GetDefaultPenWidth() const
const wxString & GetDefaultFont() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
wxDC * GetPrintDC() const
Define a library symbol object.
Definition: lib_symbol.h:78
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
Definition: lib_symbol.cpp:466
static wxString LetterSubReference(int aUnit, int aFirstId)
Definition: lib_symbol.cpp:447
A singleton reporter that reports to nowhere.
Definition: reporter.h:223
Base plotter engine class.
Definition: plotter.h:105
bool GetColorMode() const
Definition: plotter.h:133
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:752
virtual void HyperlinkMenu(const BOX2I &aBox, const std::vector< wxString > &aDestURLs)
Create a clickable hyperlink menu with a rectangular click area.
Definition: plotter.h:465
virtual std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:84
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
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.
Holds all the data relating to one schematic.
Definition: schematic.h:76
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:144
SCH_SHEET_LIST BuildUnorderedSheetList() const
Definition: schematic.h:101
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
Definition: schematic.cpp:238
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:91
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
void ClearRenderCache() override
Definition: sch_field.cpp:367
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: sch_field.cpp:1596
COLOR4D m_lastResolvedColor
Definition: sch_field.h:348
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const
Definition: sch_field.cpp:737
bool IsMandatory() const
Definition: sch_field.cpp:1484
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_field.cpp:1091
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_field.cpp:1018
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: sch_field.cpp:328
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_field.cpp:609
std::vector< std::unique_ptr< KIFONT::GLYPH > > m_renderCache
Definition: sch_field.h:346
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: sch_field.cpp:551
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1462
void SetEffectiveHorizJustify(GR_TEXT_H_ALIGN_T)
Definition: sch_field.cpp:660
int GetSchTextSize() const
Definition: sch_field.h:171
bool Replace(const EDA_SEARCH_DATA &aSearchData, void *aAuxData=nullptr) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_field.cpp:936
bool m_showName
Render the field name in addition to its value.
Definition: sch_field.h:336
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition: sch_field.cpp:1331
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_field.cpp:147
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_field.cpp:1262
bool IsNameShown() const
Definition: sch_field.h:208
bool IsHypertext() const override
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_field.h:101
bool m_autoAdded
Was this field automatically added to a LIB_SYMBOL?
Definition: sch_field.h:341
double Similarity(const SCH_ITEM &aItem) const override
Return a measure of how likely the other object is to represent the same object.
Definition: sch_field.cpp:1555
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: sch_field.cpp:420
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_field.cpp:1279
SCH_LAYER_ID GetDefaultLayer() const
Definition: sch_field.cpp:559
bool IsHorizJustifyFlipped() const
Return whether the field will be rendered with the horizontal justification inverted due to rotation ...
Definition: sch_field.cpp:637
bool IsVertJustifyFlipped() const
Definition: sch_field.cpp:694
EDA_ANGLE GetDrawRotation() const override
Adjusters to allow EDA_TEXT to draw/print/etc.
Definition: sch_field.cpp:587
void SetEffectiveVertJustify(GR_TEXT_V_ALIGN_T)
Definition: sch_field.cpp:717
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: sch_field.cpp:1085
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_field.cpp:751
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_field.cpp:1067
void SetCanAutoplace(bool aCanPlace)
Definition: sch_field.h:220
bool m_isNamedVariable
If the field name is a variable name, e.g.
Definition: sch_field.h:338
void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const override
Definition: sch_field.cpp:1138
int GetPenWidth() const override
Definition: sch_field.cpp:343
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: sch_field.cpp:1229
COLOR4D GetFieldColor() const
Definition: sch_field.cpp:531
bool IsNamedVariable() const
Named variables are fields whose names are variables like ${VAR}.
Definition: sch_field.h:217
int GetId() const
Definition: sch_field.h:133
bool operator==(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1516
SCH_FIELD & operator=(const SCH_FIELD &aField)
Definition: sch_field.cpp:118
void ImportValues(const SCH_FIELD &aSource)
Copy parameters from a SCH_FIELD source.
Definition: sch_field.cpp:504
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_field.cpp:1493
wxString GetShownName() const
Gets the fields name as displayed on the schematic or in the symbol fields table.
Definition: sch_field.cpp:196
VECTOR2I GetLibPosition() const
Definition: sch_field.h:265
bool IsEmpty()
Return true if both the name and value of the field are empty.
Definition: sch_field.h:163
SCH_FIELD(const VECTOR2I &aPos, int aFieldId, SCH_ITEM *aParent, const wxString &aName=wxEmptyString)
Definition: sch_field.cpp:60
bool m_renderCacheValid
Definition: sch_field.h:344
void BeginEdit(const VECTOR2I &aStartPoint) override
Begin drawing a symbol library draw item at aPosition.
Definition: sch_field.cpp:1079
bool IsReplaceable() const override
Override this method in any derived object that supports test find and replace.
Definition: sch_field.cpp:918
void SetSchTextSize(int aSize)
Definition: sch_field.h:172
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const
Definition: sch_field.cpp:680
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1204
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_field.cpp:1442
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_field.cpp:512
void SetName(const wxString &aName)
Definition: sch_field.cpp:1179
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_field.cpp:202
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_field.h:239
VECTOR2I m_renderCachePos
Definition: sch_field.h:345
bool CanAutoplace() const
Definition: sch_field.h:219
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const wxString &forResolvedText, const VECTOR2I &forPosition, TEXT_ATTRIBUTES &aAttrs) const
Definition: sch_field.cpp:375
void SetId(int aId)
Definition: sch_field.cpp:159
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: sch_field.cpp:1099
void ClearCaches() override
Definition: sch_field.cpp:360
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1189
VECTOR2I GetParentPosition() const
Definition: sch_field.cpp:1478
int m_id
Field index,.
Definition: sch_field.h:332
bool m_showInChooser
This field is available as a data column for the chooser.
Definition: sch_field.h:342
void OnScintillaCharAdded(SCINTILLA_TRICKS *aScintillaTricks, wxStyledTextEvent &aEvent) const
Definition: sch_field.cpp:800
wxString m_name
Definition: sch_field.h:334
void SetNameShown(bool aShown=true)
Definition: sch_field.h:209
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_field.cpp:1055
void Copy(SCH_FIELD *aTarget) const
Copy parameters of this field to another field.
Definition: sch_field.cpp:153
KIFONT::FONT * getDrawFont() const override
Definition: sch_field.cpp:349
bool m_allowAutoPlace
This field can be autoplaced.
Definition: sch_field.h:337
VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const override
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition: sch_label.cpp:1847
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
const wxString & GetDefaultFont() const
Definition: sch_item.cpp:458
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition: sch_item.h:670
const SYMBOL * GetParentSymbol() const
Definition: sch_item.cpp:166
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:150
@ SKIP_TST_POS
Definition: sch_item.h:662
@ EQUALITY
Definition: sch_item.h:660
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:250
void SetLayer(SCH_LAYER_ID aLayer)
Definition: sch_item.h:282
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:281
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:419
bool IsConnectivityDirty() const
Definition: sch_item.h:510
void SwapFlags(SCH_ITEM *aItem)
Swap the non-temp and non-edit flags.
Definition: sch_item.cpp:354
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:466
SCH_LAYER_ID m_layer
Definition: sch_item.h:723
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:316
void GetIntersheetRefs(const SCH_SHEET_PATH *aPath, std::vector< std::pair< wxString, wxString > > *pages)
Builds an array of { pageNumber, pageName } pairs.
Definition: sch_label.cpp:685
virtual bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth) const
Resolve any references to system tokens supported by the label.
Definition: sch_label.cpp:735
static const wxString GetDefaultFieldName(const wxString &aName, bool aUseDefaultName)
Definition: sch_label.cpp:254
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this label.
Definition: sch_label.cpp:722
VECTOR2I GetSchematicTextOffset(const RENDER_SETTINGS *aSettings) const override
This offset depends on the orientation, the type of text, and the area required to draw the associate...
Definition: sch_label.cpp:402
Handle actions specific to the schematic editor.
static wxString g_BackLink
void HypertextCommand(const wxString &href)
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
size_t GetCount() const
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
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...
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this sheet.
Definition: sch_sheet.cpp:212
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
Definition: sch_sheet.cpp:56
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:251
Schematic symbol object.
Definition: sch_symbol.h:105
wxString SubReference(int aUnit, bool aAddSeparator=true) const
Definition: sch_symbol.cpp:836
void SetValueFieldText(const wxString &aValue)
Definition: sch_symbol.cpp:897
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:919
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:759
void SetFootprintFieldText(const wxString &aFootprint)
Definition: sch_symbol.cpp:913
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:802
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
void GetContextualTextVars(wxArrayString *aVars) const
Return the list of system text vars & fields for this symbol.
TRANSFORM & GetTransform()
Definition: sch_symbol.h:282
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
Definition: sch_symbol.cpp:845
int GetUnitCount() const override
Return the number of units per package of the symbol.
Definition: sch_symbol.cpp:451
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:720
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
wxStyledTextCtrl * Scintilla() const
void DoAutocomplete(const wxString &aPartial, const wxArrayString &aTokens)
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
virtual std::vector< std::string > GetPinNames() const
Definition: sim_model.h:469
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
int y1
Definition: transform.h:49
TRANSFORM InverseTransform() const
Calculate the Inverse mirror/rotation transform.
Definition: transform.cpp:59
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:44
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
Definition: common.cpp:59
wxString GetTextVars(const wxString &aSource)
Returns any variables unexpanded, e.g.
Definition: common.cpp:121
The common library.
#define _HKI(x)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:398
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:397
static constexpr EDA_ANGLE ANGLE_270
Definition: eda_angle.h:406
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
bool GetGRForceBlackPenState(void)
Definition: gr_basic.cpp:165
void GRPrintText(wxDC *aDC, const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Print a graphic text through wxDC.
Definition: gr_text.cpp:142
PROJECT & Prj()
Definition: kicad.cpp:595
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:354
@ LAYER_SHEETNAME
Definition: layer_ids.h:377
@ LAYER_HIDDEN
Definition: layer_ids.h:396
@ LAYER_VALUEPART
Definition: layer_ids.h:366
@ LAYER_FIELDS
Definition: layer_ids.h:367
@ LAYER_SHEETFIELDS
Definition: layer_ids.h:379
@ LAYER_REFERENCEPART
Definition: layer_ids.h:365
@ LAYER_NETCLASS_REFS
Definition: layer_ids.h:369
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:397
@ LAYER_INTERSHEET_REFS
Definition: layer_ids.h:368
@ LAYER_SHEETFILENAME
Definition: layer_ids.h:378
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
Definition: ui_common.cpp:213
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
Definition: ui_common.cpp:195
#define TYPE_HASH(x)
Definition: property.h:71
#define DECLARE_ENUM_TO_WXANY(type)
Definition: property.h:729
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
static const std::vector< KICAD_T > labelTypes
Definition: sch_field.cpp:57
static struct SCH_FIELD_DESC _SCH_FIELD_DESC
@ SHEET_MANDATORY_FIELDS
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:49
@ SHEETNAME
Definition: sch_sheet.h:45
@ SHEETFILENAME
Definition: sch_sheet.h:46
wxString UnescapeString(const wxString &aSource)
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
Definition for symbol library class.
wxString GetCanonicalFieldName(int idx)
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
constexpr int delta
GR_TEXT_H_ALIGN_T
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
@ 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:228
@ LIB_SYMBOL_T
Definition: typeinfo.h:148
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_LABEL_T
Definition: typeinfo.h:167
@ SCH_SHEET_T
Definition: typeinfo.h:174
@ SCH_LABEL_LOCATE_ANY_T
Definition: typeinfo.h:190
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:168
#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:673