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