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