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_PART* 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 void LIB_PIN::print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset, void* aData,
172  const TRANSFORM& aTransform )
173 {
174  PART_DRAW_OPTIONS* opts = (PART_DRAW_OPTIONS*) aData;
175  bool drawHiddenFields = opts ? opts->draw_hidden_fields : false;
176  bool showPinType = opts ? opts->show_elec_type : false;
177 
178  LIB_PART* part = GetParent();
179 
180  /* Calculate pin orient taking in account the component orientation. */
181  int orient = PinDrawOrient( aTransform );
182 
183  /* Calculate the pin position */
184  wxPoint pos1 = aTransform.TransformCoordinate( m_position ) + aOffset;
185 
186  if( IsVisible() || drawHiddenFields )
187  {
188  printPinSymbol( aSettings, pos1, orient );
189 
190  printPinTexts( aSettings, pos1, orient, part->GetPinNameOffset(), part->ShowPinNumbers(),
191  part->ShowPinNames() );
192 
193  if( showPinType )
194  printPinElectricalTypeName( aSettings, pos1, orient );
195  }
196 }
197 
198 
199 void LIB_PIN::printPinSymbol( const RENDER_SETTINGS* aSettings, const wxPoint& aPos, int aOrient )
200 {
201  wxDC* DC = aSettings->GetPrintDC();
202  int MapX1, MapY1, x1, y1;
203  int width = std::max( GetPenWidth(), aSettings->GetDefaultPenWidth() );
204  int posX = aPos.x, posY = aPos.y, len = m_length;
206 
207  MapX1 = MapY1 = 0;
208  x1 = posX;
209  y1 = posY;
210 
211  switch( aOrient )
212  {
213  case PIN_UP: y1 = posY - len; MapY1 = 1; break;
214  case PIN_DOWN: y1 = posY + len; MapY1 = -1; break;
215  case PIN_LEFT: x1 = posX - len; MapX1 = 1; break;
216  case PIN_RIGHT: x1 = posX + len; MapX1 = -1; break;
217  }
218 
220  {
221  const int radius = externalPinDecoSize( aSettings, *this );
222  GRCircle( nullptr, DC, MapX1 * radius + x1, MapY1 * radius + y1, radius, width, color );
223 
224  GRMoveTo( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 );
225  GRLineTo( nullptr, DC, posX, posY, width, color );
226  }
227  else
228  {
229  GRMoveTo( x1, y1 );
230  GRLineTo( nullptr, DC, posX, posY, width, color );
231  }
232 
233  // Draw the clock shape (>)inside the symbol
238  {
239  const int clock_size = internalPinDecoSize( aSettings, *this );
240  if( MapY1 == 0 ) /* MapX1 = +- 1 */
241  {
242  GRMoveTo( x1, y1 + clock_size );
243  GRLineTo( nullptr, DC, x1 - MapX1 * clock_size * 2, y1, width, color );
244  GRLineTo( nullptr, DC, x1, y1 - clock_size, width, color );
245  }
246  else /* MapX1 = 0 */
247  {
248  GRMoveTo( x1 + clock_size, y1 );
249  GRLineTo( nullptr, DC, x1, y1 - MapY1 * clock_size * 2, width, color );
250  GRLineTo( nullptr, DC, x1 - clock_size, y1, width, color );
251  }
252  }
253 
254  // Draw the active low (or H to L active transition)
258  {
259  const int deco_size = externalPinDecoSize( aSettings, *this );
260  if( MapY1 == 0 ) /* MapX1 = +- 1 */
261  {
262  GRMoveTo( x1 + MapX1 * deco_size * 2, y1 );
263  GRLineTo( nullptr, DC, x1 + MapX1 * deco_size * 2, y1 - deco_size * 2, width, color );
264  GRLineTo( nullptr, DC, x1, y1, width, color );
265  }
266  else /* MapX1 = 0 */
267  {
268  GRMoveTo( x1, y1 + MapY1 * deco_size * 2 );
269  GRLineTo( nullptr, DC, x1 - deco_size * 2, y1 + MapY1 * deco_size * 2, width, color );
270  GRLineTo( nullptr, DC, x1, y1, width, color );
271  }
272  }
273 
274  if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
275  {
276  const int deco_size = externalPinDecoSize( aSettings, *this );
277  if( MapY1 == 0 ) /* MapX1 = +- 1 */
278  {
279  GRMoveTo( x1, y1 - deco_size * 2 );
280  GRLineTo( nullptr, DC, x1 + MapX1 * deco_size * 2, y1, width, color );
281  }
282  else /* MapX1 = 0 */
283  {
284  GRMoveTo( x1 - deco_size * 2, y1 );
285  GRLineTo( nullptr, DC, x1, y1 + MapY1 * deco_size * 2, width, color );
286  }
287  }
288  else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
289  {
290  const int deco_size = externalPinDecoSize( aSettings, *this );
291  GRMoveTo( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size );
292  GRLineTo( nullptr, DC, x1 + (MapX1 + MapY1) * deco_size,
293  y1 + ( MapY1 - MapX1 ) * deco_size, width, color );
294  GRMoveTo( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size );
295  GRLineTo( nullptr, DC, x1 + (MapX1 - MapY1) * deco_size,
296  y1 + ( MapY1 + MapX1 ) * deco_size, width, color );
297  }
298 
299  if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
300  {
301  const int deco_size = TARGET_PIN_RADIUS;
302  GRLine( nullptr, DC, posX - deco_size, posY - deco_size, posX + deco_size,
303  posY + deco_size, width, color );
304  GRLine( nullptr, DC, posX + deco_size, posY - deco_size, posX - deco_size,
305  posY + deco_size, width, color );
306  }
307 }
308 
309 
310 void LIB_PIN::printPinTexts( const RENDER_SETTINGS* aSettings, wxPoint& aPinPos, int aPinOrient,
311  int aTextInside, bool aDrawPinNum, bool aDrawPinName )
312 {
313  if( !aDrawPinName && !aDrawPinNum )
314  return;
315 
316  int x, y;
317  wxDC* DC = aSettings->GetPrintDC();
318  wxSize PinNameSize( m_nameTextSize, m_nameTextSize );
319  wxSize PinNumSize( m_numTextSize, m_numTextSize );
320 
321  int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ),
322  aSettings->GetDefaultPenWidth() );
323  int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, false ),
324  aSettings->GetDefaultPenWidth() );
325 
326  int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
327  int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
328 
329  /* Get the num and name colors */
330  COLOR4D NameColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNAM : LAYER_HIDDEN );
331  COLOR4D NumColor = aSettings->GetLayerColor( IsVisible() ? LAYER_PINNUM : LAYER_HIDDEN );
332 
333  int x1 = aPinPos.x;
334  int y1 = aPinPos.y;
335 
336  switch( aPinOrient )
337  {
338  case PIN_UP: y1 -= m_length; break;
339  case PIN_DOWN: y1 += m_length; break;
340  case PIN_LEFT: x1 -= m_length; break;
341  case PIN_RIGHT: x1 += m_length; break;
342  }
343 
344  if( m_name.IsEmpty() )
345  aDrawPinName = false;
346 
347  if( aTextInside ) // Draw the text inside, but the pin numbers outside.
348  {
349  if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
350  {
351  // It is an horizontal line
352  if( aDrawPinName )
353  {
354  if( aPinOrient == PIN_RIGHT )
355  {
356  x = x1 + aTextInside;
357  GRText( DC, wxPoint( x, y1 ), NameColor, m_name, TEXT_ANGLE_HORIZ,
359  namePenWidth, false, false );
360  }
361  else // Orient == PIN_LEFT
362  {
363  x = x1 - aTextInside;
364  GRText( DC, wxPoint( x, y1 ), NameColor, m_name, TEXT_ANGLE_HORIZ,
366  namePenWidth, false, false );
367  }
368  }
369 
370  if( aDrawPinNum )
371  {
372  GRText( DC, wxPoint(( x1 + aPinPos.x) / 2, y1 - num_offset ), NumColor, m_number,
374  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
375  }
376  }
377  else /* Its a vertical line. */
378  {
379  // Text is drawn from bottom to top (i.e. to negative value for Y axis)
380  if( aPinOrient == PIN_DOWN )
381  {
382  y = y1 + aTextInside;
383 
384  if( aDrawPinName )
385  {
386  GRText( DC, wxPoint( x1, y ), NameColor, m_name, TEXT_ANGLE_VERT, PinNameSize,
387  GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
388  false );
389  }
390 
391  if( aDrawPinNum )
392  {
393  GRText( DC, wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
395  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
396  }
397  }
398  else /* PIN_UP */
399  {
400  y = y1 - aTextInside;
401 
402  if( aDrawPinName )
403  {
404  GRText( DC, wxPoint( x1, y ), NameColor, m_name, TEXT_ANGLE_VERT, PinNameSize,
405  GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER, namePenWidth, false,
406  false );
407  }
408 
409  if( aDrawPinNum )
410  {
411  GRText( DC, wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), NumColor,
413  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
414  }
415  }
416  }
417  }
418  else /**** Draw num & text pin outside ****/
419  {
420  if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
421  {
422  /* Its an horizontal line. */
423  if( aDrawPinName )
424  {
425  x = ( x1 + aPinPos.x) / 2;
426  GRText( DC, wxPoint( x, y1 - name_offset ), NameColor, m_name, TEXT_ANGLE_HORIZ,
428  namePenWidth, false, false );
429  }
430  if( aDrawPinNum )
431  {
432  x = ( x1 + aPinPos.x) / 2;
433  GRText( DC, wxPoint( x, y1 + num_offset ), NumColor, m_number, TEXT_ANGLE_HORIZ,
434  PinNumSize, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, numPenWidth,
435  false, false );
436  }
437  }
438  else /* Its a vertical line. */
439  {
440  if( aDrawPinName )
441  {
442  y = ( y1 + aPinPos.y) / 2;
443  GRText( DC, wxPoint( x1 - name_offset, y ), NameColor, m_name, TEXT_ANGLE_VERT,
445  namePenWidth, false, false );
446  }
447 
448  if( aDrawPinNum )
449  {
450  GRText( DC, wxPoint( x1 + num_offset, ( y1 + aPinPos.y) / 2 ), NumColor, m_number,
452  numPenWidth, false, false );
453  }
454  }
455  }
456 }
457 
458 
459 
460 void LIB_PIN::printPinElectricalTypeName( const RENDER_SETTINGS* aSettings, wxPoint& aPosition,
461  int aOrientation )
462 {
463  wxDC* DC = aSettings->GetPrintDC();
464  wxString typeName = GetElectricalTypeName();
465 
466  // Use a reasonable (small) size to draw the text
467  int textSize = ( m_nameTextSize * 3 ) / 4;
468 
469  #define ETXT_MAX_SIZE Millimeter2iu( 0.7 )
470 
471  if( textSize > ETXT_MAX_SIZE )
472  textSize = ETXT_MAX_SIZE;
473 
474  // Use a reasonable pen size to draw the text
475  int pensize = textSize/6;
476 
477  // Get a suitable color
479 
480  wxPoint txtpos = aPosition;
481  int offset = Millimeter2iu( 0.4 );
483  int orient = TEXT_ANGLE_HORIZ;
484 
485  switch( aOrientation )
486  {
487  case PIN_UP:
488  txtpos.y += offset;
489  orient = TEXT_ANGLE_VERT;
490  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
491  break;
492 
493  case PIN_DOWN:
494  txtpos.y -= offset;
495  orient = TEXT_ANGLE_VERT;
496  break;
497 
498  case PIN_LEFT:
499  txtpos.x += offset;
500  break;
501 
502  case PIN_RIGHT:
503  txtpos.x -= offset;
504  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
505  break;
506  }
507 
508  GRText( DC, txtpos, color, typeName, orient, wxSize( textSize, textSize ), hjustify,
509  GR_TEXT_VJUSTIFY_CENTER, pensize, false, false, 0 );
510 }
511 
512 
513 void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrientation )
514 {
515  int MapX1, MapY1, x1, y1;
517  int penWidth = std::max( GetPenWidth(), aPlotter->RenderSettings()->GetDefaultPenWidth() );
518 
519  aPlotter->SetColor( color );
520  aPlotter->SetCurrentLineWidth( penWidth );
521 
522  MapX1 = MapY1 = 0;
523  x1 = aPosition.x; y1 = aPosition.y;
524 
525  switch( aOrientation )
526  {
527  case PIN_UP: y1 = aPosition.y - m_length; MapY1 = 1; break;
528  case PIN_DOWN: y1 = aPosition.y + m_length; MapY1 = -1; break;
529  case PIN_LEFT: x1 = aPosition.x - m_length; MapX1 = 1; break;
530  case PIN_RIGHT: x1 = aPosition.x + m_length; MapX1 = -1; break;
531  }
532 
534  {
535  const int radius = externalPinDecoSize( aPlotter->RenderSettings(), *this );
536  aPlotter->Circle( wxPoint( MapX1 * radius + x1, MapY1 * radius + y1 ), radius * 2,
537  FILL_TYPE::NO_FILL, penWidth );
538 
539  aPlotter->MoveTo( wxPoint( MapX1 * radius * 2 + x1, MapY1 * radius * 2 + y1 ) );
540  aPlotter->FinishTo( aPosition );
541  }
543  {
544  const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
545  if( MapY1 == 0 ) /* MapX1 = +- 1 */
546  {
547  aPlotter->MoveTo( wxPoint( x1, y1 + deco_size ) );
548  aPlotter->LineTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 ) );
549  aPlotter->FinishTo( wxPoint( x1, y1 - deco_size ) );
550  }
551  else /* MapX1 = 0 */
552  {
553  aPlotter->MoveTo( wxPoint( x1 + deco_size, y1 ) );
554  aPlotter->LineTo( wxPoint( x1, y1 + MapY1 * deco_size * 2 ) );
555  aPlotter->FinishTo( wxPoint( x1 - deco_size, y1 ) );
556  }
557 
558  aPlotter->MoveTo( wxPoint( MapX1 * deco_size * 2 + x1, MapY1 * deco_size * 2 + y1 ) );
559  aPlotter->FinishTo( aPosition );
560  }
561  else
562  {
563  aPlotter->MoveTo( wxPoint( x1, y1 ) );
564  aPlotter->FinishTo( aPosition );
565  }
566 
570  {
571  const int deco_size = internalPinDecoSize( aPlotter->RenderSettings(), *this );
572  if( MapY1 == 0 ) /* MapX1 = +- 1 */
573  {
574  aPlotter->MoveTo( wxPoint( x1, y1 + deco_size ) );
575  aPlotter->LineTo( wxPoint( x1 - MapX1 * deco_size * 2, y1 ) );
576  aPlotter->FinishTo( wxPoint( x1, y1 - deco_size ) );
577  }
578  else /* MapX1 = 0 */
579  {
580  aPlotter->MoveTo( wxPoint( x1 + deco_size, y1 ) );
581  aPlotter->LineTo( wxPoint( x1, y1 - MapY1 * deco_size * 2 ) );
582  aPlotter->FinishTo( wxPoint( x1 - deco_size, y1 ) );
583  }
584  }
585 
587  || m_shape == GRAPHIC_PINSHAPE::CLOCK_LOW ) /* IEEE symbol "Active Low Input" */
588  {
589  const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
590 
591  if( MapY1 == 0 ) /* MapX1 = +- 1 */
592  {
593  aPlotter->MoveTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 ) );
594  aPlotter->LineTo( wxPoint( x1 + MapX1 * deco_size * 2, y1 - deco_size * 2 ) );
595  aPlotter->FinishTo( wxPoint( x1, y1 ) );
596  }
597  else /* MapX1 = 0 */
598  {
599  aPlotter->MoveTo( wxPoint( x1, y1 + MapY1 * deco_size * 2 ) );
600  aPlotter->LineTo( wxPoint( x1 - deco_size * 2, y1 + MapY1 * deco_size * 2 ) );
601  aPlotter->FinishTo( wxPoint( x1, y1 ) );
602  }
603  }
604 
605  if( m_shape == GRAPHIC_PINSHAPE::OUTPUT_LOW ) /* IEEE symbol "Active Low Output" */
606  {
607  const int symbol_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
608 
609  if( MapY1 == 0 ) /* MapX1 = +- 1 */
610  {
611  aPlotter->MoveTo( wxPoint( x1, y1 - symbol_size * 2 ) );
612  aPlotter->FinishTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
613  }
614  else /* MapX1 = 0 */
615  {
616  aPlotter->MoveTo( wxPoint( x1 - symbol_size * 2, y1 ) );
617  aPlotter->FinishTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
618  }
619  }
620  else if( m_shape == GRAPHIC_PINSHAPE::NONLOGIC ) /* NonLogic pin symbol */
621  {
622  const int deco_size = externalPinDecoSize( aPlotter->RenderSettings(), *this );
623  aPlotter->MoveTo( wxPoint( x1 - (MapX1 + MapY1) * deco_size, y1 - (MapY1 - MapX1) * deco_size ) );
624  aPlotter->FinishTo( wxPoint( x1 + (MapX1 + MapY1) * deco_size, y1 + (MapY1 - MapX1) * deco_size ) );
625  aPlotter->MoveTo( wxPoint( x1 - (MapX1 - MapY1) * deco_size, y1 - (MapY1 + MapX1) * deco_size ) );
626  aPlotter->FinishTo( wxPoint( x1 + (MapX1 - MapY1) * deco_size, y1 + (MapY1 + MapX1) * deco_size ) );
627  }
628 
629  if( m_type == ELECTRICAL_PINTYPE::PT_NC ) // Draw a N.C. symbol
630  {
631  const int deco_size = TARGET_PIN_RADIUS;
632  const int ex1 = aPosition.x;
633  const int ey1 = aPosition.y;
634  aPlotter->MoveTo( wxPoint( ex1 - deco_size, ey1 - deco_size ) );
635  aPlotter->FinishTo( wxPoint( ex1 + deco_size, ey1 + deco_size ) );
636  aPlotter->MoveTo( wxPoint( ex1 + deco_size, ey1 - deco_size ) );
637  aPlotter->FinishTo( wxPoint( ex1 - deco_size, ey1 + deco_size ) );
638  }
639 }
640 
641 
642 void LIB_PIN::PlotPinTexts( PLOTTER* aPlotter, wxPoint& aPinPos, int aPinOrient, int aTextInside,
643  bool aDrawPinNum, bool aDrawPinName )
644 {
645  if( m_name.IsEmpty() || m_name == wxT( "~" ) )
646  aDrawPinName = false;
647 
648  if( m_number.IsEmpty() )
649  aDrawPinNum = false;
650 
651  if( !aDrawPinNum && !aDrawPinName )
652  return;
653 
654  int x, y;
655  wxSize pinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
656  wxSize pinNumSize = wxSize( m_numTextSize, m_numTextSize );
657 
658  int namePenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_nameTextSize, false ),
659  aPlotter->RenderSettings()->GetDefaultPenWidth() );
660  int numPenWidth = std::max( Clamp_Text_PenSize( GetPenWidth(), m_numTextSize, false ),
661  aPlotter->RenderSettings()->GetDefaultPenWidth() );
662 
663  int name_offset = Mils2iu( PIN_TEXT_MARGIN ) + namePenWidth;
664  int num_offset = Mils2iu( PIN_TEXT_MARGIN ) + numPenWidth;
665 
666  /* Get the num and name colors */
667  COLOR4D nameColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNAM );
668  COLOR4D numColor = aPlotter->RenderSettings()->GetLayerColor( LAYER_PINNUM );
669 
670  int x1 = aPinPos.x;
671  int y1 = aPinPos.y;
672 
673  switch( aPinOrient )
674  {
675  case PIN_UP: y1 -= m_length; break;
676  case PIN_DOWN: y1 += m_length; break;
677  case PIN_LEFT: x1 -= m_length; break;
678  case PIN_RIGHT: x1 += m_length; break;
679  }
680 
681  /* Draw the text inside, but the pin numbers outside. */
682  if( aTextInside )
683  {
684  if( ( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) ) /* Its an horizontal line. */
685  {
686  if( aDrawPinName )
687  {
688  EDA_TEXT_HJUSTIFY_T hjustify;
689  if( aPinOrient == PIN_RIGHT )
690  {
691  x = x1 + aTextInside;
692  hjustify = GR_TEXT_HJUSTIFY_LEFT;
693  }
694  else // orient == PIN_LEFT
695  {
696  x = x1 - aTextInside;
697  hjustify = GR_TEXT_HJUSTIFY_RIGHT;
698  }
699 
700  aPlotter->Text( wxPoint( x, y1 ), nameColor, m_name, TEXT_ANGLE_HORIZ, pinNameSize,
701  hjustify, GR_TEXT_VJUSTIFY_CENTER, namePenWidth,
702  false, false );
703  }
704  if( aDrawPinNum )
705  {
706  aPlotter->Text( wxPoint( ( x1 + aPinPos.x) / 2, y1 - num_offset ), numColor,
708  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
709  }
710  }
711  else /* Its a vertical line. */
712  {
713  if( aPinOrient == PIN_DOWN )
714  {
715  y = y1 + aTextInside;
716 
717  if( aDrawPinName )
718  aPlotter->Text( wxPoint( x1, y ), nameColor, m_name, TEXT_ANGLE_VERT,
720  namePenWidth, false, false );
721 
722  if( aDrawPinNum )
723  {
724  aPlotter->Text( wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
726  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
727  }
728  }
729  else /* PIN_UP */
730  {
731  y = y1 - aTextInside;
732 
733  if( aDrawPinName )
734  {
735  aPlotter->Text( wxPoint( x1, y ), nameColor, m_name, TEXT_ANGLE_VERT,
737  namePenWidth, false, false );
738  }
739 
740  if( aDrawPinNum )
741  {
742  aPlotter->Text( wxPoint( x1 - num_offset, ( y1 + aPinPos.y) / 2 ), numColor,
744  GR_TEXT_VJUSTIFY_BOTTOM, numPenWidth, false, false );
745  }
746  }
747  }
748  }
749  else /* Draw num & text pin outside */
750  {
751  if(( aPinOrient == PIN_LEFT) || ( aPinOrient == PIN_RIGHT) )
752  {
753  /* Its an horizontal line. */
754  if( aDrawPinName )
755  {
756  x = ( x1 + aPinPos.x) / 2;
757  aPlotter->Text( wxPoint( x, y1 - name_offset ), nameColor, m_name,
759  GR_TEXT_VJUSTIFY_BOTTOM, namePenWidth, false, false );
760  }
761 
762  if( aDrawPinNum )
763  {
764  x = ( x1 + aPinPos.x ) / 2;
765  aPlotter->Text( wxPoint( x, y1 + num_offset ), numColor, m_number,
767  GR_TEXT_VJUSTIFY_TOP, numPenWidth, false, false );
768  }
769  }
770  else /* Its a vertical line. */
771  {
772  if( aDrawPinName )
773  {
774  y = ( y1 + aPinPos.y ) / 2;
775  aPlotter->Text( wxPoint( x1 - name_offset, y ), nameColor, m_name,
777  GR_TEXT_VJUSTIFY_BOTTOM, namePenWidth, false, false );
778  }
779 
780  if( aDrawPinNum )
781  {
782  aPlotter->Text( wxPoint( x1 + num_offset, ( y1 + aPinPos.y ) / 2 ), numColor,
784  GR_TEXT_VJUSTIFY_TOP, numPenWidth, false, false );
785  }
786  }
787  }
788 }
789 
790 
791 int LIB_PIN::PinDrawOrient( const TRANSFORM& aTransform ) const
792 {
793  int orient;
794  wxPoint end; // position of pin end starting at 0,0 according to its orientation, length = 1
795 
796  switch( m_orientation )
797  {
798  case PIN_UP: end.y = 1; break;
799  case PIN_DOWN: end.y = -1; break;
800  case PIN_LEFT: end.x = -1; break;
801  case PIN_RIGHT: end.x = 1; break;
802  }
803 
804  // = pos of end point, according to the component orientation
805  end = aTransform.TransformCoordinate( end );
806  orient = PIN_UP;
807 
808  if( end.x == 0 )
809  {
810  if( end.y > 0 )
811  orient = PIN_DOWN;
812  }
813  else
814  {
815  orient = PIN_RIGHT;
816 
817  if( end.x < 0 )
818  orient = PIN_LEFT;
819  }
820 
821  return orient;
822 }
823 
824 
826 {
827  return new LIB_PIN( *this );
828 }
829 
830 
831 int LIB_PIN::compare( const LIB_ITEM& aOther, LIB_ITEM::COMPARE_FLAGS aCompareFlags ) const
832 {
833  wxASSERT( aOther.Type() == LIB_PIN_T );
834 
835  int retv = LIB_ITEM::compare( aOther, aCompareFlags );
836 
837  if( retv )
838  return retv;
839 
840  const LIB_PIN* tmp = (LIB_PIN*) &aOther;
841 
842  // When comparing units, we do not compare the part numbers. If everything else is
843  // identical, then we can just renumber the parts for the inherited symbol.
844  if( !( aCompareFlags & COMPARE_FLAGS::UNIT ) && m_number != tmp->m_number )
845  return m_number.Cmp( tmp->m_number );
846 
847  int result = m_name.CmpNoCase( tmp->m_name );
848 
849  if( result )
850  return result;
851 
852  if( m_position.x != tmp->m_position.x )
853  return m_position.x - tmp->m_position.x;
854 
855  if( m_position.y != tmp->m_position.y )
856  return m_position.y - tmp->m_position.y;
857 
858  if( m_length != tmp->m_length )
859  return m_length - tmp->m_length;
860 
861  if( m_orientation != tmp->m_orientation )
862  return m_orientation - tmp->m_orientation;
863 
864  if( m_shape != tmp->m_shape )
865  return static_cast<int>( m_shape ) - static_cast<int>( tmp->m_shape );
866 
867  if( m_type != tmp->m_type )
868  return static_cast<int>( m_type ) - static_cast<int>( tmp->m_type );
869 
870  if( m_attributes != tmp->m_attributes )
871  return m_attributes - tmp->m_attributes;
872 
873  if( m_numTextSize != tmp->m_numTextSize )
874  return m_numTextSize - tmp->m_numTextSize;
875 
876  if( m_nameTextSize != tmp->m_nameTextSize )
877  return m_nameTextSize - tmp->m_nameTextSize;
878 
879  if( m_alternates.size() != tmp->m_alternates.size() )
880  return m_alternates.size() - tmp->m_alternates.size();
881 
882  auto lhsItem = m_alternates.begin();
883  auto rhsItem = tmp->m_alternates.begin();
884 
885  while( lhsItem != m_alternates.end() )
886  {
887  const ALT& lhsAlt = lhsItem->second;
888  const ALT& rhsAlt = rhsItem->second;
889 
890  retv = lhsAlt.m_Name.Cmp( rhsAlt.m_Name );
891 
892  if( retv )
893  return retv;
894 
895  if( lhsAlt.m_Type != rhsAlt.m_Type )
896  return static_cast<int>( lhsAlt.m_Type ) - static_cast<int>( rhsAlt.m_Type );
897 
898  if( lhsAlt.m_Shape != rhsAlt.m_Shape )
899  return static_cast<int>( lhsAlt.m_Shape ) - static_cast<int>( rhsAlt.m_Shape );
900 
901  ++lhsItem;
902  ++rhsItem;
903  }
904 
905  return 0;
906 }
907 
908 
909 void LIB_PIN::Offset( const wxPoint& aOffset )
910 {
911  m_position += aOffset;
912 }
913 
914 
915 void LIB_PIN::MoveTo( const wxPoint& aNewPosition )
916 {
917  if( m_position != aNewPosition )
918  {
919  m_position = aNewPosition;
920  SetModified();
921  }
922 }
923 
924 
925 void LIB_PIN::MirrorHorizontal( const wxPoint& aCenter )
926 {
927  m_position.x -= aCenter.x;
928  m_position.x *= -1;
929  m_position.x += aCenter.x;
930 
931  if( m_orientation == PIN_RIGHT )
933  else if( m_orientation == PIN_LEFT )
935 }
936 
937 
938 void LIB_PIN::MirrorVertical( const wxPoint& aCenter )
939 {
940  m_position.y -= aCenter.y;
941  m_position.y *= -1;
942  m_position.y += aCenter.y;
943 
944  if( m_orientation == PIN_UP )
946  else if( m_orientation == PIN_DOWN )
948 }
949 
950 
951 void LIB_PIN::Rotate( const wxPoint& aCenter, bool aRotateCCW )
952 {
953  int rot_angle = aRotateCCW ? -900 : 900;
954 
955  RotatePoint( &m_position, aCenter, rot_angle );
956 
957  if( aRotateCCW )
958  {
959  switch( m_orientation )
960  {
961  case PIN_RIGHT: m_orientation = PIN_UP; break;
962  case PIN_UP: m_orientation = PIN_LEFT; break;
963  case PIN_LEFT: m_orientation = PIN_DOWN; break;
964  case PIN_DOWN: m_orientation = PIN_RIGHT; break;
965  }
966  }
967  else
968  {
969  switch( m_orientation )
970  {
971  case PIN_RIGHT: m_orientation = PIN_DOWN; break;
972  case PIN_UP: m_orientation = PIN_RIGHT; break;
973  case PIN_LEFT: m_orientation = PIN_UP; break;
974  case PIN_DOWN: m_orientation = PIN_LEFT; break;
975  }
976  }
977 }
978 
979 
980 void LIB_PIN::Plot( PLOTTER* aPlotter, const wxPoint& aPffset, bool aFill,
981  const TRANSFORM& aTransform )
982 {
983  if( ! IsVisible() )
984  return;
985 
986  int orient = PinDrawOrient( aTransform );
987  wxPoint pos = aTransform.TransformCoordinate( m_position ) + aPffset;
988 
989  PlotSymbol( aPlotter, pos, orient );
990  PlotPinTexts( aPlotter, pos, orient, GetParent()->GetPinNameOffset(),
992 }
993 
994 
996 {
997  wxString text = m_number.IsEmpty() ? wxT( "?" ) : m_number;
998 
999  LIB_ITEM::GetMsgPanelInfo( aFrame, aList );
1000 
1001  aList.push_back( MSG_PANEL_ITEM( _( "Name" ), m_name ) );
1002  aList.push_back( MSG_PANEL_ITEM( _( "Number" ), text ) );
1003  aList.push_back( MSG_PANEL_ITEM( _( "Type" ), ElectricalPinTypeGetText( m_type ) ) );
1004 
1005  text = PinShapeGetText( m_shape );
1006  aList.push_back( MSG_PANEL_ITEM( _( "Style" ), text ) );
1007 
1008  text = IsVisible() ? _( "Yes" ) : _( "No" );
1009  aList.push_back( MSG_PANEL_ITEM( _( "Visible" ), text ) );
1010 
1011  // Display pin length
1012  text = StringFromValue( aFrame->GetUserUnits(), m_length );
1013  aList.push_back( MSG_PANEL_ITEM( _( "Length" ), text ) );
1014 
1015  text = PinOrientationName( (unsigned) PinOrientationIndex( m_orientation ) );
1016  aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), text ) );
1017 
1018  wxPoint pinpos = GetPosition();
1019  pinpos.y = -pinpos.y; // Display coord are top to bottom
1020  // lib items coord are bottom to top
1021 
1022  text = MessageTextFromValue( aFrame->GetUserUnits(), pinpos.x );
1023  aList.push_back( MSG_PANEL_ITEM( _( "Pos X" ), text ) );
1024 
1025  text = MessageTextFromValue( aFrame->GetUserUnits(), pinpos.y );
1026  aList.push_back( MSG_PANEL_ITEM( _( "Pos Y" ), text ) );
1027 }
1028 
1029 
1030 const EDA_RECT LIB_PIN::GetBoundingBox( bool aIncludeInvisibles, bool aPinOnly ) const
1031 {
1032  EDA_RECT bbox;
1033  wxPoint begin;
1034  wxPoint end;
1035  int nameTextOffset = 0;
1036  bool showName = !m_name.IsEmpty() && ( m_name != wxT( "~" ) );
1037  bool showNum = !m_number.IsEmpty();
1038  int minsizeV = TARGET_PIN_RADIUS;
1039 
1040  if( !aIncludeInvisibles && !IsVisible() )
1041  showName = false;
1042 
1043  if( GetParent() )
1044  {
1045  if( GetParent()->ShowPinNames() )
1046  nameTextOffset = GetParent()->GetPinNameOffset();
1047  else
1048  showName = false;
1049 
1050  if( !GetParent()->ShowPinNumbers() )
1051  showNum = false;
1052  }
1053 
1054  if( aPinOnly )
1055  {
1056  showName = false;
1057  showNum = false;
1058  }
1059 
1060  // First, calculate boundary box corners position
1061  int numberTextLength = showNum ? m_numTextSize * m_number.Len() : 0;
1062 
1063  // Actual text height is bigger than text size
1064  int numberTextHeight = showNum ? KiROUND( m_numTextSize * 1.1 ) : 0;
1065 
1067  minsizeV = std::max( TARGET_PIN_RADIUS, externalPinDecoSize( nullptr, *this ) );
1068 
1069  // calculate top left corner position
1070  // for the default pin orientation (PIN_RIGHT)
1071  begin.y = std::max( minsizeV, numberTextHeight + Mils2iu( PIN_TEXT_MARGIN ) );
1072  begin.x = std::min( -TARGET_PIN_RADIUS, m_length - (numberTextLength / 2) );
1073 
1074  // calculate bottom right corner position and adjust top left corner position
1075  int nameTextLength = 0;
1076  int nameTextHeight = 0;
1077 
1078  if( showName )
1079  {
1080  int length = m_name.Len();
1081 
1082  // Don't count the line over text symbol.
1083  if( m_name.Left( 1 ) == wxT( "~" ) )
1084  length -= 1;
1085 
1086  nameTextLength = ( m_nameTextSize * length ) + nameTextOffset;
1087 
1088  // Actual text height are bigger than text size
1089  nameTextHeight = KiROUND( m_nameTextSize * 1.1 ) + Mils2iu( PIN_TEXT_MARGIN );
1090  }
1091 
1092  if( nameTextOffset ) // for values > 0, pin name is inside the body
1093  {
1094  end.x = m_length + nameTextLength + TARGET_PIN_RADIUS;
1095  end.y = std::min( -minsizeV, -nameTextHeight / 2 );
1096  }
1097  else // if value == 0:
1098  // pin name is outside the body, and above the pin line
1099  // pin num is below the pin line
1100  {
1101  end.x = std::max( m_length + TARGET_PIN_RADIUS, nameTextLength );
1102  end.y = -begin.y;
1103  begin.y = std::max( minsizeV, nameTextHeight );
1104  }
1105 
1106  // Now, calculate boundary box corners position for the actual pin orientation
1107  int orient = PinDrawOrient( DefaultTransform );
1108 
1109  /* Calculate the pin position */
1110  switch( orient )
1111  {
1112  case PIN_UP:
1113  // Pin is rotated and texts positions are mirrored
1114  RotatePoint( &begin, wxPoint( 0, 0 ), -900 );
1115  RotatePoint( &end, wxPoint( 0, 0 ), -900 );
1116  break;
1117 
1118  case PIN_DOWN:
1119  RotatePoint( &begin, wxPoint( 0, 0 ), 900 );
1120  RotatePoint( &end, wxPoint( 0, 0 ), 900 );
1121  begin.x = -begin.x;
1122  end.x = -end.x;
1123  break;
1124 
1125  case PIN_LEFT:
1126  begin.x = -begin.x;
1127  end.x = -end.x;
1128  break;
1129 
1130  case PIN_RIGHT:
1131  break;
1132  }
1133 
1134  begin += m_position;
1135  end += m_position;
1136 
1137  bbox.SetOrigin( begin );
1138  bbox.SetEnd( end );
1139  bbox.Normalize();
1140  bbox.Inflate( ( GetPenWidth() / 2 ) + 1 );
1141 
1142  // Draw Y axis is reversed in schematic:
1143  bbox.RevertYAxis();
1144 
1145  return bbox;
1146 }
1147 
1148 
1150 {
1152 }
1153 
1154 
1155 wxString LIB_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
1156 {
1157  if( !m_name.IsEmpty() )
1158  {
1159  return wxString::Format( _( "Pin %s [%s, %s, %s]" ),
1160  m_number,
1161  m_name,
1163  PinShapeGetText( m_shape ) );
1164  }
1165  else
1166  {
1167  return wxString::Format( _( "Pin %s [%s, %s]" ),
1168  m_number,
1170  PinShapeGetText( m_shape ) );
1171  }
1172 }
1173 
1174 
1175 #if defined(DEBUG)
1176 
1177 void LIB_PIN::Show( int nestLevel, std::ostream& os ) const
1178 {
1179  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
1180  << " num=\"" << m_number.mb_str()
1181  << '"' << "/>\n";
1182 
1183 // NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
1184 }
1185 
1186 #endif
1187 
1188 void LIB_PIN::CalcEdit( const wxPoint& aPosition )
1189 {
1190  if( IsMoving() )
1191  {
1192  MoveTo( aPosition );
1193  }
1194 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:267
wxString GetClass() const override
Return the class name.
Definition: lib_pin.h:115
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:167
#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:1155
void SetModified()
Definition: eda_item.cpp:79
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:125
int m_nameTextSize
Definition: lib_pin.h:75
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: lib_pin.cpp:825
void Rotate(const wxPoint &aCenter, bool aRotateCCW=true) override
Rotate the object about aCenter point.
Definition: lib_pin.cpp:951
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:61
PNG memory record (file in memory).
Definition: bitmap_def.h:29
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:69
int GetPinNameOffset()
Definition: lib_symbol.h:555
#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:915
int m_numTextSize
Definition: lib_pin.h:74
virtual void SetColor(COLOR4D color)=0
Container for data for KiCad programs.
Definition: pgm_base.h:131
LIB_PART * GetParent() const
Definition: lib_item.h:149
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:310
BITMAP_DEF GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: lib_pin.cpp:1149
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:235
bool IsMoving() const
Definition: eda_item.h:169
int color
Definition: DXF_plotter.cpp:60
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:126
int PinOrientationIndex(int code)
Definition: pin_type.cpp:145
wxString m_name
Definition: lib_pin.h:72
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:255
Definition: lib_pin.h:50
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:228
const EDA_RECT GetBoundingBox() const override
Definition: lib_pin.h:222
GRAPHIC_PINSHAPE
Definition: pin_type.h:54
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:791
int m_length
Definition: lib_pin.h:67
void RevertYAxis()
Mirror the rectangle from the X axis (negate Y pos and size).
Definition: eda_rect.h:203
ELECTRICAL_PINTYPE m_Type
Definition: lib_pin.h:62
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
bool draw_hidden_fields
Definition: lib_symbol.h:66
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 components.
Definition: lib_item.h:62
virtual void Text(const wxPoint &aPos, const COLOR4D aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=NULL)
Draws text with the plotter.
Definition: gr_text.cpp:219
void MirrorVertical(const wxPoint &aCenter) override
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
Definition: lib_pin.cpp:938
void GRLineTo(EDA_RECT *ClipBox, wxDC *DC, int x, int y, int width, COLOR4D Color)
Definition: gr_basic.cpp:264
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:166
bool ShowPinNames()
Definition: lib_symbol.h:563
wxString PinOrientationName(unsigned aPinOrientationCode)
Definition: pin_type.cpp:114
void LineTo(const wxPoint &pos)
Definition: plotter.h:262
int m_orientation
Definition: lib_pin.h:68
void printPinSymbol(const RENDER_SETTINGS *aSettings, const wxPoint &aPos, int aOrientation)
Print the pin symbol without text.
Definition: lib_pin.cpp:199
bool ShowPinNumbers()
Definition: lib_symbol.h:571
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
int Clamp_Text_PenSize(int aPenSize, int aSize, bool aBold)
Function Clamp_Text_PenSize Don't allow text to become cluttered up in its own fatness.
Definition: gr_text.cpp:69
wxString m_number
Definition: lib_pin.h:73
void PlotSymbol(PLOTTER *aPlotter, const wxPoint &aPosition, int aOrientation)
Definition: lib_pin.cpp:513
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:112
wxString const GetElectricalTypeName() const
Definition: lib_pin.h:142
COMPARE_FLAGS
The list of flags used by the compare function.
Definition: lib_item.h:84
void SetEnd(int x, int y)
Definition: eda_rect.h:187
Define a library symbol object.
Definition: lib_symbol.h:93
wxString m_Name
Definition: lib_pin.h:60
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:147
#define STRUCT_DELETED
flag indication structures to be erased
Definition: eda_item.h:115
#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:831
int GetNameTextSize() const
Definition: lib_pin.h:174
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:228
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 PlotPinTexts(PLOTTER *aPlotter, wxPoint &aPinPos, int aPinOrient, int aTextInside, bool aDrawPinNum, bool aDrawPinName)
Plot the pin number and pin text info, given the pin line coordinates.
Definition: lib_pin.cpp:642
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:995
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
Calculates the attributes of an item at aPosition when it is being edited.
Definition: lib_pin.cpp:1188
LIB_PIN(LIB_PART *aParent)
Definition: lib_pin.cpp:93
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)
Function GRText Draw a graphic text (like footprint texts)
Definition: gr_text.cpp:131
void SetConvert(int aConvert)
Definition: lib_item.h:264
wxPoint GetPosition() const override
Definition: lib_pin.h:258
void MoveTo(const wxPoint &pos)
Definition: plotter.h:257
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:71
EDA_UNITS
Definition: eda_units.h:38
void GRMoveTo(int x, int y)
Definition: gr_basic.cpp:254
void Normalize()
Ensures that the height ant width are positive.
Definition: eda_rect.cpp:35
BITMAP_DEF ElectricalPinTypeGetBitmap(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:245
void SetUnit(int aUnit)
Definition: lib_item.h:261
Base plotter engine class.
Definition: plotter.h:121
std::map< wxString, ALT > m_alternates
Definition: lib_pin.h:77
wxPoint m_position
Definition: lib_pin.h:66
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:155
int GetNumberTextSize() const
Definition: lib_pin.h:177
see class PGM_BASE
TRANSFORM DefaultTransform
Definition: eeschema.cpp:56
void SetName(const wxString &aName)
Definition: lib_pin.h:157
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:34
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:460
#define _(s)
Definition: 3d_actions.cpp:33
#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:594
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:68
#define TARGET_PIN_RADIUS
Definition: lib_pin.h:38
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
ELECTRICAL_PINTYPE m_type
Definition: lib_pin.h:70
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
SCH_RENDER_SETTINGS Stores schematic-specific render settings.
Definition: sch_painter.h:72
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:225
int GetDefaultPenWidth() const
#define TEXT_ANGLE_VERT
Definition: eda_text.h:51
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
wxString const GetCanonicalElectricalTypeName() const
Definition: lib_pin.h:137
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: eda_item.h:117
void Plot(PLOTTER *aPlotter, const wxPoint &aPffset, bool aFill, const TRANSFORM &aTransform) override
Plot the draw item using the plot object.
Definition: lib_pin.cpp:980
not connected (must be left open)
STATUS_FLAGS m_flags
Definition: eda_item.h:530
void Offset(const wxPoint &aOffset) override
Set the drawing object by aOffset from the current position.
Definition: lib_pin.cpp:909
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
GRAPHIC_PINSHAPE m_Shape
Definition: lib_pin.h:61
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:363
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:171
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:162
void MirrorHorizontal(const wxPoint &aCenter) override
Mirror the draw object along the horizontal (X) axis about aCenter point.
Definition: lib_pin.cpp:925
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98