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