KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
sch_pin.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) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
6 * Copyright (C) 2018 CERN
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 * @author Jon Evans <jon@craftyjon.com>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28#include "sch_pin.h"
29
30#include <base_units.h>
31#include <pgm_base.h>
32#include <pin_layout_cache.h>
33#include <plotters/plotter.h>
34#include <sch_draw_panel.h>
35#include <sch_edit_frame.h>
36#include <symbol_edit_frame.h>
39#include <trigo.h>
40#include <string_utils.h>
41
42
43// small margin in internal units between the pin text and the pin line
44#define PIN_TEXT_MARGIN 4
45
47{
48 // These strings are the canonical name of the electrictal type
49 // Not translated, no space in name, only ASCII chars.
50 // to use when the string name must be known and well defined
51 // must have same order than enum ELECTRICAL_PINTYPE (see sch_pin.h)
52 static const wxChar* msgPinElectricType[] =
53 {
54 wxT( "input" ),
55 wxT( "output" ),
56 wxT( "bidirectional" ),
57 wxT( "tri_state" ),
58 wxT( "passive" ),
59 wxT( "free" ),
60 wxT( "unspecified" ),
61 wxT( "power_in" ),
62 wxT( "power_out" ),
63 wxT( "open_collector" ),
64 wxT( "open_emitter" ),
65 wxT( "no_connect" )
66 };
67
68 return msgPinElectricType[static_cast<int>( aType )];
69}
70
71
75static int internalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin )
76{
77 const SCH_RENDER_SETTINGS* settings = static_cast<const SCH_RENDER_SETTINGS*>( aSettings );
78
79 if( settings && settings->m_PinSymbolSize )
80 return settings->m_PinSymbolSize;
81
82 return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
83}
84
85
89static int externalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin )
90{
91 const SCH_RENDER_SETTINGS* settings = static_cast<const SCH_RENDER_SETTINGS*>( aSettings );
92
93 if( settings && settings->m_PinSymbolSize )
94 return settings->m_PinSymbolSize;
95
96 return aPin.GetNumberTextSize() / 2;
97}
98
99
100SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol ) :
101 SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ),
102 m_libPin( nullptr ),
103 m_position( { 0, 0 } ),
104 m_orientation( PIN_ORIENTATION::PIN_RIGHT ),
105 m_shape( GRAPHIC_PINSHAPE::LINE ),
107 m_hidden( false ),
108 m_isDangling( true ),
109 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
110{
111 // Use the application settings for pin sizes if exists.
112 // pgm can be nullptr when running a shared lib from a script, not from a kicad appl
113 PGM_BASE* pgm = PgmOrNull();
114
115 if( pgm )
116 {
118 SYMBOL_EDITOR_SETTINGS* cfg = mgr.GetAppSettings<SYMBOL_EDITOR_SETTINGS>( "symbol_editor" );
119
120 m_length = schIUScale.MilsToIU( cfg->m_Defaults.pin_length );
121 m_numTextSize = schIUScale.MilsToIU( cfg->m_Defaults.pin_num_size );
122 m_nameTextSize = schIUScale.MilsToIU( cfg->m_Defaults.pin_name_size );
123 }
124 else // Use hardcoded eeschema defaults: symbol_editor settings are not existing.
125 {
127 m_numTextSize = schIUScale.MilsToIU( DEFAULT_PINNUM_SIZE );
128 m_nameTextSize = schIUScale.MilsToIU( DEFAULT_PINNAME_SIZE );
129 }
130
131 m_layer = LAYER_DEVICE;
132}
133
134
135SCH_PIN::SCH_PIN( LIB_SYMBOL* aParentSymbol, const wxString& aName, const wxString& aNumber,
136 PIN_ORIENTATION aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength,
137 int aNameTextSize, int aNumTextSize, int aBodyStyle, const VECTOR2I& aPos,
138 int aUnit ) :
139 SCH_ITEM( aParentSymbol, SCH_PIN_T, aUnit, aBodyStyle ),
140 m_libPin( nullptr ),
141 m_position( aPos ),
142 m_length( aLength ),
143 m_orientation( aOrientation ),
144 m_shape( GRAPHIC_PINSHAPE::LINE ),
145 m_type( aPinType ),
146 m_hidden( false ),
147 m_numTextSize( aNumTextSize ),
148 m_nameTextSize( aNameTextSize ),
149 m_isDangling( true ),
150 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
151{
152 SetName( aName );
153 SetNumber( aNumber );
154
156}
157
158
159SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, SCH_PIN* aLibPin ) :
160 SCH_ITEM( aParentSymbol, SCH_PIN_T, 0, 0 ),
161 m_libPin( aLibPin ),
162 m_orientation( PIN_ORIENTATION::INHERIT ),
163 m_shape( GRAPHIC_PINSHAPE::INHERIT ),
165 m_isDangling( true ),
166 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
167{
168 wxASSERT( aParentSymbol );
169
173
175}
176
177
178SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt,
179 const KIID& aUuid ) :
180 SCH_ITEM( aParentSymbol, SCH_PIN_T ),
181 m_libPin( nullptr ),
182 m_orientation( PIN_ORIENTATION::INHERIT ),
183 m_shape( GRAPHIC_PINSHAPE::INHERIT ),
185 m_number( aNumber ),
186 m_alt( aAlt ),
187 m_isDangling( true ),
188 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
189{
190 wxASSERT( aParentSymbol );
191
192 const_cast<KIID&>( m_Uuid ) = aUuid;
194}
195
196
197SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
198 SCH_ITEM( aPin ),
199 m_libPin( aPin.m_libPin ),
200 m_alternates( aPin.m_alternates ),
201 m_position( aPin.m_position ),
202 m_length( aPin.m_length ),
203 m_orientation( aPin.m_orientation ),
204 m_shape( aPin.m_shape ),
205 m_type( aPin.m_type ),
206 m_hidden( aPin.m_hidden ),
207 m_numTextSize( aPin.m_numTextSize ),
208 m_nameTextSize( aPin.m_nameTextSize ),
209 m_alt( aPin.m_alt ),
210 m_isDangling( aPin.m_isDangling ),
211 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
212{
213 SetName( aPin.m_name );
214 SetNumber( aPin.m_number );
215
216 m_layer = aPin.m_layer;
217}
218
219
221{
222}
223
224
226{
227 SCH_ITEM::operator=( aPin );
228
229 m_libPin = aPin.m_libPin;
231 m_alt = aPin.m_alt;
232 m_name = aPin.m_name;
233 m_number = aPin.m_number;
234 m_position = aPin.m_position;
235 m_length = aPin.m_length;
237 m_shape = aPin.m_shape;
238 m_type = aPin.m_type;
239 m_hidden = aPin.m_hidden;
243
244 return *this;
245}
246
247
249{
250 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
251 return symbol->GetTransform().TransformCoordinate( m_position ) + symbol->GetPosition();
252 else
253 return m_position;
254}
255
257{
258 if( m_orientation == PIN_ORIENTATION::INHERIT )
259 {
260 if( !m_libPin )
261 return PIN_ORIENTATION::PIN_RIGHT;
262
263 return m_libPin->GetOrientation();
264 }
265
266 return m_orientation;
267}
268
269
271{
272 if( !m_alt.IsEmpty() )
273 {
274 if( !m_libPin )
275 return GRAPHIC_PINSHAPE::LINE;
276
277 return m_libPin->GetAlt( m_alt ).m_Shape;
278 }
279 else if( m_shape == GRAPHIC_PINSHAPE::INHERIT )
280 {
281 if( !m_libPin )
282 return GRAPHIC_PINSHAPE::LINE;
283
284 return m_libPin->GetShape();
285 }
286
287 return m_shape;
288}
289
290
292{
293 if( !m_length.has_value() )
294 {
295 if( !m_libPin )
296 return 0;
297
298 return m_libPin->GetLength();
299 }
300
301 return m_length.value();
302}
303
304
306{
307 if( !m_alt.IsEmpty() )
308 {
309 if( !m_libPin )
310 return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
311
312 return m_libPin->GetAlt( m_alt ).m_Type;
313 }
314 else if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
315 {
316 if( !m_libPin )
317 return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
318
319 return m_libPin->GetType();
320 }
321
322 return m_type;
323}
324
326{
327 if( aType == m_type )
328 return;
329
330 m_type = aType;
332}
333
334
336{
337 if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
338 {
339 if( !m_libPin )
340 return GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
341
343 }
344
346}
347
348
350{
351 if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
352 {
353 if( !m_libPin )
354 return ElectricalPinTypeGetText( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
355
357 }
358
360}
361
362
364{
365 return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN
366 && ( !IsVisible() || GetParentSymbol()->IsGlobalPower() );
367}
368
369
371{
372 return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN
374}
375
376
378{
379 return IsLocalPower() || IsGlobalPower();
380}
381
382
384{
385 if( !m_hidden.has_value() )
386 {
387 if( !m_libPin )
388 return true;
389
390 return m_libPin->IsVisible();
391 }
392
393 return !m_hidden.value();
394}
395
396
397const wxString& SCH_PIN::GetName() const
398{
399 if( !m_alt.IsEmpty() )
400 return m_alt;
401
402 return GetBaseName();
403}
404
405
406const wxString& SCH_PIN::GetBaseName() const
407{
408 if( m_libPin )
409 return m_libPin->GetBaseName();
410
411 return m_name;
412}
413
414
415void SCH_PIN::SetName( const wxString& aName )
416{
417 if( m_name == aName )
418 return;
419
420 m_name = aName;
421
422 // pin name string does not support spaces
423 m_name.Replace( wxT( " " ), wxT( "_" ) );
424
426}
427
428
430{
431 if( GetType() == ELECTRICAL_PINTYPE::PT_NC || GetType() == ELECTRICAL_PINTYPE::PT_NIC )
432 return false;
433
434 return m_isDangling;
435}
436
437
438void SCH_PIN::SetIsDangling( bool aIsDangling )
439{
440 m_isDangling = aIsDangling;
441}
442
443
444bool SCH_PIN::IsStacked( const SCH_PIN* aPin ) const
445{
446 bool isConnectableType_a = GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE
447 || GetType() == ELECTRICAL_PINTYPE::PT_NIC;
448 bool isConnectableType_b = aPin->GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE
449 || aPin->GetType() == ELECTRICAL_PINTYPE::PT_NIC;
450
451 return m_parent == aPin->GetParent()
452 && GetPosition() == aPin->GetPosition()
453 && GetName() == aPin->GetName()
454 && ( GetType() == aPin->GetType() || isConnectableType_a || isConnectableType_b );
455}
456
457
458bool SCH_PIN::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
459{
460 const SCH_SEARCH_DATA& schSearchData =
461 dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
462
463 if( schSearchData.searchAllPins
464 && ( EDA_ITEM::Matches( GetName(), aSearchData )
465 || EDA_ITEM::Matches( GetNumber(), aSearchData ) ) )
466 {
467 return true;
468 }
469
470 SCH_CONNECTION* connection = nullptr;
471 SCH_SHEET_PATH* sheetPath = reinterpret_cast<SCH_SHEET_PATH*>( aAuxData );
472
473 if( schSearchData.searchNetNames && sheetPath && ( connection = Connection( sheetPath ) ) )
474 {
475 wxString netName = connection->GetNetName();
476
477 if( EDA_ITEM::Matches( netName, aSearchData ) )
478 return true;
479 }
480
481 return false;
482}
483
484
485bool SCH_PIN::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
486{
487 bool isReplaced = false;
488
489 /* TODO: waiting on a way to override pins in the schematic...
490 isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
491 isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
492 */
493
494 return isReplaced;
495}
496
497
498bool SCH_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
499{
500 // When looking for an "exact" hit aAccuracy will be 0 which works poorly if the pin has
501 // no pin number or name. Give it a floor.
502 if( Schematic() )
503 aAccuracy = std::max( aAccuracy, Schematic()->Settings().m_PinSymbolSize / 4 );
504
505 BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
506
507 return rect.Inflate( aAccuracy ).Contains( aPosition );
508}
509
510
511bool SCH_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
512{
514 return false;
515
516 BOX2I sel = aRect;
517
518 if ( aAccuracy )
519 sel.Inflate( aAccuracy );
520
521 if( aContained )
522 return sel.Contains( GetBoundingBox( false, false, false ) );
523
524 return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) );
525}
526
527
528wxString SCH_PIN::GetShownName() const
529{
530 if( !m_alt.IsEmpty() )
531 return m_alt;
532 else if( m_libPin )
533 return m_libPin->GetShownName();
534
535 return m_name;
536}
537
538
540{
541 return m_number;
542}
543
544
545void SCH_PIN::SetNumber( const wxString& aNumber )
546{
547 if( m_number == aNumber )
548 return;
549
550 m_number = aNumber;
551 // pin number string does not support spaces
552 m_number.Replace( wxT( " " ), wxT( "_" ) );
553
555}
556
557
559{
560 if( !m_nameTextSize.has_value() )
561 {
562 if( !m_libPin )
564
565 return m_libPin->GetNameTextSize();
566 }
567
568 return m_nameTextSize.value();
569}
570
571
573{
574 if( aSize == m_nameTextSize )
575 return;
576
577 m_nameTextSize = aSize;
579}
580
581
583{
584 if( !m_numTextSize.has_value() )
585 {
586 if( !m_libPin )
588
589 return m_libPin->GetNumberTextSize();
590 }
591
592 return m_numTextSize.value();
593}
594
595
597{
598 if( aSize == m_numTextSize )
599 return;
600
601 m_numTextSize = aSize;
603}
604
605
607{
608 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
609 {
610 const TRANSFORM& t = symbol->GetTransform();
611
612 if( !m_libPin )
613 return GetPosition();
614
615 return t.TransformCoordinate( m_libPin->GetPinRoot() ) + symbol->GetPosition();
616 }
617
618 switch( GetOrientation() )
619 {
620 default:
621 case PIN_ORIENTATION::PIN_RIGHT: return m_position + VECTOR2I( GetLength(), 0 );
622 case PIN_ORIENTATION::PIN_LEFT: return m_position + VECTOR2I( -GetLength(), 0 );
623 case PIN_ORIENTATION::PIN_UP: return m_position + VECTOR2I( 0, -GetLength() );
624 case PIN_ORIENTATION::PIN_DOWN: return m_position + VECTOR2I( 0, GetLength() );
625 }
626}
627
628
629void SCH_PIN::PlotPinType( PLOTTER *aPlotter, const VECTOR2I &aPosition,
630 PIN_ORIENTATION aOrientation, bool aDimmed ) const
631{
632 int MapX1, MapY1, x1, y1;
633 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
634 COLOR4D color = renderSettings->GetLayerColor( LAYER_PIN );
635 COLOR4D bg = renderSettings->GetBackgroundColor();
636 int penWidth = GetEffectivePenWidth( renderSettings );
637 int pinLength = GetLength();
638
639 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
640 bg = COLOR4D::WHITE;
641
642 if( aDimmed )
643 {
644 color.Desaturate( );
645 color = color.Mix( bg, 0.5f );
646 }
647
648 aPlotter->SetColor( color );
649 aPlotter->SetCurrentLineWidth( penWidth );
650
651 MapX1 = MapY1 = 0;
652 x1 = aPosition.x; y1 = aPosition.y;
653
654 switch( aOrientation )
655 {
656 case PIN_ORIENTATION::PIN_UP: y1 = aPosition.y - pinLength; MapY1 = 1; break;
657 case PIN_ORIENTATION::PIN_DOWN: y1 = aPosition.y + pinLength; MapY1 = -1; break;
658 case PIN_ORIENTATION::PIN_LEFT: x1 = aPosition.x - pinLength; MapX1 = 1; break;
659 case PIN_ORIENTATION::PIN_RIGHT: x1 = aPosition.x + pinLength; MapX1 = -1; break;
660 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); break;
661 }
662
663 if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
664 {
665 const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
666 aPlotter->Circle( VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
667 FILL_T::NO_FILL, penWidth );
668
669 aPlotter->MoveTo( VECTOR2I( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
670 aPlotter->FinishTo( aPosition );
671 }
672 else if( m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK )
673 {
674 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
675 if( MapY1 == 0 ) /* MapX1 = +- 1 */
676 {
677 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
678 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
679 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
680 }
681 else /* MapX1 = 0 */
682 {
683 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
684 aPlotter->LineTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
685 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
686 }
687
688 aPlotter->MoveTo( VECTOR2I( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
689 aPlotter->FinishTo( aPosition );
690 }
691 else
692 {
693 aPlotter->MoveTo( VECTOR2I( x1, y1 ) );
694 aPlotter->FinishTo( aPosition );
695 }
696
697 if( m_shape == GRAPHIC_PINSHAPE::CLOCK
698 || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK
699 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
700 {
701 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
702 if( MapY1 == 0 ) /* MapX1 = +- 1 */
703 {
704 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
705 aPlotter->LineTo( VECTOR2I( x1 - MapX1 * deco_size * 2, y1 ) );
706 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
707 }
708 else /* MapX1 = 0 */
709 {
710 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
711 aPlotter->LineTo( VECTOR2I( x1, y1 - MapY1 * deco_size * 2 ) );
712 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
713 }
714 }
715
716 if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW
717 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
718 {
719 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
720
721 if( MapY1 == 0 ) /* MapX1 = +- 1 */
722 {
723 aPlotter->MoveTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
724 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
725 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
726 }
727 else /* MapX1 = 0 */
728 {
729 aPlotter->MoveTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
730 aPlotter->LineTo( VECTOR2I( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
731 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
732 }
733 }
734
735 if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
736 {
737 const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
738
739 if( MapY1 == 0 ) /* MapX1 = +- 1 */
740 {
741 aPlotter->MoveTo( VECTOR2I( x1, y1 - symbol_size * 2 ) );
742 aPlotter->FinishTo( VECTOR2I( x1 + MapX1 * symbol_size * 2, y1 ) );
743 }
744 else /* MapX1 = 0 */
745 {
746 aPlotter->MoveTo( VECTOR2I( x1 - symbol_size * 2, y1 ) );
747 aPlotter->FinishTo( VECTOR2I( x1, y1 + MapY1 * symbol_size * 2 ) );
748 }
749 }
750 else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
751 {
752 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
753 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 + MapY1 ) * deco_size,
754 y1 - ( MapY1 - MapX1 ) * deco_size ) );
755 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 + MapY1 ) * deco_size,
756 y1 + ( MapY1 - MapX1 ) * deco_size ) );
757 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 - MapY1 ) * deco_size,
758 y1 - ( MapY1 + MapX1 ) * deco_size ) );
759 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 - MapY1 ) * deco_size,
760 y1 + ( MapY1 + MapX1 ) * deco_size ) );
761 }
762
763 if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
764 {
765 const int deco_size = TARGET_PIN_RADIUS;
766 const int ex1 = aPosition.x;
767 const int ey1 = aPosition.y;
768 aPlotter->MoveTo( VECTOR2I( ex1 - deco_size, ey1 - deco_size ) );
769 aPlotter->FinishTo( VECTOR2I( ex1 + deco_size, ey1 + deco_size ) );
770 aPlotter->MoveTo( VECTOR2I( ex1 + deco_size, ey1 - deco_size ) );
771 aPlotter->FinishTo( VECTOR2I( ex1 - deco_size, ey1 + deco_size ) );
772 }
773}
774
775
776void SCH_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient,
777 int aTextInside, bool aDrawPinNum, bool aDrawPinName,
778 bool aDimmed ) const
779{
780 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
781 KIFONT::FONT* font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), false, false );
782 wxString name = GetShownName();
783 wxString number = GetShownNumber();
784
785 if( name.IsEmpty() || m_nameTextSize == 0 )
786 aDrawPinName = false;
787
788 if( number.IsEmpty() || m_numTextSize == 0 )
789 aDrawPinNum = false;
790
791 if( !aDrawPinNum && !aDrawPinName )
792 return;
793
794 int namePenWidth = settings->GetDefaultPenWidth();
795 int numPenWidth = settings->GetDefaultPenWidth();
796 int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + namePenWidth;
797 int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + numPenWidth;
798
799 /* Get the num and name colors */
800 COLOR4D nameColor = settings->GetLayerColor( LAYER_PINNAM );
801 COLOR4D numColor = settings->GetLayerColor( LAYER_PINNUM );
802 COLOR4D bg = settings->GetBackgroundColor();
803
804 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
805 bg = COLOR4D::WHITE;
806
807 if( aDimmed )
808 {
809 nameColor.Desaturate( );
810 numColor.Desaturate( );
811 nameColor = nameColor.Mix( bg, 0.5f );
812 numColor = numColor.Mix( bg, 0.5f );
813 }
814
815 int x1 = aPinPos.x;
816 int y1 = aPinPos.y;
817
818 switch( aPinOrient )
819 {
820 case PIN_ORIENTATION::PIN_UP: y1 -= GetLength(); break;
821 case PIN_ORIENTATION::PIN_DOWN: y1 += GetLength(); break;
822 case PIN_ORIENTATION::PIN_LEFT: x1 -= GetLength(); break;
823 case PIN_ORIENTATION::PIN_RIGHT: x1 += GetLength(); break;
824 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aPinOrient must be resolved!" ) ); break;
825 }
826
827 auto plotName =
828 [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify,
829 GR_TEXT_V_ALIGN_T vJustify )
830 {
831 TEXT_ATTRIBUTES attrs;
832 attrs.m_StrokeWidth = namePenWidth;
833 attrs.m_Angle = angle;
835 attrs.m_Halign = hJustify;
836 attrs.m_Valign = vJustify;
837 attrs.m_Multiline = false;
838
839 aPlotter->PlotText( VECTOR2I( x, y ), nameColor, name, attrs, font,
840 GetFontMetrics() );
841 };
842
843 auto plotNum =
844 [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify,
845 GR_TEXT_V_ALIGN_T vJustify )
846 {
847 TEXT_ATTRIBUTES attrs;
848 attrs.m_StrokeWidth = numPenWidth;
849 attrs.m_Angle = angle;
851 attrs.m_Halign = hJustify;
852 attrs.m_Valign = vJustify;
853 attrs.m_Multiline = false;
854
855 aPlotter->PlotText( VECTOR2I( x, y ), numColor, number, attrs, font,
856 GetFontMetrics() );
857 };
858
859 // Draw the text inside, but the pin numbers outside.
860 if( aTextInside )
861 {
862 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
863 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) // It's a horizontal line.
864 {
865 if( aDrawPinName )
866 {
867 if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT )
868 {
869 plotName( x1 + aTextInside, y1, ANGLE_HORIZONTAL,
871 }
872 else // orient == PIN_LEFT
873 {
874 plotName( x1 - aTextInside, y1, ANGLE_HORIZONTAL,
876 }
877 }
878
879 if( aDrawPinNum )
880 {
881 plotNum( ( x1 + aPinPos.x) / 2, y1 - num_offset, ANGLE_HORIZONTAL,
883 }
884 }
885 else // It's a vertical line.
886 {
887 if( aPinOrient == PIN_ORIENTATION::PIN_DOWN )
888 {
889 if( aDrawPinName )
890 {
891 plotName( x1, y1 + aTextInside, ANGLE_VERTICAL,
893 }
894
895 if( aDrawPinNum )
896 {
897 plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL,
899 }
900 }
901 else /* PIN_UP */
902 {
903 if( aDrawPinName )
904 {
905 plotName( x1, y1 - aTextInside, ANGLE_VERTICAL,
907 }
908
909 if( aDrawPinNum )
910 {
911 plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL,
913 }
914 }
915 }
916 }
917 else // Draw num & text pin outside.
918 {
919 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
920 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
921 {
922 // It's an horizontal line.
923 if( aDrawPinName && aDrawPinNum )
924 {
925 plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
927
928 plotNum( ( x1 + aPinPos.x) / 2, y1 + num_offset, ANGLE_HORIZONTAL,
930 }
931 else if( aDrawPinName )
932 {
933 plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
935 }
936 else if( aDrawPinNum )
937 {
938 plotNum( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
940 }
941 }
942 else
943 {
944 // Its a vertical line.
945 if( aDrawPinName && aDrawPinNum )
946 {
947 plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
949
950 plotNum( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
952 }
953 else if( aDrawPinName )
954 {
955 plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
957 }
958 else if( aDrawPinNum )
959 {
960 plotNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
962 }
963 }
964 }
965}
966
967
969{
970 PIN_ORIENTATION orient;
971 VECTOR2I end; // position of pin end starting at 0,0 according to its orientation, length = 1
972
973 switch( GetOrientation() )
974 {
975 default:
976 case PIN_ORIENTATION::PIN_RIGHT: end.x = 1; break;
977 case PIN_ORIENTATION::PIN_UP: end.y = -1; break;
978 case PIN_ORIENTATION::PIN_DOWN: end.y = 1; break;
979 case PIN_ORIENTATION::PIN_LEFT: end.x = -1; break;
980 }
981
982 // = pos of end point, according to the symbol orientation.
983 end = aTransform.TransformCoordinate( end );
984 orient = PIN_ORIENTATION::PIN_UP;
985
986 if( end.x == 0 )
987 {
988 if( end.y > 0 )
989 orient = PIN_ORIENTATION::PIN_DOWN;
990 }
991 else
992 {
993 orient = PIN_ORIENTATION::PIN_RIGHT;
994
995 if( end.x < 0 )
996 orient = PIN_ORIENTATION::PIN_LEFT;
997 }
998
999 return orient;
1000}
1001
1002
1004{
1005 //return new SCH_PIN( *this );
1006 SCH_ITEM* newPin = new SCH_PIN( *this );
1007 wxASSERT( newPin->GetUnit() == m_unit && newPin->GetBodyStyle() == m_bodyStyle );
1008 return newPin;
1009}
1010
1011
1012void SCH_PIN::ChangeLength( int aLength )
1013{
1014 int lengthChange = GetLength() - aLength;
1015 int offsetX = 0;
1016 int offsetY = 0;
1017
1018 switch( m_orientation )
1019 {
1020 default:
1021 case PIN_ORIENTATION::PIN_RIGHT:
1022 offsetX = lengthChange;
1023 break;
1024 case PIN_ORIENTATION::PIN_LEFT:
1025 offsetX = -1 * lengthChange;
1026 break;
1027 case PIN_ORIENTATION::PIN_UP:
1028 offsetY = lengthChange;
1029 break;
1030 case PIN_ORIENTATION::PIN_DOWN:
1031 offsetY = -1 * lengthChange;
1032 break;
1033 }
1034
1035 m_position += VECTOR2I( offsetX, offsetY );
1036 m_length = aLength;
1037}
1038
1039
1040void SCH_PIN::Move( const VECTOR2I& aOffset )
1041{
1042 m_position += aOffset;
1043}
1044
1045
1047{
1048 m_position.x -= aCenter;
1049 m_position.x *= -1;
1050 m_position.x += aCenter;
1051
1052 if( m_orientation == PIN_ORIENTATION::PIN_RIGHT )
1053 m_orientation = PIN_ORIENTATION::PIN_LEFT;
1054 else if( m_orientation == PIN_ORIENTATION::PIN_LEFT )
1055 m_orientation = PIN_ORIENTATION::PIN_RIGHT;
1056}
1057
1058
1060{
1061 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1062 MirrorHorizontallyPin( aCenter );
1063}
1064
1065
1067{
1068 m_position.y -= aCenter;
1069 m_position.y *= -1;
1070 m_position.y += aCenter;
1071
1072 if( m_orientation == PIN_ORIENTATION::PIN_UP )
1073 m_orientation = PIN_ORIENTATION::PIN_DOWN;
1074 else if( m_orientation == PIN_ORIENTATION::PIN_DOWN )
1075 m_orientation = PIN_ORIENTATION::PIN_UP;
1076}
1077
1078
1079void SCH_PIN::MirrorVertically( int aCenter )
1080{
1081 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1082 MirrorVerticallyPin( aCenter );
1083}
1084
1085
1086void SCH_PIN::RotatePin( const VECTOR2I& aCenter, bool aRotateCCW )
1087{
1088 if( aRotateCCW )
1089 {
1090 RotatePoint( m_position, aCenter, ANGLE_90 );
1091
1092 switch( GetOrientation() )
1093 {
1094 default:
1095 case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_UP; break;
1096 case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_LEFT; break;
1097 case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break;
1098 case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break;
1099 }
1100 }
1101 else
1102 {
1103 RotatePoint( m_position, aCenter, -ANGLE_90 );
1104
1105 switch( GetOrientation() )
1106 {
1107 default:
1108 case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break;
1109 case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break;
1110 case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_UP; break;
1111 case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_LEFT; break;
1112 }
1113 }
1114}
1115
1116
1117void SCH_PIN::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
1118{
1119 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1120 RotatePin( aCenter, aRotateCCW );
1121}
1122
1123
1124void SCH_PIN::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
1125 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
1126{
1127 if( aBackground )
1128 return;
1129
1130 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1131
1132 if( !IsVisible() && !renderSettings->m_ShowHiddenPins )
1133 return;
1134
1135 const SYMBOL* part = GetParentSymbol();
1136 PIN_ORIENTATION orient = PinDrawOrient( renderSettings->m_Transform );
1137 VECTOR2I pos = renderSettings->TransformCoordinate( m_position ) + aOffset;
1138
1139 PlotPinType( aPlotter, pos, orient, aDimmed );
1140 PlotPinTexts( aPlotter, pos, orient, part->GetPinNameOffset(), part->GetShowPinNumbers(),
1141 part->GetShowPinNames(), aDimmed );
1142}
1143
1144
1145void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1146{
1147 wxString msg;
1148 SYMBOL* symbol = GetParentSymbol();
1149
1150 if( dynamic_cast<LIB_SYMBOL*>( symbol ) )
1151 {
1152 getSymbolEditorMsgPanelInfo( aFrame, aList );
1153 }
1154 else
1155 {
1156 aList.emplace_back( _( "Type" ), _( "Pin" ) );
1157
1158 if( symbol->GetUnitCount() )
1159 {
1161 wxString( "Undefined library pin." );
1162 aList.emplace_back( _( "Unit" ), msg );
1163 }
1164
1165 if( symbol->HasAlternateBodyStyle() )
1166 {
1168 wxString( "Undefined library pin." );
1169 aList.emplace_back( _( "Body Style" ), msg );
1170 }
1171 }
1172
1173 aList.emplace_back( _( "Name" ), UnescapeString( GetShownName() ) );
1174 aList.emplace_back( _( "Number" ), GetShownNumber() );
1175 aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( GetType() ) );
1176 aList.emplace_back( _( "Style" ), PinShapeGetText( GetShape() ) );
1177
1178 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
1179
1180 // Display pin length
1181 aList.emplace_back( _( "Length" ), aFrame->MessageTextFromValue( GetLength(), true ) );
1182
1183 aList.emplace_back( _( "Orientation" ), PinOrientationName( GetOrientation() ) );
1184
1185 if( dynamic_cast<LIB_SYMBOL*>( symbol ) )
1186 {
1187 aList.emplace_back( _( "Pos X" ), aFrame->MessageTextFromValue( GetPosition().x, true ) );
1188 aList.emplace_back( _( "Pos Y" ), aFrame->MessageTextFromValue( GetPosition().y, true ) );
1189 }
1190 else
1191 {
1192 SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
1193 SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
1194 SCH_SYMBOL* schsymbol = dynamic_cast<SCH_SYMBOL*>( symbol );
1195
1196 // Don't use GetShownText(); we want to see the variable references here
1197 aList.emplace_back( symbol->GetRef( currentSheet ),
1198 UnescapeString( schsymbol->GetField( FIELD_T::VALUE )->GetText() ) );
1199 }
1200
1201#if defined(DEBUG)
1202 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
1203 {
1204 SCH_CONNECTION* conn = Connection();
1205
1206 if( conn )
1207 conn->AppendInfoToMsgPanel( aList );
1208 }
1209#endif
1210}
1211
1212
1214{
1215 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1216
1217 if( aPath )
1218 m_net_name_map.erase( *aPath );
1219 else
1220 m_net_name_map.clear();
1221}
1222
1223
1224wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect )
1225{
1226 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1227
1228 // Need to check for parent as power symbol to make sure we aren't dealing
1229 // with legacy global power pins on non-power symbols
1230 if( IsGlobalPower() || IsLocalPower() )
1231 {
1232 SYMBOL* parent = GetLibPin()->GetParentSymbol();
1233
1234 if( parent->IsGlobalPower() || parent->IsLocalPower() )
1235 {
1236 return EscapeString( symbol->GetValue( true, &aPath, false ), CTX_NETNAME );
1237 }
1238 else
1239 {
1240 wxString tmp = m_libPin ? m_libPin->GetName() : wxString( "??" );
1241
1242 return EscapeString( tmp, CTX_NETNAME );
1243 }
1244 }
1245
1246 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1247
1248 auto it = m_net_name_map.find( aPath );
1249
1250 if( it != m_net_name_map.end() )
1251 {
1252 if( it->second.second == aForceNoConnect )
1253 return it->second.first;
1254 }
1255
1256 wxString name = "Net-(";
1257 bool unconnected = false;
1258
1259 if( aForceNoConnect || GetType() == ELECTRICAL_PINTYPE::PT_NC )
1260 {
1261 unconnected = true;
1262 name = ( "unconnected-(" );
1263 }
1264
1265 bool annotated = true;
1266
1267 std::vector<SCH_PIN*> pins = symbol->GetPins( &aPath );
1268 bool has_multiple = false;
1269
1270 for( SCH_PIN* pin : pins )
1271 {
1272 if( pin->GetShownName() == GetShownName()
1273 && pin->GetShownNumber() != GetShownNumber()
1274 && unconnected == ( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC ) )
1275 {
1276 has_multiple = true;
1277 break;
1278 }
1279 }
1280
1281 wxString libPinShownName = m_libPin ? m_libPin->GetShownName() : wxString( "??" );
1282 wxString libPinShownNumber = m_libPin ? m_libPin->GetShownNumber() : wxString( "??" );
1283
1284 // Use timestamp for unannotated symbols
1285 if( symbol->GetRef( &aPath, false ).Last() == '?' )
1286 {
1288
1289 wxString libPinNumber = m_libPin ? m_libPin->GetNumber() : wxString( "??" );
1290 name << "-Pad" << libPinNumber << ")";
1291 annotated = false;
1292 }
1293 else if( !libPinShownName.IsEmpty() && ( libPinShownName != libPinShownNumber ) )
1294 {
1295 // Pin names might not be unique between different units so we must have the
1296 // unit token in the reference designator
1297 name << symbol->GetRef( &aPath, true );
1298 name << "-" << EscapeString( libPinShownName, CTX_NETNAME );
1299
1300 if( unconnected || has_multiple )
1301 name << "-Pad" << EscapeString( libPinShownNumber, CTX_NETNAME );
1302
1303 name << ")";
1304 }
1305 else
1306 {
1307 // Pin numbers are unique, so we skip the unit token
1308 name << symbol->GetRef( &aPath, false );
1309 name << "-Pad" << EscapeString( libPinShownNumber, CTX_NETNAME ) << ")";
1310 }
1311
1312 if( annotated )
1313 m_net_name_map[ aPath ] = std::make_pair( name, aForceNoConnect );
1314
1315 return name;
1316}
1317
1318
1320{
1321 return GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
1322}
1323
1324
1325std::vector<int> SCH_PIN::ViewGetLayers() const
1326{
1329}
1330
1331
1332void SCH_PIN::validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText,
1333 EXTENTS_CACHE* aCache ) const
1334{
1335 if( aCache->m_Font == aFont
1336 && aCache->m_FontSize == aSize
1337 && aCache->m_Extents != VECTOR2I() )
1338 {
1339 return;
1340 }
1341
1342 aCache->m_Font = aFont;
1343 aCache->m_FontSize = aSize;
1344
1345 VECTOR2D fontSize( aSize, aSize );
1346 int penWidth = GetPenSizeForNormal( aSize );
1347
1348 aCache->m_Extents = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false,
1349 GetFontMetrics() );
1350}
1351
1352
1353BOX2I SCH_PIN::GetBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber,
1354 bool aIncludeElectricalType ) const
1355{
1356 // Just defer to the cache
1357 return m_layoutCache->GetPinBoundingBox( aIncludeLabelsOnInvisiblePins, aIncludeNameAndNumber,
1358 aIncludeElectricalType );
1359}
1360
1361
1363 const SCH_SHEET_PATH* aInstance ) const
1364{
1365 // Do not compare to ourself.
1366 if( aItem == this )
1367 return false;
1368
1369 const SCH_PIN* pin = dynamic_cast<const SCH_PIN*>( aItem );
1370
1371 // Don't compare against a different SCH_ITEM.
1372 wxCHECK( pin, false );
1373
1374 if( GetPosition() != pin->GetPosition() )
1375 return true;
1376
1377 if( GetNumber() != pin->GetNumber() )
1378 return true;
1379
1380 return GetName() != pin->GetName();
1381}
1382
1383
1385{
1386 if( !m_libPin )
1387 return false;
1388
1389 // Reciprocal checking is done in CONNECTION_GRAPH anyway
1390 return m_libPin->GetType() != ELECTRICAL_PINTYPE::PT_NC;
1391}
1392
1393
1395{
1396 if( m_libPin )
1397 return m_libPin->GetMenuImage();
1398
1400}
1401
1402
1403wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const
1404{
1405 return getItemDescription( aAlt );
1406}
1407
1408
1409wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
1410{
1411 if( m_libPin )
1412 {
1413 SCH_PIN::ALT localStorage;
1414 SCH_PIN::ALT* alt = nullptr;
1415
1416 if( !m_alt.IsEmpty() )
1417 {
1418 localStorage = m_libPin->GetAlt( m_alt );
1419 alt = &localStorage;
1420 }
1421
1422 wxString itemDesc = m_libPin ? m_libPin->GetItemDescription( aUnitsProvider, alt )
1423 : wxString( wxS( "Undefined library pin." ) );
1424
1425 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1426
1427 return wxString::Format( "Symbol %s %s",
1428 UnescapeString( symbol->GetField( FIELD_T::REFERENCE )->GetText() ),
1429 itemDesc );
1430 }
1431
1432 return getItemDescription( nullptr );
1433}
1434
1435
1436wxString SCH_PIN::getItemDescription( ALT* aAlt ) const
1437{
1438 wxString name = UnescapeString( aAlt ? aAlt->m_Name : GetShownName() );
1439 wxString electricalTypeName = ElectricalPinTypeGetText( aAlt ? aAlt->m_Type : m_type );
1440 wxString pinShapeName = PinShapeGetText( aAlt ? aAlt->m_Shape : m_shape );
1441
1442 if( IsVisible() )
1443 {
1444 if ( !name.IsEmpty() )
1445 {
1446 return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
1448 name,
1449 electricalTypeName,
1450 pinShapeName );
1451 }
1452 else
1453 {
1454 return wxString::Format( _( "Pin %s [%s, %s]" ),
1456 electricalTypeName,
1457 pinShapeName );
1458 }
1459 }
1460 else
1461 {
1462 if( !name.IsEmpty() )
1463 {
1464 return wxString::Format( _( "Hidden pin %s [%s, %s, %s]" ),
1466 name,
1467 electricalTypeName,
1468 pinShapeName );
1469 }
1470 else
1471 {
1472 return wxString::Format( _( "Hidden pin %s [%s, %s]" ),
1474 electricalTypeName,
1475 pinShapeName );
1476 }
1477 }
1478}
1479
1480
1481int SCH_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1482{
1483 // Ignore the UUID here.
1484 int retv = SCH_ITEM::compare( aOther, aCompareFlags | SCH_ITEM::COMPARE_FLAGS::EQUALITY );
1485
1486 if( retv )
1487 return retv;
1488
1489 const SCH_PIN* tmp = static_cast<const SCH_PIN*>( &aOther );
1490
1491 wxCHECK( tmp, -1 );
1492
1493 if( m_number != tmp->m_number )
1494 return m_number.Cmp( tmp->m_number );
1495
1496 if( m_position.x != tmp->m_position.x )
1497 return m_position.x - tmp->m_position.x;
1498
1499 if( m_position.y != tmp->m_position.y )
1500 return m_position.y - tmp->m_position.y;
1501
1502 if( dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
1503 {
1504 if( ( m_libPin == nullptr ) || ( tmp->m_libPin == nullptr ) )
1505 return -1;
1506
1507 retv = m_libPin->compare( *tmp->m_libPin );
1508
1509 if( retv )
1510 return retv;
1511
1512 retv = m_alt.Cmp( tmp->m_alt );
1513
1514 if( retv )
1515 return retv;
1516 }
1517
1518 if( dynamic_cast<const LIB_SYMBOL*>( GetParentSymbol() ) )
1519 {
1520 if( m_length != tmp->m_length )
1521 return m_length.value_or( 0 ) - tmp->m_length.value_or( 0 );
1522
1523 if( m_orientation != tmp->m_orientation )
1524 return static_cast<int>( m_orientation ) - static_cast<int>( tmp->m_orientation );
1525
1526 if( m_shape != tmp->m_shape )
1527 return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
1528
1529 if( m_type != tmp->m_type )
1530 return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
1531
1532 if( m_hidden != tmp->m_hidden )
1533 return m_hidden.value_or( false ) - tmp->m_hidden.value_or( false );
1534
1535 if( m_numTextSize != tmp->m_numTextSize )
1536 return m_numTextSize.value_or( 0 ) - tmp->m_numTextSize.value_or( 0 );
1537
1538 if( m_nameTextSize != tmp->m_nameTextSize )
1539 return m_nameTextSize.value_or( 0 ) - tmp->m_nameTextSize.value_or( 0 );
1540
1541 if( m_alternates.size() != tmp->m_alternates.size() )
1542 return static_cast<int>( m_alternates.size() - tmp->m_alternates.size() );
1543
1544 auto lhsItem = m_alternates.begin();
1545 auto rhsItem = tmp->m_alternates.begin();
1546
1547 while( lhsItem != m_alternates.end() )
1548 {
1549 const ALT& lhsAlt = lhsItem->second;
1550 const ALT& rhsAlt = rhsItem->second;
1551
1552 retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
1553
1554 if( retv )
1555 return retv;
1556
1557 if( lhsAlt.m_Type != rhsAlt.m_Type )
1558 return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
1559
1560 if( lhsAlt.m_Shape != rhsAlt.m_Shape )
1561 return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
1562
1563 ++lhsItem;
1564 ++rhsItem;
1565 }
1566 }
1567
1568 return 0;
1569}
1570
1571
1572double SCH_PIN::Similarity( const SCH_ITEM& aOther ) const
1573{
1574 if( aOther.m_Uuid == m_Uuid )
1575 return 1.0;
1576
1577 if( aOther.Type() != SCH_PIN_T )
1578 return 0.0;
1579
1580 const SCH_PIN* other = static_cast<const SCH_PIN*>( &aOther );
1581
1582 if( m_libPin )
1583 {
1584 if( m_number != other->m_number )
1585 return 0.0;
1586
1587 if( m_position != other->m_position )
1588 return 0.0;
1589
1590 return m_libPin->Similarity( *other->m_libPin );
1591 }
1592
1593 double similarity = SimilarityBase( aOther );
1594
1595 if( m_name != other->m_name )
1596 similarity *= 0.9;
1597
1598 if( m_number != other->m_number )
1599 similarity *= 0.9;
1600
1601 if( m_position != other->m_position )
1602 similarity *= 0.9;
1603
1604 if( m_length != other->m_length )
1605 similarity *= 0.9;
1606
1607 if( m_orientation != other->m_orientation )
1608 similarity *= 0.9;
1609
1610 if( m_shape != other->m_shape )
1611 similarity *= 0.9;
1612
1613 if( m_type != other->m_type )
1614 similarity *= 0.9;
1615
1616 if( m_hidden != other->m_hidden )
1617 similarity *= 0.9;
1618
1619 if( m_numTextSize != other->m_numTextSize )
1620 similarity *= 0.9;
1621
1622 if( m_nameTextSize != other->m_nameTextSize )
1623 similarity *= 0.9;
1624
1625 if( m_alternates.size() != other->m_alternates.size() )
1626 similarity *= 0.9;
1627
1628 return similarity;
1629}
1630
1631
1632std::ostream& SCH_PIN::operator<<( std::ostream& aStream )
1633{
1634 aStream << "SCH_PIN:" << std::endl
1635 << " Name: \"" << m_name << "\"" << std::endl
1636 << " Number: \"" << m_number << "\"" << std::endl
1637 << " Position: " << m_position << std::endl
1638 << " Length: " << GetLength() << std::endl
1639 << " Orientation: " << PinOrientationName( m_orientation ) << std::endl
1640 << " Shape: " << PinShapeGetText( m_shape ) << std::endl
1641 << " Type: " << ElectricalPinTypeGetText( m_type ) << std::endl
1642 << " Name Text Size: " << GetNameTextSize() << std::endl
1643 << " Number Text Size: " << GetNumberTextSize() << std::endl;
1644
1645 return aStream;
1646}
1647
1648
1649#if defined(DEBUG)
1650
1651void SCH_PIN::Show( int nestLevel, std::ostream& os ) const
1652{
1653 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
1654 << " num=\"" << m_number.mb_str()
1655 << '"' << "/>\n";
1656}
1657
1658#endif
1659
1660
1661void SCH_PIN::CalcEdit( const VECTOR2I& aPosition )
1662{
1663 if( IsMoving() )
1664 SetPosition( aPosition );
1665}
1666
1667
1668static struct SCH_PIN_DESC
1669{
1671 {
1672 auto& pinTypeEnum = ENUM_MAP<ELECTRICAL_PINTYPE>::Instance();
1673
1674 if( pinTypeEnum.Choices().GetCount() == 0 )
1675 {
1676 pinTypeEnum.Map( ELECTRICAL_PINTYPE::PT_INPUT, _HKI( "Input" ) )
1677 .Map( ELECTRICAL_PINTYPE::PT_OUTPUT, _HKI( "Output" ) )
1678 .Map( ELECTRICAL_PINTYPE::PT_BIDI, _HKI( "Bidirectional" ) )
1679 .Map( ELECTRICAL_PINTYPE::PT_TRISTATE, _HKI( "Tri-state" ) )
1680 .Map( ELECTRICAL_PINTYPE::PT_PASSIVE, _HKI( "Passive" ) )
1681 .Map( ELECTRICAL_PINTYPE::PT_NIC, _HKI( "Free" ) )
1682 .Map( ELECTRICAL_PINTYPE::PT_UNSPECIFIED, _HKI( "Unspecified" ) )
1683 .Map( ELECTRICAL_PINTYPE::PT_POWER_IN, _HKI( "Power input" ) )
1684 .Map( ELECTRICAL_PINTYPE::PT_POWER_OUT, _HKI( "Power output" ) )
1685 .Map( ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR, _HKI( "Open collector" ) )
1686 .Map( ELECTRICAL_PINTYPE::PT_OPENEMITTER, _HKI( "Open emitter" ) )
1687 .Map( ELECTRICAL_PINTYPE::PT_NC, _HKI( "Unconnected" ) );
1688 }
1689
1690 auto& pinShapeEnum = ENUM_MAP<GRAPHIC_PINSHAPE>::Instance();
1691
1692 if( pinShapeEnum.Choices().GetCount() == 0 )
1693 {
1694 pinShapeEnum.Map( GRAPHIC_PINSHAPE::LINE, _HKI( "Line" ) )
1695 .Map( GRAPHIC_PINSHAPE::INVERTED, _HKI( "Inverted" ) )
1696 .Map( GRAPHIC_PINSHAPE::CLOCK, _HKI( "Clock" ) )
1697 .Map( GRAPHIC_PINSHAPE::INVERTED_CLOCK, _HKI( "Inverted clock" ) )
1698 .Map( GRAPHIC_PINSHAPE::INPUT_LOW, _HKI( "Input low" ) )
1699 .Map( GRAPHIC_PINSHAPE::CLOCK_LOW, _HKI( "Clock low" ) )
1700 .Map( GRAPHIC_PINSHAPE::OUTPUT_LOW, _HKI( "Output low" ) )
1701 .Map( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, _HKI( "Falling edge clock" ) )
1702 .Map( GRAPHIC_PINSHAPE::NONLOGIC, _HKI( "NonLogic" ) );
1703 }
1704
1705 auto& orientationEnum = ENUM_MAP<PIN_ORIENTATION>::Instance();
1706
1707 if( orientationEnum.Choices().GetCount() == 0 )
1708 {
1709 orientationEnum.Map( PIN_ORIENTATION::PIN_RIGHT, _( "Right" ) )
1710 .Map( PIN_ORIENTATION::PIN_LEFT, _( "Left" ) )
1711 .Map( PIN_ORIENTATION::PIN_UP, _( "Up" ) )
1712 .Map( PIN_ORIENTATION::PIN_DOWN, _( "Down" ) );
1713 }
1714
1715 auto isSymbolEditor =
1716 []( INSPECTABLE* aItem ) -> bool
1717 {
1718 if( SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aItem ) )
1719 return dynamic_cast<LIB_SYMBOL*>( pin->GetParentSymbol() ) != nullptr;
1720
1721 return false;
1722 };
1723
1728
1729 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Name" ),
1731 .SetWriteableFunc( isSymbolEditor );
1732
1733 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Number" ),
1735 .SetWriteableFunc( isSymbolEditor );
1736
1738 _HKI( "Electrical Type" ),
1740 .SetWriteableFunc( isSymbolEditor );
1741
1743 _HKI( "Graphic Style" ),
1745 .SetWriteableFunc( isSymbolEditor );
1746
1747 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position X" ),
1748 &SCH_PIN::SetX, &SCH_PIN::GetX, PROPERTY_DISPLAY::PT_COORD ) )
1749 .SetAvailableFunc( isSymbolEditor );
1750
1751 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position Y" ),
1752 &SCH_PIN::SetY, &SCH_PIN::GetY, PROPERTY_DISPLAY::PT_COORD ) )
1753 .SetAvailableFunc( isSymbolEditor );
1754
1755 propMgr.AddProperty( new PROPERTY_ENUM<SCH_PIN, PIN_ORIENTATION>( _HKI( "Orientation" ),
1757 .SetWriteableFunc( isSymbolEditor );
1758
1759 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Length" ),
1761 PROPERTY_DISPLAY::PT_SIZE ) )
1762 .SetWriteableFunc( isSymbolEditor );
1763
1764 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Name Text Size" ),
1766 PROPERTY_DISPLAY::PT_SIZE ) )
1767 .SetAvailableFunc( isSymbolEditor );
1768
1769 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Number Text Size" ),
1771 PROPERTY_DISPLAY::PT_SIZE ) )
1772 .SetAvailableFunc( isSymbolEditor );
1773
1774 propMgr.AddProperty( new PROPERTY<SCH_PIN, bool>( _HKI( "Visible" ),
1776 .SetAvailableFunc( isSymbolEditor );
1777
1778 }
1780
1781
int color
Definition: DXF_plotter.cpp:60
const char * name
Definition: DXF_plotter.cpp:59
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
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 bool Contains(const Vec &aPoint) const
Definition: box2.h:168
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
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:95
const KIID m_Uuid
Definition: eda_item.h:494
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:107
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:505
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:382
EDA_ITEM * GetParent() const
Definition: eda_item.h:109
EDA_ITEM * m_parent
Linked list: Link (parent struct).
Definition: eda_item.h:506
bool IsMoving() const
Definition: eda_item.h:114
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
static ENUM_MAP< T > & Instance()
Definition: property.h:680
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
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
Definition: font.cpp:427
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
COLOR4D & Desaturate()
Removes color (in HSL model)
Definition: color4d.cpp:511
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition: color4d.h:295
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
int GetDefaultPenWidth() const
const wxString & GetDefaultFont() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
virtual const COLOR4D & GetBackgroundColor() const =0
Return current background color settings.
Definition: kiid.h:49
wxString AsString() const
Definition: kiid.cpp:246
Define a library symbol object.
Definition: lib_symbol.h:85
Definition: line.h:36
Container for data for KiCad programs.
Definition: pgm_base.h:103
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
A pin layout helper is a class that manages the layout of the parts of a pin on a schematic symbol:
Base plotter engine class.
Definition: plotter.h:105
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
void MoveTo(const VECTOR2I &pos)
Definition: plotter.h:247
void FinishTo(const VECTOR2I &pos)
Definition: plotter.h:257
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:136
bool GetColorMode() const
Definition: plotter.h:133
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
void LineTo(const VECTOR2I &pos)
Definition: plotter.h:252
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:754
virtual void SetColor(const COLOR4D &color)=0
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition: property.h:257
PROPERTY_BASE & SetWriteableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Definition: property.h:268
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.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString GetNetName() const
void AppendInfoToMsgPanel(std::vector< MSG_PANEL_ITEM > &aList) const
Adds information about the connection object to aList.
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
int m_unit
Definition: sch_item.h:711
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition: sch_item.cpp:103
int m_bodyStyle
Definition: sch_item.h:712
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition: sch_item.h:657
const SYMBOL * GetParentSymbol() const
Definition: sch_item.cpp:172
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:156
int GetBodyStyle() const
Definition: sch_item.h:243
static wxString GetUnitDescription(int aUnit)
Definition: sch_item.cpp:52
@ EQUALITY
Definition: sch_item.h:638
int GetUnit() const
Definition: sch_item.h:240
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:441
bool IsConnectivityDirty() const
Definition: sch_item.h:527
static wxString GetBodyStyleDescription(int aBodyStyle)
Definition: sch_item.cpp:61
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:224
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:489
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition: sch_item.cpp:498
SCH_LAYER_ID m_layer
Definition: sch_item.h:710
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:332
void getSymbolEditorMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Definition: sch_item.cpp:524
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_pin.cpp:1117
std::ostream & operator<<(std::ostream &aStream)
Definition: sch_pin.cpp:1632
void PlotPinTexts(PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed) const
Plot the pin name and number.
Definition: sch_pin.cpp:776
int GetNumberTextSize() const
Definition: sch_pin.cpp:582
int GetLength() const
Definition: sch_pin.cpp:291
std::optional< bool > m_hidden
Definition: sch_pin.h:362
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_pin.cpp:458
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_pin.cpp:1145
std::unique_ptr< PIN_LAYOUT_CACHE > m_layoutCache
The layout cache for this pin.
Definition: sch_pin.h:378
void MirrorVerticallyPin(int aCenter)
Definition: sch_pin.cpp:1066
void validateExtentsCache(KIFONT::FONT *aFont, int aSize, const wxString &aText, EXTENTS_CACHE *aCache) const
Definition: sch_pin.cpp:1332
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: sch_pin.cpp:1319
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_pin.cpp:1325
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: sch_pin.cpp:1661
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:545
std::optional< int > m_nameTextSize
Definition: sch_pin.h:366
PIN_ORIENTATION PinDrawOrient(const TRANSFORM &aTransform) const
Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), according to its orientation...
Definition: sch_pin.cpp:968
void SetVisible(bool aVisible)
Definition: sch_pin.h:113
int GetX() const
Definition: sch_pin.h:217
void ChangeLength(int aLength)
Change the length of a pin and adjust its position based on orientation.
Definition: sch_pin.cpp:1012
ALT GetAlt(const wxString &aAlt)
Definition: sch_pin.h:147
void SetX(int aX)
Definition: sch_pin.h:218
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
Definition: sch_pin.cpp:1362
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:225
wxString GetShownNumber() const
Definition: sch_pin.cpp:539
SCH_PIN * m_libPin
Definition: sch_pin.h:351
void Move(const VECTOR2I &aOffset) override
Move the item by aMoveVector to a new position.
Definition: sch_pin.cpp:1040
std::map< const SCH_SHEET_PATH, std::pair< wxString, bool > > m_net_name_map
Definition: sch_pin.h:382
PIN_ORIENTATION m_orientation
Definition: sch_pin.h:359
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition: sch_pin.h:92
void SetName(const wxString &aName)
Definition: sch_pin.cpp:415
bool IsGlobalPower() const
Return whether this pin forms a global power connection: i.e., is part of a power symbol and of type ...
Definition: sch_pin.cpp:363
wxString getItemDescription(ALT *aAlt) const
Definition: sch_pin.cpp:1436
bool IsVisible() const
Definition: sch_pin.cpp:383
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_pin.cpp:1384
std::optional< int > m_numTextSize
Definition: sch_pin.h:365
VECTOR2I GetPinRoot() const
Definition: sch_pin.cpp:606
bool IsLocalPower() const
Local power pin is the same except that it is sheet-local and it does not support the legacy hidden p...
Definition: sch_pin.cpp:370
ELECTRICAL_PINTYPE m_type
Definition: sch_pin.h:361
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_pin.cpp:1079
SCH_PIN * GetLibPin() const
Definition: sch_pin.h:88
void SetPosition(const VECTOR2I &aPos) override
Definition: sch_pin.h:214
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: sch_pin.cpp:1572
bool m_isDangling
Definition: sch_pin.h:371
void SetIsDangling(bool aIsDangling)
Definition: sch_pin.cpp:438
wxString GetElectricalTypeName() const
Definition: sch_pin.cpp:349
std::map< wxString, ALT > m_alternates
Definition: sch_pin.h:354
const wxString & GetName() const
Definition: sch_pin.cpp:397
void SetLength(int aLength)
Definition: sch_pin.h:98
bool IsDangling() const override
Definition: sch_pin.cpp:429
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_pin.cpp:1124
void MirrorHorizontally(int aCenter) override
These transforms have effect only if the pin has a LIB_SYMBOL as parent.
Definition: sch_pin.cpp:1059
std::recursive_mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition: sch_pin.h:381
PIN_ORIENTATION GetOrientation() const
Definition: sch_pin.cpp:256
wxString GetClass() const override
Return the class name.
Definition: sch_pin.h:73
void SetNumberTextSize(int aSize)
Definition: sch_pin.cpp:596
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: sch_pin.h:95
void RotatePin(const VECTOR2I &aCenter, bool aRotateCCW=true)
Definition: sch_pin.cpp:1086
VECTOR2I GetPosition() const override
Definition: sch_pin.cpp:248
wxString GetCanonicalElectricalTypeName() const
Definition: sch_pin.cpp:335
bool Replace(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) override
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: sch_pin.cpp:485
int GetNameTextSize() const
Definition: sch_pin.cpp:558
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_pin.cpp:1409
VECTOR2I m_position
Definition: sch_pin.h:357
GRAPHIC_PINSHAPE m_shape
Definition: sch_pin.h:360
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
The pin specific sort order is as follows:
Definition: sch_pin.cpp:1481
wxString GetShownName() const
Definition: sch_pin.cpp:528
void MirrorHorizontallyPin(int aCenter)
These transforms have always effects.
Definition: sch_pin.cpp:1046
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_pin.cpp:498
wxString m_name
Definition: sch_pin.h:363
wxString m_alt
Definition: sch_pin.h:367
void SetType(ELECTRICAL_PINTYPE aType)
Definition: sch_pin.cpp:325
const wxString & GetBaseName() const
Get the name without any alternates.
Definition: sch_pin.cpp:406
~SCH_PIN()
Definition: sch_pin.cpp:220
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:1213
void SetY(int aY)
Definition: sch_pin.h:220
SCH_PIN(LIB_SYMBOL *aParentSymbol)
Definition: sch_pin.cpp:100
bool IsStacked(const SCH_PIN *aPin) const
Definition: sch_pin.cpp:444
const wxString & GetNumber() const
Definition: sch_pin.h:123
wxString m_number
Definition: sch_pin.h:364
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_pin.cpp:1003
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_pin.h:178
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition: sch_pin.cpp:1224
std::optional< int > m_length
Definition: sch_pin.h:358
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:270
void PlotPinType(PLOTTER *aPlotter, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, bool aDimmed) const
Definition: sch_pin.cpp:629
int GetY() const
Definition: sch_pin.h:219
bool IsPower() const
Check if the pin is either a global or local power pin.
Definition: sch_pin.cpp:377
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:305
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_pin.cpp:1394
void SetNameTextSize(int aSize)
Definition: sch_pin.cpp:572
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition: sch_symbol.h:75
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
Definition: sch_symbol.cpp:781
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:611
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:813
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition: symbol.h:63
virtual bool IsGlobalPower() const =0
virtual int GetUnitCount() const =0
virtual bool IsLocalPower() const =0
virtual const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const =0
int GetPinNameOffset() const
Definition: symbol.h:153
virtual bool GetShowPinNames() const
Definition: symbol.h:159
virtual bool GetShowPinNumbers() const
Definition: symbol.h:165
virtual bool HasAlternateBodyStyle() const =0
Test if symbol has more than one body conversion type (DeMorgan).
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
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().
#define DEFAULT_PINNUM_SIZE
The default pin name size when creating pins(can be changed in preference menu)
#define DEFAULT_PINNAME_SIZE
The default selection highlight thickness (can be changed in preference menu)
#define DEFAULT_PIN_LENGTH
The default pin number size when creating pins(can be changed in preference menu)
#define _HKI(x)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:398
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:397
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define SHOW_ELEC_TYPE
Show pin electrical type.
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:60
@ LAYER_DANGLING
Definition: layer_ids.h:466
@ LAYER_PINNUM
Definition: layer_ids.h:447
@ LAYER_DEVICE
Definition: layer_ids.h:455
@ LAYER_PINNAM
Definition: layer_ids.h:448
@ LAYER_PIN
Definition: layer_ids.h:459
@ LAYER_OP_CURRENTS
Definition: layer_ids.h:490
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:483
STL namespace.
PGM_BASE * PgmOrNull()
Return a reference that can be nullptr when running a shared lib from a script, not from a kicad app.
Definition: pgm_base.cpp:1079
see class PGM_BASE
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:212
BITMAPS ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:226
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:240
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition: pin_type.cpp:268
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:36
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
PIN_ORIENTATION
The symbol library pin object orientations.
Definition: pin_type.h:80
@ PIN_RIGHT
The pin extends rightwards from the connection point.
GRAPHIC_PINSHAPE
Definition: pin_type.h:59
#define TYPE_HASH(x)
Definition: property.h:71
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:782
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
static int externalPinDecoSize(const RENDER_SETTINGS *aSettings, const SCH_PIN &aPin)
Utility for getting the size of the 'external' pin decorators (as a radius) i.e.
Definition: sch_pin.cpp:89
#define PIN_TEXT_MARGIN
Definition: sch_pin.cpp:44
static int internalPinDecoSize(const RENDER_SETTINGS *aSettings, const SCH_PIN &aPin)
Utility for getting the size of the 'internal' pin decorators (as a radius) i.e.
Definition: sch_pin.cpp:75
static struct SCH_PIN_DESC _SCH_PIN_DESC
#define TARGET_PIN_RADIUS
Definition: sch_pin.h:36
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_NETNAME
Definition: string_utils.h:53
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
wxString m_Name
Definition: sch_pin.h:44
GRAPHIC_PINSHAPE m_Shape
Definition: sch_pin.h:45
ELECTRICAL_PINTYPE m_Type
Definition: sch_pin.h:46
KIFONT::FONT * m_Font
Definition: sch_pin.h:321
int radius
VECTOR2I end
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_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
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
@ SCH_PIN_T
Definition: typeinfo.h:153
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695