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
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
73// i.e. the clock symbols (falling clock is actually external but is of
74// the same kind)
75
76static int internalPinDecoSize( const RENDER_SETTINGS* aSettings, const SCH_PIN &aPin )
77{
78 const SCH_RENDER_SETTINGS* settings = static_cast<const SCH_RENDER_SETTINGS*>( aSettings );
79
80 if( settings && settings->m_PinSymbolSize )
81 return settings->m_PinSymbolSize;
82
83 return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
84}
85
87// i.e. the negation circle, the polarity 'slopes' and the nonlogic
88// marker
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
182SCH_PIN::SCH_PIN( SCH_SYMBOL* aParentSymbol, const wxString& aNumber, const wxString& aAlt,
183 const KIID& aUuid ) :
184 SCH_ITEM( aParentSymbol, SCH_PIN_T ),
185 m_libPin( nullptr ),
186 m_orientation( PIN_ORIENTATION::INHERIT ),
187 m_shape( GRAPHIC_PINSHAPE::INHERIT ),
189 m_number( aNumber ),
190 m_alt( aAlt ),
191 m_isDangling( true ),
192 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
193{
194 wxASSERT( aParentSymbol );
195
196 const_cast<KIID&>( m_Uuid ) = aUuid;
198}
199
200
201SCH_PIN::SCH_PIN( const SCH_PIN& aPin ) :
202 SCH_ITEM( aPin ),
203 m_libPin( aPin.m_libPin ),
204 m_alternates( aPin.m_alternates ),
205 m_position( aPin.m_position ),
206 m_length( aPin.m_length ),
207 m_orientation( aPin.m_orientation ),
208 m_shape( aPin.m_shape ),
209 m_type( aPin.m_type ),
210 m_hidden( aPin.m_hidden ),
211 m_numTextSize( aPin.m_numTextSize ),
212 m_nameTextSize( aPin.m_nameTextSize ),
213 m_alt( aPin.m_alt ),
214 m_isDangling( aPin.m_isDangling ),
215 m_layoutCache( std::make_unique<PIN_LAYOUT_CACHE>( *this ) )
216{
217 SetName( aPin.m_name );
218 SetNumber( aPin.m_number );
219
220 m_layer = aPin.m_layer;
221}
222
223
225{
226}
227
228
230{
231 SCH_ITEM::operator=( aPin );
232
233 m_libPin = aPin.m_libPin;
235 m_alt = aPin.m_alt;
236 m_name = aPin.m_name;
237 m_number = aPin.m_number;
238 m_position = aPin.m_position;
239 m_length = aPin.m_length;
241 m_shape = aPin.m_shape;
242 m_type = aPin.m_type;
243 m_hidden = aPin.m_hidden;
247
248 return *this;
249}
250
251
253{
254 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
255 return symbol->GetTransform().TransformCoordinate( m_position ) + symbol->GetPosition();
256 else
257 return m_position;
258}
259
261{
262 if( m_orientation == PIN_ORIENTATION::INHERIT )
263 {
264 if( !m_libPin )
265 return PIN_ORIENTATION::PIN_RIGHT;
266
267 return m_libPin->GetOrientation();
268 }
269
270 return m_orientation;
271}
272
273
275{
276 if( !m_alt.IsEmpty() )
277 {
278 if( !m_libPin )
279 return GRAPHIC_PINSHAPE::LINE;
280
281 return m_libPin->GetAlt( m_alt ).m_Shape;
282 }
283 else if( m_shape == GRAPHIC_PINSHAPE::INHERIT )
284 {
285 if( !m_libPin )
286 return GRAPHIC_PINSHAPE::LINE;
287
288 return m_libPin->GetShape();
289 }
290
291 return m_shape;
292}
293
294
296{
297 if( !m_length.has_value() )
298 {
299 if( !m_libPin )
300 return 0;
301
302 return m_libPin->GetLength();
303 }
304
305 return m_length.value();
306}
307
308
310{
311 if( !m_alt.IsEmpty() )
312 {
313 if( !m_libPin )
314 return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
315
316 return m_libPin->GetAlt( m_alt ).m_Type;
317 }
318 else if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
319 {
320 if( !m_libPin )
321 return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
322
323 return m_libPin->GetType();
324 }
325
326 return m_type;
327}
328
330{
331 if( aType == m_type )
332 return;
333
334 m_type = aType;
336}
337
338
340{
341 if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
342 {
343 if( !m_libPin )
344 return GetCanonicalElectricalTypeName( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
345
347 }
348
350}
351
352
354{
355 if( m_type == ELECTRICAL_PINTYPE::PT_INHERIT )
356 {
357 if( !m_libPin )
358 return ElectricalPinTypeGetText( ELECTRICAL_PINTYPE::PT_UNSPECIFIED );
359
361 }
362
364}
365
366
368{
369 return GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN
370 && ( !IsVisible() || GetParentSymbol()->IsPower() );
371}
372
373
375{
376 if( !m_hidden.has_value() )
377 {
378 if( !m_libPin )
379 return true;
380
381 return m_libPin->IsVisible();
382 }
383
384 return !m_hidden.value();
385}
386
387
388const wxString& SCH_PIN::GetName() const
389{
390 if( !m_alt.IsEmpty() )
391 return m_alt;
392
393 return GetBaseName();
394}
395
396
397const wxString& SCH_PIN::GetBaseName() const
398{
399 if( m_libPin )
400 return m_libPin->GetBaseName();
401
402 return m_name;
403}
404
405
406void SCH_PIN::SetName( const wxString& aName )
407{
408 if( m_name == aName )
409 return;
410
411 m_name = aName;
412 // pin name string does not support spaces
413 m_name.Replace( wxT( " " ), wxT( "_" ) );
414
416}
417
418
420{
421 if( GetType() == ELECTRICAL_PINTYPE::PT_NC || GetType() == ELECTRICAL_PINTYPE::PT_NIC )
422 return false;
423
424 return m_isDangling;
425}
426
427
428void SCH_PIN::SetIsDangling( bool aIsDangling )
429{
430 m_isDangling = aIsDangling;
431}
432
433
434bool SCH_PIN::IsStacked( const SCH_PIN* aPin ) const
435{
436 bool isConnectableType_a = GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE
437 || GetType() == ELECTRICAL_PINTYPE::PT_NIC;
438 bool isConnectableType_b = aPin->GetType() == ELECTRICAL_PINTYPE::PT_PASSIVE
439 || aPin->GetType() == ELECTRICAL_PINTYPE::PT_NIC;
440
441 return m_parent == aPin->GetParent()
442 && GetPosition() == aPin->GetPosition()
443 && GetName() == aPin->GetName()
444 && ( GetType() == aPin->GetType() || isConnectableType_a || isConnectableType_b );
445}
446
447
448bool SCH_PIN::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
449{
450 const SCH_SEARCH_DATA& schSearchData =
451 dynamic_cast<const SCH_SEARCH_DATA&>( aSearchData );
452
453 if( !schSearchData.searchAllPins )
454 return false;
455
456 return EDA_ITEM::Matches( GetName(), aSearchData )
457 || EDA_ITEM::Matches( GetNumber(), aSearchData );
458}
459
460
461bool SCH_PIN::Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData )
462{
463 bool isReplaced = false;
464
465 /* TODO: waiting on a way to override pins in the schematic...
466 isReplaced |= EDA_ITEM::Replace( aSearchData, m_name );
467 isReplaced |= EDA_ITEM::Replace( aSearchData, m_number );
468 */
469
470 return isReplaced;
471}
472
473
474bool SCH_PIN::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
475{
476 // When looking for an "exact" hit aAccuracy will be 0 which works poorly if the pin has
477 // no pin number or name. Give it a floor.
478 if( Schematic() )
479 aAccuracy = std::max( aAccuracy, Schematic()->Settings().m_PinSymbolSize / 4 );
480
481 BOX2I rect = GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
482
483 return rect.Inflate( aAccuracy ).Contains( aPosition );
484}
485
486
487bool SCH_PIN::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
488{
490 return false;
491
492 BOX2I sel = aRect;
493
494 if ( aAccuracy )
495 sel.Inflate( aAccuracy );
496
497 if( aContained )
498 return sel.Contains( GetBoundingBox( false, false, false ) );
499
500 return sel.Intersects( GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE ) );
501}
502
503
504wxString SCH_PIN::GetShownName() const
505{
506 if( !m_alt.IsEmpty() )
507 return m_alt;
508 else if( m_libPin )
509 return m_libPin->GetShownName();
510
511 if( m_name == wxS( "~" ) )
512 return wxEmptyString;
513 else
514 return m_name;
515}
516
517
519{
520 if( m_number == wxS( "~" ) )
521 return wxEmptyString;
522 else
523 return m_number;
524}
525
526
527void SCH_PIN::SetNumber( const wxString& aNumber )
528{
529 if( m_number == aNumber )
530 return;
531
532 m_number = aNumber;
533 // pin number string does not support spaces
534 m_number.Replace( wxT( " " ), wxT( "_" ) );
535
537}
538
539
541{
542 if( !m_nameTextSize.has_value() )
543 {
544 if( !m_libPin )
546
547 return m_libPin->GetNameTextSize();
548 }
549
550 return m_nameTextSize.value();
551}
552
553
555{
556 if( aSize == m_nameTextSize )
557 return;
558
559 m_nameTextSize = aSize;
561}
562
563
565{
566 if( !m_numTextSize.has_value() )
567 {
568 if( !m_libPin )
570
571 return m_libPin->GetNumberTextSize();
572 }
573
574 return m_numTextSize.value();
575}
576
577
579{
580 if( aSize == m_numTextSize )
581 return;
582
583 m_numTextSize = aSize;
585}
586
587
589{
590 if( const SCH_SYMBOL* symbol = dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
591 {
592 const TRANSFORM& t = symbol->GetTransform();
593
594 if( !m_libPin )
595 return GetPosition();
596
597 return t.TransformCoordinate( m_libPin->GetPinRoot() ) + symbol->GetPosition();
598 }
599
600 switch( GetOrientation() )
601 {
602 default:
603 case PIN_ORIENTATION::PIN_RIGHT: return m_position + VECTOR2I( GetLength(), 0 );
604 case PIN_ORIENTATION::PIN_LEFT: return m_position + VECTOR2I( -GetLength(), 0 );
605 case PIN_ORIENTATION::PIN_UP: return m_position + VECTOR2I( 0, -GetLength() );
606 case PIN_ORIENTATION::PIN_DOWN: return m_position + VECTOR2I( 0, GetLength() );
607 }
608}
609
610
611void SCH_PIN::Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
612 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed )
613{
614 LIB_SYMBOL* part = dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() );
615
616 wxCHECK( part && aSettings, /* void */ );
617
618 /* Calculate pin orient taking in account the symbol orientation. */
619 PIN_ORIENTATION orient = PinDrawOrient( aSettings->m_Transform );
620
621 /* Calculate the pin position */
622 VECTOR2I pos1 = aSettings->TransformCoordinate( m_position ) + aOffset;
623
624 if( IsVisible() || aSettings->m_ShowHiddenFields )
625 {
626 printPinSymbol( aSettings, pos1, orient, aDimmed );
627
628 printPinTexts( aSettings, pos1, orient, part->GetPinNameOffset(),
629 aSettings->m_ShowPinNumbers || part->GetShowPinNumbers(),
630 aSettings->m_ShowPinNames || part->GetShowPinNames(),
631 aDimmed );
632
633 if( aSettings->m_ShowPinsElectricalType )
634 printPinElectricalTypeName( aSettings, pos1, orient, aDimmed );
635
636 if( aSettings->m_ShowConnectionPoints
637 && m_type != ELECTRICAL_PINTYPE::PT_NC
638 && m_type != ELECTRICAL_PINTYPE::PT_NIC )
639 {
640 wxDC* DC = aSettings->GetPrintDC();
642
643 COLOR4D bg = aSettings->GetBackgroundColor();
644
645 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
646 bg = COLOR4D::WHITE;
647
648 if( aDimmed )
649 {
650 color.Desaturate( );
651 color = color.Mix( bg, 0.5f );
652 }
653
654 GRCircle( DC, pos1, TARGET_PIN_RADIUS, 0, color );
655 }
656 }
657}
658
659
660void SCH_PIN::printPinSymbol( const SCH_RENDER_SETTINGS* aSettings, const VECTOR2I& aPos,
661 PIN_ORIENTATION aOrientation, bool aDimmed )
662{
663 wxDC* DC = aSettings->GetPrintDC();
664 int MapX1, MapY1, x1, y1;
665 int width = GetEffectivePenWidth( aSettings );
666 int posX = aPos.x;
667 int posY = aPos.y;
668 int len = GetLength();
670 COLOR4D bg = aSettings->GetBackgroundColor();
671
672 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
673 bg = COLOR4D::WHITE;
674
675 if( !IsVisible() )
676 bg = aSettings->GetLayerColor( LAYER_HIDDEN );
677
678 if( aDimmed )
679 {
680 color.Desaturate( );
681 color = color.Mix( bg, 0.5f );
682 }
683
684 MapX1 = MapY1 = 0;
685 x1 = posX;
686 y1 = posY;
687
688 switch( aOrientation )
689 {
690 case PIN_ORIENTATION::PIN_UP: y1 = posY - len; MapY1 = 1; break;
691 case PIN_ORIENTATION::PIN_DOWN: y1 = posY + len; MapY1 = -1; break;
692 case PIN_ORIENTATION::PIN_LEFT: x1 = posX - len; MapX1 = 1; break;
693 case PIN_ORIENTATION::PIN_RIGHT: x1 = posX + len; MapX1 = -1; break;
694 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); break;
695 }
696
697 if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
698 {
699 const int radius = externalPinDecoSize( aSettings, *this );
700 GRCircle( DC, VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius, width, color );
701
702 GRMoveTo( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 );
703 GRLineTo( DC, posX, posY, width, color );
704 }
705 else
706 {
707 GRMoveTo( x1, y1 );
708 GRLineTo( DC, posX, posY, width, color );
709 }
710
711 // Draw the clock shape (>)inside the symbol
712 if( m_shape == GRAPHIC_PINSHAPE::CLOCK
713 || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK
714 || m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK
715 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
716 {
717 const int clock_size = internalPinDecoSize( aSettings, *this );
718 if( MapY1 == 0 ) /* MapX1 = +- 1 */
719 {
720 GRMoveTo( x1, y1 + clock_size );
721 GRLineTo( DC, x1 - MapX1 * clock_size * 2, y1, width, color );
722 GRLineTo( DC, x1, y1 - clock_size, width, color );
723 }
724 else /* MapX1 = 0 */
725 {
726 GRMoveTo( x1 + clock_size, y1 );
727 GRLineTo( DC, x1, y1 - MapY1 * clock_size * 2, width, color );
728 GRLineTo( DC, x1 - clock_size, y1, width, color );
729 }
730 }
731
732 // Draw the active low (or H to L active transition)
733 if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW
734 || m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK
735 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
736 {
737 const int deco_size = externalPinDecoSize( aSettings, *this );
738 if( MapY1 == 0 ) /* MapX1 = +- 1 */
739 {
740 GRMoveTo( x1 + MapX1 * deco_size * 2, y1 );
741 GRLineTo( DC, x1 + MapX1 * deco_size * 2, y1 - deco_size * 2, width, color );
742 GRLineTo( DC, x1, y1, width, color );
743 }
744 else /* MapX1 = 0 */
745 {
746 GRMoveTo( x1, y1 + MapY1 * deco_size * 2 );
747 GRLineTo( DC, x1 - deco_size * 2, y1 + MapY1 * deco_size * 2, width, color );
748 GRLineTo( DC, x1, y1, width, color );
749 }
750 }
751
752 if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
753 {
754 const int deco_size = externalPinDecoSize( aSettings, *this );
755 if( MapY1 == 0 ) /* MapX1 = +- 1 */
756 {
757 GRMoveTo( x1, y1 - deco_size * 2 );
758 GRLineTo( DC, x1 + MapX1 * deco_size * 2, y1, width, color );
759 }
760 else /* MapX1 = 0 */
761 {
762 GRMoveTo( x1 - deco_size * 2, y1 );
763 GRLineTo( DC, x1, y1 + MapY1 * deco_size * 2, width, color );
764 }
765 }
766 else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
767 {
768 const int deco_size = externalPinDecoSize( aSettings, *this );
769 GRMoveTo( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size );
770 GRLineTo( DC, x1 + (MapX1 + MapY1) * deco_size, y1 + ( MapY1 - MapX1 ) * deco_size, width,
771 color );
772 GRMoveTo( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size );
773 GRLineTo( DC, x1 + (MapX1 - MapY1) * deco_size, y1 + ( MapY1 + MapX1 ) * deco_size, width,
774 color );
775 }
776
777 if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
778 {
779 const int deco_size = TARGET_PIN_RADIUS;
780 GRLine( DC, posX - deco_size, posY - deco_size, posX + deco_size, posY + deco_size, width,
781 color );
782 GRLine( DC, posX + deco_size, posY - deco_size, posX - deco_size, posY + deco_size, width,
783 color );
784 }
785}
786
787
788void SCH_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, const VECTOR2I& aPinPos,
789 PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum,
790 bool aDrawPinName, bool aDimmed )
791{
792 if( !aDrawPinName && !aDrawPinNum )
793 return;
794
795 KIFONT::FONT* font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), false, false );
796 wxString name = GetShownName();
797 wxString number = GetShownNumber();
800 int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN );
801 int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN );
802
803 /* Get the num and name colors */
804 COLOR4D nameColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNAM : LAYER_HIDDEN );
805 COLOR4D numColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNUM : LAYER_HIDDEN );
806 COLOR4D bg = aSettings->GetBackgroundColor();
807
808 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
809 bg = COLOR4D::WHITE;
810
811 if( !IsVisible() )
812 bg = aSettings->GetLayerColor( LAYER_HIDDEN );
813
814 if( aDimmed )
815 {
816 nameColor.Desaturate();
817 numColor.Desaturate();
818 nameColor = nameColor.Mix( bg, 0.5f );
819 numColor = numColor.Mix( bg, 0.5f );
820 }
821
822 int x1 = aPinPos.x;
823 int y1 = aPinPos.y;
824
825 switch( aPinOrient )
826 {
827 case PIN_ORIENTATION::PIN_UP: y1 -= GetLength(); break;
828 case PIN_ORIENTATION::PIN_DOWN: y1 += GetLength(); break;
829 case PIN_ORIENTATION::PIN_LEFT: x1 -= GetLength(); break;
830 case PIN_ORIENTATION::PIN_RIGHT: x1 += GetLength(); break;
831 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxT( "aPinOrient must be resolved!" ) ); break;
832 }
833
834 if( name.IsEmpty() || m_nameTextSize == 0 )
835 aDrawPinName = false;
836
837 if( number.IsEmpty() || m_numTextSize == 0 )
838 aDrawPinNum = false;
839
840 auto printName =
841 [&]( int x, int y, const EDA_ANGLE& angle, enum GR_TEXT_H_ALIGN_T hAlign,
842 enum GR_TEXT_V_ALIGN_T vAlign )
843 {
844 GRPrintText( aSettings->GetPrintDC(), VECTOR2I( x, y ), nameColor, name, angle,
845 nameSize, hAlign, vAlign, 0, false, false, font, GetFontMetrics() );
846 };
847
848 auto printNum =
849 [&]( int x, int y, const EDA_ANGLE& angle, enum GR_TEXT_H_ALIGN_T hAlign,
850 enum GR_TEXT_V_ALIGN_T vAlign )
851 {
852 GRPrintText( aSettings->GetPrintDC(), VECTOR2I( x, y ), numColor, number, angle,
853 numSize, hAlign, vAlign, 0, false, false, font, GetFontMetrics() );
854 };
855
856 if( aTextInside ) // Draw the text inside, but the pin numbers outside.
857 {
858 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
859 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
860 {
861 // It is an horizontal line
862 if( aDrawPinName )
863 {
864 if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT )
865 {
866 printName( x1 + aTextInside, y1, ANGLE_HORIZONTAL,
868 }
869 else // Orient == PIN_LEFT
870 {
871 printName( x1 - aTextInside, y1, ANGLE_HORIZONTAL,
873 }
874 }
875
876 if( aDrawPinNum )
877 {
878 printNum( ( x1 + aPinPos.x ) / 2, y1 - num_offset, ANGLE_HORIZONTAL,
880 }
881 }
882 else /* Its a vertical line. */
883 {
884 // Text is drawn from bottom to top (i.e. to negative value for Y axis)
885 if( aPinOrient == PIN_ORIENTATION::PIN_DOWN )
886 {
887 if( aDrawPinName )
888 {
889 printName( x1, y1 + aTextInside, ANGLE_VERTICAL,
891 }
892
893 if( aDrawPinNum )
894 {
895 printNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
897 }
898 }
899 else /* PIN_UP */
900 {
901 if( aDrawPinName )
902 {
903 printName( x1, y1 - aTextInside, ANGLE_VERTICAL,
905 }
906
907 if( aDrawPinNum )
908 {
909 printNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL,
911 }
912 }
913 }
914 }
915 else /**** Draw num & text pin outside ****/
916 {
917 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
918 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
919 {
920 /* Its an horizontal line. */
921 if( aDrawPinName && aDrawPinNum )
922 {
923 printName( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
925
926 printNum( ( x1 + aPinPos.x ) / 2, y1 + num_offset, ANGLE_HORIZONTAL,
928 }
929 else if( aDrawPinName )
930 {
931 printName( ( x1 + aPinPos.x ) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
933 }
934 else if( aDrawPinNum )
935 {
936 printNum( ( x1 + aPinPos.x ) / 2, y1 - num_offset, ANGLE_HORIZONTAL,
938 }
939 }
940 else /* Its a vertical line. */
941 {
942 if( aDrawPinName && aDrawPinNum )
943 {
944 printName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
946
947 printNum( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
949 }
950 else if( aDrawPinName )
951 {
952 printName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
954 }
955 else if( aDrawPinNum )
956 {
957 printNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
959 }
960 }
961 }
962}
963
964
966 const VECTOR2I& aPosition, PIN_ORIENTATION aOrientation,
967 bool aDimmed )
968{
969 wxDC* DC = aSettings->GetPrintDC();
970 wxString typeName = GetElectricalTypeName();
971
972 // Use a reasonable (small) size to draw the text
973 int textSize = ( GetNameTextSize() * 3 ) / 4;
974
975 #define ETXT_MAX_SIZE schIUScale.mmToIU( 0.7 )
976
977 if( textSize > ETXT_MAX_SIZE )
978 textSize = ETXT_MAX_SIZE;
979
980 // Use a reasonable pen size to draw the text
981 int pensize = textSize/6;
982
983 // Get a suitable color
985 COLOR4D bg = aSettings->GetBackgroundColor();
986
987 if( bg == COLOR4D::UNSPECIFIED || GetGRForceBlackPenState() )
988 bg = COLOR4D::WHITE;
989
990 if( !IsVisible() )
991 bg = aSettings->GetLayerColor( LAYER_HIDDEN );
992
993 if( aDimmed )
994 {
995 color.Desaturate( );
996 color = color.Mix( bg, 0.5f );
997 }
998
999 VECTOR2I txtpos = aPosition;
1000 int offset = schIUScale.mmToIU( 0.4 );
1002 EDA_ANGLE orient = ANGLE_HORIZONTAL;
1003 KIFONT::FONT* font = KIFONT::FONT::GetFont( aSettings->GetDefaultFont(), false, false );
1004
1005 switch( aOrientation )
1006 {
1007 case PIN_ORIENTATION::PIN_UP:
1008 txtpos.y += offset;
1009 orient = ANGLE_VERTICAL;
1010 hjustify = GR_TEXT_H_ALIGN_RIGHT;
1011 break;
1012
1013 case PIN_ORIENTATION::PIN_DOWN:
1014 txtpos.y -= offset;
1015 orient = ANGLE_VERTICAL;
1016 break;
1017
1018 case PIN_ORIENTATION::PIN_LEFT:
1019 txtpos.x += offset;
1020 break;
1021
1022 case PIN_ORIENTATION::PIN_RIGHT:
1023 txtpos.x -= offset;
1024 hjustify = GR_TEXT_H_ALIGN_RIGHT;
1025 break;
1026
1027 case PIN_ORIENTATION::INHERIT:
1028 wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) );
1029 break;
1030 }
1031
1032 GRPrintText( DC, txtpos, color, typeName, orient, VECTOR2I( textSize, textSize ), hjustify,
1033 GR_TEXT_V_ALIGN_CENTER, pensize, false, false, font, GetFontMetrics() );
1034}
1035
1036
1037void SCH_PIN::PlotPinType( PLOTTER *aPlotter, const VECTOR2I &aPosition,
1038 PIN_ORIENTATION aOrientation, bool aDimmed ) const
1039{
1040 int MapX1, MapY1, x1, y1;
1041 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1042 COLOR4D color = renderSettings->GetLayerColor( LAYER_PIN );
1043 COLOR4D bg = renderSettings->GetBackgroundColor();
1044 int penWidth = GetEffectivePenWidth( renderSettings );
1045 int pinLength = GetLength();
1046
1047 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
1048 bg = COLOR4D::WHITE;
1049
1050 if( aDimmed )
1051 {
1052 color.Desaturate( );
1053 color = color.Mix( bg, 0.5f );
1054 }
1055
1056 aPlotter->SetColor( color );
1057 aPlotter->SetCurrentLineWidth( penWidth );
1058
1059 MapX1 = MapY1 = 0;
1060 x1 = aPosition.x; y1 = aPosition.y;
1061
1062 switch( aOrientation )
1063 {
1064 case PIN_ORIENTATION::PIN_UP: y1 = aPosition.y - pinLength; MapY1 = 1; break;
1065 case PIN_ORIENTATION::PIN_DOWN: y1 = aPosition.y + pinLength; MapY1 = -1; break;
1066 case PIN_ORIENTATION::PIN_LEFT: x1 = aPosition.x - pinLength; MapX1 = 1; break;
1067 case PIN_ORIENTATION::PIN_RIGHT: x1 = aPosition.x + pinLength; MapX1 = -1; break;
1068 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aOrientation must be resolved!" ) ); break;
1069 }
1070
1071 if( m_shape == GRAPHIC_PINSHAPE::INVERTED || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK )
1072 {
1073 const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1074 aPlotter->Circle( VECTOR2I( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
1075 FILL_T::NO_FILL, penWidth );
1076
1077 aPlotter->MoveTo( VECTOR2I( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
1078 aPlotter->FinishTo( aPosition );
1079 }
1080 else if( m_shape == GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK )
1081 {
1082 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
1083 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1084 {
1085 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
1086 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
1087 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
1088 }
1089 else /* MapX1 = 0 */
1090 {
1091 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
1092 aPlotter->LineTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
1093 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
1094 }
1095
1096 aPlotter->MoveTo( VECTOR2I( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
1097 aPlotter->FinishTo( aPosition );
1098 }
1099 else
1100 {
1101 aPlotter->MoveTo( VECTOR2I( x1, y1 ) );
1102 aPlotter->FinishTo( aPosition );
1103 }
1104
1105 if( m_shape == GRAPHIC_PINSHAPE::CLOCK
1106 || m_shape == GRAPHIC_PINSHAPE::INVERTED_CLOCK
1107 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW )
1108 {
1109 const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
1110 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1111 {
1112 aPlotter->MoveTo( VECTOR2I( x1, y1 + deco_size ) );
1113 aPlotter->LineTo( VECTOR2I( x1 - MapX1 * deco_size * 2, y1 ) );
1114 aPlotter->FinishTo( VECTOR2I( x1, y1 - deco_size ) );
1115 }
1116 else /* MapX1 = 0 */
1117 {
1118 aPlotter->MoveTo( VECTOR2I( x1 + deco_size, y1 ) );
1119 aPlotter->LineTo( VECTOR2I( x1, y1 - MapY1 * deco_size * 2 ) );
1120 aPlotter->FinishTo( VECTOR2I( x1 - deco_size, y1 ) );
1121 }
1122 }
1123
1124 if( m_shape == GRAPHIC_PINSHAPE::INPUT_LOW
1125 || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
1126 {
1127 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1128
1129 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1130 {
1131 aPlotter->MoveTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 ) );
1132 aPlotter->LineTo( VECTOR2I( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
1133 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
1134 }
1135 else /* MapX1 = 0 */
1136 {
1137 aPlotter->MoveTo( VECTOR2I( x1, y1 + MapY1 * deco_size * 2 ) );
1138 aPlotter->LineTo( VECTOR2I( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
1139 aPlotter->FinishTo( VECTOR2I( x1, y1 ) );
1140 }
1141 }
1142
1143 if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1144 {
1145 const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1146
1147 if( MapY1 == 0 ) /* MapX1 = +- 1 */
1148 {
1149 aPlotter->MoveTo( VECTOR2I( x1, y1 - symbol_size * 2 ) );
1150 aPlotter->FinishTo( VECTOR2I( x1 + MapX1 * symbol_size * 2, y1 ) );
1151 }
1152 else /* MapX1 = 0 */
1153 {
1154 aPlotter->MoveTo( VECTOR2I( x1 - symbol_size * 2, y1 ) );
1155 aPlotter->FinishTo( VECTOR2I( x1, y1 + MapY1 * symbol_size * 2 ) );
1156 }
1157 }
1158 else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
1159 {
1160 const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
1161 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 + MapY1 ) * deco_size,
1162 y1 - ( MapY1 - MapX1 ) * deco_size ) );
1163 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 + MapY1 ) * deco_size,
1164 y1 + ( MapY1 - MapX1 ) * deco_size ) );
1165 aPlotter->MoveTo( VECTOR2I( x1 - ( MapX1 - MapY1 ) * deco_size,
1166 y1 - ( MapY1 + MapX1 ) * deco_size ) );
1167 aPlotter->FinishTo( VECTOR2I( x1 + ( MapX1 - MapY1 ) * deco_size,
1168 y1 + ( MapY1 + MapX1 ) * deco_size ) );
1169 }
1170
1171 if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
1172 {
1173 const int deco_size = TARGET_PIN_RADIUS;
1174 const int ex1 = aPosition.x;
1175 const int ey1 = aPosition.y;
1176 aPlotter->MoveTo( VECTOR2I( ex1 - deco_size, ey1 - deco_size ) );
1177 aPlotter->FinishTo( VECTOR2I( ex1 + deco_size, ey1 + deco_size ) );
1178 aPlotter->MoveTo( VECTOR2I( ex1 + deco_size, ey1 - deco_size ) );
1179 aPlotter->FinishTo( VECTOR2I( ex1 - deco_size, ey1 + deco_size ) );
1180 }
1181}
1182
1183
1184void SCH_PIN::PlotPinTexts( PLOTTER *aPlotter, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient,
1185 int aTextInside, bool aDrawPinNum, bool aDrawPinName,
1186 bool aDimmed ) const
1187{
1188 RENDER_SETTINGS* settings = aPlotter->RenderSettings();
1189 KIFONT::FONT* font = KIFONT::FONT::GetFont( settings->GetDefaultFont(), false, false );
1190 wxString name = GetShownName();
1191 wxString number = GetShownNumber();
1192
1193 if( name.IsEmpty() || m_nameTextSize == 0 )
1194 aDrawPinName = false;
1195
1196 if( number.IsEmpty() || m_numTextSize == 0 )
1197 aDrawPinNum = false;
1198
1199 if( !aDrawPinNum && !aDrawPinName )
1200 return;
1201
1202 int namePenWidth = settings->GetDefaultPenWidth();
1203 int numPenWidth = settings->GetDefaultPenWidth();
1204 int name_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + namePenWidth;
1205 int num_offset = schIUScale.MilsToIU( PIN_TEXT_MARGIN ) + numPenWidth;
1206
1207 /* Get the num and name colors */
1208 COLOR4D nameColor = settings->GetLayerColor( LAYER_PINNAM );
1209 COLOR4D numColor = settings->GetLayerColor( LAYER_PINNUM );
1210 COLOR4D bg = settings->GetBackgroundColor();
1211
1212 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
1213 bg = COLOR4D::WHITE;
1214
1215 if( aDimmed )
1216 {
1217 nameColor.Desaturate( );
1218 numColor.Desaturate( );
1219 nameColor = nameColor.Mix( bg, 0.5f );
1220 numColor = numColor.Mix( bg, 0.5f );
1221 }
1222
1223 int x1 = aPinPos.x;
1224 int y1 = aPinPos.y;
1225
1226 switch( aPinOrient )
1227 {
1228 case PIN_ORIENTATION::PIN_UP: y1 -= GetLength(); break;
1229 case PIN_ORIENTATION::PIN_DOWN: y1 += GetLength(); break;
1230 case PIN_ORIENTATION::PIN_LEFT: x1 -= GetLength(); break;
1231 case PIN_ORIENTATION::PIN_RIGHT: x1 += GetLength(); break;
1232 case PIN_ORIENTATION::INHERIT: wxFAIL_MSG( wxS( "aPinOrient must be resolved!" ) ); break;
1233 }
1234
1235 auto plotName =
1236 [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify,
1237 GR_TEXT_V_ALIGN_T vJustify )
1238 {
1239 TEXT_ATTRIBUTES attrs;
1240 attrs.m_StrokeWidth = namePenWidth;
1241 attrs.m_Angle = angle;
1243 attrs.m_Halign = hJustify;
1244 attrs.m_Valign = vJustify;
1245 attrs.m_Multiline = false;
1246
1247 aPlotter->PlotText( VECTOR2I( x, y ), nameColor, name, attrs, font, GetFontMetrics() );
1248 };
1249
1250 auto plotNum =
1251 [&]( int x, int y, const EDA_ANGLE& angle, GR_TEXT_H_ALIGN_T hJustify,
1252 GR_TEXT_V_ALIGN_T vJustify )
1253 {
1254 TEXT_ATTRIBUTES attrs;
1255 attrs.m_StrokeWidth = numPenWidth;
1256 attrs.m_Angle = angle;
1258 attrs.m_Halign = hJustify;
1259 attrs.m_Valign = vJustify;
1260 attrs.m_Multiline = false;
1261
1262 aPlotter->PlotText( VECTOR2I( x, y ), numColor, number, attrs, font, GetFontMetrics() );
1263 };
1264
1265 /* Draw the text inside, but the pin numbers outside. */
1266 if( aTextInside )
1267 {
1268 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
1269 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) ) /* Its an horizontal line. */
1270 {
1271 if( aDrawPinName )
1272 {
1273 if( aPinOrient == PIN_ORIENTATION::PIN_RIGHT )
1274 {
1275 plotName( x1 + aTextInside, y1, ANGLE_HORIZONTAL,
1277 }
1278 else // orient == PIN_LEFT
1279 {
1280 plotName( x1 - aTextInside, y1, ANGLE_HORIZONTAL,
1282 }
1283 }
1284
1285 if( aDrawPinNum )
1286 {
1287 plotNum( ( x1 + aPinPos.x) / 2, y1 - num_offset, ANGLE_HORIZONTAL,
1289 }
1290 }
1291 else /* Its a vertical line. */
1292 {
1293 if( aPinOrient == PIN_ORIENTATION::PIN_DOWN )
1294 {
1295 if( aDrawPinName )
1296 {
1297 plotName( x1, y1 + aTextInside, ANGLE_VERTICAL,
1299 }
1300
1301 if( aDrawPinNum )
1302 {
1303 plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL,
1305 }
1306 }
1307 else /* PIN_UP */
1308 {
1309 if( aDrawPinName )
1310 {
1311 plotName( x1, y1 - aTextInside, ANGLE_VERTICAL,
1313 }
1314
1315 if( aDrawPinNum )
1316 {
1317 plotNum( x1 - num_offset, ( y1 + aPinPos.y) / 2, ANGLE_VERTICAL,
1319 }
1320 }
1321 }
1322 }
1323 else /* Draw num & text pin outside */
1324 {
1325 if( ( aPinOrient == PIN_ORIENTATION::PIN_LEFT )
1326 || ( aPinOrient == PIN_ORIENTATION::PIN_RIGHT ) )
1327 {
1328 /* Its an horizontal line. */
1329 if( aDrawPinName && aDrawPinNum )
1330 {
1331 plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1333
1334 plotNum( ( x1 + aPinPos.x) / 2, y1 + num_offset, ANGLE_HORIZONTAL,
1336 }
1337 else if( aDrawPinName )
1338 {
1339 plotName( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1341 }
1342 else if( aDrawPinNum )
1343 {
1344 plotNum( ( x1 + aPinPos.x) / 2, y1 - name_offset, ANGLE_HORIZONTAL,
1346 }
1347 }
1348 else
1349 {
1350 /* Its a vertical line. */
1351 if( aDrawPinName && aDrawPinNum )
1352 {
1353 plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1355
1356 plotNum( x1 + num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1358 }
1359 else if( aDrawPinName )
1360 {
1361 plotName( x1 - name_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1363 }
1364 else if( aDrawPinNum )
1365 {
1366 plotNum( x1 - num_offset, ( y1 + aPinPos.y ) / 2, ANGLE_VERTICAL,
1368 }
1369 }
1370 }
1371}
1372
1373
1375{
1376 PIN_ORIENTATION orient;
1377 VECTOR2I end; // position of pin end starting at 0,0 according to its orientation, length = 1
1378
1379 switch( GetOrientation() )
1380 {
1381 default:
1382 case PIN_ORIENTATION::PIN_RIGHT: end.x = 1; break;
1383 case PIN_ORIENTATION::PIN_UP: end.y = -1; break;
1384 case PIN_ORIENTATION::PIN_DOWN: end.y = 1; break;
1385 case PIN_ORIENTATION::PIN_LEFT: end.x = -1; break;
1386 }
1387
1388 // = pos of end point, according to the symbol orientation.
1389 end = aTransform.TransformCoordinate( end );
1390 orient = PIN_ORIENTATION::PIN_UP;
1391
1392 if( end.x == 0 )
1393 {
1394 if( end.y > 0 )
1395 orient = PIN_ORIENTATION::PIN_DOWN;
1396 }
1397 else
1398 {
1399 orient = PIN_ORIENTATION::PIN_RIGHT;
1400
1401 if( end.x < 0 )
1402 orient = PIN_ORIENTATION::PIN_LEFT;
1403 }
1404
1405 return orient;
1406}
1407
1408
1410{
1411 //return new SCH_PIN( *this );
1412 SCH_ITEM* newPin = new SCH_PIN( *this );
1413 wxASSERT( newPin->GetUnit() == m_unit && newPin->GetBodyStyle() == m_bodyStyle );
1414 return newPin;
1415}
1416
1417
1418void SCH_PIN::ChangeLength( int aLength )
1419{
1420 int lengthChange = GetLength() - aLength;
1421 int offsetX = 0;
1422 int offsetY = 0;
1423
1424 switch( m_orientation )
1425 {
1426 default:
1427 case PIN_ORIENTATION::PIN_RIGHT:
1428 offsetX = lengthChange;
1429 break;
1430 case PIN_ORIENTATION::PIN_LEFT:
1431 offsetX = -1 * lengthChange;
1432 break;
1433 case PIN_ORIENTATION::PIN_UP:
1434 offsetY = lengthChange;
1435 break;
1436 case PIN_ORIENTATION::PIN_DOWN:
1437 offsetY = -1 * lengthChange;
1438 break;
1439 }
1440
1441 m_position += VECTOR2I( offsetX, offsetY );
1442 m_length = aLength;
1443}
1444
1445
1446void SCH_PIN::Move( const VECTOR2I& aOffset )
1447{
1448 m_position += aOffset;
1449}
1450
1451
1453{
1454 m_position.x -= aCenter;
1455 m_position.x *= -1;
1456 m_position.x += aCenter;
1457
1458 if( m_orientation == PIN_ORIENTATION::PIN_RIGHT )
1459 m_orientation = PIN_ORIENTATION::PIN_LEFT;
1460 else if( m_orientation == PIN_ORIENTATION::PIN_LEFT )
1461 m_orientation = PIN_ORIENTATION::PIN_RIGHT;
1462}
1463
1464
1466{
1467 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1468 MirrorHorizontallyPin( aCenter );
1469}
1470
1471
1473{
1474 m_position.y -= aCenter;
1475 m_position.y *= -1;
1476 m_position.y += aCenter;
1477
1478 if( m_orientation == PIN_ORIENTATION::PIN_UP )
1479 m_orientation = PIN_ORIENTATION::PIN_DOWN;
1480 else if( m_orientation == PIN_ORIENTATION::PIN_DOWN )
1481 m_orientation = PIN_ORIENTATION::PIN_UP;
1482}
1483
1484
1485void SCH_PIN::MirrorVertically( int aCenter )
1486{
1487 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1488 MirrorVerticallyPin( aCenter );
1489}
1490
1491
1492void SCH_PIN::RotatePin( const VECTOR2I& aCenter, bool aRotateCCW )
1493{
1494 if( aRotateCCW )
1495 {
1496 RotatePoint( m_position, aCenter, ANGLE_90 );
1497
1498 switch( GetOrientation() )
1499 {
1500 default:
1501 case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_UP; break;
1502 case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_LEFT; break;
1503 case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break;
1504 case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break;
1505 }
1506 }
1507 else
1508 {
1509 RotatePoint( m_position, aCenter, -ANGLE_90 );
1510
1511 switch( GetOrientation() )
1512 {
1513 default:
1514 case PIN_ORIENTATION::PIN_RIGHT: m_orientation = PIN_ORIENTATION::PIN_DOWN; break;
1515 case PIN_ORIENTATION::PIN_UP: m_orientation = PIN_ORIENTATION::PIN_RIGHT; break;
1516 case PIN_ORIENTATION::PIN_LEFT: m_orientation = PIN_ORIENTATION::PIN_UP; break;
1517 case PIN_ORIENTATION::PIN_DOWN: m_orientation = PIN_ORIENTATION::PIN_LEFT; break;
1518 }
1519 }
1520}
1521
1522
1523void SCH_PIN::Rotate( const VECTOR2I& aCenter, bool aRotateCCW )
1524{
1525 if( dynamic_cast<LIB_SYMBOL*>( GetParentSymbol() ) )
1526 RotatePin( aCenter, aRotateCCW );
1527}
1528
1529
1530void SCH_PIN::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
1531 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
1532{
1533 if( aBackground )
1534 return;
1535
1536 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
1537
1538 if( !IsVisible() && !renderSettings->m_ShowHiddenPins )
1539 return;
1540
1541 const SYMBOL* part = GetParentSymbol();
1542 PIN_ORIENTATION orient = PinDrawOrient( renderSettings->m_Transform );
1543 VECTOR2I pos = renderSettings->TransformCoordinate( m_position ) + aOffset;
1544
1545 PlotPinType( aPlotter, pos, orient, aDimmed );
1546 PlotPinTexts( aPlotter, pos, orient, part->GetPinNameOffset(), part->GetShowPinNumbers(),
1547 part->GetShowPinNames(), aDimmed );
1548}
1549
1550
1551void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1552{
1553 wxString msg;
1554 SYMBOL* symbol = GetParentSymbol();
1555
1556 if( dynamic_cast<LIB_SYMBOL*>( symbol ) )
1557 {
1558 getSymbolEditorMsgPanelInfo( aFrame, aList );
1559 }
1560 else
1561 {
1562 aList.emplace_back( _( "Type" ), _( "Pin" ) );
1563
1564 if( symbol->GetUnitCount() )
1565 {
1567 wxString( "Undefined library pin." );
1568 aList.emplace_back( _( "Unit" ), msg );
1569 }
1570
1571 if( symbol->HasAlternateBodyStyle() )
1572 {
1574 wxString( "Undefined library pin." );
1575 aList.emplace_back( _( "Body Style" ), msg );
1576 }
1577 }
1578
1579 aList.emplace_back( _( "Name" ), UnescapeString( GetShownName() ) );
1580 aList.emplace_back( _( "Number" ), GetShownNumber() );
1581 aList.emplace_back( _( "Type" ), ElectricalPinTypeGetText( GetType() ) );
1582 aList.emplace_back( _( "Style" ), PinShapeGetText( GetShape() ) );
1583
1584 aList.emplace_back( _( "Visible" ), IsVisible() ? _( "Yes" ) : _( "No" ) );
1585
1586 // Display pin length
1587 aList.emplace_back( _( "Length" ), aFrame->MessageTextFromValue( GetLength(), true ) );
1588
1589 aList.emplace_back( _( "Orientation" ), PinOrientationName( GetOrientation() ) );
1590
1591 if( dynamic_cast<LIB_SYMBOL*>( symbol ) )
1592 {
1593 aList.emplace_back( _( "Pos X" ), aFrame->MessageTextFromValue( GetPosition().x, true ) );
1594 aList.emplace_back( _( "Pos Y" ), aFrame->MessageTextFromValue( GetPosition().y, true ) );
1595 }
1596 else
1597 {
1598 SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
1599 SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
1600 SCH_SYMBOL* schsymbol = dynamic_cast<SCH_SYMBOL*>( symbol );
1601
1602 // Don't use GetShownText(); we want to see the variable references here
1603 aList.emplace_back( symbol->GetRef( currentSheet ),
1604 UnescapeString( schsymbol->GetField( VALUE_FIELD )->GetText() ) );
1605 }
1606
1607#if defined(DEBUG)
1608 if( !IsConnectivityDirty() && dynamic_cast<SCH_EDIT_FRAME*>( aFrame ) )
1609 {
1610 SCH_CONNECTION* conn = Connection();
1611
1612 if( conn )
1613 conn->AppendInfoToMsgPanel( aList );
1614 }
1615#endif
1616}
1617
1618
1620{
1621 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1622
1623 if( aPath )
1624 m_net_name_map.erase( *aPath );
1625 else
1626 m_net_name_map.clear();
1627}
1628
1629
1630wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath, bool aForceNoConnect )
1631{
1632 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1633
1634 // Need to check for parent as power symbol to make sure we aren't dealing
1635 // with legacy global power pins on non-power symbols
1636 if( IsGlobalPower() )
1637 {
1638 if( GetLibPin()->GetParentSymbol()->IsPower() )
1639 {
1640 return EscapeString( symbol->GetValue( true, &aPath, false ), CTX_NETNAME );
1641 }
1642 else
1643 {
1644 wxString tmp = m_libPin ? m_libPin->GetName() : wxString( "??" );
1645
1646 return EscapeString( tmp, CTX_NETNAME );
1647 }
1648 }
1649
1650 std::lock_guard<std::recursive_mutex> lock( m_netmap_mutex );
1651
1652 auto it = m_net_name_map.find( aPath );
1653
1654 if( it != m_net_name_map.end() )
1655 {
1656 if( it->second.second == aForceNoConnect )
1657 return it->second.first;
1658 }
1659
1660 wxString name = "Net-(";
1661 bool unconnected = false;
1662
1663 if( aForceNoConnect || GetType() == ELECTRICAL_PINTYPE::PT_NC )
1664 {
1665 unconnected = true;
1666 name = ( "unconnected-(" );
1667 }
1668
1669 bool annotated = true;
1670
1671 std::vector<SCH_PIN*> pins = symbol->GetPins( &aPath );
1672 bool has_multiple = false;
1673
1674 for( SCH_PIN* pin : pins )
1675 {
1676 if( pin->GetShownName() == GetShownName()
1677 && pin->GetShownNumber() != GetShownNumber()
1678 && unconnected == ( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC ) )
1679 {
1680 has_multiple = true;
1681 break;
1682 }
1683 }
1684
1685 wxString libPinShownName = m_libPin ? m_libPin->GetShownName() : wxString( "??" );
1686 wxString libPinShownNumber = m_libPin ? m_libPin->GetShownNumber() : wxString( "??" );
1687
1688 // Use timestamp for unannotated symbols
1689 if( symbol->GetRef( &aPath, false ).Last() == '?' )
1690 {
1692
1693 wxString libPinNumber = m_libPin ? m_libPin->GetNumber() : wxString( "??" );
1694 name << "-Pad" << libPinNumber << ")";
1695 annotated = false;
1696 }
1697 else if( !libPinShownName.IsEmpty() && ( libPinShownName != libPinShownNumber ) )
1698 {
1699 // Pin names might not be unique between different units so we must have the
1700 // unit token in the reference designator
1701 name << symbol->GetRef( &aPath, true );
1702 name << "-" << EscapeString( libPinShownName, CTX_NETNAME );
1703
1704 if( unconnected || has_multiple )
1705 name << "-Pad" << EscapeString( libPinShownNumber, CTX_NETNAME );
1706
1707 name << ")";
1708 }
1709 else
1710 {
1711 // Pin numbers are unique, so we skip the unit token
1712 name << symbol->GetRef( &aPath, false );
1713 name << "-Pad" << EscapeString( libPinShownNumber, CTX_NETNAME ) << ")";
1714 }
1715
1716 if( annotated )
1717 m_net_name_map[ aPath ] = std::make_pair( name, aForceNoConnect );
1718
1719 return name;
1720}
1721
1722
1724{
1725 return GetBoundingBox( false, true, m_flags & SHOW_ELEC_TYPE );
1726}
1727
1728
1729std::vector<int> SCH_PIN::ViewGetLayers() const
1730{
1733}
1734
1735
1736void SCH_PIN::validateExtentsCache( KIFONT::FONT* aFont, int aSize, const wxString& aText,
1737 EXTENTS_CACHE* aCache ) const
1738{
1739 if( aCache->m_Font == aFont
1740 && aCache->m_FontSize == aSize
1741 && aCache->m_Extents != VECTOR2I() )
1742 {
1743 return;
1744 }
1745
1746 aCache->m_Font = aFont;
1747 aCache->m_FontSize = aSize;
1748
1749 VECTOR2D fontSize( aSize, aSize );
1750 int penWidth = GetPenSizeForNormal( aSize );
1751
1752 aCache->m_Extents = aFont->StringBoundaryLimits( aText, fontSize, penWidth, false, false,
1753 GetFontMetrics() );
1754}
1755
1756
1757BOX2I SCH_PIN::GetBoundingBox( bool aIncludeLabelsOnInvisiblePins, bool aIncludeNameAndNumber,
1758 bool aIncludeElectricalType ) const
1759{
1760 // Just defer to the cache
1761 return m_layoutCache->GetPinBoundingBox( aIncludeLabelsOnInvisiblePins, aIncludeNameAndNumber,
1762 aIncludeElectricalType );
1763}
1764
1765
1767 const SCH_SHEET_PATH* aInstance ) const
1768{
1769 // Do not compare to ourself.
1770 if( aItem == this )
1771 return false;
1772
1773 const SCH_PIN* pin = dynamic_cast<const SCH_PIN*>( aItem );
1774
1775 // Don't compare against a different SCH_ITEM.
1776 wxCHECK( pin, false );
1777
1778 if( GetPosition() != pin->GetPosition() )
1779 return true;
1780
1781 if( GetNumber() != pin->GetNumber() )
1782 return true;
1783
1784 return GetName() != pin->GetName();
1785}
1786
1787
1789{
1790 if( !m_libPin )
1791 return false;
1792
1793 // Reciprocal checking is done in CONNECTION_GRAPH anyway
1794 return m_libPin->GetType() != ELECTRICAL_PINTYPE::PT_NC;
1795}
1796
1797
1799{
1801}
1802
1803
1804wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, ALT* aAlt ) const
1805{
1806 return getItemDescription( aAlt );
1807}
1808
1809
1810wxString SCH_PIN::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
1811{
1812 if( m_libPin )
1813 {
1814 SCH_PIN::ALT localStorage;
1815 SCH_PIN::ALT* alt = nullptr;
1816
1817 if( !m_alt.IsEmpty() )
1818 {
1819 localStorage = m_libPin->GetAlt( m_alt );
1820 alt = &localStorage;
1821 }
1822
1823 wxString itemDesc = m_libPin ? m_libPin->GetItemDescription( aUnitsProvider, alt )
1824 : wxString( wxS( "Undefined library pin." ) );
1825
1826 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( GetParentSymbol() );
1827
1828 return wxString::Format( "Symbol %s %s",
1830 itemDesc );
1831 }
1832
1833 return getItemDescription( nullptr );
1834}
1835
1836
1837wxString SCH_PIN::getItemDescription( ALT* aAlt ) const
1838{
1839 // This code previously checked "m_name.IsEmpty()" to choose the correct
1840 // formatting path, but that check fails if the pin is called "~" which is
1841 // the default for an empty pin name. Instead we get the final display string
1842 // that will be shown and check if it's empty.
1843
1844 wxString name = UnescapeString( aAlt ? aAlt->m_Name : GetShownName() );
1845 wxString electricalTypeName = ElectricalPinTypeGetText( aAlt ? aAlt->m_Type : m_type );
1846 wxString pinShapeName = PinShapeGetText( aAlt ? aAlt->m_Shape : m_shape );
1847
1848 if( IsVisible() )
1849 {
1850 if ( !name.IsEmpty() )
1851 {
1852 return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
1854 name,
1855 electricalTypeName,
1856 pinShapeName );
1857 }
1858 else
1859 {
1860 return wxString::Format( _( "Pin %s [%s, %s]" ),
1862 electricalTypeName,
1863 pinShapeName );
1864 }
1865 }
1866 else
1867 {
1868 if( !name.IsEmpty() )
1869 {
1870 return wxString::Format( _( "Hidden pin %s [%s, %s, %s]" ),
1872 name,
1873 electricalTypeName,
1874 pinShapeName );
1875 }
1876 else
1877 {
1878 return wxString::Format( _( "Hidden pin %s [%s, %s]" ),
1880 electricalTypeName,
1881 pinShapeName );
1882 }
1883 }
1884}
1885
1886
1887
1888
1889int SCH_PIN::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1890{
1891 // Ignore the UUID here.
1892 int retv = SCH_ITEM::compare( aOther, aCompareFlags | SCH_ITEM::COMPARE_FLAGS::EQUALITY );
1893
1894 if( retv )
1895 return retv;
1896
1897 const SCH_PIN* tmp = static_cast<const SCH_PIN*>( &aOther );
1898
1899 wxCHECK( tmp, -1 );
1900
1901 // When comparing units, we do not compare the part numbers. If everything else is
1902 // identical, then we can just renumber the parts for the inherited symbol.
1903 // if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number )
1904 // return m_number.Cmp( tmp->m_number );
1905
1906 // int result = m_name.Cmp( tmp->m_name );
1907
1908 // if( result )
1909 // return result;
1910
1911 // if( m_position.x != tmp->m_position.x )
1912 // return m_position.x - tmp->m_position.x;
1913
1914 // if( m_position.y != tmp->m_position.y )
1915 // return m_position.y - tmp->m_position.y;
1916
1917 // if( m_length != tmp->m_length )
1918 // return m_length.value_or( 0 ) - tmp->m_length.value_or( 0 );
1919
1920 // if( m_orientation != tmp->m_orientation )
1921 // return static_cast<int>( m_orientation ) - static_cast<int>( tmp->m_orientation );
1922
1923 // if( m_shape != tmp->m_shape )
1924 // return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
1925
1926 // if( m_type != tmp->m_type )
1927 // return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
1928
1929 // if( m_hidden != tmp->m_hidden )
1930 // return m_hidden.value_or( false ) - tmp->m_hidden.value_or( false );
1931
1932 // if( m_numTextSize != tmp->m_numTextSize )
1933 // return m_numTextSize.value_or( 0 ) - tmp->m_numTextSize.value_or( 0 );
1934
1935 // if( m_nameTextSize != tmp->m_nameTextSize )
1936 // return m_nameTextSize.value_or( 0 ) - tmp->m_nameTextSize.value_or( 0 );
1937
1938 // if( m_alternates.size() != tmp->m_alternates.size() )
1939 // return static_cast<int>( m_alternates.size() - tmp->m_alternates.size() );
1940
1941 // auto lhsItem = m_alternates.begin();
1942 // auto rhsItem = tmp->m_alternates.begin();
1943
1944 // while( lhsItem != m_alternates.end() )
1945 // {
1946 // const ALT& lhsAlt = lhsItem->second;
1947 // const ALT& rhsAlt = rhsItem->second;
1948
1949 // int retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
1950
1951 // if( retv )
1952 // return retv;
1953
1954 // if( lhsAlt.m_Type != rhsAlt.m_Type )
1955 // return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
1956
1957 // if( lhsAlt.m_Shape != rhsAlt.m_Shape )
1958 // return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
1959
1960 // ++lhsItem;
1961 // ++rhsItem;
1962 // }
1963
1964 if( m_number != tmp->m_number )
1965 return m_number.Cmp( tmp->m_number );
1966
1967 if( m_position.x != tmp->m_position.x )
1968 return m_position.x - tmp->m_position.x;
1969
1970 if( m_position.y != tmp->m_position.y )
1971 return m_position.y - tmp->m_position.y;
1972
1973 if( dynamic_cast<const SCH_SYMBOL*>( GetParentSymbol() ) )
1974 {
1975 if( ( m_libPin == nullptr ) || ( tmp->m_libPin == nullptr ) )
1976 return -1;
1977
1978 retv = m_libPin->compare( *tmp->m_libPin );
1979
1980 if( retv )
1981 return retv;
1982
1983 retv = m_alt.Cmp( tmp->m_alt );
1984
1985 if( retv )
1986 return retv;
1987 }
1988
1989 if( dynamic_cast<const LIB_SYMBOL*>( GetParentSymbol() ) )
1990 {
1991 if( m_length != tmp->m_length )
1992 return m_length.value_or( 0 ) - tmp->m_length.value_or( 0 );
1993
1994 if( m_orientation != tmp->m_orientation )
1995 return static_cast<int>( m_orientation ) - static_cast<int>( tmp->m_orientation );
1996
1997 if( m_shape != tmp->m_shape )
1998 return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
1999
2000 if( m_type != tmp->m_type )
2001 return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
2002
2003 if( m_hidden != tmp->m_hidden )
2004 return m_hidden.value_or( false ) - tmp->m_hidden.value_or( false );
2005
2006 if( m_numTextSize != tmp->m_numTextSize )
2007 return m_numTextSize.value_or( 0 ) - tmp->m_numTextSize.value_or( 0 );
2008
2009 if( m_nameTextSize != tmp->m_nameTextSize )
2010 return m_nameTextSize.value_or( 0 ) - tmp->m_nameTextSize.value_or( 0 );
2011
2012 if( m_alternates.size() != tmp->m_alternates.size() )
2013 return static_cast<int>( m_alternates.size() - tmp->m_alternates.size() );
2014
2015 auto lhsItem = m_alternates.begin();
2016 auto rhsItem = tmp->m_alternates.begin();
2017
2018 while( lhsItem != m_alternates.end() )
2019 {
2020 const ALT& lhsAlt = lhsItem->second;
2021 const ALT& rhsAlt = rhsItem->second;
2022
2023 retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
2024
2025 if( retv )
2026 return retv;
2027
2028 if( lhsAlt.m_Type != rhsAlt.m_Type )
2029 return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
2030
2031 if( lhsAlt.m_Shape != rhsAlt.m_Shape )
2032 return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
2033
2034 ++lhsItem;
2035 ++rhsItem;
2036 }
2037 }
2038
2039 return 0;
2040}
2041
2042
2043double SCH_PIN::Similarity( const SCH_ITEM& aOther ) const
2044{
2045 if( aOther.m_Uuid == m_Uuid )
2046 return 1.0;
2047
2048 if( aOther.Type() != SCH_PIN_T )
2049 return 0.0;
2050
2051 const SCH_PIN* other = static_cast<const SCH_PIN*>( &aOther );
2052
2053 if( m_libPin )
2054 {
2055 if( m_number != other->m_number )
2056 return 0.0;
2057
2058 if( m_position != other->m_position )
2059 return 0.0;
2060
2061 return m_libPin->Similarity( *other->m_libPin );
2062 }
2063
2064 double similarity = SimilarityBase( aOther );
2065
2066 if( m_name != other->m_name )
2067 similarity *= 0.9;
2068
2069 if( m_number != other->m_number )
2070 similarity *= 0.9;
2071
2072 if( m_position != other->m_position )
2073 similarity *= 0.9;
2074
2075 if( m_length != other->m_length )
2076 similarity *= 0.9;
2077
2078 if( m_orientation != other->m_orientation )
2079 similarity *= 0.9;
2080
2081 if( m_shape != other->m_shape )
2082 similarity *= 0.9;
2083
2084 if( m_type != other->m_type )
2085 similarity *= 0.9;
2086
2087 if( m_hidden != other->m_hidden )
2088 similarity *= 0.9;
2089
2090 if( m_numTextSize != other->m_numTextSize )
2091 similarity *= 0.9;
2092
2093 if( m_nameTextSize != other->m_nameTextSize )
2094 similarity *= 0.9;
2095
2096 if( m_alternates.size() != other->m_alternates.size() )
2097 similarity *= 0.9;
2098
2099 return similarity;
2100}
2101
2102
2103std::ostream& SCH_PIN::operator<<( std::ostream& aStream )
2104{
2105 aStream << "SCH_PIN:" << std::endl
2106 << " Name: \"" << m_name << "\"" << std::endl
2107 << " Number: \"" << m_number << "\"" << std::endl
2108 << " Position: " << m_position << std::endl
2109 << " Length: " << GetLength() << std::endl
2110 << " Orientation: " << PinOrientationName( m_orientation ) << std::endl
2111 << " Shape: " << PinShapeGetText( m_shape ) << std::endl
2112 << " Type: " << ElectricalPinTypeGetText( m_type ) << std::endl
2113 << " Name Text Size: " << GetNameTextSize() << std::endl
2114 << " Number Text Size: " << GetNumberTextSize() << std::endl;
2115
2116 return aStream;
2117}
2118
2119
2120#if defined(DEBUG)
2121
2122void SCH_PIN::Show( int nestLevel, std::ostream& os ) const
2123{
2124 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
2125 << " num=\"" << m_number.mb_str()
2126 << '"' << "/>\n";
2127
2128// NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
2129}
2130
2131#endif
2132
2133void SCH_PIN::CalcEdit( const VECTOR2I& aPosition )
2134{
2135 if( IsMoving() )
2136 SetPosition( aPosition );
2137}
2138
2139
2140static struct SCH_PIN_DESC
2141{
2143 {
2144 auto& pinTypeEnum = ENUM_MAP<ELECTRICAL_PINTYPE>::Instance();
2145
2146 if( pinTypeEnum.Choices().GetCount() == 0 )
2147 {
2148 pinTypeEnum.Map( ELECTRICAL_PINTYPE::PT_INPUT, _HKI( "Input" ) )
2149 .Map( ELECTRICAL_PINTYPE::PT_OUTPUT, _HKI( "Output" ) )
2150 .Map( ELECTRICAL_PINTYPE::PT_BIDI, _HKI( "Bidirectional" ) )
2151 .Map( ELECTRICAL_PINTYPE::PT_TRISTATE, _HKI( "Tri-state" ) )
2152 .Map( ELECTRICAL_PINTYPE::PT_PASSIVE, _HKI( "Passive" ) )
2153 .Map( ELECTRICAL_PINTYPE::PT_NIC, _HKI( "Free" ) )
2154 .Map( ELECTRICAL_PINTYPE::PT_UNSPECIFIED, _HKI( "Unspecified" ) )
2155 .Map( ELECTRICAL_PINTYPE::PT_POWER_IN, _HKI( "Power input" ) )
2156 .Map( ELECTRICAL_PINTYPE::PT_POWER_OUT, _HKI( "Power output" ) )
2157 .Map( ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR, _HKI( "Open collector" ) )
2158 .Map( ELECTRICAL_PINTYPE::PT_OPENEMITTER, _HKI( "Open emitter" ) )
2159 .Map( ELECTRICAL_PINTYPE::PT_NC, _HKI( "Unconnected" ) );
2160 }
2161
2162 auto& pinShapeEnum = ENUM_MAP<GRAPHIC_PINSHAPE>::Instance();
2163
2164 if( pinShapeEnum.Choices().GetCount() == 0 )
2165 {
2166 pinShapeEnum.Map( GRAPHIC_PINSHAPE::LINE, _HKI( "Line" ) )
2167 .Map( GRAPHIC_PINSHAPE::INVERTED, _HKI( "Inverted" ) )
2168 .Map( GRAPHIC_PINSHAPE::CLOCK, _HKI( "Clock" ) )
2169 .Map( GRAPHIC_PINSHAPE::INVERTED_CLOCK, _HKI( "Inverted clock" ) )
2170 .Map( GRAPHIC_PINSHAPE::INPUT_LOW, _HKI( "Input low" ) )
2171 .Map( GRAPHIC_PINSHAPE::CLOCK_LOW, _HKI( "Clock low" ) )
2172 .Map( GRAPHIC_PINSHAPE::OUTPUT_LOW, _HKI( "Output low" ) )
2173 .Map( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK, _HKI( "Falling edge clock" ) )
2174 .Map( GRAPHIC_PINSHAPE::NONLOGIC, _HKI( "NonLogic" ) );
2175 }
2176
2177 auto& orientationEnum = ENUM_MAP<PIN_ORIENTATION>::Instance();
2178
2179 if( orientationEnum.Choices().GetCount() == 0 )
2180 {
2181 orientationEnum.Map( PIN_ORIENTATION::PIN_RIGHT, _( "Right" ) )
2182 .Map( PIN_ORIENTATION::PIN_LEFT, _( "Left" ) )
2183 .Map( PIN_ORIENTATION::PIN_UP, _( "Up" ) )
2184 .Map( PIN_ORIENTATION::PIN_DOWN, _( "Down" ) );
2185 }
2186
2187 auto isSymbolEditor =
2188 []( INSPECTABLE* aItem ) -> bool
2189 {
2190 if( SCH_PIN* pin = dynamic_cast<SCH_PIN*>( aItem ) )
2191 return dynamic_cast<LIB_SYMBOL*>( pin->GetParentSymbol() ) != nullptr;
2192
2193 return false;
2194 };
2195
2200
2201 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Name" ),
2203 .SetWriteableFunc( isSymbolEditor );
2204
2205 propMgr.AddProperty( new PROPERTY<SCH_PIN, wxString>( _HKI( "Pin Number" ),
2207 .SetWriteableFunc( isSymbolEditor );
2208
2210 _HKI( "Electrical Type" ),
2212 .SetWriteableFunc( isSymbolEditor );
2213
2215 _HKI( "Graphic Style" ),
2217 .SetWriteableFunc( isSymbolEditor );
2218
2219 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position X" ),
2220 &SCH_PIN::SetX, &SCH_PIN::GetX, PROPERTY_DISPLAY::PT_COORD ) )
2221 .SetAvailableFunc( isSymbolEditor );
2222
2223 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Position Y" ),
2224 &SCH_PIN::SetY, &SCH_PIN::GetY, PROPERTY_DISPLAY::PT_COORD ) )
2225 .SetAvailableFunc( isSymbolEditor );
2226
2227 propMgr.AddProperty( new PROPERTY_ENUM<SCH_PIN, PIN_ORIENTATION>( _HKI( "Orientation" ),
2229 .SetWriteableFunc( isSymbolEditor );
2230
2231 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Length" ),
2233 PROPERTY_DISPLAY::PT_SIZE ) )
2234 .SetWriteableFunc( isSymbolEditor );
2235
2236 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Name Text Size" ),
2238 PROPERTY_DISPLAY::PT_SIZE ) )
2239 .SetAvailableFunc( isSymbolEditor );
2240
2241 propMgr.AddProperty( new PROPERTY<SCH_PIN, int>( _HKI( "Number Text Size" ),
2243 PROPERTY_DISPLAY::PT_SIZE ) )
2244 .SetAvailableFunc( isSymbolEditor );
2245
2246 propMgr.AddProperty( new PROPERTY<SCH_PIN, bool>( _HKI( "Visible" ),
2248 .SetAvailableFunc( isSymbolEditor );
2249
2250 }
2252
2253
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:89
const KIID m_Uuid
Definition: eda_item.h:490
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:501
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:378
EDA_ITEM * GetParent() const
Definition: eda_item.h:103
EDA_ITEM * m_parent
Linked list: Link (parent struct).
Definition: eda_item.h:502
bool IsMoving() const
Definition: eda_item.h:108
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:146
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:426
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.
wxDC * GetPrintDC() const
Definition: kiid.h:49
wxString AsString() const
Definition: kiid.cpp:246
Define a library symbol object.
Definition: lib_symbol.h:84
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:244
void FinishTo(const VECTOR2I &pos)
Definition: plotter.h:254
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:249
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).
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:167
int m_unit
Definition: sch_item.h:710
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition: sch_item.cpp:101
int m_bodyStyle
Definition: sch_item.h:711
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition: sch_item.h:656
const SYMBOL * GetParentSymbol() const
Definition: sch_item.cpp:166
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:150
int GetBodyStyle() const
Definition: sch_item.h:233
static wxString GetUnitDescription(int aUnit)
Definition: sch_item.cpp:52
@ EQUALITY
Definition: sch_item.h:646
int GetUnit() const
Definition: sch_item.h:230
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:416
bool IsConnectivityDirty() const
Definition: sch_item.h:511
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:218
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:464
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition: sch_item.cpp:473
SCH_LAYER_ID m_layer
Definition: sch_item.h:709
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:317
void getSymbolEditorMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Definition: sch_item.cpp:499
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_pin.cpp:1523
std::ostream & operator<<(std::ostream &aStream)
Definition: sch_pin.cpp:2103
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:1184
int GetNumberTextSize() const
Definition: sch_pin.cpp:564
int GetLength() const
Definition: sch_pin.cpp:295
std::optional< bool > m_hidden
Definition: sch_pin.h:369
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: sch_pin.cpp:448
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:1551
std::unique_ptr< PIN_LAYOUT_CACHE > m_layoutCache
The layout cache for this pin.
Definition: sch_pin.h:384
void MirrorVerticallyPin(int aCenter)
Definition: sch_pin.cpp:1472
void validateExtentsCache(KIFONT::FONT *aFont, int aSize, const wxString &aText, EXTENTS_CACHE *aCache) const
Definition: sch_pin.cpp:1736
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: sch_pin.cpp:1723
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:1729
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: sch_pin.cpp:2133
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:527
std::optional< int > m_nameTextSize
Definition: sch_pin.h:373
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:1374
void SetVisible(bool aVisible)
Definition: sch_pin.h:106
int GetX() const
Definition: sch_pin.h:201
void ChangeLength(int aLength)
Change the length of a pin and adjust its position based on orientation.
Definition: sch_pin.cpp:1418
ALT GetAlt(const wxString &aAlt)
Definition: sch_pin.h:140
void SetX(int aX)
Definition: sch_pin.h:202
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:1766
SCH_PIN & operator=(const SCH_PIN &aPin)
Definition: sch_pin.cpp:229
wxString GetShownNumber() const
Definition: sch_pin.cpp:518
SCH_PIN * m_libPin
Definition: sch_pin.h:358
void Move(const VECTOR2I &aOffset) override
Move the item by aMoveVector to a new position.
Definition: sch_pin.cpp:1446
std::map< const SCH_SHEET_PATH, std::pair< wxString, bool > > m_net_name_map
Definition: sch_pin.h:388
PIN_ORIENTATION m_orientation
Definition: sch_pin.h:366
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition: sch_pin.h:85
void SetName(const wxString &aName)
Definition: sch_pin.cpp:406
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:367
wxString getItemDescription(ALT *aAlt) const
Definition: sch_pin.cpp:1837
bool IsVisible() const
Definition: sch_pin.cpp:374
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_pin.cpp:1788
std::optional< int > m_numTextSize
Definition: sch_pin.h:372
VECTOR2I GetPinRoot() const
Definition: sch_pin.cpp:588
ELECTRICAL_PINTYPE m_type
Definition: sch_pin.h:368
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_pin.cpp:1485
SCH_PIN * GetLibPin() const
Definition: sch_pin.h:81
void SetPosition(const VECTOR2I &aPos) override
Definition: sch_pin.h:198
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:2043
bool m_isDangling
Definition: sch_pin.h:378
void SetIsDangling(bool aIsDangling)
Definition: sch_pin.cpp:428
wxString GetElectricalTypeName() const
Definition: sch_pin.cpp:353
std::map< wxString, ALT > m_alternates
Definition: sch_pin.h:361
const wxString & GetName() const
Definition: sch_pin.cpp:388
void SetLength(int aLength)
Definition: sch_pin.h:91
bool IsDangling() const override
Definition: sch_pin.cpp:419
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:1530
void MirrorHorizontally(int aCenter) override
these transforms have effect only if the pin has a LIB_SYMBOL as parent
Definition: sch_pin.cpp:1465
std::recursive_mutex m_netmap_mutex
The name that this pin connection will drive onto a net.
Definition: sch_pin.h:387
PIN_ORIENTATION GetOrientation() const
Definition: sch_pin.cpp:260
wxString GetClass() const override
Return the class name.
Definition: sch_pin.h:66
void SetNumberTextSize(int aSize)
Definition: sch_pin.cpp:578
void printPinTexts(const RENDER_SETTINGS *aSettings, const VECTOR2I &aPinPos, PIN_ORIENTATION aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName, bool aDimmed)
Put the pin number and pin text info, given the pin line coordinates.
Definition: sch_pin.cpp:788
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: sch_pin.h:88
void RotatePin(const VECTOR2I &aCenter, bool aRotateCCW=true)
Definition: sch_pin.cpp:1492
VECTOR2I GetPosition() const override
Definition: sch_pin.cpp:252
wxString GetCanonicalElectricalTypeName() const
Definition: sch_pin.cpp:339
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:461
int GetNameTextSize() const
Definition: sch_pin.cpp:540
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_pin.cpp:1810
VECTOR2I m_position
Definition: sch_pin.h:364
void printPinSymbol(const SCH_RENDER_SETTINGS *aSettings, const VECTOR2I &aPos, PIN_ORIENTATION aOrientation, bool aDimmed)
Print the pin symbol without text.
Definition: sch_pin.cpp:660
GRAPHIC_PINSHAPE m_shape
Definition: sch_pin.h:367
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
The pin specific sort order is as follows:
Definition: sch_pin.cpp:1889
wxString GetShownName() const
Definition: sch_pin.cpp:504
void MirrorHorizontallyPin(int aCenter)
these transforms have always effects
Definition: sch_pin.cpp:1452
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:474
wxString m_name
Definition: sch_pin.h:370
wxString m_alt
Definition: sch_pin.h:374
void SetType(ELECTRICAL_PINTYPE aType)
Definition: sch_pin.cpp:329
const wxString & GetBaseName() const
Get the name without any alternates.
Definition: sch_pin.cpp:397
~SCH_PIN()
Definition: sch_pin.cpp:224
void ClearDefaultNetName(const SCH_SHEET_PATH *aPath)
Definition: sch_pin.cpp:1619
void SetY(int aY)
Definition: sch_pin.h:204
void printPinElectricalTypeName(const RENDER_SETTINGS *aSettings, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, bool aDimmed)
Draw the electrical type text of the pin (only for the footprint editor)
Definition: sch_pin.cpp:965
SCH_PIN(LIB_SYMBOL *aParentSymbol)
Definition: sch_pin.cpp:100
bool IsStacked(const SCH_PIN *aPin) const
Definition: sch_pin.cpp:434
const wxString & GetNumber() const
Definition: sch_pin.h:116
wxString m_number
Definition: sch_pin.h:371
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_pin.cpp:1409
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_pin.h:174
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: sch_pin.cpp:611
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition: sch_pin.cpp:1630
std::optional< int > m_length
Definition: sch_pin.h:365
GRAPHIC_PINSHAPE GetShape() const
Definition: sch_pin.cpp:274
void PlotPinType(PLOTTER *aPlotter, const VECTOR2I &aPosition, PIN_ORIENTATION aOrientation, bool aDimmed) const
Definition: sch_pin.cpp:1037
int GetY() const
Definition: sch_pin.h:203
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:309
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_pin.cpp:1798
void SetNameTextSize(int aSize)
Definition: sch_pin.cpp:554
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:77
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:905
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
Definition: sch_symbol.cpp:873
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:703
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 int GetUnitCount() const =0
virtual const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const =0
virtual bool IsPower() const =0
int GetPinNameOffset() const
Definition: symbol.h:151
virtual bool GetShowPinNames() const
Definition: symbol.h:157
virtual bool GetShowPinNumbers() const
Definition: symbol.h:163
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. Shared with IS_ROLLOVER.
void GRLineTo(wxDC *DC, int x, int y, int width, const COLOR4D &Color)
Definition: gr_basic.cpp:195
void GRCircle(wxDC *aDC, const VECTOR2I &aPos, int aRadius, int aWidth, const COLOR4D &aColor)
Definition: gr_basic.cpp:358
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:188
void GRLine(wxDC *DC, int x1, int y1, int x2, int y2, int width, const COLOR4D &Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:171
bool GetGRForceBlackPenState(void)
Definition: gr_basic.cpp:165
int GetPenSizeForNormal(int aTextSize)
Definition: gr_text.cpp:60
void GRPrintText(wxDC *aDC, const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics)
Print a graphic text through wxDC.
Definition: gr_text.cpp:109
@ LAYER_DANGLING
Definition: layer_ids.h:429
@ LAYER_PINNUM
Definition: layer_ids.h:410
@ LAYER_DEVICE
Definition: layer_ids.h:418
@ LAYER_HIDDEN
Definition: layer_ids.h:444
@ LAYER_PINNAM
Definition: layer_ids.h:411
@ LAYER_PRIVATE_NOTES
Definition: layer_ids.h:420
@ LAYER_PIN
Definition: layer_ids.h:422
@ LAYER_OP_CURRENTS
Definition: layer_ids.h:453
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:446
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:1081
see class PGM_BASE
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:207
BITMAPS ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:220
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:233
wxString PinOrientationName(PIN_ORIENTATION aOrientation)
Definition: pin_type.cpp:259
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:78
@ PIN_RIGHT
The pin extends rightwards from the connection point.
GRAPHIC_PINSHAPE
Definition: pin_type.h:57
#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
#define ETXT_MAX_SIZE
static int externalPinDecoSize(const RENDER_SETTINGS *aSettings, const SCH_PIN &aPin)
Utility for getting the size of the 'external' pin decorators (as a radius)
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)
Definition: sch_pin.cpp:76
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
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
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:304
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
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