KiCad PCB EDA Suite
lib_pin.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
30 #include <wx/tokenzr.h>
31 
32 #include <fctsys.h>
33 #include <pgm_base.h>
34 #include <gr_basic.h>
35 #include <macros.h>
36 #include <trigo.h>
37 #include <class_drawpanel.h>
38 #include <drawtxt.h>
39 #include <class_plotter.h>
40 #include <schframe.h>
41 #include <base_units.h>
42 #include <msgpanel.h>
43 
44 #include <general.h>
45 #include <libeditframe.h>
46 #include <class_libentry.h>
47 #include <lib_pin.h>
48 #include <transform.h>
49 #include <sch_component.h>
50 
51 
52 static const int pin_orientation_codes[] =
53 {
54  PIN_RIGHT,
55  PIN_LEFT,
56  PIN_UP,
57  PIN_DOWN
58 };
59 #define PIN_ORIENTATION_CNT DIM( pin_orientation_codes )
60 
61 // small margin in internal units between the pin text and the pin line
62 #define PIN_TEXT_MARGIN 4
63 
64 // bitmaps to show pins orientations in dialog editor
65 // must have same order than pin_orientation_names
67 {
68  pinorient_right_xpm,
69  pinorient_left_xpm,
70  pinorient_up_xpm,
71  pinorient_down_xpm,
72 };
73 
74 
76 {
77  if( aType < 0 || aType >= (int) PINTYPE_COUNT )
78  return wxT( "???" );
79 
80  // These strings are the canonical name of the electrictal type
81  // Not translated, no space in name, only ASCII chars.
82  // to use when the string name must be known and well defined
83  // must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h)
84  static const wxChar* msgPinElectricType[] =
85  {
86  wxT( "input" ),
87  wxT( "output" ),
88  wxT( "BiDi" ),
89  wxT( "3state" ),
90  wxT( "passive" ),
91  wxT( "unspc" ),
92  wxT( "power_in" ),
93  wxT( "power_out" ),
94  wxT( "openCol" ),
95  wxT( "openEm" ),
96  wxT( "NotConnected" )
97  };
98 
99  return msgPinElectricType[ aType ];
100 }
101 
102 
103 // Helper functions to get the pin orientation name from pin_orientation_codes
104 // Note: the strings are *not* static because they are translated and must be built
105 // on the fly, to be properly translated
106 
107 static const wxString getPinOrientationName( unsigned aPinOrientationCode )
108 {
109  /* Note: The following name lists are sentence capitalized per the GNOME UI
110  * standards for list controls. Please do not change the capitalization
111  * of these strings unless the GNOME UI standards are changed.
112  */
113  const wxString pin_orientation_names[] =
114  {
115  _( "Right" ),
116  _( "Left" ),
117  _( "Up" ),
118  _( "Down" ),
119  wxT( "???" )
120  };
121 
122  if( aPinOrientationCode > PIN_ORIENTATION_CNT )
123  aPinOrientationCode = PIN_ORIENTATION_CNT;
124 
125  return pin_orientation_names[ aPinOrientationCode ];
126 }
127 
129 // i.e. the clock symbols (falling clock is actually external but is of
130 // the same kind)
131 
132 static int InternalPinDecoSize( const LIB_PIN &aPin )
133 {
134 
135  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
136 }
137 
139 // i.e. the negation circle, the polarity 'slopes' and the nonlogic
140 // marker
141 static int ExternalPinDecoSize( const LIB_PIN &aPin )
142 {
143  return aPin.GetNumberTextSize() / 2;
144 }
145 
147  LIB_ITEM( LIB_PIN_T, aParent ),
148  m_shape( PINSHAPE_LINE )
149 {
151  m_orientation = PIN_RIGHT; // Pin orient: Up, Down, Left, Right
152  m_type = PIN_UNSPECIFIED; // electrical type of pin
153  m_attributes = 0; // bit 0 != 0: pin invisible
156  m_width = 0;
157  m_typeName = _( "Pin" );
158 }
159 
160 
161 void LIB_PIN::SetName( const wxString& aName, bool aTestOtherPins )
162 {
163  wxString tmp = ( aName.IsEmpty() ) ? wxT( "~" ) : aName;
164 
165  // pin name string does not support spaces
166  tmp.Replace( wxT( " " ), wxT( "_" ) );
167 
168  if( m_name != tmp )
169  {
170  m_name = tmp;
171  SetModified();
172  }
173 
174  if( !aTestOtherPins )
175  return;
176 
177  if( GetParent() == NULL )
178  return;
179 
180  LIB_PINS pinList;
181  GetParent()->GetPins( pinList );
182 
183  for( size_t i = 0; i < pinList.size(); i++ )
184  {
185  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_name == m_name )
186  continue;
187 
188  pinList[i]->m_name = m_name;
189  SetModified();
190  }
191 }
192 
193 
194 void LIB_PIN::SetNameTextSize( int size, bool aTestOtherPins )
195 {
196  if( size != m_nameTextSize )
197  {
198  m_nameTextSize = size;
199  SetModified();
200  }
201 
202  if( !aTestOtherPins )
203  return;
204 
205  if( GetParent() == NULL )
206  return;
207 
208  LIB_PINS pinList;
209  GetParent()->GetPins( pinList );
210 
211  for( size_t i = 0; i < pinList.size(); i++ )
212  {
213  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_nameTextSize == size )
214  continue;
215 
216  pinList[i]->m_nameTextSize = size;
217  SetModified();
218  }
219 }
220 
221 
222 void LIB_PIN::SetNumber( const wxString& aNumber )
223 {
224  // Unlike SetName, others pin numbers marked by EnableEditMode() are
225  // not modified because each pin has its own number, so set number
226  // only for this.
227 
228  wxString tmp = ( aNumber.IsEmpty() ) ? wxT( "~" ) : aNumber;
229 
230  // pin number string does not support spaces
231  tmp.Replace( wxT( " " ), wxT( "_" ) );
232 
233  if( m_number != tmp )
234  {
235  m_number = tmp;
236  SetModified();
237  }
238 }
239 
240 
241 void LIB_PIN::SetNumberTextSize( int size, bool aTestOtherPins )
242 {
243  if( size != m_numTextSize )
244  {
245  m_numTextSize = size;
246  SetModified();
247  }
248 
249  if( !aTestOtherPins )
250  return;
251 
252  if( GetParent() == NULL )
253  return;
254 
255  LIB_PINS pinList;
256  GetParent()->GetPins( pinList );
257 
258  for( size_t i = 0; i < pinList.size(); i++ )
259  {
260  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_numTextSize == size )
261  continue;
262 
263  pinList[i]->m_numTextSize = size;
264  SetModified();
265  }
266 }
267 
268 
269 void LIB_PIN::SetOrientation( int orientation, bool aTestOtherPins )
270 {
271  if( m_orientation != orientation )
272  {
273  m_orientation = orientation;
274  SetModified();
275  }
276 
277  if( !aTestOtherPins )
278  return;
279 
280  if( GetParent() == NULL )
281  return;
282 
283  LIB_PINS pinList;
284  GetParent()->GetPins( pinList );
285 
286  for( size_t i = 0; i < pinList.size(); i++ )
287  {
288  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 ||
289  pinList[i]->m_orientation == orientation )
290  continue;
291 
292  pinList[i]->m_orientation = orientation;
293  SetModified();
294  }
295 }
296 
297 
299 {
300  assert( aShape >= 0 && aShape < int( PINSHAPE_COUNT ) );
301 
302  if( m_shape != aShape )
303  {
304  m_shape = aShape;
305  SetModified();
306  }
307 
308  if( GetParent() == NULL )
309  return;
310 
311  LIB_PINS pinList;
312  GetParent()->GetPins( pinList );
313 
314  for( size_t i = 0; i < pinList.size(); i++ )
315  {
316  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
317  || pinList[i]->m_Convert != m_Convert
318  || pinList[i]->m_shape == aShape )
319  continue;
320 
321  pinList[i]->m_shape = aShape;
322  SetModified();
323  }
324 }
325 
326 
327 void LIB_PIN::SetType( ELECTRICAL_PINTYPE aType, bool aTestOtherPins )
328 {
329  assert( aType >= 0 && aType < (int)PINTYPE_COUNT );
330 
331  if( aType < PIN_INPUT )
332  aType = PIN_INPUT;
333 
334  if( aType >= (int)PINTYPE_COUNT )
335  aType = PIN_NC;
336 
337  if( m_type != aType )
338  {
339  m_type = aType;
340  SetModified();
341  }
342 
343  if( !aTestOtherPins )
344  return;
345 
346  if( GetParent() == NULL )
347  return;
348 
349  LIB_PINS pinList;
350  GetParent()->GetPins( pinList );
351 
352  for( size_t i = 0; i < pinList.size(); i++ )
353  {
354  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->m_type == aType )
355  continue;
356 
357  pinList[i]->m_type = aType;
358  SetModified();
359  }
360 }
361 
362 
363 void LIB_PIN::SetLength( int length, bool aTestOtherPins )
364 {
365  if( m_length != length )
366  {
367  m_length = length;
368  SetModified();
369  }
370 
371  if( !aTestOtherPins )
372  return;
373 
374  if( GetParent() == NULL )
375  return;
376 
377  LIB_PINS pinList;
378  GetParent()->GetPins( pinList );
379 
380  for( size_t i = 0; i < pinList.size(); i++ )
381  {
382  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
383  || pinList[i]->m_Convert != m_Convert
384  || pinList[i]->m_length == length )
385  continue;
386 
387  pinList[i]->m_length = length;
388  SetModified();
389  }
390 }
391 
392 
394 {
395  if( m_position != aPosition )
396  {
397  m_position = aPosition;
398  SetModified();
399  }
400 
401  if( GetParent() == NULL )
402  return;
403 
404  LIB_PINS pinList;
405  GetParent()->GetPins( pinList );
406 
407  for( size_t i = 0; i < pinList.size(); i++ )
408  {
409  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0
410  || pinList[i]->m_Convert != m_Convert
411  || pinList[i]->m_position == aPosition )
412  continue;
413 
414  pinList[i]->m_position = aPosition;
415  SetModified();
416  }
417 }
418 
419 
420 void LIB_PIN::SetPartNumber( int part )
421 {
422  if( m_Unit == part )
423  return;
424 
425  m_Unit = part;
426  SetModified();
427 
428  if( m_Unit == 0 )
429  {
430  LIB_PIN* pin;
431  LIB_PIN* tmp = GetParent()->GetNextPin();
432 
433  while( tmp != NULL )
434  {
435  pin = tmp;
436  tmp = GetParent()->GetNextPin( pin );
437 
438  if( pin->m_Flags == 0 || pin == this
439  || ( m_Convert && ( m_Convert != pin->m_Convert ) )
440  || ( m_position != pin->m_position )
441  || ( pin->m_orientation != m_orientation ) )
442  continue;
443 
444  GetParent()->RemoveDrawItem( (LIB_ITEM*) pin );
445  }
446  }
447 }
448 
449 
450 void LIB_PIN::SetConversion( int style )
451 {
452  if( m_Convert == style )
453  return;
454 
455  m_Convert = style;
456  SetFlags( IS_CHANGED );
457 
458  if( style == 0 )
459  {
460  LIB_PIN* pin;
461  LIB_PIN* tmp = GetParent()->GetNextPin();
462 
463  while( tmp != NULL )
464  {
465  pin = tmp;
466  tmp = GetParent()->GetNextPin( pin );
467 
468  if( ( pin->m_Flags & IS_LINKED ) == 0
469  || ( pin == this )
470  || ( m_Unit && ( m_Unit != pin->m_Unit ) )
471  || ( m_position != pin->m_position )
472  || ( pin->m_orientation != m_orientation ) )
473  continue;
474 
475  GetParent()->RemoveDrawItem( (LIB_ITEM*) pin );
476  }
477  }
478 }
479 
480 
481 void LIB_PIN::SetVisible( bool visible )
482 {
483  if( visible == IsVisible() )
484  return;
485 
486  if( visible )
488  else
490 
491  SetModified();
492 
493  if( GetParent() == NULL )
494  return;
495 
496  LIB_PINS pinList;
497  GetParent()->GetPins( pinList );
498 
499  for( size_t i = 0; i < pinList.size(); i++ )
500  {
501  if( ( pinList[i]->m_Flags & IS_LINKED ) == 0 || pinList[i]->IsVisible() == visible )
502  continue;
503 
504  if( visible )
505  pinList[i]->m_attributes &= ~PIN_INVISIBLE;
506  else
507  pinList[i]->m_attributes |= PIN_INVISIBLE;
508 
509  SetModified();
510  }
511 }
512 
513 
514 void LIB_PIN::EnableEditMode( bool enable, bool editPinByPin )
515 {
516  LIB_PINS pinList;
517 
518  if( GetParent() == NULL )
519  return;
520 
521  GetParent()->GetPins( pinList );
522 
523  for( size_t i = 0; i < pinList.size(); i++ )
524  {
525  if( pinList[i] == this )
526  continue;
527 
528  if( ( pinList[i]->m_position == m_position )
529  && ( pinList[i]->m_orientation == m_orientation )
530  && !IsNew()
531  && editPinByPin == false
532  && enable )
533  pinList[i]->SetFlags( IS_LINKED | IN_EDIT );
534  else
535  pinList[i]->ClearFlags( IS_LINKED | IN_EDIT );
536  }
537 }
538 
539 
540 bool LIB_PIN::HitTest( const wxPoint& aPosition ) const
541 {
542  return HitTest( aPosition, 0, DefaultTransform );
543 }
544 
545 
546 bool LIB_PIN::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
547 {
548  if( aThreshold < 0 )
549  aThreshold = 0;
550 
551  TRANSFORM transform = DefaultTransform;
552  DefaultTransform = aTransform;
553 
554  EDA_RECT rect = GetBoundingBox();
555  rect.Inflate( aThreshold );
556 
557  //Restore matrix
558  DefaultTransform = transform;
559 
560  return rect.Contains( aPosition );
561 }
562 
563 
565 {
566  return ( m_width == 0 ) ? GetDefaultLineThickness() : m_width;
567 }
568 
569 
571  wxDC* aDC,
572  const wxPoint& aOffset,
573  COLOR4D aColor,
574  GR_DRAWMODE aDrawMode,
575  void* aData,
576  const TRANSFORM& aTransform )
577 {
578  // aData is used here as a bitfield of flags.
579  uintptr_t flags = (uintptr_t) aData;
580  bool drawPinText = flags & PIN_DRAW_TEXTS;
581  bool drawPinDangling = flags & PIN_DRAW_DANGLING;
582  bool drawDanglingHidden = flags & PIN_DANGLING_HIDDEN;
583  bool drawElectricalTypeName = flags & PIN_DRAW_ELECTRICAL_TYPE_NAME;
584 
585  LIB_PART* Entry = GetParent();
586 
587  /* Calculate pin orient taking in account the component orientation. */
588  int orient = PinDrawOrient( aTransform );
589 
590  /* Calculate the pin position */
591  wxPoint pos1 = aTransform.TransformCoordinate( m_position ) + aOffset;
592 
593  // Invisible pins are only drawn on request.
594  // They are drawn in GetInvisibleItemColor().
595  // in schematic, they are drawn only if m_showAllPins is true.
596  // In other windows, they are always drawn because we must see them.
597  if( ! IsVisible() )
598  {
599  EDA_DRAW_FRAME* frame = NULL;
600 
601  if( aPanel && aPanel->GetParent() )
602  frame = (EDA_DRAW_FRAME*)aPanel->GetParent();
603 
604  if( frame && frame->IsType( FRAME_SCH ) &&
605  ! ((SCH_EDIT_FRAME*)frame)->GetShowAllPins() )
606  {
607  if( drawPinDangling && drawDanglingHidden )
608  {
609  // Draw the target
610  DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor, drawPinDangling,
611  /* aOnlyTarget */ true );
612  }
613  return;
614  }
615 
616  aColor = GetInvisibleItemColor();
617  }
618 
619  /* Drawing from the pin and the special symbol combination */
620  DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor, drawPinDangling );
621 
622  if( drawPinText )
623  {
624  DrawPinTexts( aPanel, aDC, pos1, orient, Entry->GetPinNameOffset(),
625  Entry->ShowPinNumbers(), Entry->ShowPinNames(),
626  aColor, aDrawMode );
627  }
628 
629  if( drawElectricalTypeName )
630  DrawPinElectricalTypeName( aPanel, aDC, pos1, orient, aColor, aDrawMode );
631 
632 
633  /* Set to one (1) to draw bounding box around pin to validate bounding
634  * box calculation. */
635 #if 0
636  EDA_RECT bBox = GetBoundingBox();
637  bBox.RevertYAxis();
638  bBox = aTransform.TransformCoordinate( bBox );
639  bBox.Move( aOffset );
640  GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDC, bBox, 0, LIGHTMAGENTA );
641 #endif
642 }
643 
644 
646  wxDC* aDC,
647  const wxPoint& aPinPos,
648  int aOrient,
649  GR_DRAWMODE aDrawMode,
650  COLOR4D aColor,
651  bool aDrawDangling,
652  bool aOnlyTarget )
653 {
654  int MapX1, MapY1, x1, y1;
655  int width = GetPenSize();
656  int posX = aPinPos.x, posY = aPinPos.y, len = m_length;
657  EDA_RECT* clipbox = aPanel ? aPanel->GetClipBox() : NULL;
658 
660 
661  if( aColor == COLOR4D::UNSPECIFIED ) // Used normal color or selected color
662  {
663  if( IsSelected() )
664  color = GetItemSelectedColor();
665  }
666  else
667  color = aColor;
668 
669  GRSetDrawMode( aDC, aDrawMode );
670 
671  MapX1 = MapY1 = 0;
672  x1 = posX;
673  y1 = posY;
674 
675  switch( aOrient )
676  {
677  case PIN_UP:
678  y1 = posY - len;
679  MapY1 = 1;
680  break;
681 
682  case PIN_DOWN:
683  y1 = posY + len;
684  MapY1 = -1;
685  break;
686 
687  case PIN_LEFT:
688  x1 = posX - len;
689  MapX1 = 1;
690  break;
691 
692  case PIN_RIGHT:
693  x1 = posX + len;
694  MapX1 = -1;
695  break;
696  }
697 
698  // Draw the pin end target (active end of the pin)
699  BASE_SCREEN* screen = aPanel ? aPanel->GetScreen() : NULL;
700  #define NCSYMB_PIN_DIM TARGET_PIN_RADIUS
701 
702  // Draw but do not print the pin end target 1 pixel width
703  if( m_type != PIN_NC && ( screen == NULL || !screen->m_IsPrinting ) )
704  {
705  if( aDrawDangling )
706  GRCircle( clipbox, aDC, posX, posY, TARGET_PIN_RADIUS, 0, color );
707  }
708 
709  if( aOnlyTarget )
710  return;
711 
712 
714  {
715  const int radius = ExternalPinDecoSize( *this );
716  GRCircle( clipbox, aDC, MapX1 * radius + x1,
717  MapY1 * radius + y1,
718  radius, width, color );
719 
720  GRMoveTo( MapX1 * radius * 2 + x1,
721  MapY1 * radius * 2 + y1 );
722  GRLineTo( clipbox, aDC, posX, posY, width, color );
723  }
724  else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK ) /* an alternative for Inverted Clock */
725  {
726  const int clock_size = InternalPinDecoSize( *this );
727  if( MapY1 == 0 ) /* MapX1 = +- 1 */
728  {
729  GRMoveTo( x1, y1 + clock_size );
730  GRLineTo( clipbox, aDC, x1 + MapX1 * clock_size * 2, y1,
731  width, color );
732  GRLineTo( clipbox, aDC, x1, y1 - clock_size, width, color );
733  }
734  else /* MapX1 = 0 */
735  {
736  GRMoveTo( x1 + clock_size, y1 );
737  GRLineTo( clipbox, aDC, x1, y1 + MapY1 * clock_size * 2,
738  width, color );
739  GRLineTo( clipbox, aDC, x1 - clock_size, y1,
740  width, color );
741  }
742  GRMoveTo( MapX1 * clock_size * 2 + x1, MapY1 * clock_size * 2 + y1 );
743  GRLineTo( clipbox, aDC, posX, posY, width, color );
744  }
745  else
746  {
747  GRMoveTo( x1, y1 );
748  GRLineTo( clipbox, aDC, posX, posY, width, color );
749  }
750 
752  {
753  const int clock_size = InternalPinDecoSize( *this );
754  if( MapY1 == 0 ) /* MapX1 = +- 1 */
755  {
756  GRMoveTo( x1, y1 + clock_size );
757  GRLineTo( clipbox, aDC, x1 - MapX1 * clock_size * 2, y1,
758  width, color );
759  GRLineTo( clipbox, aDC, x1, y1 - clock_size,
760  width, color );
761  }
762  else /* MapX1 = 0 */
763  {
764  GRMoveTo( x1 + clock_size, y1 );
765  GRLineTo( clipbox, aDC, x1, y1 - MapY1 * clock_size * 2,
766  width, color );
767  GRLineTo( clipbox, aDC, x1 - clock_size, y1,
768  width, color );
769  }
770  }
771 
773  {
774  const int symbol_size = ExternalPinDecoSize( *this );
775  if( MapY1 == 0 ) /* MapX1 = +- 1 */
776  {
777  GRMoveTo( x1 + MapX1 * symbol_size * 2, y1 );
778  GRLineTo( clipbox, aDC,
779  x1 + MapX1 * symbol_size * 2, y1 - symbol_size * 2,
780  width, color );
781  GRLineTo( clipbox, aDC, x1, y1, width, color );
782  }
783  else /* MapX1 = 0 */
784  {
785  GRMoveTo( x1, y1 + MapY1 * symbol_size * 2 );
786  GRLineTo( clipbox, aDC, x1 - symbol_size * 2,
787  y1 + MapY1 * symbol_size * 2, width, color );
788  GRLineTo( clipbox, aDC, x1, y1, width, color );
789  }
790  }
791 
792 
793  if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
794  {
795  const int symbol_size = ExternalPinDecoSize( *this );
796  if( MapY1 == 0 ) /* MapX1 = +- 1 */
797  {
798  GRMoveTo( x1, y1 - symbol_size * 2 );
799  GRLineTo( clipbox,
800  aDC,
801  x1 + MapX1 * symbol_size * 2,
802  y1,
803  width,
804  color );
805  }
806  else /* MapX1 = 0 */
807  {
808  GRMoveTo( x1 - symbol_size * 2, y1 );
809  GRLineTo( clipbox, aDC, x1, y1 + MapY1 * symbol_size * 2,
810  width, color );
811  }
812  }
813  else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
814  {
815  const int symbol_size = ExternalPinDecoSize( *this );
816  GRMoveTo( x1 - (MapX1 + MapY1) * symbol_size,
817  y1 - (MapY1 - MapX1) * symbol_size );
818  GRLineTo( clipbox, aDC,
819  x1 + (MapX1 + MapY1) * symbol_size,
820  y1 + (MapY1 - MapX1) * symbol_size,
821  width, color );
822  GRMoveTo( x1 - (MapX1 - MapY1) * symbol_size,
823  y1 - (MapY1 + MapX1) * symbol_size );
824  GRLineTo( clipbox, aDC,
825  x1 + (MapX1 - MapY1) * symbol_size,
826  y1 + (MapY1 + MapX1) * symbol_size,
827  width, color );
828  }
829 
830  if( m_type == PIN_NC ) // Draw a N.C. symbol
831  {
832  GRLine( clipbox, aDC,
833  posX - NCSYMB_PIN_DIM, posY - NCSYMB_PIN_DIM,
834  posX + NCSYMB_PIN_DIM, posY + NCSYMB_PIN_DIM,
835  width, color );
836  GRLine( clipbox, aDC,
837  posX + NCSYMB_PIN_DIM, posY - NCSYMB_PIN_DIM,
838  posX - NCSYMB_PIN_DIM, posY + NCSYMB_PIN_DIM,
839  width, color );
840  }
841 }
842 
843 
845  wxDC* DC,
846  wxPoint& pin_pos,
847  int orient,
848  int TextInside,
849  bool DrawPinNum,
850  bool DrawPinName,
851  COLOR4D Color,
852  GR_DRAWMODE DrawMode )
853 {
854  if( !DrawPinName && !DrawPinNum )
855  return;
856 
857  int x, y;
858 
859  wxSize PinNameSize( m_nameTextSize, m_nameTextSize );
860  wxSize PinNumSize( m_numTextSize, m_numTextSize );
861 
862  int nameLineWidth = GetPenSize();
863 
864  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
865  int numLineWidth = GetPenSize();
866  numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
867 
868  int name_offset = PIN_TEXT_MARGIN +
869  ( nameLineWidth + GetDefaultLineThickness() ) / 2;
870  int num_offset = PIN_TEXT_MARGIN +
871  ( numLineWidth + GetDefaultLineThickness() ) / 2;
872 
873  GRSetDrawMode( DC, DrawMode );
874  EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
875 
876  /* Get the num and name colors */
877  if( ( Color == COLOR4D::UNSPECIFIED ) && IsSelected() )
878  Color = GetItemSelectedColor();
879 
880  COLOR4D NameColor = Color == COLOR4D::UNSPECIFIED ?
881  GetLayerColor( LAYER_PINNAM ) : Color;
882  COLOR4D NumColor = Color == COLOR4D::UNSPECIFIED ?
883  GetLayerColor( LAYER_PINNUM ) : Color;
884 
885  int x1 = pin_pos.x;
886  int y1 = pin_pos.y;
887 
888  switch( orient )
889  {
890  case PIN_UP:
891  y1 -= m_length;
892  break;
893 
894  case PIN_DOWN:
895  y1 += m_length;
896  break;
897 
898  case PIN_LEFT:
899  x1 -= m_length;
900  break;
901 
902  case PIN_RIGHT:
903  x1 += m_length;
904  break;
905  }
906 
907  if( m_name.IsEmpty() )
908  DrawPinName = false;
909 
910  if( TextInside ) // Draw the text inside, but the pin numbers outside.
911  {
912  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
913  {
914  // It is an horizontal line
915  if( DrawPinName )
916  {
917  if( orient == PIN_RIGHT )
918  {
919  x = x1 + TextInside;
920  DrawGraphicText( clipbox, DC, wxPoint( x, y1 ), NameColor,
921  m_name,
923  PinNameSize,
925  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
926  false, false );
927  }
928  else // Orient == PIN_LEFT
929  {
930  x = x1 - TextInside;
931  DrawGraphicText( clipbox, DC, wxPoint( x, y1 ), NameColor,
932  m_name,
934  PinNameSize,
936  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
937  false, false );
938  }
939  }
940 
941  if( DrawPinNum )
942  {
943  DrawGraphicText( clipbox, DC,
944  wxPoint( (x1 + pin_pos.x) / 2,
945  y1 - num_offset ), NumColor,
946  m_number,
947  TEXT_ANGLE_HORIZ, PinNumSize,
949  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
950  false, false );
951  }
952  }
953  else /* Its a vertical line. */
954  {
955  // Text is drawn from bottom to top (i.e. to negative value for Y axis)
956  if( orient == PIN_DOWN )
957  {
958  y = y1 + TextInside;
959 
960  if( DrawPinName )
961  DrawGraphicText( clipbox, DC, wxPoint( x1, y ), NameColor,
962  m_name,
963  TEXT_ANGLE_VERT, PinNameSize,
965  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
966  false, false );
967 
968  if( DrawPinNum )
969  DrawGraphicText( clipbox, DC,
970  wxPoint( x1 - num_offset,
971  (y1 + pin_pos.y) / 2 ), NumColor,
972  m_number,
973  TEXT_ANGLE_VERT, PinNumSize,
975  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
976  false, false );
977  }
978  else /* PIN_UP */
979  {
980  y = y1 - TextInside;
981 
982  if( DrawPinName )
983  DrawGraphicText( clipbox, DC, wxPoint( x1, y ), NameColor,
984  m_name,
985  TEXT_ANGLE_VERT, PinNameSize,
987  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
988  false, false );
989 
990  if( DrawPinNum )
991  DrawGraphicText( clipbox, DC,
992  wxPoint( x1 - num_offset,
993  (y1 + pin_pos.y) / 2 ), NumColor,
994  m_number,
995  TEXT_ANGLE_VERT, PinNumSize,
997  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
998  false, false );
999  }
1000  }
1001  }
1002  else /**** Draw num & text pin outside ****/
1003  {
1004  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1005  {
1006  /* Its an horizontal line. */
1007  if( DrawPinName )
1008  {
1009  x = (x1 + pin_pos.x) / 2;
1010  DrawGraphicText( clipbox, DC, wxPoint( x, y1 - name_offset ),
1011  NameColor, m_name,
1012  TEXT_ANGLE_HORIZ, PinNameSize,
1014  GR_TEXT_VJUSTIFY_BOTTOM, nameLineWidth,
1015  false, false );
1016  }
1017  if( DrawPinNum )
1018  {
1019  x = (x1 + pin_pos.x) / 2;
1020  DrawGraphicText( clipbox, DC, wxPoint( x, y1 + num_offset ),
1021  NumColor, m_number,
1022  TEXT_ANGLE_HORIZ, PinNumSize,
1024  GR_TEXT_VJUSTIFY_TOP, numLineWidth,
1025  false, false );
1026  }
1027  }
1028  else /* Its a vertical line. */
1029  {
1030  if( DrawPinName )
1031  {
1032  y = (y1 + pin_pos.y) / 2;
1033  DrawGraphicText( clipbox, DC, wxPoint( x1 - name_offset, y ),
1034  NameColor, m_name,
1035  TEXT_ANGLE_VERT, PinNameSize,
1037  GR_TEXT_VJUSTIFY_BOTTOM, nameLineWidth,
1038  false, false );
1039  }
1040 
1041  if( DrawPinNum )
1042  {
1043  DrawGraphicText( clipbox, DC,
1044  wxPoint( x1 + num_offset, (y1 + pin_pos.y)
1045  / 2 ),
1046  NumColor, m_number,
1047  TEXT_ANGLE_VERT, PinNumSize,
1049  GR_TEXT_VJUSTIFY_TOP, numLineWidth,
1050  false, false );
1051  }
1052  }
1053  }
1054 }
1055 
1056 
1057 
1059  wxPoint& aPosition, int aOrientation,
1060  COLOR4D aColor, GR_DRAWMODE aDrawMode )
1061 {
1062  wxString etypeName = GetElectricalTypeName();
1063 
1064  // Use a reasonable (small) size to draw the text
1065  int etextSize = (m_nameTextSize*3)/4;
1066 
1067  #define ETXT_MAX_SIZE Millimeter2iu(0.7 )
1068  if( etextSize > ETXT_MAX_SIZE )
1069  etextSize = ETXT_MAX_SIZE;
1070 
1071  // Use a reasonable pen size to draw the text
1072  int pensize = etextSize/6;
1073 
1074  // Get a suitable color
1075  if( ( aColor == COLOR4D::UNSPECIFIED ) && IsSelected() )
1076  aColor = GetItemSelectedColor();
1077  else if( !IsVisible() )
1078  aColor = GetInvisibleItemColor();
1079  else
1080  aColor = GetLayerColor( LAYER_NOTES );
1081 
1082  wxPoint txtpos = aPosition;
1083  int offset = Millimeter2iu( 0.4 );
1085  int orient = TEXT_ANGLE_HORIZ;
1086 
1087  switch( aOrientation )
1088  {
1089  case PIN_UP:
1090  txtpos.y += offset;
1091  orient = TEXT_ANGLE_VERT;
1092  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1093  break;
1094 
1095  case PIN_DOWN:
1096  txtpos.y -= offset;
1097  orient = TEXT_ANGLE_VERT;
1098  break;
1099 
1100  case PIN_LEFT:
1101  txtpos.x += offset;
1102  break;
1103 
1104  case PIN_RIGHT:
1105  txtpos.x -= offset;
1106  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1107  break;
1108  }
1109 
1110  GRSetDrawMode( aDC, aDrawMode );
1111  EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL;
1112 
1113  DrawGraphicText( clipbox, aDC, txtpos, aColor, etypeName,
1114  orient, wxSize( etextSize, etextSize ),
1115  hjustify, GR_TEXT_VJUSTIFY_CENTER, pensize,
1116  false, false );
1117 }
1118 
1119 
1120 void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation )
1121 {
1122  int MapX1, MapY1, x1, y1;
1124 
1125  aPlotter->SetColor( color );
1126  aPlotter->SetCurrentLineWidth( GetPenSize() );
1127 
1128  MapX1 = MapY1 = 0;
1129  x1 = aPosition.x; y1 = aPosition.y;
1130 
1131  switch( aOrientation )
1132  {
1133  case PIN_UP:
1134  y1 = aPosition.y - m_length;
1135  MapY1 = 1;
1136  break;
1137 
1138  case PIN_DOWN:
1139  y1 = aPosition.y + m_length;
1140  MapY1 = -1;
1141  break;
1142 
1143  case PIN_LEFT:
1144  x1 = aPosition.x - m_length;
1145  MapX1 = 1;
1146  break;
1147 
1148  case PIN_RIGHT:
1149  x1 = aPosition.x + m_length;
1150  MapX1 = -1;
1151  break;
1152  }
1153 
1155  {
1156  const int radius = ExternalPinDecoSize( *this );
1157  aPlotter->Circle( wxPoint( MapX1 * radius + x1,
1158  MapY1 * radius + y1 ),
1159  radius * 2, // diameter
1160  NO_FILL, // fill option
1161  GetPenSize() ); // width
1162 
1163  aPlotter->MoveTo( wxPoint( MapX1 * radius * 2 + x1,
1164  MapY1 * radius * 2 + y1 ) );
1165  aPlotter->FinishTo( aPosition );
1166  }
1167  else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK )
1168  {
1169  const int clock_size = InternalPinDecoSize( *this );
1170  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1171  {
1172  aPlotter->MoveTo( wxPoint( x1, y1 + clock_size ) );
1173  aPlotter->LineTo( wxPoint( x1 + MapX1 * clock_size * 2, y1 ) );
1174  aPlotter->FinishTo( wxPoint( x1, y1 - clock_size ) );
1175  }
1176  else /* MapX1 = 0 */
1177  {
1178  aPlotter->MoveTo( wxPoint( x1 + clock_size, y1 ) );
1179  aPlotter->LineTo( wxPoint( x1, y1 + MapY1 * clock_size * 2 ) );
1180  aPlotter->FinishTo( wxPoint( x1 - clock_size, y1 ) );
1181  }
1182 
1183  aPlotter->MoveTo( wxPoint( MapX1 * clock_size * 2 + x1,
1184  MapY1 * clock_size * 2 + y1 ) );
1185  aPlotter->FinishTo( aPosition );
1186  }
1187  else
1188  {
1189  aPlotter->MoveTo( wxPoint( x1, y1 ) );
1190  aPlotter->FinishTo( aPosition );
1191  }
1192 
1195  {
1196  const int clock_size = InternalPinDecoSize( *this );
1197  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1198  {
1199  aPlotter->MoveTo( wxPoint( x1, y1 + clock_size ) );
1200  aPlotter->LineTo( wxPoint( x1 - MapX1 * clock_size * 2, y1 ) );
1201  aPlotter->FinishTo( wxPoint( x1, y1 - clock_size ) );
1202  }
1203  else /* MapX1 = 0 */
1204  {
1205  aPlotter->MoveTo( wxPoint( x1 + clock_size, y1 ) );
1206  aPlotter->LineTo( wxPoint( x1, y1 - MapY1 * clock_size * 2 ) );
1207  aPlotter->FinishTo( wxPoint( x1 - clock_size, y1 ) );
1208  }
1209  }
1210 
1211  if( m_shape == PINSHAPE_INPUT_LOW || m_shape == PINSHAPE_CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
1212  {
1213  const int symbol_size = ExternalPinDecoSize( *this );
1214 
1215  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1216  {
1217  aPlotter->MoveTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
1218  aPlotter->LineTo( wxPoint( x1 + MapX1 * symbol_size * 2,
1219  y1 - symbol_size * 2 ) );
1220  aPlotter->FinishTo( wxPoint( x1, y1 ) );
1221  }
1222  else /* MapX1 = 0 */
1223  {
1224  aPlotter->MoveTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
1225  aPlotter->LineTo( wxPoint( x1 - symbol_size * 2,
1226  y1 + MapY1 * symbol_size * 2 ) );
1227  aPlotter->FinishTo( wxPoint( x1, y1 ) );
1228  }
1229  }
1230 
1231 
1232  if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1233  {
1234  const int symbol_size = ExternalPinDecoSize( *this );
1235 
1236  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1237  {
1238  aPlotter->MoveTo( wxPoint( x1, y1 - symbol_size * 2 ) );
1239  aPlotter->FinishTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
1240  }
1241  else /* MapX1 = 0 */
1242  {
1243  aPlotter->MoveTo( wxPoint( x1 - symbol_size * 2, y1 ) );
1244  aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
1245  }
1246  }
1247  else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
1248  {
1249  const int symbol_size = ExternalPinDecoSize( *this );
1250  aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * symbol_size,
1251  y1 - (MapY1 - MapX1) * symbol_size ) );
1252  aPlotter->FinishTo( wxPoint( x1 + (MapX1 + MapY1) * symbol_size,
1253  y1 + (MapY1 - MapX1) * symbol_size ) );
1254  aPlotter->MoveTo( wxPoint( x1 - (MapX1 - MapY1) * symbol_size,
1255  y1 - (MapY1 + MapX1) * symbol_size ) );
1256  aPlotter->FinishTo( wxPoint( x1 + (MapX1 - MapY1) * symbol_size,
1257  y1 + (MapY1 + MapX1) * symbol_size ) );
1258  }
1259  if( m_type == PIN_NC ) // Draw a N.C. symbol
1260  {
1261  const int ex1 = aPosition.x;
1262  const int ey1 = aPosition.y;
1263  aPlotter->MoveTo( wxPoint( ex1 - NCSYMB_PIN_DIM, ey1 - NCSYMB_PIN_DIM ) );
1264  aPlotter->FinishTo( wxPoint( ex1 + NCSYMB_PIN_DIM, ey1 + NCSYMB_PIN_DIM ) );
1265  aPlotter->MoveTo( wxPoint( ex1 + NCSYMB_PIN_DIM, ey1 - NCSYMB_PIN_DIM ) );
1266  aPlotter->FinishTo( wxPoint( ex1 - NCSYMB_PIN_DIM, ey1 + NCSYMB_PIN_DIM ) );
1267  }
1268 }
1269 
1270 
1271 void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
1272  int TextInside, bool DrawPinNum,
1273  bool DrawPinName, int aWidth )
1274 {
1275  if( m_name.IsEmpty() || m_name == wxT( "~" ) )
1276  DrawPinName = false;
1277 
1278  if( m_number.IsEmpty() )
1279  DrawPinNum = false;
1280 
1281  if( !DrawPinNum && !DrawPinName )
1282  return;
1283 
1284  int x, y;
1285  wxSize PinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
1286  wxSize PinNumSize = wxSize( m_numTextSize, m_numTextSize );
1287 
1288  int nameLineWidth = GetPenSize();
1289  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
1290  int numLineWidth = GetPenSize();
1291  numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
1292 
1293  int name_offset = PIN_TEXT_MARGIN +
1294  ( nameLineWidth + GetDefaultLineThickness() ) / 2;
1295  int num_offset = PIN_TEXT_MARGIN +
1296  ( numLineWidth + GetDefaultLineThickness() ) / 2;
1297 
1298  /* Get the num and name colors */
1299  COLOR4D NameColor = GetLayerColor( LAYER_PINNAM );
1300  COLOR4D NumColor = GetLayerColor( LAYER_PINNUM );
1301 
1302  int x1 = pin_pos.x;
1303  int y1 = pin_pos.y;
1304 
1305  switch( orient )
1306  {
1307  case PIN_UP:
1308  y1 -= m_length;
1309  break;
1310 
1311  case PIN_DOWN:
1312  y1 += m_length;
1313  break;
1314 
1315  case PIN_LEFT:
1316  x1 -= m_length;
1317  break;
1318 
1319  case PIN_RIGHT:
1320  x1 += m_length;
1321  break;
1322  }
1323 
1324  /* Draw the text inside, but the pin numbers outside. */
1325  if( TextInside )
1326  {
1327  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) ) /* Its an horizontal line. */
1328  {
1329  if( DrawPinName )
1330  {
1331  if( orient == PIN_RIGHT )
1332  {
1333  x = x1 + TextInside;
1334  plotter->Text( wxPoint( x, y1 ), NameColor,
1335  m_name,
1337  PinNameSize,
1340  aWidth, false, false );
1341  }
1342  else // orient == PIN_LEFT
1343  {
1344  x = x1 - TextInside;
1345 
1346  if( DrawPinName )
1347  plotter->Text( wxPoint( x, y1 ),
1348  NameColor, m_name, TEXT_ANGLE_HORIZ,
1349  PinNameSize,
1352  aWidth, false, false );
1353  }
1354  }
1355  if( DrawPinNum )
1356  {
1357  plotter->Text( wxPoint( (x1 + pin_pos.x) / 2,
1358  y1 - num_offset ),
1359  NumColor, m_number,
1360  TEXT_ANGLE_HORIZ, PinNumSize,
1363  aWidth, false, false );
1364  }
1365  }
1366  else /* Its a vertical line. */
1367  {
1368  if( orient == PIN_DOWN )
1369  {
1370  y = y1 + TextInside;
1371 
1372  if( DrawPinName )
1373  plotter->Text( wxPoint( x1, y ), NameColor,
1374  m_name,
1375  TEXT_ANGLE_VERT, PinNameSize,
1378  aWidth, false, false );
1379 
1380  if( DrawPinNum )
1381  {
1382  plotter->Text( wxPoint( x1 - num_offset,
1383  (y1 + pin_pos.y) / 2 ),
1384  NumColor, m_number,
1385  TEXT_ANGLE_VERT, PinNumSize,
1388  aWidth, false, false );
1389  }
1390  }
1391  else /* PIN_UP */
1392  {
1393  y = y1 - TextInside;
1394 
1395  if( DrawPinName )
1396  plotter->Text( wxPoint( x1, y ), NameColor,
1397  m_name,
1398  TEXT_ANGLE_VERT, PinNameSize,
1401  aWidth, false, false );
1402 
1403  if( DrawPinNum )
1404  {
1405  plotter->Text( wxPoint( x1 - num_offset,
1406  (y1 + pin_pos.y) / 2 ),
1407  NumColor, m_number,
1408  TEXT_ANGLE_VERT, PinNumSize,
1411  aWidth, false, false );
1412  }
1413  }
1414  }
1415  }
1416  else /* Draw num & text pin outside */
1417  {
1418  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1419  {
1420  /* Its an horizontal line. */
1421  if( DrawPinName )
1422  {
1423  x = (x1 + pin_pos.x) / 2;
1424  plotter->Text( wxPoint( x, y1 - name_offset ),
1425  NameColor, m_name,
1426  TEXT_ANGLE_HORIZ, PinNameSize,
1429  aWidth, false, false );
1430  }
1431 
1432  if( DrawPinNum )
1433  {
1434  x = ( x1 + pin_pos.x ) / 2;
1435  plotter->Text( wxPoint( x, y1 + num_offset ),
1436  NumColor, m_number,
1437  TEXT_ANGLE_HORIZ, PinNumSize,
1440  aWidth, false, false );
1441  }
1442  }
1443  else /* Its a vertical line. */
1444  {
1445  if( DrawPinName )
1446  {
1447  y = ( y1 + pin_pos.y ) / 2;
1448  plotter->Text( wxPoint( x1 - name_offset, y ),
1449  NameColor, m_name,
1450  TEXT_ANGLE_VERT, PinNameSize,
1453  aWidth, false, false );
1454  }
1455 
1456  if( DrawPinNum )
1457  {
1458  plotter->Text( wxPoint( x1 + num_offset,
1459  ( y1 + pin_pos.y ) / 2 ),
1460  NumColor, m_number,
1461  TEXT_ANGLE_VERT, PinNumSize,
1464  aWidth, false, false );
1465  }
1466  }
1467  }
1468 }
1469 
1470 
1472 {
1473  wxPoint pos = m_position;
1474 
1475  switch( m_orientation )
1476  {
1477  case PIN_UP:
1478  pos.y += m_length;
1479  break;
1480 
1481  case PIN_DOWN:
1482  pos.y -= m_length;
1483  break;
1484 
1485  case PIN_LEFT:
1486  pos.x -= m_length;
1487  break;
1488 
1489  case PIN_RIGHT:
1490  pos.x += m_length;
1491  break;
1492  }
1493 
1494  return pos;
1495 }
1496 
1497 
1498 int LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const
1499 {
1500  int orient;
1501  wxPoint end; // position of pin end starting at 0,0 according to its orientation, length = 1
1502 
1503  switch( m_orientation )
1504  {
1505  case PIN_UP:
1506  end.y = 1;
1507  break;
1508 
1509  case PIN_DOWN:
1510  end.y = -1;
1511  break;
1512 
1513  case PIN_LEFT:
1514  end.x = -1;
1515  break;
1516 
1517  case PIN_RIGHT:
1518  end.x = 1;
1519  break;
1520  }
1521 
1522  // = pos of end point, according to the component orientation
1523  end = aTransform.TransformCoordinate( end );
1524  orient = PIN_UP;
1525 
1526  if( end.x == 0 )
1527  {
1528  if( end.y > 0 )
1529  orient = PIN_DOWN;
1530  }
1531  else
1532  {
1533  orient = PIN_RIGHT;
1534 
1535  if( end.x < 0 )
1536  orient = PIN_LEFT;
1537  }
1538 
1539  return orient;
1540 }
1541 
1542 
1544 {
1545  return new LIB_PIN( *this );
1546 }
1547 
1548 
1549 int LIB_PIN::compare( const LIB_ITEM& other ) const
1550 {
1551  wxASSERT( other.Type() == LIB_PIN_T );
1552 
1553  const LIB_PIN* tmp = (LIB_PIN*) &other;
1554 
1555  if( m_number != tmp->m_number )
1556  return m_number.Cmp( tmp->m_number );
1557 
1558  int result = m_name.CmpNoCase( tmp->m_name );
1559 
1560  if( result != 0 )
1561  return result;
1562 
1563  if( m_position.x != tmp->m_position.x )
1564  return m_position.x - tmp->m_position.x;
1565 
1566  if( m_position.y != tmp->m_position.y )
1567  return m_position.y - tmp->m_position.y;
1568 
1569  return 0;
1570 }
1571 
1572 
1573 void LIB_PIN::SetOffset( const wxPoint& aOffset )
1574 {
1575  m_position += aOffset;
1576 }
1577 
1578 
1579 bool LIB_PIN::Inside( EDA_RECT& rect ) const
1580 {
1581  wxPoint end = PinEndPoint();
1582 
1583  return rect.Contains( m_position.x, -m_position.y ) || rect.Contains( end.x, -end.y );
1584 }
1585 
1586 
1587 void LIB_PIN::Move( const wxPoint& newPosition )
1588 {
1589  if( m_position != newPosition )
1590  {
1591  m_position = newPosition;
1592  SetModified();
1593  }
1594 }
1595 
1596 
1597 void LIB_PIN::MirrorHorizontal( const wxPoint& center )
1598 {
1599  m_position.x -= center.x;
1600  m_position.x *= -1;
1601  m_position.x += center.x;
1602 
1603  if( m_orientation == PIN_RIGHT )
1605  else if( m_orientation == PIN_LEFT )
1607 }
1608 
1609 void LIB_PIN::MirrorVertical( const wxPoint& center )
1610 {
1611  m_position.y -= center.y;
1612  m_position.y *= -1;
1613  m_position.y += center.y;
1614 
1615  if( m_orientation == PIN_UP )
1617  else if( m_orientation == PIN_DOWN )
1619 }
1620 
1621 void LIB_PIN::Rotate( const wxPoint& center, bool aRotateCCW )
1622 {
1623  int rot_angle = aRotateCCW ? -900 : 900;
1624 
1625  RotatePoint( &m_position, center, rot_angle );
1626 
1627  if( aRotateCCW )
1628  {
1629  switch( m_orientation )
1630  {
1631  case PIN_RIGHT:
1633  break;
1634 
1635  case PIN_UP:
1637  break;
1638  case PIN_LEFT:
1640  break;
1641 
1642  case PIN_DOWN:
1644  break;
1645  }
1646  }
1647  else
1648  {
1649  switch( m_orientation )
1650  {
1651  case PIN_RIGHT:
1653  break;
1654 
1655  case PIN_UP:
1657  break;
1658  case PIN_LEFT:
1660  break;
1661 
1662  case PIN_DOWN:
1664  break;
1665  }
1666  }
1667 }
1668 
1669 
1670 void LIB_PIN::Plot( PLOTTER* plotter, const wxPoint& offset, bool fill,
1671  const TRANSFORM& aTransform )
1672 {
1673  if( ! IsVisible() )
1674  return;
1675 
1676  int orient = PinDrawOrient( aTransform );
1677 
1678  wxPoint pos = aTransform.TransformCoordinate( m_position ) + offset;
1679 
1680  PlotSymbol( plotter, pos, orient );
1681  PlotPinTexts( plotter, pos, orient, GetParent()->GetPinNameOffset(),
1682  GetParent()->ShowPinNumbers(), GetParent()->ShowPinNames(),
1683  GetPenSize() );
1684 }
1685 
1686 
1687 void LIB_PIN::SetWidth( int aWidth )
1688 {
1689  if( m_width != aWidth )
1690  {
1691  m_width = aWidth;
1692  SetModified();
1693  }
1694 }
1695 
1696 
1698 {
1699  wxString text = m_number.IsEmpty() ? wxT( "?" ) : m_number;
1700 
1701  LIB_ITEM::GetMsgPanelInfo( aList );
1702 
1703  aList.push_back( MSG_PANEL_ITEM( _( "Name" ), m_name, DARKCYAN ) );
1704 
1705  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), text, DARKCYAN ) );
1706 
1707  aList.push_back( MSG_PANEL_ITEM( _( "Type" ),
1708  GetText( m_type ),
1709  RED ) );
1710 
1711  text = GetText( m_shape );
1712 
1713  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text, BLUE ) );
1714 
1715  if( IsVisible() )
1716  text = _( "Yes" );
1717  else
1718  text = _( "No" );
1719 
1720  aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), text, DARKGREEN ) );
1721 
1722  // Display pin length
1723  text = StringFromValue( g_UserUnit, m_length, true );
1724  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), text, MAGENTA ) );
1725 
1727  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), text, DARKMAGENTA ) );
1728 }
1729 
1731 {
1732  getMsgPanelInfoBase( aList );
1733 
1734  wxString text;
1735  wxPoint pinpos = GetPosition();
1736  pinpos.y = -pinpos.y; // Display coord are top to bottom
1737  // lib items coord are bottom to top
1738 
1739  text = StringFromValue( g_UserUnit, pinpos.x, true );
1740  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text, DARKMAGENTA ) );
1741 
1742  text = StringFromValue( g_UserUnit, pinpos.y, true );
1743  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text, DARKMAGENTA ) );
1744 }
1745 
1746 void LIB_PIN::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList,
1747  SCH_COMPONENT* aComponent )
1748 {
1749  getMsgPanelInfoBase( aList );
1750 
1751  if( !aComponent )
1752  return;
1753 
1754  wxString text;
1755  wxPoint pinpos = aComponent->GetTransform().TransformCoordinate( GetPosition() )
1756  + aComponent->GetPosition();
1757 
1758  text = StringFromValue( g_UserUnit, pinpos.x, true );
1759  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text, DARKMAGENTA ) );
1760 
1761  text = StringFromValue( g_UserUnit, pinpos.y, true );
1762  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text, DARKMAGENTA ) );
1763 
1764  aList.push_back( MSG_PANEL_ITEM( aComponent->GetField( REFERENCE )->GetShownText(),
1765  aComponent->GetField( VALUE )->GetShownText(),
1766  DARKCYAN ) );
1767 }
1768 
1769 const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles ) const
1770 {
1771  LIB_PART* entry = (LIB_PART* ) m_Parent;
1772  EDA_RECT bbox;
1773  wxPoint begin;
1774  wxPoint end;
1775  int nameTextOffset = 0;
1776  bool showName = !m_name.IsEmpty() && (m_name != wxT( "~" ));
1777  bool showNum = !m_number.IsEmpty();
1778  int minsizeV = TARGET_PIN_RADIUS;
1779 
1780  if( !aIncludeInvisibles && !IsVisible() )
1781  showName = false;
1782 
1783  if( entry )
1784  {
1785  if( entry->ShowPinNames() )
1786  nameTextOffset = entry->GetPinNameOffset();
1787  else
1788  showName = false;
1789 
1790  showNum = entry->ShowPinNumbers();
1791  }
1792 
1793  // First, calculate boundary box corners position
1794  int numberTextLength = showNum ? m_numTextSize * m_number.Len() : 0;
1795 
1796  // Actual text height is bigger than text size
1797  int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
1798 
1800  minsizeV = std::max( TARGET_PIN_RADIUS, ExternalPinDecoSize( *this ) );
1801 
1802  // calculate top left corner position
1803  // for the default pin orientation (PIN_RIGHT)
1804  begin.y = std::max( minsizeV, numberTextHeight + PIN_TEXT_MARGIN );
1805  begin.x = std::min( -TARGET_PIN_RADIUS, m_length - (numberTextLength / 2) );
1806 
1807  // calculate bottom right corner position and adjust top left corner position
1808  int nameTextLength = 0;
1809  int nameTextHeight = 0;
1810 
1811  if( showName )
1812  {
1813  int length = m_name.Len();
1814 
1815  // Don't count the line over text symbol.
1816  if( m_name.Left( 1 ) == wxT( "~" ) )
1817  length -= 1;
1818 
1819  nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
1820 
1821  // Actual text height are bigger than text size
1822  nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + PIN_TEXT_MARGIN;
1823  }
1824 
1825  if( nameTextOffset ) // for values > 0, pin name is inside the body
1826  {
1827  end.x = m_length + nameTextLength;
1828  end.y = std::min( -minsizeV, -nameTextHeight / 2 );
1829  }
1830  else // if value == 0:
1831  // pin name is outside the body, and above the pin line
1832  // pin num is below the pin line
1833  {
1834  end.x = std::max(m_length, nameTextLength);
1835  end.y = -begin.y;
1836  begin.y = std::max( minsizeV, nameTextHeight );
1837  }
1838 
1839  // Now, calculate boundary box corners position for the actual pin orientation
1840  int orient = PinDrawOrient( DefaultTransform );
1841 
1842  /* Calculate the pin position */
1843  switch( orient )
1844  {
1845  case PIN_UP:
1846  // Pin is rotated and texts positions are mirrored
1847  RotatePoint( &begin, wxPoint( 0, 0 ), -900 );
1848  RotatePoint( &end, wxPoint( 0, 0 ), -900 );
1849  break;
1850 
1851  case PIN_DOWN:
1852  RotatePoint( &begin, wxPoint( 0, 0 ), 900 );
1853  RotatePoint( &end, wxPoint( 0, 0 ), 900 );
1854  begin.x = -begin.x;
1855  end.x = -end.x;
1856  break;
1857 
1858  case PIN_LEFT:
1859  begin.x = -begin.x;
1860  end.x = -end.x;
1861  break;
1862 
1863  case PIN_RIGHT:
1864  break;
1865  }
1866 
1867  begin += m_position;
1868  end += m_position;
1869 
1870  bbox.SetOrigin( begin );
1871  bbox.SetEnd( end );
1872  bbox.Normalize();
1873  bbox.Inflate( ( GetPenSize() / 2 ) + 1 );
1874 
1875  // Draw Y axis is reversed in schematic:
1876  bbox.RevertYAxis();
1877 
1878  return bbox;
1879 }
1880 
1881 
1882 wxArrayString LIB_PIN::GetOrientationNames( void )
1883 {
1884  wxArrayString tmp;
1885 
1886  for( unsigned ii = 0; ii < PIN_ORIENTATION_CNT; ii++ )
1887  tmp.Add( getPinOrientationName( ii ) );
1888 
1889  return tmp;
1890 }
1891 
1892 
1894 {
1895  if( index >= 0 && index < (int) PIN_ORIENTATION_CNT )
1896  return pin_orientation_codes[ index ];
1897 
1898  return PIN_RIGHT;
1899 }
1900 
1901 
1903 {
1904  size_t i;
1905 
1906  for( i = 0; i < PIN_ORIENTATION_CNT; i++ )
1907  {
1908  if( pin_orientation_codes[i] == code )
1909  return (int) i;
1910  }
1911 
1912  return wxNOT_FOUND;
1913 }
1914 
1915 
1917 {
1918  int orient = PIN_RIGHT;
1919 
1920  switch( GetOrientation() )
1921  {
1922  case PIN_UP:
1923  orient = PIN_LEFT;
1924  break;
1925 
1926  case PIN_DOWN:
1927  orient = PIN_RIGHT;
1928  break;
1929 
1930  case PIN_LEFT:
1931  orient = PIN_DOWN;
1932  break;
1933 
1934  case PIN_RIGHT:
1935  orient = PIN_UP;
1936  break;
1937  }
1938 
1939  // Set the new orientation
1940  SetOrientation( orient );
1941 }
1942 
1943 
1945 {
1946  return iconsPinsOrientations;
1947 }
1948 
1949 
1951 {
1952  return GetBitmap( m_type );
1953 }
1954 
1955 
1957 {
1958  wxString tmp;
1959  wxString style;
1960 
1961  style = GetText( m_shape );
1962 
1963  tmp.Printf( _( "Pin %s, %s, %s" ),
1965 
1966  return tmp;
1967 }
1968 
1969 
1970 bool LIB_PIN::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation )
1971 {
1972  wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText() );
1973 
1974  // Note: this will have to be modified if we add find and replace capability to the
1975  // compoment library editor. Otherwise, you wont be able to replace pin text.
1976  if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_PINS )
1977  || ( aSearchData.GetFlags() & FR_SEARCH_REPLACE ) )
1978  return false;
1979 
1980  wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText() );
1981 
1982  if( EDA_ITEM::Matches( GetName(), aSearchData ) || EDA_ITEM::Matches( m_number, aSearchData ) )
1983  {
1984  if( aFindLocation )
1985  *aFindLocation = GetBoundingBox().Centre();
1986 
1987  return true;
1988  }
1989 
1990  return false;
1991 }
1992 
1993 
1994 #if defined(DEBUG)
1995 
1996 void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
1997 {
1998  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
1999  << " num=\"" << m_number.mb_str()
2000  << '"' << "/>\n";
2001 
2002 // NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
2003 }
2004 
2005 #endif
Definition: colors.h:57
void FinishTo(const wxPoint &pos)
#define IS_LINKED
Used in calculation to mark linked items (temporary use)
Definition: base_struct.h:124
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:108
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:1970
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_pin.cpp:1549
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
void SetModified()
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:80
void SetLength(int aLength, bool aTestOtherPins=true)
Set the pin length.
Definition: lib_pin.cpp:363
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:1543
void DrawGraphicText(EDA_RECT *aClipBox, wxDC *aDC, const wxPoint &aPos, COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, void(*aCallback)(int x0, int y0, int xf, int yf), PLOTTER *aPlotter)
Function DrawGraphicText Draw a graphic text (like module texts)
Definition: drawtxt.cpp:122
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:195
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:125
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:47
void DrawPinElectricalTypeName(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation, COLOR4D aColor, GR_DRAWMODE aDrawMode)
Draw the electrical type text of the pin (only for the footprint editor) aDrawMode = GR_OR...
Definition: lib_pin.cpp:1058
TRANSFORM & GetTransform() const
static int ExternalPinDecoSize(const LIB_PIN &aPin)
Utility for getting the size of the 'external' pin decorators (as a radius)
Definition: lib_pin.cpp:141
PNG memory record (file in memory).
Definition: bitmap_types.h:41
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:73
int GetPinNameOffset()
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:318
wxString m_typeName
Name of object displayed in the message panel.
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
#define ETXT_MAX_SIZE
static const wxString getPinOrientationName(unsigned aPinOrientationCode)
Definition: lib_pin.cpp:107
Implementation of conversion functions that require both schematic and board internal units...
int m_numTextSize
Definition: lib_pin.h:79
bool IsNew() const
Definition: base_struct.h:243
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:1882
void getMsgPanelInfoBase(std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:1697
virtual void SetColor(COLOR4D color)=0
bool Contains(const wxPoint &aPoint) const
Function Contains.
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1950
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:298
Definition: colors.h:61
wxString StringFromValue(EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:204
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:427
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
static int GetDefaultPinLength()
Definition: libeditframe.h:186
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:255
void SetName(const wxString &aName, bool aTestOtherPins=true)
Set the pin name.
Definition: lib_pin.cpp:161
bool IsSelected() const
Definition: base_struct.h:248
static const BITMAP_DEF iconsPinsOrientations[]
Definition: lib_pin.cpp:66
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:264
void SetOrigin(const wxPoint &pos)
void SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_pin.cpp:1687
void SetOffset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1573
Search texts (name and number (a 4 letters text) )in pins.
int m_Unit
Unit identification for multiple parts per package.
wxString m_name
Definition: lib_pin.h:77
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:1944
Schematic editor (Eeschema) main window.
Definition: schframe.h:118
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Definition: lib_pin.cpp:1730
Definition: lib_pin.h:55
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
void EnableEditMode(bool aEnable, bool aEditPinByPin=false)
Enable or clear pin editing mode.
Definition: lib_pin.cpp:514
void PlotPinTexts(PLOTTER *aPlotter, wxPoint &aPosition, int aOrientation, int aTextInside, bool aDrawPinNum, bool aDrawPinName, int aWidth)
Plot the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:1271
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:134
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:54
int GetNameTextSize() const
Definition: lib_pin.h:181
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:167
int GetOrientation() const
Definition: lib_pin.h:210
int m_length
Length of the pin.
Definition: lib_pin.h:71
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size) ...
static int GetOrientationCodeIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:1902
#define TEXT_ANGLE_VERT
Definition: common.h:92
COLOR4D GetInvisibleItemColor()
Field Reference of part, i.e. "IC21".
int GetNumberTextSize() const
Definition: lib_pin.h:208
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
This file contains miscellaneous commonly used macros and functions.
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL)
Draws text with the plotter.
Definition: drawtxt.cpp:229
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:1609
void drawGraphic(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform) override
Draw a pin, with or without the pin texts.
Definition: lib_pin.cpp:570
const wxString & GetName() const
Definition: lib_pin.h:155
void SetConversion(int aConversion)
Set the body style (conversion) of the pin.
Definition: lib_pin.cpp:450
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:133
void GRLineTo(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int width, COLOR4D Color)
Definition: gr_basic.cpp:432
void SetNumber(const wxString &aNumber)
Set the pin number.
Definition: lib_pin.cpp:222
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41
bool ShowPinNames()
int GetPenSize() const override
Definition: lib_pin.cpp:564
static int GetPinNumDefaultSize()
Definition: libeditframe.h:178
void LineTo(const wxPoint &pos)
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:72
GRAPHIC_PINSHAPE
Definition: pin_shape.h:35
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:123
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1098
bool ShowPinNumbers()
LIB_PART * GetParent() const
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
const wxString traceFindItem
Flag to enable finding schematic item debug output.
wxString m_number
Definition: lib_pin.h:78
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:1120
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:280
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
#define PIN_INVISIBLE
Definition: lib_pin.h:46
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Class LIB_ITEM definition.
void SetEnd(int x, int y)
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize As a rule, pen width should not be >1/4em, otherwise the character will b...
Definition: drawtxt.cpp:67
bool Inside(EDA_RECT &aRect) const override
Test if any part of the draw object is inside rectangle bounds of aRect.
Definition: lib_pin.cpp:1579
bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
Definition: lib_pin.cpp:540
Define a library symbol object.
void SetVisible(bool aVisible)
Set or clear the visibility flag for the pin.
Definition: lib_pin.cpp:481
EDA_RECT * GetClipBox()
void Rotate() override
Rotate the draw item.
Definition: lib_pin.cpp:1916
Definition: colors.h:60
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:181
static const int pin_orientation_codes[]
Definition: lib_pin.cpp:52
wxPoint Centre() const
static int InternalPinDecoSize(const LIB_PIN &aPin)
Utility for getting the size of the 'internal' pin decorators (as a radius)
Definition: lib_pin.cpp:132
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:349
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:380
void DrawPinTexts(EDA_DRAW_PANEL *aPanel, wxDC *aDC, wxPoint &aPosition, int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName, COLOR4D aColor, GR_DRAWMODE aDrawMode)
Put the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:844
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:146
void SetPinPosition(wxPoint aPosition)
move this and all linked pins to the new position used in pin edition.
Definition: lib_pin.cpp:393
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:450
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
void MoveTo(const wxPoint &pos)
LIB_PIN * GetNextPin(LIB_PIN *aItem=NULL)
Return the next pin object from the draw list.
int m_attributes
Set bit 0 to indicate pin is invisible.
Definition: lib_pin.h:76
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:422
void Normalize()
Function Normalize ensures that the height ant width are positive.
#define NCSYMB_PIN_DIM
Base plotter engine class.
Definition: class_plotter.h:96
Definition the SCH_COMPONENT class for Eeschema.
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:70
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:60
virtual void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
void SetPartNumber(int aPart)
Set the pin part number.
Definition: lib_pin.cpp:420
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:58
void Plot(PLOTTER *aPlotter, const wxPoint &aOffset, bool aFill, const TRANSFORM &aTransform) override
Plot the draw item using the plot object.
Definition: lib_pin.cpp:1670
wxPoint PinEndPoint() const
Definition: lib_pin.cpp:1471
static int GetPinNameDefaultSize()
Definition: libeditframe.h:182
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
#define max(a, b)
Definition: auxiliary.h:86
#define PIN_TEXT_MARGIN
Definition: lib_pin.cpp:62
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, COLOR4D Color)
Definition: gr_basic.cpp:850
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:1956
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:202
Perform a search for a item that has replaceable text.
Class EDA_RECT handles the component boundary box.
void SetType(ELECTRICAL_PINTYPE aType, bool aTestOtherPins=true)
Set the electrical type of the pin.
Definition: lib_pin.cpp:327
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
wxPoint GetPosition() const override
Function GetPosition.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:194
void RemoveDrawItem(LIB_ITEM *aItem, EDA_DRAW_PANEL *aPanel=NULL, wxDC *aDc=NULL)
Remove draw aItem from list.
void Move(const wxPoint &aPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:1587
#define TARGET_PIN_RADIUS
Definition: lib_pin.h:43
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:178
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:75
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
int m_Convert
Shape identification for alternate body styles.
This file is part of the common libary.
void SetOrientation(int aOrientation, bool aTestOtherPins=true)
Set orientation on the pin.
Definition: lib_pin.cpp:269
COLOR4D GetItemSelectedColor()
bool IsType(FRAME_T aType) const
Definition: wxstruct.h:227
BITMAP_DEF GetBitmap(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:70
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
void SetNameTextSize(int aSize, bool aTestOtherPins=true)
Set the aSize of the pin name text.
Definition: lib_pin.cpp:194
Message panel definition file.
int m_width
Line width of the pin.
Definition: lib_pin.h:74
void DrawPinSymbol(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, int aOrientation, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED, bool aDrawDangling=true, bool aOnlyTarget=false)
Draw the pin symbol without text.
Definition: lib_pin.cpp:645
#define VALUE
#define PIN_ORIENTATION_CNT
Definition: lib_pin.cpp:59
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
Definition of class LIB_EDIT_FRAME.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
int PinDrawOrient(const TRANSFORM &aTransform) const
Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), according to its orientation...
Definition: lib_pin.cpp:1498
void SetNumberTextSize(int aSize, bool aTestOtherPins=true)
Set the size of the pin number text.
Definition: lib_pin.cpp:241
#define min(a, b)
Definition: auxiliary.h:85
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:1597
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
static int GetOrientationCode(int aIndex)
Get the orientation code by index used to set the pin orientation.
Definition: lib_pin.cpp:1893
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39