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-2021 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 
26 #include <pgm_base.h>
27 #include <sch_draw_panel.h>
28 #include <sch_edit_frame.h>
29 #include <symbol_edit_frame.h>
30 #include <lib_pin.h>
33 #include <trigo.h>
34 #include "sch_painter.h"
35 
36 // small margin in internal units between the pin text and the pin line
37 #define PIN_TEXT_MARGIN 4
38 
40 {
41  // These strings are the canonical name of the electrictal type
42  // Not translated, no space in name, only ASCII chars.
43  // to use when the string name must be known and well defined
44  // must have same order than enum ELECTRICAL_PINTYPE (see lib_pin.h)
45  static const wxChar* msgPinElectricType[] =
46  {
47  wxT( "input" ),
48  wxT( "output" ),
49  wxT( "bidirectional" ),
50  wxT( "tri_state" ),
51  wxT( "passive" ),
52  wxT( "free" ),
53  wxT( "unspecified" ),
54  wxT( "power_in" ),
55  wxT( "power_out" ),
56  wxT( "open_collector" ),
57  wxT( "open_emitter" ),
58  wxT( "no_connect" )
59  };
60 
61  return msgPinElectricType[static_cast<int>( aType )];
62 }
63 
64 
66 // i.e. the clock symbols (falling clock is actually external but is of
67 // the same kind)
68 
69 static int internalPinDecoSize( const RENDER_SETTINGS* aSettings, const LIB_PIN &aPin )
70 {
71  const KIGFX::SCH_RENDER_SETTINGS* settings = static_cast<const KIGFX::SCH_RENDER_SETTINGS*>( aSettings );
72 
73  if( settings && settings->m_PinSymbolSize )
74  return settings->m_PinSymbolSize;
75 
76  return aPin.GetNameTextSize() != 0 ? aPin.GetNameTextSize() / 2 : aPin.GetNumberTextSize() / 2;
77 }
78 
80 // i.e. the negation circle, the polarity 'slopes' and the nonlogic
81 // marker
82 static int externalPinDecoSize( const RENDER_SETTINGS* aSettings, const LIB_PIN &aPin )
83 {
84  const KIGFX::SCH_RENDER_SETTINGS* settings = static_cast<const KIGFX::SCH_RENDER_SETTINGS*>( aSettings );
85 
86  if( settings && settings->m_PinSymbolSize )
87  return settings->m_PinSymbolSize;
88 
89  return aPin.GetNumberTextSize() / 2;
90 }
91 
92 
94  LIB_ITEM( LIB_PIN_T, aParent ),
95  m_orientation( PIN_RIGHT ),
96  m_shape( GRAPHIC_PINSHAPE::LINE ),
98  m_attributes( 0 )
99 {
100  // Use the application settings for pin sizes if exists.
101  // pgm can be nullptr when running a shared lib from a script, not from a kicad appl
102  PGM_BASE* pgm = PgmOrNull();
103 
104  if( pgm )
105  {
106  auto* settings = pgm->GetSettingsManager().GetAppSettings<SYMBOL_EDITOR_SETTINGS>();
107  m_length = Mils2iu( settings->m_Defaults.pin_length );
108  m_numTextSize = Mils2iu( settings->m_Defaults.pin_num_size );
109  m_nameTextSize = Mils2iu( settings->m_Defaults.pin_name_size );
110  }
111  else // Use hardcoded eeschema defaults: symbol_editor settings are not existing.
112  {
113  m_length = Mils2iu( DEFAULT_PIN_LENGTH );
114  m_numTextSize = Mils2iu( DEFAULT_PINNUM_SIZE );
116  }
117 }
118 
119 
120 LIB_PIN::LIB_PIN( LIB_SYMBOL* aParent, const wxString& aName, const wxString& aNumber,
121  int aOrientation, ELECTRICAL_PINTYPE aPinType, int aLength, int aNameTextSize,
122  int aNumTextSize, int aConvert, const wxPoint& aPos, int aUnit ) :
123  LIB_ITEM( LIB_PIN_T, aParent ),
124  m_position( aPos ),
125  m_length( aLength ),
126  m_orientation( aOrientation ),
127  m_shape( GRAPHIC_PINSHAPE::LINE ),
128  m_type( aPinType ),
129  m_attributes( 0 ),
130  m_numTextSize( aNumTextSize ),
131  m_nameTextSize( aNameTextSize )
132 {
133  SetName( aName );
134  SetNumber( aNumber );
135  SetUnit( aUnit );
136  SetConvert( aConvert );
137 }
138 
139 
140 bool LIB_PIN::HitTest( const wxPoint& aPosition, int aAccuracy ) const
141 {
142  EDA_RECT rect = GetBoundingBox();
143 
144  return rect.Inflate( aAccuracy ).Contains( aPosition );
145 }
146 
147 
148 bool LIB_PIN::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
149 {
150  if( m_flags & (STRUCT_DELETED | SKIP_STRUCT ) )
151  return false;
152 
153  EDA_RECT sel = aRect;
154 
155  if ( aAccuracy )
156  sel.Inflate( aAccuracy );
157 
158  if( aContained )
159  return sel.Contains( GetBoundingBox( false, true ) );
160 
161  return sel.Intersects( GetBoundingBox( false, true ) );
162 }
163 
164 
166 {
167  return 1;
168 }
169 
170 
171 wxString LIB_PIN::GetShownName() const
172 {
173  if( m_name == "~" )
174  return wxEmptyString;
175  else
176  return m_name;
177 }
178 
179 
180 void LIB_PIN::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
181  const TRANSFORM& aTransform )
182 {
183  LIB_SYMBOL_OPTIONS* opts = (LIB_SYMBOL_OPTIONS*) aData;
184  bool drawHiddenFields = opts ? opts->draw_hidden_fields : false;
185  bool showPinType = opts ? opts->show_elec_type : false;
186  bool show_connect_point = opts ? opts->show_connect_point : false;
187 
188  LIB_SYMBOL* part = GetParent();
189 
190  /* Calculate pin orient taking in account the symbol orientation. */
191  int orient = PinDrawOrient( aTransform );
192 
193  /* Calculate the pin position */
194  wxPoint pos1 = aTransform.TransformCoordinate( m_position ) + aOffset;
195 
196  if( IsVisible() || drawHiddenFields )
197  {
198  printPinSymbol( aSettings, pos1, orient );
199 
200  printPinTexts( aSettings, pos1, orient, part->GetPinNameOffset(), part->ShowPinNumbers(),
201  part->ShowPinNames() );
202 
203  if( showPinType )
204  printPinElectricalTypeName( aSettings, pos1, orient );
205 
206  if( show_connect_point )
207  {
208  wxDC* DC = aSettings->GetPrintDC();
210  GRCircle( nullptr, DC, pos1.x, pos1.y, TARGET_PIN_RADIUS, 0, color );
211  }
212  }
213 }
214 
215 
216 void LIB_PIN::printPinSymbol( const RENDER_SETTINGS* aSettings, const wxPoint& aPos, int aOrient )
217 {
218  wxDC* DC = aSettings->GetPrintDC();
219  int MapX1, MapY1, x1, y1;
220  int width = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
221  int posX = aPos.x, posY = aPos.y, len = m_length;
223 
224  MapX1 = MapY1 = 0;
225  x1 = posX;
226  y1 = posY;
227 
228  switch( aOrient )
229  {
230  case PIN_UP: y1 = posY - len; MapY1 = 1; break;
231  case PIN_DOWN: y1 = posY + len; MapY1 = -1; break;
232  case PIN_LEFT: x1 = posX - len; MapX1 = 1; break;
233  case PIN_RIGHT: x1 = posX + len; MapX1 = -1; break;
234  }
235 
237  {
238  const int radius = externalPinDecoSize( aSettings, *this );
239  GRCircle( nullptr, DC, MapX1 * radius + x1, MapY1 * radius + y1, radius, width, color );
240 
241  GRMoveTo( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 );
242  GRLineTo( nullptr, DC, posX, posY, width, color );
243  }
244  else
245  {
246  GRMoveTo( x1, y1 );
247  GRLineTo( nullptr, DC, posX, posY, width, color );
248  }
249 
250  // Draw the clock shape (>)inside the symbol
255  {
256  const int clock_size = internalPinDecoSize( aSettings, *this );
257  if( MapY1 == 0 ) /* MapX1 = +- 1 */
258  {
259  GRMoveTo( x1, y1 + clock_size );
260  GRLineTo( nullptr, DC, x1 - MapX1 * clock_size * 2, y1, width, color );
261  GRLineTo( nullptr, DC, x1, y1 - clock_size, width, color );
262  }
263  else /* MapX1 = 0 */
264  {
265  GRMoveTo( x1 + clock_size, y1 );
266  GRLineTo( nullptr, DC, x1, y1 - MapY1 * clock_size * 2, width, color );
267  GRLineTo( nullptr, DC, x1 - clock_size, y1, width, color );
268  }
269  }
270 
271  // Draw the active low (or H to L active transition)
275  {
276  const int deco_size = externalPinDecoSize( aSettings, *this );
277  if( MapY1 == 0 ) /* MapX1 = +- 1 */
278  {
279  GRMoveTo( x1 + MapX1 * deco_size * 2, y1 );
280  GRLineTo( nullptr, DC, x1 + MapX1 * deco_size * 2, y1 - deco_size * 2, width, color );
281  GRLineTo( nullptr, DC, x1, y1, width, color );
282  }
283  else /* MapX1 = 0 */
284  {
285  GRMoveTo( x1, y1 + MapY1 * deco_size * 2 );
286  GRLineTo( nullptr, DC, x1 - deco_size * 2, y1 + MapY1 * deco_size * 2, width, color );
287  GRLineTo( nullptr, DC, x1, y1, width, color );
288  }
289  }
290 
291  if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
292  {
293  const int deco_size = externalPinDecoSize( aSettings, *this );
294  if( MapY1 == 0 ) /* MapX1 = +- 1 */
295  {
296  GRMoveTo( x1, y1 - deco_size * 2 );
297  GRLineTo( nullptr, DC, x1 + MapX1 * deco_size * 2, y1, width, color );
298  }
299  else /* MapX1 = 0 */
300  {
301  GRMoveTo( x1 - deco_size * 2, y1 );
302  GRLineTo( nullptr, DC, x1, y1 + MapY1 * deco_size * 2, width, color );
303  }
304  }
305  else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
306  {
307  const int deco_size = externalPinDecoSize( aSettings, *this );
308  GRMoveTo( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size );
309  GRLineTo( nullptr, DC, x1 + (MapX1 + MapY1) * deco_size,
310  y1 + ( MapY1 - MapX1 ) * deco_size, width, color );
311  GRMoveTo( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size );
312  GRLineTo( nullptr, DC, x1 + (MapX1 - MapY1) * deco_size,
313  y1 + ( MapY1 + MapX1 ) * deco_size, width, color );
314  }
315 
316  if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
317  {
318  const int deco_size = TARGET_PIN_RADIUS;
319  GRLine( nullptr, DC, posX - deco_size, posY - deco_size, posX + deco_size,
320  posY + deco_size, width, color );
321  GRLine( nullptr, DC, posX + deco_size, posY - deco_size, posX - deco_size,
322  posY + deco_size, width, color );
323  }
324 }
325 
326 
327 void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos, int aPinOrient,
328  int aTextInside, bool aDrawPinNum, bool aDrawPinName )
329 {
330  if( !aDrawPinName && !aDrawPinNum )
331  return;
332 
333  int x, y;
334  wxDC* DC = aSettings->GetPrintDC();
335  wxSize PinNameSize( m_nameTextSize, m_nameTextSize );
336  wxSize PinNumSize( m_numTextSize, m_numTextSize );
337 
338  int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ),
339  aSettings->GetDefaultPenWidth() );
340  int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, false ),
341  aSettings->GetDefaultPenWidth() );
342 
343  int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
344  int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
345 
346  /* Get the num and name colors */
347  COLOR4D NameColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNAM : LAYER_HIDDEN );
348  COLOR4D NumColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNUM : LAYER_HIDDEN );
349 
350  int x1 = aPinPos.x;
351  int y1 = aPinPos.y;
352 
353  switch( aPinOrient )
354  {
355  case PIN_UP: y1 -= m_length; break;
356  case PIN_DOWN: y1 += m_length; break;
357  case PIN_LEFT: x1 -= m_length; break;
358  case PIN_RIGHT: x1 += m_length; break;
359  }
360 
361  wxString name = GetShownName();
362  wxString number = GetShownNumber();
363 
364  if( name.IsEmpty() )
365  aDrawPinName = false;
366 
367  if( number.IsEmpty() )
368  aDrawPinNum = false;
369 
370  if( aTextInside ) // Draw the text inside, but the pin numbers outside.
371  {
372  if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
373  {
374  // It is an horizontal line
375  if( aDrawPinName )
376  {
377  if( aPinOrient == PIN_RIGHT )
378  {
379  x = x1 + aTextInside;
380  GRText( DC, wxPoint( x, y1 ), NameColor, name, TEXT_ANGLE_HORIZ, PinNameSize,
381  GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
382  false );
383  }
384  else // Orient == PIN_LEFT
385  {
386  x = x1 - aTextInside;
387  GRText( DC, wxPoint( x, y1 ), NameColor, name, TEXT_ANGLE_HORIZ, PinNameSize,
388  GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
389  false );
390  }
391  }
392 
393  if( aDrawPinNum )
394  {
395  GRText( DC, wxPoint(( x1 + aPinPos.x) / 2, y1 - num_offset ), NumColor, number,
397  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
398  }
399  }
400  else /* Its a vertical line. */
401  {
402  // Text is drawn from bottom to top (i.e. to negative value for Y axis)
403  if( aPinOrient == PIN_DOWN )
404  {
405  y = y1 + aTextInside;
406 
407  if( aDrawPinName )
408  {
409  GRText( DC, wxPoint( x1, y ), NameColor, name, TEXT_ANGLE_VERT, PinNameSize,
410  GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
411  false );
412  }
413 
414  if( aDrawPinNum )
415  {
416  GRText( DC, wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
417  number, TEXT_ANGLE_VERT, PinNumSize, GR_TEXT_HJUSTIFY_CENTER,
418  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
419  }
420  }
421  else /* PIN_UP */
422  {
423  y = y1 - aTextInside;
424 
425  if( aDrawPinName )
426  {
427  GRText( DC, wxPoint( x1, y ), NameColor, name, TEXT_ANGLE_VERT, PinNameSize,
428  GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
429  false );
430  }
431 
432  if( aDrawPinNum )
433  {
434  GRText( DC, wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
435  number, TEXT_ANGLE_VERT, PinNumSize, GR_TEXT_HJUSTIFY_CENTER,
436  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
437  }
438  }
439  }
440  }
441  else /**** Draw num & text pin outside ****/
442  {
443  if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
444  {
445  /* Its an horizontal line. */
446  if( aDrawPinName )
447  {
448  x = ( x1 + aPinPos.x) / 2;
449  GRText( DC, wxPoint( x, y1 - name_offset ), NameColor, name, TEXT_ANGLE_HORIZ,
451  namePenWidth, false, false );
452  }
453  if( aDrawPinNum )
454  {
455  x = ( x1 + aPinPos.x) / 2;
456  GRText( DC, wxPoint( x, y1 + num_offset ), NumColor, number, TEXT_ANGLE_HORIZ,
457  PinNumSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, numPenWidth,
458  false, false );
459  }
460  }
461  else /* Its a vertical line. */
462  {
463  if( aDrawPinName )
464  {
465  y = ( y1 + aPinPos.y) / 2;
466  GRText( DC, wxPoint( x1 - name_offset, y ), NameColor, name, TEXT_ANGLE_VERT,
468  namePenWidth, false, false );
469  }
470 
471  if( aDrawPinNum )
472  {
473  GRText( DC, wxPoint( x1 + num_offset, ( y1 + aPinPos.y) / 2 ), NumColor, number,
475  numPenWidth, false, false );
476  }
477  }
478  }
479 }
480 
481 
482 
483 void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, wxPoint& aPosition,
484  int aOrientation )
485 {
486  wxDC* DC = aSettings->GetPrintDC();
487  wxString typeName = GetElectricalTypeName();
488 
489  // Use a reasonable (small) size to draw the text
490  int textSize = ( m_nameTextSize * 3 ) / 4;
491 
492  #define ETXT_MAX_SIZE Millimeter2iu( 0.7 )
493 
494  if( textSize > ETXT_MAX_SIZE )
495  textSize = ETXT_MAX_SIZE;
496 
497  // Use a reasonable pen size to draw the text
498  int pensize = textSize/6;
499 
500  // Get a suitable color
502 
503  wxPoint txtpos = aPosition;
504  int offset = Millimeter2iu( 0.4 );
506  int orient = TEXT_ANGLE_HORIZ;
507 
508  switch( aOrientation )
509  {
510  case PIN_UP:
511  txtpos.y += offset;
512  orient = TEXT_ANGLE_VERT;
513  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
514  break;
515 
516  case PIN_DOWN:
517  txtpos.y -= offset;
518  orient = TEXT_ANGLE_VERT;
519  break;
520 
521  case PIN_LEFT:
522  txtpos.x += offset;
523  break;
524 
525  case PIN_RIGHT:
526  txtpos.x -= offset;
527  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
528  break;
529  }
530 
531  GRText( DC, txtpos, color, typeName, orient, wxSize( textSize, textSize ), hjustify,
532  GR_TEXT_VJUSTIFY_CENTER, pensize, false, false, nullptr );
533 }
534 
535 
536 void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation ) const
537 {
538  int MapX1, MapY1, x1, y1;
540  int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
541 
542  aPlotter->SetColor( color );
543  aPlotter->SetCurrentLineWidth( penWidth );
544 
545  MapX1 = MapY1 = 0;
546  x1 = aPosition.x; y1 = aPosition.y;
547 
548  switch( aOrientation )
549  {
550  case PIN_UP: y1 = aPosition.y - m_length; MapY1 = 1; break;
551  case PIN_DOWN: y1 = aPosition.y + m_length; MapY1 = -1; break;
552  case PIN_LEFT: x1 = aPosition.x - m_length; MapX1 = 1; break;
553  case PIN_RIGHT: x1 = aPosition.x + m_length; MapX1 = -1; break;
554  }
555 
557  {
558  const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
559  aPlotter->Circle( wxPoint( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
560  FILL_TYPE::NO_FILL, penWidth );
561 
562  aPlotter->MoveTo( wxPoint( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
563  aPlotter->FinishTo( aPosition );
564  }
566  {
567  const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
568  if( MapY1 == 0 ) /* MapX1 = +- 1 */
569  {
570  aPlotter->MoveTo( wxPoint( x1, y1 + deco_size ) );
571  aPlotter->LineTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 ) );
572  aPlotter->FinishTo( wxPoint( x1, y1 - deco_size ) );
573  }
574  else /* MapX1 = 0 */
575  {
576  aPlotter->MoveTo( wxPoint( x1 + deco_size, y1 ) );
577  aPlotter->LineTo( wxPoint( x1, y1 + MapY1 * deco_size * 2 ) );
578  aPlotter->FinishTo( wxPoint( x1 - deco_size, y1 ) );
579  }
580 
581  aPlotter->MoveTo( wxPoint( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
582  aPlotter->FinishTo( aPosition );
583  }
584  else
585  {
586  aPlotter->MoveTo( wxPoint( x1, y1 ) );
587  aPlotter->FinishTo( aPosition );
588  }
589 
593  {
594  const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
595  if( MapY1 == 0 ) /* MapX1 = +- 1 */
596  {
597  aPlotter->MoveTo( wxPoint( x1, y1 + deco_size ) );
598  aPlotter->LineTo( wxPoint( x1 - MapX1 * deco_size * 2, y1 ) );
599  aPlotter->FinishTo( wxPoint( x1, y1 - deco_size ) );
600  }
601  else /* MapX1 = 0 */
602  {
603  aPlotter->MoveTo( wxPoint( x1 + deco_size, y1 ) );
604  aPlotter->LineTo( wxPoint( x1, y1 - MapY1 * deco_size * 2 ) );
605  aPlotter->FinishTo( wxPoint( x1 - deco_size, y1 ) );
606  }
607  }
608 
610  || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
611  {
612  const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
613 
614  if( MapY1 == 0 ) /* MapX1 = +- 1 */
615  {
616  aPlotter->MoveTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 ) );
617  aPlotter->LineTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
618  aPlotter->FinishTo( wxPoint( x1, y1 ) );
619  }
620  else /* MapX1 = 0 */
621  {
622  aPlotter->MoveTo( wxPoint( x1, y1 + MapY1 * deco_size * 2 ) );
623  aPlotter->LineTo( wxPoint( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
624  aPlotter->FinishTo( wxPoint( x1, y1 ) );
625  }
626  }
627 
628  if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
629  {
630  const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
631 
632  if( MapY1 == 0 ) /* MapX1 = +- 1 */
633  {
634  aPlotter->MoveTo( wxPoint( x1, y1 - symbol_size * 2 ) );
635  aPlotter->FinishTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
636  }
637  else /* MapX1 = 0 */
638  {
639  aPlotter->MoveTo( wxPoint( x1 - symbol_size * 2, y1 ) );
640  aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
641  }
642  }
643  else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
644  {
645  const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
646  aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size ) );
647  aPlotter->FinishTo( wxPoint( x1 + (MapX1 + MapY1) * deco_size, y1 + (MapY1 - MapX1) * deco_size ) );
648  aPlotter->MoveTo( wxPoint( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size ) );
649  aPlotter->FinishTo( wxPoint( x1 + (MapX1 - MapY1) * deco_size, y1 + (MapY1 + MapX1) * deco_size ) );
650  }
651 
652  if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
653  {
654  const int deco_size = TARGET_PIN_RADIUS;
655  const int ex1 = aPosition.x;
656  const int ey1 = aPosition.y;
657  aPlotter->MoveTo( wxPoint( ex1 - deco_size, ey1 - deco_size ) );
658  aPlotter->FinishTo( wxPoint( ex1 + deco_size, ey1 + deco_size ) );
659  aPlotter->MoveTo( wxPoint( ex1 + deco_size, ey1 - deco_size ) );
660  aPlotter->FinishTo( wxPoint( ex1 - deco_size, ey1 + deco_size ) );
661  }
662 }
663 
664 
665 void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, const wxPoint& aPinPos, int aPinOrient, int aTextInside,
666  bool aDrawPinNum, bool aDrawPinName ) const
667 {
668  wxString name = GetShownName();
669  wxString number = GetShownNumber();
670 
671  if( name.IsEmpty() )
672  aDrawPinName = false;
673 
674  if( number.IsEmpty() )
675  aDrawPinNum = false;
676 
677  if( !aDrawPinNum && !aDrawPinName )
678  return;
679 
680  int x, y;
681  wxSize pinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
682  wxSize pinNumSize = wxSize( m_numTextSize, m_numTextSize );
683 
684  int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ),
685  aPlotter->RenderSettings()->GetDefaultPenWidth() );
686  int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, false ),
687  aPlotter->RenderSettings()->GetDefaultPenWidth() );
688 
689  int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
690  int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
691 
692  /* Get the num and name colors */
693  COLOR4D nameColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNAM );
694  COLOR4D numColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNUM );
695 
696  int x1 = aPinPos.x;
697  int y1 = aPinPos.y;
698 
699  switch( aPinOrient )
700  {
701  case PIN_UP: y1 -= m_length; break;
702  case PIN_DOWN: y1 += m_length; break;
703  case PIN_LEFT: x1 -= m_length; break;
704  case PIN_RIGHT: x1 += m_length; break;
705  }
706 
707  /* Draw the text inside, but the pin numbers outside. */
708  if( aTextInside )
709  {
710  if( ( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) ) /* Its an horizontal line. */
711  {
712  if( aDrawPinName )
713  {
714  EDA_TEXT_HJUSTIFY_T hjustify;
715  if( aPinOrient == PIN_RIGHT )
716  {
717  x = x1 + aTextInside;
718  hjustify = GR_TEXT_HJUSTIFY_LEFT;
719  }
720  else // orient == PIN_LEFT
721  {
722  x = x1 - aTextInside;
723  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
724  }
725 
726  aPlotter->Text( wxPoint( x, y1 ), nameColor, name, TEXT_ANGLE_HORIZ, pinNameSize,
727  hjustify, GR_TEXT_VJUSTIFY_CENTER, namePenWidth,
728  false, false );
729  }
730  if( aDrawPinNum )
731  {
732  aPlotter->Text( wxPoint( ( x1 + aPinPos.x) / 2, y1 - num_offset ), numColor,
733  number, TEXT_ANGLE_HORIZ, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
734  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
735  }
736  }
737  else /* Its a vertical line. */
738  {
739  if( aPinOrient == PIN_DOWN )
740  {
741  y = y1 + aTextInside;
742 
743  if( aDrawPinName )
744  aPlotter->Text( wxPoint( x1, y ), nameColor, name, TEXT_ANGLE_VERT,
746  namePenWidth, false, false );
747 
748  if( aDrawPinNum )
749  {
750  aPlotter->Text( wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
751  number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
752  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
753  }
754  }
755  else /* PIN_UP */
756  {
757  y = y1 - aTextInside;
758 
759  if( aDrawPinName )
760  {
761  aPlotter->Text( wxPoint( x1, y ), nameColor, name, TEXT_ANGLE_VERT,
763  namePenWidth, false, false );
764  }
765 
766  if( aDrawPinNum )
767  {
768  aPlotter->Text( wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
769  number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
770  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
771  }
772  }
773  }
774  }
775  else /* Draw num & text pin outside */
776  {
777  if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
778  {
779  /* Its an horizontal line. */
780  if( aDrawPinName )
781  {
782  x = ( x1 + aPinPos.x) / 2;
783  aPlotter->Text( wxPoint( x, y1 - name_offset ), nameColor, name,
785  GR_TEXT_VJUSTIFY_BOTTOM, namePenWidth, false, false );
786  }
787 
788  if( aDrawPinNum )
789  {
790  x = ( x1 + aPinPos.x ) / 2;
791  aPlotter->Text( wxPoint( x, y1 + num_offset ), numColor, number,
793  GR_TEXT_VJUSTIFY_TOP, numPenWidth, false, false );
794  }
795  }
796  else /* Its a vertical line. */
797  {
798  if( aDrawPinName )
799  {
800  y = ( y1 + aPinPos.y ) / 2;
801  aPlotter->Text( wxPoint( x1 - name_offset, y ), nameColor, name,
803  GR_TEXT_VJUSTIFY_BOTTOM, namePenWidth, false, false );
804  }
805 
806  if( aDrawPinNum )
807  {
808  aPlotter->Text( wxPoint( x1 + num_offset, ( y1 + aPinPos.y ) / 2 ), numColor,
809  number, TEXT_ANGLE_VERT, pinNumSize, GR_TEXT_HJUSTIFY_CENTER,
810  GR_TEXT_VJUSTIFY_TOP, numPenWidth, false, false );
811  }
812  }
813  }
814 }
815 
816 
817 int LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const
818 {
819  int orient;
820  wxPoint end; // position of pin end starting at 0,0 according to its orientation, length = 1
821 
822  switch( m_orientation )
823  {
824  case PIN_UP: end.y = 1; break;
825  case PIN_DOWN: end.y = -1; break;
826  case PIN_LEFT: end.x = -1; break;
827  case PIN_RIGHT: end.x = 1; break;
828  }
829 
830  // = pos of end point, according to the symbol orientation.
831  end = aTransform.TransformCoordinate( end );
832  orient = PIN_UP;
833 
834  if( end.x == 0 )
835  {
836  if( end.y > 0 )
837  orient = PIN_DOWN;
838  }
839  else
840  {
841  orient = PIN_RIGHT;
842 
843  if( end.x < 0 )
844  orient = PIN_LEFT;
845  }
846 
847  return orient;
848 }
849 
850 
852 {
853  return new LIB_PIN( *this );
854 }
855 
856 
857 int LIB_PIN::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
858 {
859  wxASSERT( aOther.Type() == LIB_PIN_T );
860 
861  int retv = LIB_ITEM::compare( aOther, aCompareFlags );
862 
863  if( retv )
864  return retv;
865 
866  const LIB_PIN* tmp = (LIB_PIN*) &aOther;
867 
868  // When comparing units, we do not compare the part numbers. If everything else is
869  // identical, then we can just renumber the parts for the inherited symbol.
870  if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number )
871  return m_number.Cmp( tmp->m_number );
872 
873  int result = m_name.CmpNoCase( tmp->m_name );
874 
875  if( result )
876  return result;
877 
878  if( m_position.x != tmp->m_position.x )
879  return m_position.x - tmp->m_position.x;
880 
881  if( m_position.y != tmp->m_position.y )
882  return m_position.y - tmp->m_position.y;
883 
884  if( m_length != tmp->m_length )
885  return m_length - tmp->m_length;
886 
887  if( m_orientation != tmp->m_orientation )
888  return m_orientation - tmp->m_orientation;
889 
890  if( m_shape != tmp->m_shape )
891  return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
892 
893  if( m_type != tmp->m_type )
894  return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
895 
896  if( m_attributes != tmp->m_attributes )
897  return m_attributes - tmp->m_attributes;
898 
899  if( m_numTextSize != tmp->m_numTextSize )
900  return m_numTextSize - tmp->m_numTextSize;
901 
902  if( m_nameTextSize != tmp->m_nameTextSize )
903  return m_nameTextSize - tmp->m_nameTextSize;
904 
905  if( m_alternates.size() != tmp->m_alternates.size() )
906  return m_alternates.size() - tmp->m_alternates.size();
907 
908  auto lhsItem = m_alternates.begin();
909  auto rhsItem = tmp->m_alternates.begin();
910 
911  while( lhsItem != m_alternates.end() )
912  {
913  const ALT& lhsAlt = lhsItem->second;
914  const ALT& rhsAlt = rhsItem->second;
915 
916  retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
917 
918  if( retv )
919  return retv;
920 
921  if( lhsAlt.m_Type != rhsAlt.m_Type )
922  return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
923 
924  if( lhsAlt.m_Shape != rhsAlt.m_Shape )
925  return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
926 
927  ++lhsItem;
928  ++rhsItem;
929  }
930 
931  return 0;
932 }
933 
934 
935 void LIB_PIN::Offset( const wxPoint& aOffset )
936 {
937  m_position += aOffset;
938 }
939 
940 
941 void LIB_PIN::MoveTo( const wxPoint& aNewPosition )
942 {
943  if( m_position != aNewPosition )
944  {
945  m_position = aNewPosition;
946  SetModified();
947  }
948 }
949 
950 
951 void LIB_PIN::MirrorHorizontal( const wxPoint& aCenter )
952 {
953  m_position.x -= aCenter.x;
954  m_position.x *= -1;
955  m_position.x += aCenter.x;
956 
957  if( m_orientation == PIN_RIGHT )
959  else if( m_orientation == PIN_LEFT )
961 }
962 
963 
964 void LIB_PIN::MirrorVertical( const wxPoint& aCenter )
965 {
966  m_position.y -= aCenter.y;
967  m_position.y *= -1;
968  m_position.y += aCenter.y;
969 
970  if( m_orientation == PIN_UP )
972  else if( m_orientation == PIN_DOWN )
974 }
975 
976 
977 void LIB_PIN::Rotate( const wxPoint& aCenter, bool aRotateCCW )
978 {
979  int rot_angle = aRotateCCW ? -900 : 900;
980 
981  RotatePoint( &m_position, aCenter, rot_angle );
982 
983  if( aRotateCCW )
984  {
985  switch( m_orientation )
986  {
987  case PIN_RIGHT: m_orientation = PIN_UP; break;
988  case PIN_UP: m_orientation = PIN_LEFT; break;
989  case PIN_LEFT: m_orientation = PIN_DOWN; break;
990  case PIN_DOWN: m_orientation = PIN_RIGHT; break;
991  }
992  }
993  else
994  {
995  switch( m_orientation )
996  {
997  case PIN_RIGHT: m_orientation = PIN_DOWN; break;
998  case PIN_UP: m_orientation = PIN_RIGHT; break;
999  case PIN_LEFT: m_orientation = PIN_UP; break;
1000  case PIN_DOWN: m_orientation = PIN_LEFT; break;
1001  }
1002  }
1003 }
1004 
1005 
1006 void LIB_PIN::Plot( PLOTTER* aPlotter, const wxPoint& aPffset, bool aFill,
1007  const TRANSFORM& aTransform ) const
1008 {
1009  if( !IsVisible() )
1010  return;
1011 
1012  int orient = PinDrawOrient( aTransform );
1013  wxPoint pos = aTransform.TransformCoordinate( m_position ) + aPffset;
1014 
1015  PlotSymbol( aPlotter, pos, orient );
1016  PlotPinTexts( aPlotter, pos, orient, GetParent()->GetPinNameOffset(),
1017  GetParent()->ShowPinNumbers(), GetParent()->ShowPinNames() );
1018 }
1019 
1020 
1022 {
1023  LIB_ITEM::GetMsgPanelInfo( aFrame, aList );
1024 
1025  aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetShownName() ) );
1026  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), GetShownNumber() ) );
1027  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( m_type ) ) );
1028  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), PinShapeGetText( m_shape ) ) );
1029 
1030  wxString text = IsVisible() ? _( "Yes" ) : _( "No" );
1031  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text ) );
1032 
1033  // Display pin length
1034  text = StringFromValue( aFrame->GetUserUnits(), m_length );
1035  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), text ) );
1036 
1038  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), text ) );
1039 
1040  wxPoint pinpos = GetPosition();
1041  pinpos.y = -pinpos.y; // Display coord are top to bottom
1042  // lib items coord are bottom to top
1043 
1044  text = MessageTextFromValue( aFrame->GetUserUnits(), pinpos.x );
1045  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text ) );
1046 
1047  text = MessageTextFromValue( aFrame->GetUserUnits(), pinpos.y );
1048  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text ) );
1049 }
1050 
1051 
1052 const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles, bool aPinOnly ) const
1053 {
1054  EDA_RECT bbox;
1055  wxPoint begin;
1056  wxPoint end;
1057  int nameTextOffset = 0;
1058  wxString name = GetShownName();
1059  wxString number = GetShownNumber();
1060  bool showName = !name.IsEmpty();
1061  bool showNum = !number.IsEmpty();
1062  int minsizeV = TARGET_PIN_RADIUS;
1063 
1064  if( !aIncludeInvisibles && !IsVisible() )
1065  showName = false;
1066 
1067  if( GetParent() )
1068  {
1069  if( GetParent()->ShowPinNames() )
1070  nameTextOffset = GetParent()->GetPinNameOffset();
1071  else
1072  showName = false;
1073 
1074  if( !GetParent()->ShowPinNumbers() )
1075  showNum = false;
1076  }
1077 
1078  if( aPinOnly )
1079  {
1080  showName = false;
1081  showNum = false;
1082  }
1083 
1084  // First, calculate boundary box corners position
1085  int numberTextLength = showNum ? m_numTextSize * number.Len() : 0;
1086 
1087  // Actual text height is bigger than text size
1088  int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
1089 
1091  minsizeV = std::max( TARGET_PIN_RADIUS, externalPinDecoSize( nullptr, *this ) );
1092 
1093  // calculate top left corner position
1094  // for the default pin orientation (PIN_RIGHT)
1095  begin.y = std::max( minsizeV, numberTextHeight + Mils2iu( PIN_TEXT_MARGIN ) );
1096  begin.x = std::min( -TARGET_PIN_RADIUS, m_length - (numberTextLength / 2) );
1097 
1098  // calculate bottom right corner position and adjust top left corner position
1099  int nameTextLength = 0;
1100  int nameTextHeight = 0;
1101 
1102  if( showName )
1103  {
1104  int length = name.Len();
1105 
1106  // TODO: exclude markup characters!
1107  nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
1108 
1109  // Actual text height are bigger than text size
1110  nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + Mils2iu( PIN_TEXT_MARGIN );
1111  }
1112 
1113  if( nameTextOffset ) // for values > 0, pin name is inside the body
1114  {
1115  end.x = m_length + nameTextLength + TARGET_PIN_RADIUS;
1116  end.y = std::min( -minsizeV, -nameTextHeight / 2 );
1117  }
1118  else // if value == 0:
1119  // pin name is outside the body, and above the pin line
1120  // pin num is below the pin line
1121  {
1122  end.x = std::max( m_length + TARGET_PIN_RADIUS, nameTextLength );
1123  end.y = -begin.y;
1124  begin.y = std::max( minsizeV, nameTextHeight );
1125  }
1126 
1127  // Now, calculate boundary box corners position for the actual pin orientation
1128  int orient = PinDrawOrient( DefaultTransform );
1129 
1130  /* Calculate the pin position */
1131  switch( orient )
1132  {
1133  case PIN_UP:
1134  // Pin is rotated and texts positions are mirrored
1135  RotatePoint( &begin, wxPoint( 0, 0 ), -900 );
1136  RotatePoint( &end, wxPoint( 0, 0 ), -900 );
1137  break;
1138 
1139  case PIN_DOWN:
1140  RotatePoint( &begin, wxPoint( 0, 0 ), 900 );
1141  RotatePoint( &end, wxPoint( 0, 0 ), 900 );
1142  begin.x = -begin.x;
1143  end.x = -end.x;
1144  break;
1145 
1146  case PIN_LEFT:
1147  begin.x = -begin.x;
1148  end.x = -end.x;
1149  break;
1150 
1151  case PIN_RIGHT:
1152  break;
1153  }
1154 
1155  begin += m_position;
1156  end += m_position;
1157 
1158  bbox.SetOrigin( begin );
1159  bbox.SetEnd( end );
1160  bbox.Normalize();
1161  bbox.Inflate( ( GetPenWidth() / 2 ) + 1 );
1162 
1163  // Draw Y axis is reversed in schematic:
1164  bbox.RevertYAxis();
1165 
1166  return bbox;
1167 }
1168 
1169 
1171 {
1173 }
1174 
1175 
1176 wxString LIB_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
1177 {
1178  if( !m_name.IsEmpty() )
1179  {
1180  return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
1181  m_number,
1182  m_name,
1184  PinShapeGetText( m_shape ) );
1185  }
1186  else
1187  {
1188  return wxString::Format( _( "Pin %s [%s, %s]" ),
1189  m_number,
1191  PinShapeGetText( m_shape ) );
1192  }
1193 }
1194 
1195 
1196 #if defined(DEBUG)
1197 
1198 void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
1199 {
1200  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
1201  << " num=\"" << m_number.mb_str()
1202  << '"' << "/>\n";
1203 
1204 // NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
1205 }
1206 
1207 #endif
1208 
1209 void LIB_PIN::CalcEdit( const wxPoint& aPosition )
1210 {
1211  if( IsMoving() )
1212  MoveTo( aPosition );
1213 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
wxString GetClass() const override
Return the class name.
Definition: lib_pin.h:65
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:129
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:50
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: lib_pin.cpp:1176
void SetModified()
Definition: eda_item.cpp:65
int GetPinNameOffset() const
Definition: lib_symbol.h:561
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:104
int m_nameTextSize
Definition: lib_pin.h:289
wxString GetShownNumber() const
Definition: lib_pin.h:117
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:851
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:977
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:61
void Plot(PLOTTER *aPlotter, const wxPoint &aPffset, bool aFill, const TRANSFORM &aTransform) const override
Plot the draw item using the plot object.
Definition: lib_pin.cpp:1006
void PlotPinTexts(PLOTTER *aPlotter, const wxPoint &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName) const
Plot the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:665
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:283
#define ETXT_MAX_SIZE
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void MoveTo(const wxPoint &aNewPosition) override
Move a draw object to aPosition.
Definition: lib_pin.cpp:941
int m_numTextSize
Definition: lib_pin.h:288
Container for data for KiCad programs.
Definition: pgm_base.h:93
void printPinTexts(const RENDER_SETTINGS *aSettings, wxPoint &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName)
Put the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:327
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:237
LIB_PIN(LIB_SYMBOL *aParent)
Definition: lib_pin.cpp:93
bool IsMoving() const
Definition: eda_item.h:120
int color
Definition: DXF_plotter.cpp:60
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation) const
Definition: lib_pin.cpp:536
BITMAPS ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:247
bool ShowPinNumbers() const
Definition: lib_symbol.h:577
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
unknown electrical properties: creates always a warning when connected
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:121
int PinOrientationIndex(int code)
Definition: pin_type.cpp:147
wxString m_name
Definition: lib_pin.h:286
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: lib_pin.cpp:140
#define DEFAULT_PIN_LENGTH
The default pin number size when creating pins(can be changed in preference menu)
wxString PinShapeGetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:258
Definition: lib_pin.h:48
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:481
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:174
GRAPHIC_PINSHAPE
Definition: pin_type.h:55
The base class for create windows for drawing purpose.
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:817
int m_length
Definition: lib_pin.h:281
Define a library symbol object.
Definition: lib_symbol.h:96
void RevertYAxis()
Mirror the rectangle from the X axis (negate Y pos and size).
Definition: eda_rect.h:198
ELECTRICAL_PINTYPE m_Type
Definition: lib_pin.h:60
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:42
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:964
void GRLineTo(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int width, COLOR4D Color)
Definition: gr_basic.cpp:268
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:118
wxString PinOrientationName(unsigned aPinOrientationCode)
Definition: pin_type.cpp:116
void LineTo(const wxPoint &pos)
Definition: plotter.h:268
int m_orientation
Definition: lib_pin.h:282
void printPinSymbol(const RENDER_SETTINGS *aSettings, const wxPoint &aPos, int aOrientation)
Print the pin symbol without text.
Definition: lib_pin.cpp:216
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Don't allow text to become cluttered up in its own fatness.
Definition: gr_text.cpp:68
wxString m_number
Definition: lib_pin.h:287
PGM_BASE * PgmOrNull()
similar to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: cvpcb.cpp:125
wxString const GetElectricalTypeName() const
Definition: lib_pin.h:92
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:81
void SetEnd(int x, int y)
Definition: eda_rect.h:182
wxString m_Name
Definition: lib_pin.h:58
bool ShowPinNames() const
Definition: lib_symbol.h:569
#define STRUCT_DELETED
flag indication structures to be erased
#define _(s)
AppSettings * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
int GetPenWidth() const override
Definition: lib_pin.cpp:165
wxDC * GetPrintDC() const
bool IsVisible() const
Definition: lib_pin.h:97
#define DEFAULT_PINNUM_SIZE
The default pin name size when creating pins(can be changed in preference menu)
int compare(const LIB_ITEM &aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags=LIB_ITEM::COMPARE_FLAGS::NORMAL) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_pin.cpp:857
int GetNameTextSize() const
Definition: lib_pin.h:126
wxString GetShownName() const
Definition: lib_pin.cpp:171
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:231
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1170
virtual void Circle(const wxPoint &pos, int diametre, FILL_TYPE fill, int width=USE_DEFAULT_LINE_WIDTH)=0
#define DEFAULT_PINNAME_SIZE
The default selection highlight thickness (can be changed in preference menu)
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, 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:1021
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Definition: lib_item.cpp:50
void CalcEdit(const wxPoint &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1209
virtual void SetColor(const COLOR4D &color)=0
void GRText(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)
Draw a graphic text (like footprint texts).
Definition: gr_text.cpp:130
void SetConvert(int aConvert)
Definition: lib_item.h:261
wxPoint GetPosition() const override
Definition: lib_pin.h:210
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
int m_attributes
Definition: lib_pin.h:285
EDA_UNITS
Definition: eda_units.h:38
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:258
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:146
void SetUnit(int aUnit)
Definition: lib_item.h:258
Base plotter engine class.
Definition: plotter.h:121
std::map< wxString, ALT > m_alternates
Definition: lib_pin.h:291
wxPoint m_position
Definition: lib_pin.h:280
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:156
int GetNumberTextSize() const
Definition: lib_pin.h:129
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:56
void SetName(const wxString &aName)
Definition: lib_pin.h:108
#define SKIP_STRUCT
flag indicating that the structure should be ignored
const char * name
Definition: DXF_plotter.cpp:59
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:35
static int internalPinDecoSize(const RENDER_SETTINGS *aSettings, const LIB_PIN &aPin)
Utility for getting the size of the 'internal' pin decorators (as a radius)
Definition: lib_pin.cpp:69
void printPinElectricalTypeName(const RENDER_SETTINGS *aSettings, wxPoint &aPosition, int aOrientation)
Draw the electrical type text of the pin (only for the footprint editor)
Definition: lib_pin.cpp:483
#define PIN_TEXT_MARGIN
Definition: lib_pin.cpp:37
static int externalPinDecoSize(const RENDER_SETTINGS *aSettings, const LIB_PIN &aPin)
Utility for getting the size of the 'external' pin decorators (as a radius)
Definition: lib_pin.cpp:82
void GRCircle(EDA_RECT *ClipBox, wxDC *DC, int xc, int yc, int r, int width, COLOR4D Color)
Definition: gr_basic.cpp:597
Handle the component boundary box.
Definition: eda_rect.h:42
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
#define TARGET_PIN_RADIUS
Definition: lib_pin.h:36
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
ELECTRICAL_PINTYPE m_type
Definition: lib_pin.h:284
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
Store schematic specific render settings.
Definition: sch_painter.h:70
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
int GetDefaultPenWidth() const
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=nullptr)
Draw text with the plotter.
Definition: gr_text.cpp:217
#define TEXT_ANGLE_VERT
Definition: eda_text.h:51
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:87
not connected (must be left open)
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:935
static constexpr int Millimeter2iu(double mm)
virtual int compare(const LIB_ITEM &aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags=LIB_ITEM::COMPARE_FLAGS::NORMAL) const
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_item.cpp:74
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
GRAPHIC_PINSHAPE m_Shape
Definition: lib_pin.h:59
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364
void print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset, void *aData, const TRANSFORM &aTransform) override
Print a pin, with or without the pin texts.
Definition: lib_pin.cpp:180
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:951
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103