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 <sch_draw_panel.h>
38 #include <draw_graphic_text.h>
39 #include <plotter.h>
40 #include <sch_edit_frame.h>
41 #include <base_units.h>
42 #include <msgpanel.h>
43 
44 #include <general.h>
45 #include <lib_edit_frame.h>
46 #include <class_libentry.h>
47 #include <lib_pin.h>
48 #include <transform.h>
49 #include <sch_component.h>
50 #include <trace_helpers.h>
51 
52 
53 static const int pin_orientation_codes[] =
54 {
55  PIN_RIGHT,
56  PIN_LEFT,
57  PIN_UP,
58  PIN_DOWN
59 };
60 #define PIN_ORIENTATION_CNT DIM( pin_orientation_codes )
61 
62 // small margin in internal units between the pin text and the pin line
63 #define PIN_TEXT_MARGIN 4
64 
65 // bitmaps to show pins orientations in dialog editor
66 // must have same order than pin_orientation_names
68 {
69  pinorient_right_xpm,
70  pinorient_left_xpm,
71  pinorient_up_xpm,
72  pinorient_down_xpm,
73 };
74 
75 
77 {
78  if( aType < 0 || aType >= (int) PINTYPE_COUNT )
79  return wxT( "???" );
80 
81  // These strings are the canonical name of the electrictal type
82  // Not translated, no space in name, only ASCII chars.
83  // to use when the string name must be known and well defined
84  // must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h)
85  static const wxChar* msgPinElectricType[] =
86  {
87  wxT( "input" ),
88  wxT( "output" ),
89  wxT( "BiDi" ),
90  wxT( "3state" ),
91  wxT( "passive" ),
92  wxT( "unspc" ),
93  wxT( "power_in" ),
94  wxT( "power_out" ),
95  wxT( "openCol" ),
96  wxT( "openEm" ),
97  wxT( "NotConnected" )
98  };
99 
100  return msgPinElectricType[ aType ];
101 }
102 
103 
104 // Helper functions to get the pin orientation name from pin_orientation_codes
105 // Note: the strings are *not* static because they are translated and must be built
106 // on the fly, to be properly translated
107 
108 static const wxString getPinOrientationName( unsigned aPinOrientationCode )
109 {
110  /* Note: The following name lists are sentence capitalized per the GNOME UI
111  * standards for list controls. Please do not change the capitalization
112  * of these strings unless the GNOME UI standards are changed.
113  */
114  const wxString pin_orientation_names[] =
115  {
116  _( "Right" ),
117  _( "Left" ),
118  _( "Up" ),
119  _( "Down" ),
120  wxT( "???" )
121  };
122 
123  if( aPinOrientationCode > PIN_ORIENTATION_CNT )
124  aPinOrientationCode = PIN_ORIENTATION_CNT;
125 
126  return pin_orientation_names[ aPinOrientationCode ];
127 }
128 
130 // i.e. the clock symbols (falling clock is actually external but is of
131 // the same kind)
132 
133 static int InternalPinDecoSize( const LIB_PIN &aPin )
134 {
135 
136  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
137 }
138 
140 // i.e. the negation circle, the polarity 'slopes' and the nonlogic
141 // marker
142 static int ExternalPinDecoSize( const LIB_PIN &aPin )
143 {
144  return aPin.GetNumberTextSize() / 2;
145 }
146 
148  LIB_ITEM( LIB_PIN_T, aParent ),
150 {
152  m_orientation = PIN_RIGHT; // Pin orient: Up, Down, Left, Right
153  m_type = PIN_UNSPECIFIED; // electrical type of pin
154  m_attributes = 0; // bit 0 != 0: pin invisible
157  m_width = 0;
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 aEnable, bool aEditPinByPin )
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() && !aEditPinByPin && aEnable )
531  {
532  pinList[i]->SetFlags( IS_LINKED | IN_EDIT );
533  }
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  if( m_width > 0 )
567  return m_width;
568 
569  if( m_width == 0 )
570  return GetDefaultLineThickness();
571 
572  return 0;
573 }
574 
575 
577  wxDC* aDC,
578  const wxPoint& aOffset,
579  COLOR4D aColor,
580  GR_DRAWMODE aDrawMode,
581  void* aData,
582  const TRANSFORM& aTransform )
583 {
584  // aData is used here as a bitfield of flags.
585  uintptr_t flags = (uintptr_t) aData;
586  bool drawPinText = flags & PIN_DRAW_TEXTS;
587  bool drawPinDangling = flags & PIN_DRAW_DANGLING;
588  bool drawDanglingHidden = flags & PIN_DANGLING_HIDDEN;
589  bool drawElectricalTypeName = flags & PIN_DRAW_ELECTRICAL_TYPE_NAME;
590 
591  LIB_PART* Entry = GetParent();
592 
593  /* Calculate pin orient taking in account the component orientation. */
594  int orient = PinDrawOrient( aTransform );
595 
596  /* Calculate the pin position */
597  wxPoint pos1 = aTransform.TransformCoordinate( m_position ) + aOffset;
598 
599  // Invisible pins are only drawn on request.
600  // They are drawn in GetInvisibleItemColor().
601  if( ! IsVisible() )
602  {
603  bool drawHidden = false;
604 
605  if( aPanel && aPanel->GetParent() )
606  {
607  EDA_DRAW_FRAME* frame = aPanel->GetParent();
608 
609  if( frame->IsType( FRAME_SCH ) )
610  drawHidden = dynamic_cast<SCH_EDIT_FRAME*>( frame )->GetShowAllPins();
611  else if( frame->IsType( FRAME_SCH_LIB_EDITOR ) )
612  drawHidden = true; // must be able to edit
613  }
614 
615  if( !drawHidden )
616  {
617  if( drawPinDangling && drawDanglingHidden )
618  {
619  // Draw the target
620  DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor, drawPinDangling,
621  /* aOnlyTarget */ true );
622  }
623  return;
624  }
625 
626  aColor = GetInvisibleItemColor();
627  }
628 
629  /* Drawing from the pin and the special symbol combination */
630  DrawPinSymbol( aPanel, aDC, pos1, orient, aDrawMode, aColor, drawPinDangling );
631 
632  if( drawPinText )
633  {
634  DrawPinTexts( aPanel, aDC, pos1, orient, Entry->GetPinNameOffset(),
635  Entry->ShowPinNumbers(), Entry->ShowPinNames(),
636  aColor, aDrawMode );
637  }
638 
639  if( drawElectricalTypeName )
640  DrawPinElectricalTypeName( aPanel, aDC, pos1, orient, aColor, aDrawMode );
641 
642 
643  /* Set to one (1) to draw bounding box around pin to validate bounding
644  * box calculation. */
645 #if 0
646  EDA_RECT bBox = GetBoundingBox();
647  bBox.RevertYAxis();
648  bBox = aTransform.TransformCoordinate( bBox );
649  bBox.Move( aOffset );
650  GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDC, bBox, 0, LIGHTMAGENTA );
651 #endif
652 }
653 
654 
656  wxDC* aDC,
657  const wxPoint& aPinPos,
658  int aOrient,
659  GR_DRAWMODE aDrawMode,
660  COLOR4D aColor,
661  bool aDrawDangling,
662  bool aOnlyTarget )
663 {
664  int MapX1, MapY1, x1, y1;
665  int width = GetPenSize();
666  int posX = aPinPos.x, posY = aPinPos.y, len = m_length;
667  EDA_RECT* clipbox = aPanel ? aPanel->GetClipBox() : NULL;
668 
670 
671  if( aColor == COLOR4D::UNSPECIFIED ) // Used normal color or selected color
672  {
673  if( IsSelected() )
674  color = GetItemSelectedColor();
675  }
676  else
677  color = aColor;
678 
679  GRSetDrawMode( aDC, aDrawMode );
680 
681  MapX1 = MapY1 = 0;
682  x1 = posX;
683  y1 = posY;
684 
685  switch( aOrient )
686  {
687  case PIN_UP:
688  y1 = posY - len;
689  MapY1 = 1;
690  break;
691 
692  case PIN_DOWN:
693  y1 = posY + len;
694  MapY1 = -1;
695  break;
696 
697  case PIN_LEFT:
698  x1 = posX - len;
699  MapX1 = 1;
700  break;
701 
702  case PIN_RIGHT:
703  x1 = posX + len;
704  MapX1 = -1;
705  break;
706  }
707 
708  // Draw the pin end target (active end of the pin)
709  BASE_SCREEN* screen = aPanel ? aPanel->GetScreen() : NULL;
710  #define NCSYMB_PIN_DIM TARGET_PIN_RADIUS
711 
712  // Draw but do not print the pin end target 1 pixel width
713  if( m_type != PIN_NC && ( screen == NULL || !screen->m_IsPrinting ) )
714  {
715  if( aDrawDangling )
716  GRCircle( clipbox, aDC, posX, posY, TARGET_PIN_RADIUS, 0, color );
717  }
718 
719  if( aOnlyTarget )
720  return;
721 
722 
724  {
725  const int radius = ExternalPinDecoSize( *this );
726  GRCircle( clipbox, aDC, MapX1 * radius + x1,
727  MapY1 * radius + y1,
728  radius, width, color );
729 
730  GRMoveTo( MapX1 * radius * 2 + x1,
731  MapY1 * radius * 2 + y1 );
732  GRLineTo( clipbox, aDC, posX, posY, width, color );
733  }
734  else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK ) /* an alternative for Inverted Clock */
735  {
736  const int clock_size = InternalPinDecoSize( *this );
737  if( MapY1 == 0 ) /* MapX1 = +- 1 */
738  {
739  GRMoveTo( x1, y1 + clock_size );
740  GRLineTo( clipbox, aDC, x1 + MapX1 * clock_size * 2, y1,
741  width, color );
742  GRLineTo( clipbox, aDC, x1, y1 - clock_size, width, color );
743  }
744  else /* MapX1 = 0 */
745  {
746  GRMoveTo( x1 + clock_size, y1 );
747  GRLineTo( clipbox, aDC, x1, y1 + MapY1 * clock_size * 2,
748  width, color );
749  GRLineTo( clipbox, aDC, x1 - clock_size, y1,
750  width, color );
751  }
752  GRMoveTo( MapX1 * clock_size * 2 + x1, MapY1 * clock_size * 2 + y1 );
753  GRLineTo( clipbox, aDC, posX, posY, width, color );
754  }
755  else
756  {
757  GRMoveTo( x1, y1 );
758  GRLineTo( clipbox, aDC, posX, posY, width, color );
759  }
760 
762  {
763  const int clock_size = InternalPinDecoSize( *this );
764  if( MapY1 == 0 ) /* MapX1 = +- 1 */
765  {
766  GRMoveTo( x1, y1 + clock_size );
767  GRLineTo( clipbox, aDC, x1 - MapX1 * clock_size * 2, y1,
768  width, color );
769  GRLineTo( clipbox, aDC, x1, y1 - clock_size,
770  width, color );
771  }
772  else /* MapX1 = 0 */
773  {
774  GRMoveTo( x1 + clock_size, y1 );
775  GRLineTo( clipbox, aDC, x1, y1 - MapY1 * clock_size * 2,
776  width, color );
777  GRLineTo( clipbox, aDC, x1 - clock_size, y1,
778  width, color );
779  }
780  }
781 
783  {
784  const int symbol_size = ExternalPinDecoSize( *this );
785  if( MapY1 == 0 ) /* MapX1 = +- 1 */
786  {
787  GRMoveTo( x1 + MapX1 * symbol_size * 2, y1 );
788  GRLineTo( clipbox, aDC,
789  x1 + MapX1 * symbol_size * 2, y1 - symbol_size * 2,
790  width, color );
791  GRLineTo( clipbox, aDC, x1, y1, width, color );
792  }
793  else /* MapX1 = 0 */
794  {
795  GRMoveTo( x1, y1 + MapY1 * symbol_size * 2 );
796  GRLineTo( clipbox, aDC, x1 - symbol_size * 2,
797  y1 + MapY1 * symbol_size * 2, width, color );
798  GRLineTo( clipbox, aDC, x1, y1, width, color );
799  }
800  }
801 
802 
803  if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
804  {
805  const int symbol_size = ExternalPinDecoSize( *this );
806  if( MapY1 == 0 ) /* MapX1 = +- 1 */
807  {
808  GRMoveTo( x1, y1 - symbol_size * 2 );
809  GRLineTo( clipbox,
810  aDC,
811  x1 + MapX1 * symbol_size * 2,
812  y1,
813  width,
814  color );
815  }
816  else /* MapX1 = 0 */
817  {
818  GRMoveTo( x1 - symbol_size * 2, y1 );
819  GRLineTo( clipbox, aDC, x1, y1 + MapY1 * symbol_size * 2,
820  width, color );
821  }
822  }
823  else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
824  {
825  const int symbol_size = ExternalPinDecoSize( *this );
826  GRMoveTo( x1 - (MapX1 + MapY1) * symbol_size,
827  y1 - (MapY1 - MapX1) * symbol_size );
828  GRLineTo( clipbox, aDC,
829  x1 + (MapX1 + MapY1) * symbol_size,
830  y1 + (MapY1 - MapX1) * symbol_size,
831  width, color );
832  GRMoveTo( x1 - (MapX1 - MapY1) * symbol_size,
833  y1 - (MapY1 + MapX1) * symbol_size );
834  GRLineTo( clipbox, aDC,
835  x1 + (MapX1 - MapY1) * symbol_size,
836  y1 + (MapY1 + MapX1) * symbol_size,
837  width, color );
838  }
839 
840  if( m_type == PIN_NC ) // Draw a N.C. symbol
841  {
842  GRLine( clipbox, aDC,
843  posX - NCSYMB_PIN_DIM, posY - NCSYMB_PIN_DIM,
844  posX + NCSYMB_PIN_DIM, posY + NCSYMB_PIN_DIM,
845  width, color );
846  GRLine( clipbox, aDC,
847  posX + NCSYMB_PIN_DIM, posY - NCSYMB_PIN_DIM,
848  posX - NCSYMB_PIN_DIM, posY + NCSYMB_PIN_DIM,
849  width, color );
850  }
851 }
852 
853 
855  wxDC* DC,
856  wxPoint& pin_pos,
857  int orient,
858  int TextInside,
859  bool DrawPinNum,
860  bool DrawPinName,
861  COLOR4D Color,
862  GR_DRAWMODE DrawMode )
863 {
864  if( !DrawPinName && !DrawPinNum )
865  return;
866 
867  int x, y;
868 
869  wxSize PinNameSize( m_nameTextSize, m_nameTextSize );
870  wxSize PinNumSize( m_numTextSize, m_numTextSize );
871 
872  int nameLineWidth = GetPenSize();
873 
874  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
875  int numLineWidth = GetPenSize();
876  numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
877 
878  int name_offset = PIN_TEXT_MARGIN +
879  ( nameLineWidth + GetDefaultLineThickness() ) / 2;
880  int num_offset = PIN_TEXT_MARGIN +
881  ( numLineWidth + GetDefaultLineThickness() ) / 2;
882 
883  GRSetDrawMode( DC, DrawMode );
884  EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL;
885 
886  /* Get the num and name colors */
887  if( ( Color == COLOR4D::UNSPECIFIED ) && IsSelected() )
888  Color = GetItemSelectedColor();
889 
890  COLOR4D NameColor = Color == COLOR4D::UNSPECIFIED ?
891  GetLayerColor( LAYER_PINNAM ) : Color;
892  COLOR4D NumColor = Color == COLOR4D::UNSPECIFIED ?
893  GetLayerColor( LAYER_PINNUM ) : Color;
894 
895  int x1 = pin_pos.x;
896  int y1 = pin_pos.y;
897 
898  switch( orient )
899  {
900  case PIN_UP:
901  y1 -= m_length;
902  break;
903 
904  case PIN_DOWN:
905  y1 += m_length;
906  break;
907 
908  case PIN_LEFT:
909  x1 -= m_length;
910  break;
911 
912  case PIN_RIGHT:
913  x1 += m_length;
914  break;
915  }
916 
917  if( m_name.IsEmpty() )
918  DrawPinName = false;
919 
920  if( TextInside ) // Draw the text inside, but the pin numbers outside.
921  {
922  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
923  {
924  // It is an horizontal line
925  if( DrawPinName )
926  {
927  if( orient == PIN_RIGHT )
928  {
929  x = x1 + TextInside;
930  DrawGraphicText( clipbox, DC, wxPoint( x, y1 ), NameColor,
931  m_name,
933  PinNameSize,
935  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
936  false, false );
937  }
938  else // Orient == PIN_LEFT
939  {
940  x = x1 - TextInside;
941  DrawGraphicText( clipbox, DC, wxPoint( x, y1 ), NameColor,
942  m_name,
944  PinNameSize,
946  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
947  false, false );
948  }
949  }
950 
951  if( DrawPinNum )
952  {
953  DrawGraphicText( clipbox, DC,
954  wxPoint( (x1 + pin_pos.x) / 2,
955  y1 - num_offset ), NumColor,
956  m_number,
957  TEXT_ANGLE_HORIZ, PinNumSize,
959  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
960  false, false );
961  }
962  }
963  else /* Its a vertical line. */
964  {
965  // Text is drawn from bottom to top (i.e. to negative value for Y axis)
966  if( orient == PIN_DOWN )
967  {
968  y = y1 + TextInside;
969 
970  if( DrawPinName )
971  DrawGraphicText( clipbox, DC, wxPoint( x1, y ), NameColor,
972  m_name,
973  TEXT_ANGLE_VERT, PinNameSize,
975  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
976  false, false );
977 
978  if( DrawPinNum )
979  DrawGraphicText( clipbox, DC,
980  wxPoint( x1 - num_offset,
981  (y1 + pin_pos.y) / 2 ), NumColor,
982  m_number,
983  TEXT_ANGLE_VERT, PinNumSize,
985  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
986  false, false );
987  }
988  else /* PIN_UP */
989  {
990  y = y1 - TextInside;
991 
992  if( DrawPinName )
993  DrawGraphicText( clipbox, DC, wxPoint( x1, y ), NameColor,
994  m_name,
995  TEXT_ANGLE_VERT, PinNameSize,
997  GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
998  false, false );
999 
1000  if( DrawPinNum )
1001  DrawGraphicText( clipbox, DC,
1002  wxPoint( x1 - num_offset,
1003  (y1 + pin_pos.y) / 2 ), NumColor,
1004  m_number,
1005  TEXT_ANGLE_VERT, PinNumSize,
1007  GR_TEXT_VJUSTIFY_BOTTOM, numLineWidth,
1008  false, false );
1009  }
1010  }
1011  }
1012  else /**** Draw num & text pin outside ****/
1013  {
1014  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1015  {
1016  /* Its an horizontal line. */
1017  if( DrawPinName )
1018  {
1019  x = (x1 + pin_pos.x) / 2;
1020  DrawGraphicText( clipbox, DC, wxPoint( x, y1 - name_offset ),
1021  NameColor, m_name,
1022  TEXT_ANGLE_HORIZ, PinNameSize,
1024  GR_TEXT_VJUSTIFY_BOTTOM, nameLineWidth,
1025  false, false );
1026  }
1027  if( DrawPinNum )
1028  {
1029  x = (x1 + pin_pos.x) / 2;
1030  DrawGraphicText( clipbox, DC, wxPoint( x, y1 + num_offset ),
1031  NumColor, m_number,
1032  TEXT_ANGLE_HORIZ, PinNumSize,
1034  GR_TEXT_VJUSTIFY_TOP, numLineWidth,
1035  false, false );
1036  }
1037  }
1038  else /* Its a vertical line. */
1039  {
1040  if( DrawPinName )
1041  {
1042  y = (y1 + pin_pos.y) / 2;
1043  DrawGraphicText( clipbox, DC, wxPoint( x1 - name_offset, y ),
1044  NameColor, m_name,
1045  TEXT_ANGLE_VERT, PinNameSize,
1047  GR_TEXT_VJUSTIFY_BOTTOM, nameLineWidth,
1048  false, false );
1049  }
1050 
1051  if( DrawPinNum )
1052  {
1053  DrawGraphicText( clipbox, DC,
1054  wxPoint( x1 + num_offset, (y1 + pin_pos.y)
1055  / 2 ),
1056  NumColor, m_number,
1057  TEXT_ANGLE_VERT, PinNumSize,
1059  GR_TEXT_VJUSTIFY_TOP, numLineWidth,
1060  false, false );
1061  }
1062  }
1063  }
1064 }
1065 
1066 
1067 
1069  wxPoint& aPosition, int aOrientation,
1070  COLOR4D aColor, GR_DRAWMODE aDrawMode )
1071 {
1072  wxString etypeName = GetElectricalTypeName();
1073 
1074  // Use a reasonable (small) size to draw the text
1075  int etextSize = (m_nameTextSize*3)/4;
1076 
1077  #define ETXT_MAX_SIZE Millimeter2iu(0.7 )
1078  if( etextSize > ETXT_MAX_SIZE )
1079  etextSize = ETXT_MAX_SIZE;
1080 
1081  // Use a reasonable pen size to draw the text
1082  int pensize = etextSize/6;
1083 
1084  // Get a suitable color
1085  if( ( aColor == COLOR4D::UNSPECIFIED ) && IsSelected() )
1086  aColor = GetItemSelectedColor();
1087  else if( !IsVisible() )
1088  aColor = GetInvisibleItemColor();
1089  else
1090  aColor = GetLayerColor( LAYER_NOTES );
1091 
1092  wxPoint txtpos = aPosition;
1093  int offset = Millimeter2iu( 0.4 );
1095  int orient = TEXT_ANGLE_HORIZ;
1096 
1097  switch( aOrientation )
1098  {
1099  case PIN_UP:
1100  txtpos.y += offset;
1101  orient = TEXT_ANGLE_VERT;
1102  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1103  break;
1104 
1105  case PIN_DOWN:
1106  txtpos.y -= offset;
1107  orient = TEXT_ANGLE_VERT;
1108  break;
1109 
1110  case PIN_LEFT:
1111  txtpos.x += offset;
1112  break;
1113 
1114  case PIN_RIGHT:
1115  txtpos.x -= offset;
1116  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
1117  break;
1118  }
1119 
1120  GRSetDrawMode( aDC, aDrawMode );
1121  EDA_RECT* clipbox = aPanel? aPanel->GetClipBox() : NULL;
1122 
1123  DrawGraphicText( clipbox, aDC, txtpos, aColor, etypeName,
1124  orient, wxSize( etextSize, etextSize ),
1125  hjustify, GR_TEXT_VJUSTIFY_CENTER, pensize,
1126  false, false );
1127 }
1128 
1129 
1130 void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation )
1131 {
1132  int MapX1, MapY1, x1, y1;
1134 
1135  aPlotter->SetColor( color );
1136  aPlotter->SetCurrentLineWidth( GetPenSize() );
1137 
1138  MapX1 = MapY1 = 0;
1139  x1 = aPosition.x; y1 = aPosition.y;
1140 
1141  switch( aOrientation )
1142  {
1143  case PIN_UP:
1144  y1 = aPosition.y - m_length;
1145  MapY1 = 1;
1146  break;
1147 
1148  case PIN_DOWN:
1149  y1 = aPosition.y + m_length;
1150  MapY1 = -1;
1151  break;
1152 
1153  case PIN_LEFT:
1154  x1 = aPosition.x - m_length;
1155  MapX1 = 1;
1156  break;
1157 
1158  case PIN_RIGHT:
1159  x1 = aPosition.x + m_length;
1160  MapX1 = -1;
1161  break;
1162  }
1163 
1165  {
1166  const int radius = ExternalPinDecoSize( *this );
1167  aPlotter->Circle( wxPoint( MapX1 * radius + x1,
1168  MapY1 * radius + y1 ),
1169  radius * 2, // diameter
1170  NO_FILL, // fill option
1171  GetPenSize() ); // width
1172 
1173  aPlotter->MoveTo( wxPoint( MapX1 * radius * 2 + x1,
1174  MapY1 * radius * 2 + y1 ) );
1175  aPlotter->FinishTo( aPosition );
1176  }
1177  else if( m_shape == PINSHAPE_FALLING_EDGE_CLOCK )
1178  {
1179  const int clock_size = InternalPinDecoSize( *this );
1180  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1181  {
1182  aPlotter->MoveTo( wxPoint( x1, y1 + clock_size ) );
1183  aPlotter->LineTo( wxPoint( x1 + MapX1 * clock_size * 2, y1 ) );
1184  aPlotter->FinishTo( wxPoint( x1, y1 - clock_size ) );
1185  }
1186  else /* MapX1 = 0 */
1187  {
1188  aPlotter->MoveTo( wxPoint( x1 + clock_size, y1 ) );
1189  aPlotter->LineTo( wxPoint( x1, y1 + MapY1 * clock_size * 2 ) );
1190  aPlotter->FinishTo( wxPoint( x1 - clock_size, y1 ) );
1191  }
1192 
1193  aPlotter->MoveTo( wxPoint( MapX1 * clock_size * 2 + x1,
1194  MapY1 * clock_size * 2 + y1 ) );
1195  aPlotter->FinishTo( aPosition );
1196  }
1197  else
1198  {
1199  aPlotter->MoveTo( wxPoint( x1, y1 ) );
1200  aPlotter->FinishTo( aPosition );
1201  }
1202 
1205  {
1206  const int clock_size = InternalPinDecoSize( *this );
1207  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1208  {
1209  aPlotter->MoveTo( wxPoint( x1, y1 + clock_size ) );
1210  aPlotter->LineTo( wxPoint( x1 - MapX1 * clock_size * 2, y1 ) );
1211  aPlotter->FinishTo( wxPoint( x1, y1 - clock_size ) );
1212  }
1213  else /* MapX1 = 0 */
1214  {
1215  aPlotter->MoveTo( wxPoint( x1 + clock_size, y1 ) );
1216  aPlotter->LineTo( wxPoint( x1, y1 - MapY1 * clock_size * 2 ) );
1217  aPlotter->FinishTo( wxPoint( x1 - clock_size, y1 ) );
1218  }
1219  }
1220 
1221  if( m_shape == PINSHAPE_INPUT_LOW || m_shape == PINSHAPE_CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
1222  {
1223  const int symbol_size = ExternalPinDecoSize( *this );
1224 
1225  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1226  {
1227  aPlotter->MoveTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
1228  aPlotter->LineTo( wxPoint( x1 + MapX1 * symbol_size * 2,
1229  y1 - symbol_size * 2 ) );
1230  aPlotter->FinishTo( wxPoint( x1, y1 ) );
1231  }
1232  else /* MapX1 = 0 */
1233  {
1234  aPlotter->MoveTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
1235  aPlotter->LineTo( wxPoint( x1 - symbol_size * 2,
1236  y1 + MapY1 * symbol_size * 2 ) );
1237  aPlotter->FinishTo( wxPoint( x1, y1 ) );
1238  }
1239  }
1240 
1241 
1242  if( m_shape == PINSHAPE_OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
1243  {
1244  const int symbol_size = ExternalPinDecoSize( *this );
1245 
1246  if( MapY1 == 0 ) /* MapX1 = +- 1 */
1247  {
1248  aPlotter->MoveTo( wxPoint( x1, y1 - symbol_size * 2 ) );
1249  aPlotter->FinishTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
1250  }
1251  else /* MapX1 = 0 */
1252  {
1253  aPlotter->MoveTo( wxPoint( x1 - symbol_size * 2, y1 ) );
1254  aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
1255  }
1256  }
1257  else if( m_shape == PINSHAPE_NONLOGIC ) /* NonLogic pin symbol */
1258  {
1259  const int symbol_size = ExternalPinDecoSize( *this );
1260  aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * symbol_size,
1261  y1 - (MapY1 - MapX1) * symbol_size ) );
1262  aPlotter->FinishTo( wxPoint( x1 + (MapX1 + MapY1) * symbol_size,
1263  y1 + (MapY1 - MapX1) * symbol_size ) );
1264  aPlotter->MoveTo( wxPoint( x1 - (MapX1 - MapY1) * symbol_size,
1265  y1 - (MapY1 + MapX1) * symbol_size ) );
1266  aPlotter->FinishTo( wxPoint( x1 + (MapX1 - MapY1) * symbol_size,
1267  y1 + (MapY1 + MapX1) * symbol_size ) );
1268  }
1269  if( m_type == PIN_NC ) // Draw a N.C. symbol
1270  {
1271  const int ex1 = aPosition.x;
1272  const int ey1 = aPosition.y;
1273  aPlotter->MoveTo( wxPoint( ex1 - NCSYMB_PIN_DIM, ey1 - NCSYMB_PIN_DIM ) );
1274  aPlotter->FinishTo( wxPoint( ex1 + NCSYMB_PIN_DIM, ey1 + NCSYMB_PIN_DIM ) );
1275  aPlotter->MoveTo( wxPoint( ex1 + NCSYMB_PIN_DIM, ey1 - NCSYMB_PIN_DIM ) );
1276  aPlotter->FinishTo( wxPoint( ex1 - NCSYMB_PIN_DIM, ey1 + NCSYMB_PIN_DIM ) );
1277  }
1278 }
1279 
1280 
1281 void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
1282  int TextInside, bool DrawPinNum,
1283  bool DrawPinName, int aWidth )
1284 {
1285  if( m_name.IsEmpty() || m_name == wxT( "~" ) )
1286  DrawPinName = false;
1287 
1288  if( m_number.IsEmpty() )
1289  DrawPinNum = false;
1290 
1291  if( !DrawPinNum && !DrawPinName )
1292  return;
1293 
1294  int x, y;
1295  wxSize PinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
1296  wxSize PinNumSize = wxSize( m_numTextSize, m_numTextSize );
1297 
1298  int nameLineWidth = GetPenSize();
1299  nameLineWidth = Clamp_Text_PenSize( nameLineWidth, m_nameTextSize, false );
1300  int numLineWidth = GetPenSize();
1301  numLineWidth = Clamp_Text_PenSize( numLineWidth, m_numTextSize, false );
1302 
1303  int name_offset = PIN_TEXT_MARGIN +
1304  ( nameLineWidth + GetDefaultLineThickness() ) / 2;
1305  int num_offset = PIN_TEXT_MARGIN +
1306  ( numLineWidth + GetDefaultLineThickness() ) / 2;
1307 
1308  /* Get the num and name colors */
1309  COLOR4D NameColor = GetLayerColor( LAYER_PINNAM );
1310  COLOR4D NumColor = GetLayerColor( LAYER_PINNUM );
1311 
1312  int x1 = pin_pos.x;
1313  int y1 = pin_pos.y;
1314 
1315  switch( orient )
1316  {
1317  case PIN_UP:
1318  y1 -= m_length;
1319  break;
1320 
1321  case PIN_DOWN:
1322  y1 += m_length;
1323  break;
1324 
1325  case PIN_LEFT:
1326  x1 -= m_length;
1327  break;
1328 
1329  case PIN_RIGHT:
1330  x1 += m_length;
1331  break;
1332  }
1333 
1334  /* Draw the text inside, but the pin numbers outside. */
1335  if( TextInside )
1336  {
1337  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) ) /* Its an horizontal line. */
1338  {
1339  if( DrawPinName )
1340  {
1341  if( orient == PIN_RIGHT )
1342  {
1343  x = x1 + TextInside;
1344  plotter->Text( wxPoint( x, y1 ), NameColor,
1345  m_name,
1347  PinNameSize,
1350  aWidth, false, false );
1351  }
1352  else // orient == PIN_LEFT
1353  {
1354  x = x1 - TextInside;
1355 
1356  if( DrawPinName )
1357  plotter->Text( wxPoint( x, y1 ),
1358  NameColor, m_name, TEXT_ANGLE_HORIZ,
1359  PinNameSize,
1362  aWidth, false, false );
1363  }
1364  }
1365  if( DrawPinNum )
1366  {
1367  plotter->Text( wxPoint( (x1 + pin_pos.x) / 2,
1368  y1 - num_offset ),
1369  NumColor, m_number,
1370  TEXT_ANGLE_HORIZ, PinNumSize,
1373  aWidth, false, false );
1374  }
1375  }
1376  else /* Its a vertical line. */
1377  {
1378  if( orient == PIN_DOWN )
1379  {
1380  y = y1 + TextInside;
1381 
1382  if( DrawPinName )
1383  plotter->Text( wxPoint( x1, y ), NameColor,
1384  m_name,
1385  TEXT_ANGLE_VERT, PinNameSize,
1388  aWidth, false, false );
1389 
1390  if( DrawPinNum )
1391  {
1392  plotter->Text( wxPoint( x1 - num_offset,
1393  (y1 + pin_pos.y) / 2 ),
1394  NumColor, m_number,
1395  TEXT_ANGLE_VERT, PinNumSize,
1398  aWidth, false, false );
1399  }
1400  }
1401  else /* PIN_UP */
1402  {
1403  y = y1 - TextInside;
1404 
1405  if( DrawPinName )
1406  plotter->Text( wxPoint( x1, y ), NameColor,
1407  m_name,
1408  TEXT_ANGLE_VERT, PinNameSize,
1411  aWidth, false, false );
1412 
1413  if( DrawPinNum )
1414  {
1415  plotter->Text( wxPoint( x1 - num_offset,
1416  (y1 + pin_pos.y) / 2 ),
1417  NumColor, m_number,
1418  TEXT_ANGLE_VERT, PinNumSize,
1421  aWidth, false, false );
1422  }
1423  }
1424  }
1425  }
1426  else /* Draw num & text pin outside */
1427  {
1428  if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
1429  {
1430  /* Its an horizontal line. */
1431  if( DrawPinName )
1432  {
1433  x = (x1 + pin_pos.x) / 2;
1434  plotter->Text( wxPoint( x, y1 - name_offset ),
1435  NameColor, m_name,
1436  TEXT_ANGLE_HORIZ, PinNameSize,
1439  aWidth, false, false );
1440  }
1441 
1442  if( DrawPinNum )
1443  {
1444  x = ( x1 + pin_pos.x ) / 2;
1445  plotter->Text( wxPoint( x, y1 + num_offset ),
1446  NumColor, m_number,
1447  TEXT_ANGLE_HORIZ, PinNumSize,
1450  aWidth, false, false );
1451  }
1452  }
1453  else /* Its a vertical line. */
1454  {
1455  if( DrawPinName )
1456  {
1457  y = ( y1 + pin_pos.y ) / 2;
1458  plotter->Text( wxPoint( x1 - name_offset, y ),
1459  NameColor, m_name,
1460  TEXT_ANGLE_VERT, PinNameSize,
1463  aWidth, false, false );
1464  }
1465 
1466  if( DrawPinNum )
1467  {
1468  plotter->Text( wxPoint( x1 + num_offset,
1469  ( y1 + pin_pos.y ) / 2 ),
1470  NumColor, m_number,
1471  TEXT_ANGLE_VERT, PinNumSize,
1474  aWidth, false, false );
1475  }
1476  }
1477  }
1478 }
1479 
1480 
1482 {
1483  wxPoint pos = m_position;
1484 
1485  switch( m_orientation )
1486  {
1487  case PIN_UP:
1488  pos.y += m_length;
1489  break;
1490 
1491  case PIN_DOWN:
1492  pos.y -= m_length;
1493  break;
1494 
1495  case PIN_LEFT:
1496  pos.x -= m_length;
1497  break;
1498 
1499  case PIN_RIGHT:
1500  pos.x += m_length;
1501  break;
1502  }
1503 
1504  return pos;
1505 }
1506 
1507 
1508 int LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const
1509 {
1510  int orient;
1511  wxPoint end; // position of pin end starting at 0,0 according to its orientation, length = 1
1512 
1513  switch( m_orientation )
1514  {
1515  case PIN_UP:
1516  end.y = 1;
1517  break;
1518 
1519  case PIN_DOWN:
1520  end.y = -1;
1521  break;
1522 
1523  case PIN_LEFT:
1524  end.x = -1;
1525  break;
1526 
1527  case PIN_RIGHT:
1528  end.x = 1;
1529  break;
1530  }
1531 
1532  // = pos of end point, according to the component orientation
1533  end = aTransform.TransformCoordinate( end );
1534  orient = PIN_UP;
1535 
1536  if( end.x == 0 )
1537  {
1538  if( end.y > 0 )
1539  orient = PIN_DOWN;
1540  }
1541  else
1542  {
1543  orient = PIN_RIGHT;
1544 
1545  if( end.x < 0 )
1546  orient = PIN_LEFT;
1547  }
1548 
1549  return orient;
1550 }
1551 
1552 
1554 {
1555  return new LIB_PIN( *this );
1556 }
1557 
1558 
1559 int LIB_PIN::compare( const LIB_ITEM& other ) const
1560 {
1561  wxASSERT( other.Type() == LIB_PIN_T );
1562 
1563  const LIB_PIN* tmp = (LIB_PIN*) &other;
1564 
1565  if( m_number != tmp->m_number )
1566  return m_number.Cmp( tmp->m_number );
1567 
1568  int result = m_name.CmpNoCase( tmp->m_name );
1569 
1570  if( result != 0 )
1571  return result;
1572 
1573  if( m_position.x != tmp->m_position.x )
1574  return m_position.x - tmp->m_position.x;
1575 
1576  if( m_position.y != tmp->m_position.y )
1577  return m_position.y - tmp->m_position.y;
1578 
1579  return 0;
1580 }
1581 
1582 
1583 void LIB_PIN::SetOffset( const wxPoint& aOffset )
1584 {
1585  m_position += aOffset;
1586 }
1587 
1588 
1589 bool LIB_PIN::Inside( EDA_RECT& rect ) const
1590 {
1591  wxPoint end = PinEndPoint();
1592 
1593  return rect.Contains( m_position.x, -m_position.y ) || rect.Contains( end.x, -end.y );
1594 }
1595 
1596 
1597 void LIB_PIN::Move( const wxPoint& newPosition )
1598 {
1599  if( m_position != newPosition )
1600  {
1601  m_position = newPosition;
1602  SetModified();
1603  }
1604 }
1605 
1606 
1607 void LIB_PIN::MirrorHorizontal( const wxPoint& center )
1608 {
1609  m_position.x -= center.x;
1610  m_position.x *= -1;
1611  m_position.x += center.x;
1612 
1613  if( m_orientation == PIN_RIGHT )
1615  else if( m_orientation == PIN_LEFT )
1617 }
1618 
1619 void LIB_PIN::MirrorVertical( const wxPoint& center )
1620 {
1621  m_position.y -= center.y;
1622  m_position.y *= -1;
1623  m_position.y += center.y;
1624 
1625  if( m_orientation == PIN_UP )
1627  else if( m_orientation == PIN_DOWN )
1629 }
1630 
1631 void LIB_PIN::Rotate( const wxPoint& center, bool aRotateCCW )
1632 {
1633  int rot_angle = aRotateCCW ? -900 : 900;
1634 
1635  RotatePoint( &m_position, center, rot_angle );
1636 
1637  if( aRotateCCW )
1638  {
1639  switch( m_orientation )
1640  {
1641  case PIN_RIGHT:
1643  break;
1644 
1645  case PIN_UP:
1647  break;
1648  case PIN_LEFT:
1650  break;
1651 
1652  case PIN_DOWN:
1654  break;
1655  }
1656  }
1657  else
1658  {
1659  switch( m_orientation )
1660  {
1661  case PIN_RIGHT:
1663  break;
1664 
1665  case PIN_UP:
1667  break;
1668  case PIN_LEFT:
1670  break;
1671 
1672  case PIN_DOWN:
1674  break;
1675  }
1676  }
1677 }
1678 
1679 
1680 void LIB_PIN::Plot( PLOTTER* plotter, const wxPoint& offset, bool fill,
1681  const TRANSFORM& aTransform )
1682 {
1683  if( ! IsVisible() )
1684  return;
1685 
1686  int orient = PinDrawOrient( aTransform );
1687 
1688  wxPoint pos = aTransform.TransformCoordinate( m_position ) + offset;
1689 
1690  PlotSymbol( plotter, pos, orient );
1691  PlotPinTexts( plotter, pos, orient, GetParent()->GetPinNameOffset(),
1692  GetParent()->ShowPinNumbers(), GetParent()->ShowPinNames(),
1693  GetPenSize() );
1694 }
1695 
1696 
1697 void LIB_PIN::SetWidth( int aWidth )
1698 {
1699  if( m_width != aWidth )
1700  {
1701  m_width = aWidth;
1702  SetModified();
1703  }
1704 }
1705 
1706 
1708 {
1709  wxString text = m_number.IsEmpty() ? wxT( "?" ) : m_number;
1710 
1711  LIB_ITEM::GetMsgPanelInfo( aUnits, aList );
1712 
1713  aList.push_back( MSG_PANEL_ITEM( _( "Name" ), m_name, DARKCYAN ) );
1714 
1715  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), text, DARKCYAN ) );
1716 
1717  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), GetText( m_type ), RED ) );
1718 
1719  text = GetText( m_shape );
1720 
1721  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text, BLUE ) );
1722 
1723  if( IsVisible() )
1724  text = _( "Yes" );
1725  else
1726  text = _( "No" );
1727 
1728  aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), text, DARKGREEN ) );
1729 
1730  // Display pin length
1731  text = StringFromValue( aUnits, m_length, true );
1732  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), text, MAGENTA ) );
1733 
1735  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), text, DARKMAGENTA ) );
1736 }
1737 
1739 {
1740  getMsgPanelInfoBase( aUnits, aList );
1741 
1742  wxString text;
1743  wxPoint pinpos = GetPosition();
1744  pinpos.y = -pinpos.y; // Display coord are top to bottom
1745  // lib items coord are bottom to top
1746 
1747  text = MessageTextFromValue( aUnits, pinpos.x, true );
1748  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text, DARKMAGENTA ) );
1749 
1750  text = MessageTextFromValue( aUnits, pinpos.y, true );
1751  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text, DARKMAGENTA ) );
1752 }
1753 
1754 void LIB_PIN::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList,
1755  SCH_COMPONENT* aComponent )
1756 {
1757  getMsgPanelInfoBase( aUnits, aList );
1758 
1759  if( !aComponent )
1760  return;
1761 
1762  wxString text;
1763  wxPoint pinpos = aComponent->GetTransform().TransformCoordinate( GetPosition() )
1764  + aComponent->GetPosition();
1765 
1766  text = MessageTextFromValue( aUnits, pinpos.x, true );
1767  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text, DARKMAGENTA ) );
1768 
1769  text = MessageTextFromValue( aUnits, pinpos.y, true );
1770  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text, DARKMAGENTA ) );
1771 
1772  aList.push_back( MSG_PANEL_ITEM( aComponent->GetField( REFERENCE )->GetShownText(),
1773  aComponent->GetField( VALUE )->GetShownText(),
1774  DARKCYAN ) );
1775 }
1776 
1777 const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles ) const
1778 {
1779  LIB_PART* entry = (LIB_PART* ) m_Parent;
1780  EDA_RECT bbox;
1781  wxPoint begin;
1782  wxPoint end;
1783  int nameTextOffset = 0;
1784  bool showName = !m_name.IsEmpty() && (m_name != wxT( "~" ));
1785  bool showNum = !m_number.IsEmpty();
1786  int minsizeV = TARGET_PIN_RADIUS;
1787 
1788  if( !aIncludeInvisibles && !IsVisible() )
1789  showName = false;
1790 
1791  if( entry )
1792  {
1793  if( entry->ShowPinNames() )
1794  nameTextOffset = entry->GetPinNameOffset();
1795  else
1796  showName = false;
1797 
1798  showNum = entry->ShowPinNumbers();
1799  }
1800 
1801  // First, calculate boundary box corners position
1802  int numberTextLength = showNum ? m_numTextSize * m_number.Len() : 0;
1803 
1804  // Actual text height is bigger than text size
1805  int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
1806 
1808  minsizeV = std::max( TARGET_PIN_RADIUS, ExternalPinDecoSize( *this ) );
1809 
1810  // calculate top left corner position
1811  // for the default pin orientation (PIN_RIGHT)
1812  begin.y = std::max( minsizeV, numberTextHeight + PIN_TEXT_MARGIN );
1813  begin.x = std::min( -TARGET_PIN_RADIUS, m_length - (numberTextLength / 2) );
1814 
1815  // calculate bottom right corner position and adjust top left corner position
1816  int nameTextLength = 0;
1817  int nameTextHeight = 0;
1818 
1819  if( showName )
1820  {
1821  int length = m_name.Len();
1822 
1823  // Don't count the line over text symbol.
1824  if( m_name.Left( 1 ) == wxT( "~" ) )
1825  length -= 1;
1826 
1827  nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
1828 
1829  // Actual text height are bigger than text size
1830  nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + PIN_TEXT_MARGIN;
1831  }
1832 
1833  if( nameTextOffset ) // for values > 0, pin name is inside the body
1834  {
1835  end.x = m_length + nameTextLength;
1836  end.y = std::min( -minsizeV, -nameTextHeight / 2 );
1837  }
1838  else // if value == 0:
1839  // pin name is outside the body, and above the pin line
1840  // pin num is below the pin line
1841  {
1842  end.x = std::max(m_length, nameTextLength);
1843  end.y = -begin.y;
1844  begin.y = std::max( minsizeV, nameTextHeight );
1845  }
1846 
1847  // Now, calculate boundary box corners position for the actual pin orientation
1848  int orient = PinDrawOrient( DefaultTransform );
1849 
1850  /* Calculate the pin position */
1851  switch( orient )
1852  {
1853  case PIN_UP:
1854  // Pin is rotated and texts positions are mirrored
1855  RotatePoint( &begin, wxPoint( 0, 0 ), -900 );
1856  RotatePoint( &end, wxPoint( 0, 0 ), -900 );
1857  break;
1858 
1859  case PIN_DOWN:
1860  RotatePoint( &begin, wxPoint( 0, 0 ), 900 );
1861  RotatePoint( &end, wxPoint( 0, 0 ), 900 );
1862  begin.x = -begin.x;
1863  end.x = -end.x;
1864  break;
1865 
1866  case PIN_LEFT:
1867  begin.x = -begin.x;
1868  end.x = -end.x;
1869  break;
1870 
1871  case PIN_RIGHT:
1872  break;
1873  }
1874 
1875  begin += m_position;
1876  end += m_position;
1877 
1878  bbox.SetOrigin( begin );
1879  bbox.SetEnd( end );
1880  bbox.Normalize();
1881  bbox.Inflate( ( GetPenSize() / 2 ) + 1 );
1882 
1883  // Draw Y axis is reversed in schematic:
1884  bbox.RevertYAxis();
1885 
1886  return bbox;
1887 }
1888 
1889 
1890 wxArrayString LIB_PIN::GetOrientationNames( void )
1891 {
1892  wxArrayString tmp;
1893 
1894  for( unsigned ii = 0; ii < PIN_ORIENTATION_CNT; ii++ )
1895  tmp.Add( getPinOrientationName( ii ) );
1896 
1897  return tmp;
1898 }
1899 
1900 
1902 {
1903  if( index >= 0 && index < (int) PIN_ORIENTATION_CNT )
1904  return pin_orientation_codes[ index ];
1905 
1906  return PIN_RIGHT;
1907 }
1908 
1909 
1911 {
1912  size_t i;
1913 
1914  for( i = 0; i < PIN_ORIENTATION_CNT; i++ )
1915  {
1916  if( pin_orientation_codes[i] == code )
1917  return (int) i;
1918  }
1919 
1920  return wxNOT_FOUND;
1921 }
1922 
1923 
1925 {
1926  int orient = PIN_RIGHT;
1927 
1928  switch( GetOrientation() )
1929  {
1930  case PIN_UP:
1931  orient = PIN_LEFT;
1932  break;
1933 
1934  case PIN_DOWN:
1935  orient = PIN_RIGHT;
1936  break;
1937 
1938  case PIN_LEFT:
1939  orient = PIN_DOWN;
1940  break;
1941 
1942  case PIN_RIGHT:
1943  orient = PIN_UP;
1944  break;
1945  }
1946 
1947  // Set the new orientation
1948  SetOrientation( orient );
1949 }
1950 
1951 
1953 {
1954  return iconsPinsOrientations;
1955 }
1956 
1957 
1959 {
1960  return GetBitmap( m_type );
1961 }
1962 
1963 
1964 wxString LIB_PIN::GetSelectMenuText( EDA_UNITS_T aUnits ) const
1965 {
1966  return wxString::Format( _( "Pin %s, %s, %s" ),
1967  m_number,
1969  GetText( m_shape ));
1970 }
1971 
1972 
1973 bool LIB_PIN::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation )
1974 {
1975  wxLogTrace( traceFindItem, wxT( " item " ) + GetSelectMenuText( MILLIMETRES ) );
1976 
1977  // Note: this will have to be modified if we add find and replace capability to the
1978  // compoment library editor. Otherwise, you wont be able to replace pin text.
1979  if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_PINS )
1980  || ( aSearchData.GetFlags() & FR_SEARCH_REPLACE ) )
1981  return false;
1982 
1983  wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText( MILLIMETRES ) );
1984 
1985  if( EDA_ITEM::Matches( GetName(), aSearchData ) || EDA_ITEM::Matches( m_number, aSearchData ) )
1986  {
1987  if( aFindLocation )
1988  *aFindLocation = GetBoundingBox().Centre();
1989 
1990  return true;
1991  }
1992 
1993  return false;
1994 }
1995 
1996 
1997 #if defined(DEBUG)
1998 
1999 void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
2000 {
2001  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
2002  << " num=\"" << m_number.mb_str()
2003  << '"' << "/>\n";
2004 
2005 // NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
2006 }
2007 
2008 #endif
2009 
2010 void LIB_PIN::CalcEdit( const wxPoint& aPosition )
2011 {
2012  DBG(printf("m_Flags %x\n", m_Flags );)
2013  if( m_Flags == IS_NEW )
2014  {
2015  SetPosition( aPosition );
2016  }
2017  else if( m_Flags == IS_MOVED )
2018  {
2019  DBG(printf("MOVEPIN\n");)
2020  Move( aPosition );
2021  }
2022 }
virtual BASE_SCREEN * GetScreen()=0
Definition: colors.h:57
#define TEXT_ANGLE_HORIZ
void FinishTo(const wxPoint &pos)
Definition: plotter.h:251
#define IS_LINKED
Used in calculation to mark linked items (temporary use)
Definition: base_struct.h:111
wxString GetClass() const override
Function GetClass returns the class name.
Definition: lib_pin.h:113
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: lib_pin.cpp:1973
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
int compare(const LIB_ITEM &aOther) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_pin.cpp:1559
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
void SetModified()
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:85
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:1553
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...
EDA_ITEM * m_Parent
Linked list: Link (parent struct)
Definition: base_struct.h:171
#define IN_EDIT
Item currently edited.
Definition: base_struct.h:112
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:62
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:1068
TRANSFORM & GetTransform() const
static int ExternalPinDecoSize(const LIB_PIN &aPin)
Utility for getting the size of the &#39;external&#39; pin decorators (as a radius)
Definition: lib_pin.cpp:142
PNG memory record (file in memory).
Definition: bitmap_types.h:43
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:78
int GetPinNameOffset()
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
#define ETXT_MAX_SIZE
void SetPosition(const wxPoint &aPosition)
#define TEXT_ANGLE_VERT
static const wxString getPinOrientationName(unsigned aPinOrientationCode)
Definition: lib_pin.cpp:108
static int GetOrientationIndex(int aCode)
Get the index of the orientation code.
Definition: lib_pin.cpp:1910
Implementation of conversion functions that require both schematic and board internal units...
int m_numTextSize
Definition: lib_pin.h:84
bool IsNew() const
Definition: base_struct.h:219
static wxArrayString GetOrientationNames()
Get a list of pin orientation names.
Definition: lib_pin.cpp:1890
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:1958
void SetShape(GRAPHIC_PINSHAPE aShape)
Set the shape of the pin to aShape.
Definition: lib_pin.cpp:298
Definition: colors.h:61
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:420
int color
Definition: DXF_plotter.cpp:62
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
static int GetDefaultPinLength()
wxString const GetCanonicalElectricalTypeName() const
return a string giving the electrical type of the pin.
Definition: lib_pin.h:266
void SetName(const wxString &aName, bool aTestOtherPins=true)
Set the pin name.
Definition: lib_pin.cpp:161
bool IsSelected() const
Definition: base_struct.h:224
static const BITMAP_DEF iconsPinsOrientations[]
Definition: lib_pin.cpp:67
wxString const GetElectricalTypeName() const
return a translated string for messages giving the electrical type of the pin.
Definition: lib_pin.h:275
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
void SetWidth(int aWidth) override
Set the width of the draw item to aWidth.
Definition: lib_pin.cpp:1697
void SetOffset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:1583
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:82
static const BITMAP_DEF * GetOrientationSymbols()
Get a list of pin orientation bitmaps for menus and dialogs.
Definition: lib_pin.cpp:1952
virtual EDA_RECT * GetClipBox()
Definition: lib_pin.h:55
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
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:1281
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:145
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
int GetNameTextSize() const
Definition: lib_pin.h:192
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:174
int GetOrientation() const
Definition: lib_pin.h:221
int m_length
Length of the pin.
Definition: lib_pin.h:76
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size) ...
Definition: eda_rect.h:144
COLOR4D GetInvisibleItemColor()
Field Reference of part, i.e. "IC21".
int GetNumberTextSize() const
Definition: lib_pin.h:219
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, void *aData), void *aCallbackData, PLOTTER *aPlotter)
Function DrawGraphicText Draw a graphic text (like module texts)
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
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.
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:1619
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:576
const wxString & GetName() const
Definition: lib_pin.h:166
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:148
void GRLineTo(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int width, COLOR4D Color)
Definition: gr_basic.cpp:337
wxString MessageTextFromValue(EDA_UNITS_T aUnits, int aValue, bool aUseMils)
Definition: base_units.cpp:125
#define IS_NEW
New item, just created.
Definition: base_struct.h:114
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.
virtual EDA_DRAW_FRAME * GetParent() const =0
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()
void LineTo(const wxPoint &pos)
Definition: plotter.h:246
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:77
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:110
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1003
bool ShowPinNumbers()
LIB_PART * GetParent() const
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
wxString m_number
Definition: lib_pin.h:83
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:1130
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
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 ...)
Definition: base_screen.h:76
Class LIB_ITEM definition.
void SetEnd(int x, int y)
Definition: eda_rect.h:134
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:1589
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
wxLogTrace helper definitions.
void Rotate() override
Rotate the draw item.
Definition: lib_pin.cpp:1924
Definition: colors.h:60
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
static const int pin_orientation_codes[]
Definition: lib_pin.cpp:53
wxPoint Centre() const
Definition: eda_rect.h:60
static int InternalPinDecoSize(const LIB_PIN &aPin)
Utility for getting the size of the &#39;internal&#39; pin decorators (as a radius)
Definition: lib_pin.cpp:133
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:362
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:285
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:854
bool m_IsPrinting
Definition: base_screen.h:220
void CalcEdit(const wxPoint &aPosition) override
Calculates the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:2010
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:147
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: lib_pin.cpp:1964
void SetPinPosition(wxPoint aPosition)
move this and all linked pins to the new position used in pin editing.
Definition: lib_pin.cpp:393
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:463
void MoveTo(const wxPoint &pos)
Definition: plotter.h:241
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:81
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:327
void Normalize()
Function Normalize ensures that the height ant width are positive.
#define NCSYMB_PIN_DIM
Base plotter engine class.
Definition: plotter.h:97
Definition the SCH_COMPONENT class for Eeschema.
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:75
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:61
void SetPartNumber(int aPart)
Set the pin part number.
Definition: lib_pin.cpp:420
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:59
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:1680
wxPoint PinEndPoint() const
Definition: lib_pin.cpp:1481
const wxChar *const traceFindItem
Flag to enable find debug tracing.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static int GetPinNameDefaultSize()
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:63
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, COLOR4D Color)
Definition: gr_basic.cpp:755
STATUS_FLAGS m_Flags
Flag bits for editing and other uses.
Definition: base_struct.h:178
size_t i
Definition: json11.cpp:597
Perform a search for a item that has replaceable text.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
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.
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:1597
#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:154
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:80
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
int m_Convert
Shape identification for alternate body styles.
wxString StringFromValue(EDA_UNITS_T aUnits, int aValue, bool aAddUnitSymbol, bool aUseMils)
Function StringFromValue returns the string from aValue according to units (inch, mm ...
Definition: base_units.cpp:210
Definition of class LIB_EDIT_FRAME.
void SetOrientation(int aOrientation, bool aTestOtherPins=true)
Set orientation on the pin.
Definition: lib_pin.cpp:269
COLOR4D GetItemSelectedColor()
#define DBG(x)
Definition: fctsys.h:33
bool IsType(FRAME_T aType) const
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:79
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:655
#define VALUE
#define PIN_ORIENTATION_CNT
Definition: lib_pin.cpp:60
EDA_UNITS_T
Definition: common.h:159
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
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:1508
void getMsgPanelInfoBase(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Build the pin basic info to display in message panel.
Definition: lib_pin.cpp:1707
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:1607
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:1901
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
#define IS_MOVED
Item being moved.
Definition: base_struct.h:113