KiCad PCB EDA Suite
class_libentry.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) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
6  * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
30 #include <fctsys.h>
31 #include <macros.h>
32 #include <kicad_string.h>
33 #include <class_drawpanel.h>
34 #include <plotter.h>
35 #include <gr_basic.h>
36 #include <sch_screen.h>
37 #include <richio.h>
38 #include <kicad_string.h>
39 #include <trace_helpers.h>
40 
41 #include <general.h>
42 #include <template_fieldnames.h>
43 #include <transform.h>
44 #include <class_library.h>
45 #include <class_libentry.h>
46 #include <lib_pin.h>
47 #include <lib_arc.h>
48 #include <lib_bezier.h>
49 #include <lib_circle.h>
50 #include <lib_polyline.h>
51 #include <lib_rectangle.h>
52 #include <lib_text.h>
53 
54 
55 // the separator char between the subpart id and the reference
56 // 0 (no separator) or '.' or some other character
58 
59 // the ascii char value to calculate the subpart symbol id from the part number:
60 // 'A' or '1' usually. (to print U1.A or U1.1)
61 // if this a a digit, a number is used as id symbol
63 
64 
65 LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_PART* aRootPart ):
67  shared( aRootPart )
68 {
69  SetName( aName );
70 }
71 
72 
73 LIB_ALIAS::LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_PART* aRootPart ) :
74  EDA_ITEM( aAlias ),
75  shared( aRootPart )
76 {
77  name = aAlias.name;
78 
79  description = aAlias.description;
80  keyWords = aAlias.keyWords;
81  docFileName = aAlias.docFileName;
82 }
83 
84 
86 {
87  wxLogTrace( traceSchLibMem, wxT( "%s: destroying alias:'%s'" ),
88  GetChars( wxString::FromAscii( __WXFUNCTION__ ) ), GetChars( GetName() ) );
89 
90  wxCHECK_RET( shared, wxT( "~LIB_ALIAS() without a LIB_PART" ) );
91 
92  if( shared )
93  shared->RemoveAlias( this );
94 }
95 
96 
97 const wxString LIB_ALIAS::GetLibraryName()
98 {
99  wxASSERT_MSG( shared, wxT( "LIB_ALIAS without a LIB_PART" ) );
100 
101  if( shared )
102  return shared->GetLibraryName();
103 
104  return wxString( _( "none" ) );
105 }
106 
107 
108 bool LIB_ALIAS::IsRoot() const
109 {
110  return name == shared->GetName();
111 }
112 
113 
115 {
116  return shared->GetLib();
117 }
118 
119 
120 void LIB_ALIAS::SetName( const wxString& aName )
121 {
123 }
124 
125 
126 
127 bool LIB_ALIAS::operator==( const wxChar* aName ) const
128 {
129  return name == aName;
130 }
131 
132 
133 bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 )
134 {
135  return aItem1.GetName() < aItem2.GetName();
136 }
137 
138 
139 int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 )
140 {
141  return aItem1->GetName().Cmp( aItem2->GetName() );
142 }
143 
144 
147 {
148  void operator()(void const *) const
149  {
150  }
151 };
152 
153 
154 LIB_PART::LIB_PART( const wxString& aName, PART_LIB* aLibrary ) :
155  EDA_ITEM( LIB_PART_T ),
156  m_me( this, null_deleter() )
157 {
158  m_dateLastEdition = 0;
159  m_unitCount = 1;
160  m_pinNameOffset = 40;
162  m_unitsLocked = false;
163  m_showPinNumbers = true;
164  m_showPinNames = true;
165 
166  // Add the MANDATORY_FIELDS in RAM only. These are assumed to be present
167  // when the field editors are invoked.
172 
173  SetLib( aLibrary );
174  SetName( aName );
175 }
176 
177 
178 LIB_PART::LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary ) :
179  EDA_ITEM( aPart ),
180  m_me( this, null_deleter() )
181 {
182  LIB_ITEM* newItem;
183 
184  m_library = aLibrary;
186  m_unitCount = aPart.m_unitCount;
192  m_options = aPart.m_options;
193  m_libId = aPart.m_libId;
194 
195  for( LIB_ITEM& oldItem : aPart.m_drawings )
196  {
197  if( oldItem.IsNew() )
198  continue;
199 
200  newItem = (LIB_ITEM*) oldItem.Clone();
201  newItem->SetParent( this );
202  m_drawings.push_back( newItem );
203  }
204 
205  for( size_t i = 0; i < aPart.m_aliases.size(); i++ )
206  {
207  LIB_ALIAS* alias = new LIB_ALIAS( *aPart.m_aliases[i], this );
208  m_aliases.push_back( alias );
209  }
210 }
211 
212 
214 {
215  wxLogTrace( traceSchLibMem,
216  wxT( "%s: destroying symbol with alias list count of %llu" ),
217  GetChars( wxString::FromAscii( __WXFUNCTION__ ) ),
218  (long long unsigned) m_aliases.size() );
219 
220  // If the part is being deleted directly rather than through the library,
221  // delete all of the aliases.
222  while( m_aliases.size() )
223  {
224  LIB_ALIAS* alias = m_aliases.back();
225  m_aliases.pop_back();
226  delete alias;
227  }
228 }
229 
230 
231 const wxString LIB_PART::GetLibraryName()
232 {
233  if( m_library )
234  return m_library->GetName();
235 
236  return wxString( _( "none" ) );
237 }
238 
239 
240 wxString LIB_PART::SubReference( int aUnit, bool aAddSeparator )
241 {
242  wxString subRef;
243 
244  if( m_subpartIdSeparator != 0 && aAddSeparator )
245  subRef << wxChar( m_subpartIdSeparator );
246 
247  if( m_subpartFirstId >= '0' && m_subpartFirstId <= '9' )
248  subRef << aUnit;
249  else
250  {
251  // use letters as notation. To allow more than 26 units, the sub ref
252  // use one letter if letter = A .. Z or a ... z, and 2 letters otherwise
253  // first letter is expected to be 'A' or 'a' (i.e. 26 letters are available)
254  int u;
255  aUnit -= 1; // Unit number starts to 1. now to 0.
256 
257  while( aUnit >= 26 ) // more than one letter are needed
258  {
259  u = aUnit / 26;
260  subRef << wxChar( m_subpartFirstId + u -1 );
261  aUnit %= 26;
262  }
263 
264  u = m_subpartFirstId + aUnit;
265  subRef << wxChar( u );
266  }
267 
268  return subRef;
269 }
270 
271 
272 const wxString& LIB_PART::GetName() const
273 {
274  static wxString dummy;
275 
276  wxCHECK_MSG( m_aliases.size(), dummy, "no aliases defined for symbol" );
277 
278  return m_aliases[0]->GetName();
279 }
280 
281 
282 void LIB_PART::SetName( const wxString& aName )
283 {
284  // The LIB_ALIAS that is the LIB_PART name has to be created so create it.
285  if( m_aliases.empty() )
286  m_aliases.push_back( new LIB_ALIAS( aName, this ) );
287  else
288  m_aliases[0]->SetName( aName );
289 
290  // LIB_ALIAS validates the name, reuse it instead of validating the name again
291  wxString validatedName( m_aliases[0]->GetName() );
292  m_libId.SetLibItemName( validatedName, false );
293 
294  LIB_FIELD& valueField = GetValueField();
295 
296  // LIB_FIELD::SetText() calls LIB_PART::SetName(),
297  // the following if-clause is to break an infinite loop
298  if( valueField.GetText() != validatedName )
299  valueField.SetText( validatedName );
300 }
301 
302 
303 void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
304  int aMulti, int aConvert, const PART_DRAW_OPTIONS& aOpts )
305 {
306  BASE_SCREEN* screen = aPanel ? aPanel->GetScreen() : NULL;
307 
308  GRSetDrawMode( aDc, aOpts.draw_mode );
309 
310  /* draw background for filled items using background option
311  * Solid lines will be drawn after the background
312  * Note also, background is not drawn when:
313  * printing in black and white
314  * If the color is not the default color (aColor != -1 )
315  */
316  if( ! ( screen && screen->m_IsPrinting && GetGRForceBlackPenState() )
317  && ( aOpts.color == COLOR4D::UNSPECIFIED ) )
318  {
319  for( LIB_ITEM& drawItem : m_drawings )
320  {
321  if( drawItem.m_Fill != FILLED_WITH_BG_BODYCOLOR )
322  continue;
323 
324  if( aOpts.only_selected && !drawItem.IsSelected() )
325  continue;
326 
327  // Do not draw an item while moving (the cursor handler does that)
328  if( drawItem.m_Flags & IS_MOVED )
329  continue;
330 
331  // Do not draw items not attached to the current part
332  if( aMulti && drawItem.m_Unit && ( drawItem.m_Unit != aMulti ) )
333  continue;
334 
335  if( aConvert && drawItem.m_Convert && ( drawItem.m_Convert != aConvert ) )
336  continue;
337 
338  if( drawItem.Type() == LIB_FIELD_T )
339  continue;
340 
341  if( drawItem.Type() == LIB_FIELD_T ) // TODO dead code?
342  {
343  drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
344  aOpts.draw_mode, (void*) NULL, aOpts.transform );
345  }
346 
347  // Now, draw only the background for items with
348  // m_Fill == FILLED_WITH_BG_BODYCOLOR:
349  drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
350  aOpts.draw_mode, (void*) false, aOpts.transform );
351  }
352  }
353 
354  // Track the index into the dangling pins list
355  size_t pin_index = 0;
356 
357  for( LIB_ITEM& drawItem : m_drawings )
358  {
359  if( aOpts.only_selected && !drawItem.IsSelected() )
360  continue;
361 
362  // Do not draw an item while moving (the cursor handler does that)
363  if( drawItem.m_Flags & IS_MOVED )
364  continue;
365 
366  // Do not draw items not attached to the current part
367  if( aMulti && drawItem.m_Unit && ( drawItem.m_Unit != aMulti ) )
368  continue;
369 
370  if( aConvert && drawItem.m_Convert && ( drawItem.m_Convert != aConvert ) )
371  continue;
372 
373  if( drawItem.Type() == LIB_FIELD_T )
374  {
375  LIB_FIELD& field = dynamic_cast<LIB_FIELD&>( drawItem );
376 
377  if( field.IsVisible() && !aOpts.draw_visible_fields )
378  continue;
379 
380  if( !field.IsVisible() && !aOpts.draw_hidden_fields )
381  continue;
382  }
383 
384  if( drawItem.Type() == LIB_PIN_T )
385  {
386  LIB_PIN& pin = dynamic_cast<LIB_PIN&>( drawItem );
387 
388  uintptr_t flags = 0;
389  if( aOpts.show_pin_text )
390  flags |= PIN_DRAW_TEXTS;
391 
392  if( aOpts.show_elec_type )
394 
395  if( aOpts.PinIsDangling( pin_index ) )
396  flags |= PIN_DRAW_DANGLING;
397 
398  if( pin.IsPowerConnection() && IsPower() )
399  flags |= PIN_DANGLING_HIDDEN;
400 
401  drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
402  aOpts.draw_mode, (void*) flags, aOpts.transform );
403 
404  ++pin_index;
405  }
406  else if( drawItem.Type() == LIB_FIELD_T )
407  {
408  drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
409  aOpts.draw_mode, (void*) NULL, aOpts.transform );
410  }
411  else
412  {
413  bool forceNoFill = drawItem.m_Fill == FILLED_WITH_BG_BODYCOLOR;
414  drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
415  aOpts.draw_mode, (void*) forceNoFill,
416  aOpts.transform );
417  }
418  }
419 
420  // Enable this to draw the anchor of the component.
421 #if 0
422  int len = aDc->DeviceToLogicalXRel( 3 );
423  EDA_RECT* const clipbox = aPanel ? aPanel->GetClipBox() : NULL;
424 
425  GRLine( clipbox, aDc, aOffset.x, aOffset.y - len, aOffset.x,
426  aOffset.y + len, 0, aOpts.color );
427  GRLine( clipbox, aDc, aOffset.x - len, aOffset.y, aOffset.x + len,
428  aOffset.y, 0, aOpts.color );
429 #endif
430 
431  /* Enable this to draw the bounding box around the component to validate
432  * the bounding box calculations. */
433 #if 0
434  EDA_RECT bBox = GetUnitBoundingBox( aMulti, aConvert );
435  bBox.RevertYAxis();
436  bBox = aOpts.transform.TransformCoordinate( bBox );
437  bBox.Move( aOffset );
438  GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDc, bBox, 0, LIGHTMAGENTA );
439 #endif
440 }
441 
442 
443 void LIB_PART::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
444  const wxPoint& aOffset, const TRANSFORM& aTransform )
445 {
446  wxASSERT( aPlotter != NULL );
447 
448  aPlotter->SetColor( GetLayerColor( LAYER_DEVICE ) );
449  bool fill = aPlotter->GetColorMode();
450 
451  // draw background for filled items using background option
452  // Solid lines will be drawn after the background
453  for( LIB_ITEM& item : m_drawings )
454  {
455  // Lib Fields are not plotted here, because this plot function
456  // is used to plot schematic items, which have they own fields
457  if( item.Type() == LIB_FIELD_T )
458  continue;
459 
460  if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
461  continue;
462 
463  if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
464  continue;
465 
466  if( item.m_Fill == FILLED_WITH_BG_BODYCOLOR )
467  item.Plot( aPlotter, aOffset, fill, aTransform );
468  }
469 
470  // Not filled items and filled shapes are now plotted
471  // (plot only items which are not already plotted)
472  for( LIB_ITEM& item : m_drawings )
473  {
474  if( item.Type() == LIB_FIELD_T )
475  continue;
476 
477  if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
478  continue;
479 
480  if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
481  continue;
482 
483  if( item.m_Fill != FILLED_WITH_BG_BODYCOLOR )
484  item.Plot( aPlotter, aOffset, fill, aTransform );
485  }
486 }
487 
488 
489 void LIB_PART::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
490  const wxPoint& aOffset, const TRANSFORM& aTransform )
491 {
492  wxASSERT( aPlotter != NULL );
493 
494  aPlotter->SetColor( GetLayerColor( LAYER_FIELDS ) );
495  bool fill = aPlotter->GetColorMode();
496 
497  for( LIB_ITEM& item : m_drawings )
498  {
499  if( item.Type() != LIB_FIELD_T )
500  continue;
501 
502  if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
503  continue;
504 
505  if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
506  continue;
507 
508  // The reference is a special case: we should change the basic text
509  // to add '?' and the part id
510  LIB_FIELD& field = (LIB_FIELD&) item;
511  wxString tmp = field.GetShownText();
512  if( field.GetId() == REFERENCE )
513  {
514  wxString text = field.GetFullText( aUnit );
515  field.SetText( text );
516  }
517  item.Plot( aPlotter, aOffset, fill, aTransform );
518  field.SetText( tmp );
519  }
520 }
521 
522 
523 void LIB_PART::RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel, wxDC* aDc )
524 {
525  wxASSERT( aItem != NULL );
526 
527  // none of the MANDATORY_FIELDS may be removed in RAM, but they may be
528  // omitted when saving to disk.
529  if( aItem->Type() == LIB_FIELD_T )
530  {
531  LIB_FIELD* field = (LIB_FIELD*) aItem;
532 
533  if( field->GetId() < MANDATORY_FIELDS )
534  {
535  wxLogWarning( _(
536  "An attempt was made to remove the %s field from component %s in library %s." ),
537  GetChars( field->GetName() ), GetChars( GetName() ),
538  GetChars( GetLibraryName() ) );
539  return;
540  }
541  }
542 
543  LIB_ITEMS& items = m_drawings[ aItem->Type() ];
544 
545  for( LIB_ITEMS::iterator i = items.begin(); i != items.end(); i++ )
546  {
547  if( *i == aItem )
548  {
549  if( aDc != NULL )
550  aItem->Draw( aPanel, aDc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED,
551  g_XorMode, NULL, DefaultTransform );
552 
553  items.erase( i );
554  SetModified();
555  break;
556  }
557  }
558 }
559 
560 
562 {
563  wxASSERT( aItem != NULL );
564 
565  m_drawings.push_back( aItem );
566 }
567 
568 
570 {
571  if( m_drawings.empty( aType ) )
572  return NULL;
573 
574  if( aItem == NULL )
575  return &( *( m_drawings.begin( aType ) ) );
576 
577  // Search for the last item, assume aItem is of type aType
578  wxASSERT( ( aType == TYPE_NOT_INIT ) || ( aType == aItem->Type() ) );
580 
581  while( ( it != m_drawings.end( aType ) ) && ( aItem != &( *it ) ) )
582  ++it;
583 
584  // Search the next item
585  if( it != m_drawings.end( aType ) )
586  {
587  ++it;
588 
589  if( it != m_drawings.end( aType ) )
590  return &( *it );
591  }
592 
593  return NULL;
594 }
595 
596 
597 void LIB_PART::GetPins( LIB_PINS& aList, int aUnit, int aConvert )
598 {
599  if( m_drawings.empty( LIB_PIN_T ) )
600  return;
601 
602  /* Notes:
603  * when aUnit == 0: no unit filtering
604  * when aConvert == 0: no convert (shape selection) filtering
605  * when .m_Unit == 0, the body item is common to units
606  * when .m_Convert == 0, the body item is common to shapes
607  */
608  for( LIB_ITEM& item : m_drawings[ LIB_PIN_T ] )
609  {
610  // Unit filtering:
611  if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
612  continue;
613 
614  // Shape filtering:
615  if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
616  continue;
617 
618  aList.push_back( (LIB_PIN*) &item );
619  }
620 }
621 
622 
623 LIB_PIN* LIB_PART::GetPin( const wxString& aNumber, int aUnit, int aConvert )
624 {
625  LIB_PINS pinList;
626 
627  GetPins( pinList, aUnit, aConvert );
628 
629  for( size_t i = 0; i < pinList.size(); i++ )
630  {
631  wxASSERT( pinList[i]->Type() == LIB_PIN_T );
632 
633  if( aNumber == pinList[i]->GetNumber() )
634  return pinList[i];
635  }
636 
637  return NULL;
638 }
639 
640 
641 bool LIB_PART::PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
642  bool aTestType, bool aTestOrientation, bool aTestLength )
643 {
644  LIB_PINS thisPinList;
645  GetPins( thisPinList, /* aUnit */ 0, /* aConvert */ 0 );
646 
647  for( LIB_PIN* eachThisPin : thisPinList )
648  {
649  wxASSERT( eachThisPin );
650  LIB_PINS otherPinList;
651  aOtherPart.GetPins( otherPinList, /* aUnit */ 0, /* aConvert */ 0 );
652  bool foundMatch = false;
653 
654  for( LIB_PIN* eachOtherPin : otherPinList )
655  {
656  wxASSERT( eachOtherPin );
657  // Same position?
658  if( eachThisPin->GetPosition() != eachOtherPin->GetPosition() )
659  continue;
660 
661  // Same number?
662  if( aTestNums && ( eachThisPin->GetNumber() != eachOtherPin->GetNumber() ))
663  continue;
664 
665  // Same name?
666  if( aTestNames && ( eachThisPin->GetName() != eachOtherPin->GetName() ))
667  continue;
668 
669  // Same electrical type?
670  if( aTestType && ( eachThisPin->GetType() != eachOtherPin->GetType() ))
671  continue;
672 
673  // Same orientation?
674  if( aTestOrientation && ( eachThisPin->GetOrientation() != eachOtherPin->GetOrientation() ))
675  continue;
676 
677  // Same length?
678  if( aTestLength && ( eachThisPin->GetLength() != eachOtherPin->GetLength() ))
679  continue;
680 
681  foundMatch = true;
682  }
683 
684  if( !foundMatch )
685  {
686  // This means there was not an identical (according to the arguments)
687  // pin at the same position in the other component.
688  return true;
689  }
690  }
691 
692  // The loop never gave up, so no conflicts were found.
693  return false;
694 }
695 
696 
697 const EDA_RECT LIB_PART::GetUnitBoundingBox( int aUnit, int aConvert ) const
698 {
699  EDA_RECT bBox;
700  bool initialized = false;
701 
702  for( const LIB_ITEM& item : m_drawings )
703  {
704  if( ( item.m_Unit > 0 ) && ( ( m_unitCount > 1 ) && ( aUnit > 0 )
705  && ( aUnit != item.m_Unit ) ) )
706  continue;
707 
708  if( item.m_Convert > 0 && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
709  continue;
710 
711  if ( ( item.Type() == LIB_FIELD_T ) && !( ( LIB_FIELD& ) item ).IsVisible() )
712  continue;
713 
714  if( initialized )
715  bBox.Merge( item.GetBoundingBox() );
716  else
717  {
718  bBox = item.GetBoundingBox();
719  initialized = true;
720  }
721  }
722 
723  return bBox;
724 }
725 
726 
727 const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const
728 {
729  EDA_RECT bBox;
730  bool initialized = false;
731 
732  for( const LIB_ITEM& item : m_drawings )
733  {
734  if( ( item.m_Unit > 0 ) && ( ( m_unitCount > 1 ) && ( aUnit > 0 )
735  && ( aUnit != item.m_Unit ) ) )
736  continue;
737 
738  if( item.m_Convert > 0 && ( ( aConvert > 0 ) && ( aConvert != item.m_Convert ) ) )
739  continue;
740 
741  if( item.Type() == LIB_FIELD_T )
742  continue;
743 
744  if( initialized )
745  bBox.Merge( item.GetBoundingBox() );
746  else
747  {
748  bBox = item.GetBoundingBox();
749  initialized = true;
750  }
751  }
752 
753  return bBox;
754 }
755 
756 
758 {
759  m_drawings[ LIB_FIELD_T ].clear();
760 }
761 
762 
763 void LIB_PART::SetFields( const std::vector <LIB_FIELD>& aFields )
764 {
765  deleteAllFields();
766 
767  for( unsigned i=0; i<aFields.size(); ++i )
768  {
769  // drawings is a ptr_vector, new and copy an object on the heap.
770  LIB_FIELD* field = new LIB_FIELD( aFields[i] );
771 
772  field->SetParent( this );
773  m_drawings.push_back( field );
774  }
775 }
776 
777 
779 {
780  LIB_FIELD* field;
781 
782  // The only caller of this function is the library field editor, so it
783  // establishes policy here.
784 
785  // Grab the MANDATORY_FIELDS first, in expected order given by
786  // enum NumFieldType
787  for( int id=0; id<MANDATORY_FIELDS; ++id )
788  {
789  field = GetField( id );
790 
791  // the MANDATORY_FIELDS are exactly that in RAM.
792  wxASSERT( field );
793 
794  aList.push_back( *field );
795  }
796 
797  // Now grab all the rest of fields.
798  for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
799  {
800  field = ( LIB_FIELD* ) &item;
801 
802  if( (unsigned) field->GetId() < MANDATORY_FIELDS )
803  continue; // was added above
804 
805  aList.push_back( *field );
806  }
807 }
808 
809 
811 {
812  for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
813  {
814  LIB_FIELD* field = ( LIB_FIELD* ) &item;
815 
816  if( field->GetId() == aId )
817  return field;
818  }
819 
820  return NULL;
821 }
822 
823 
824 LIB_FIELD* LIB_PART::FindField( const wxString& aFieldName )
825 {
826  for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
827  {
828  LIB_FIELD* field = ( LIB_FIELD* ) &item;
829 
830  if( field->GetName() == aFieldName )
831  return field;
832  }
833 
834  return NULL;
835 }
836 
837 
839 {
840  LIB_FIELD* field = GetField( VALUE );
841  wxASSERT( field != NULL );
842  return *field;
843 }
844 
845 
847 {
848  LIB_FIELD* field = GetField( REFERENCE );
849  wxASSERT( field != NULL );
850  return *field;
851 }
852 
853 
855 {
856  LIB_FIELD* field = GetField( FOOTPRINT );
857  wxASSERT( field != NULL );
858  return *field;
859 }
860 
861 
863 {
864  int year, mon, day, hour, min, sec;
865 
866  if( m_dateLastEdition == 0 )
867  return true;
868 
869  sec = m_dateLastEdition & 63;
870  min = ( m_dateLastEdition >> 6 ) & 63;
871  hour = ( m_dateLastEdition >> 12 ) & 31;
872  day = ( m_dateLastEdition >> 17 ) & 31;
873  mon = ( m_dateLastEdition >> 22 ) & 15;
874  year = ( m_dateLastEdition >> 26 ) + 1990;
875 
876  aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
877 
878  return true;
879 }
880 
881 
882 bool LIB_PART::LoadDateAndTime( char* aLine )
883 {
884  int year, mon, day, hour, min, sec;
885 
886  year = mon = day = hour = min = sec = 0;
887  strtok( aLine, " \r\t\n" );
888  strtok( NULL, " \r\t\n" );
889 
890  if( sscanf( aLine, "%d/%d/%d %d:%d:%d", &year, &mon, &day, &hour, &min, &sec ) != 6 )
891  return false;
892 
893  m_dateLastEdition = ( sec & 63 ) + ( ( min & 63 ) << 6 ) +
894  ( ( hour & 31 ) << 12 ) + ( ( day & 31 ) << 17 ) +
895  ( ( mon & 15 ) << 22 ) + ( ( year - 1990 ) << 26 );
896 
897  return true;
898 }
899 
900 
901 void LIB_PART::SetOffset( const wxPoint& aOffset )
902 {
903  for( LIB_ITEM& item : m_drawings )
904  item.SetOffset( aOffset );
905 }
906 
907 
909 {
910  m_drawings.unique();
911 }
912 
913 
915 {
916  for( const LIB_ITEM& item : m_drawings )
917  {
918  if( item.m_Convert > 1 )
919  return true;
920  }
921 
922  return false;
923 }
924 
925 
927 {
928  for( LIB_ITEM& item : m_drawings )
929  {
930  item.m_Flags = 0;
931  }
932 }
933 
934 
935 int LIB_PART::SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool aSyncPinEdit )
936 {
937  int itemCount = 0;
938 
939  for( LIB_ITEM& item : m_drawings )
940  {
941  item.ClearFlags( SELECTED );
942 
943  if( ( item.m_Unit && item.m_Unit != aUnit )
944  || ( item.m_Convert && item.m_Convert != aConvert ) )
945  {
946  if( item.Type() != LIB_PIN_T )
947  continue;
948 
949  // Specific rules for pins:
950  // - do not select pins in other units when synchronized pin edit mode is disabled
951  // - do not select pins in other units when units are not interchangeable
952  // - in other cases verify if the pin belongs to the requested unit
953  if( !aSyncPinEdit || m_unitsLocked
954  || ( item.m_Convert && item.m_Convert != aConvert ) )
955  continue;
956  }
957 
958  if( item.Inside( aRect ) )
959  {
960  item.SetFlags( SELECTED );
961  itemCount++;
962  }
963  }
964 
965  return itemCount;
966 }
967 
968 
969 void LIB_PART::MoveSelectedItems( const wxPoint& aOffset )
970 {
971  for( LIB_ITEM& item : m_drawings )
972  {
973  if( !item.IsSelected() )
974  continue;
975 
976  item.SetOffset( aOffset );
977  item.m_Flags = 0;
978  }
979 }
980 
981 
983 {
984  for( LIB_ITEM& item : m_drawings )
985  {
986  item.m_Flags = 0;
987  }
988 }
989 
990 
992 {
994 
995  // We *do not* remove the 2 mandatory fields: reference and value
996  // so skip them (do not remove) if they are flagged selected.
997  // Skip also not visible items.
998  // But I think fields must not be deleted by a block delete command or other global command
999  // because they are not really graphic items
1000  while( item != m_drawings.end() )
1001  {
1002  if( item->Type() == LIB_FIELD_T )
1003  {
1004  item->ClearFlags( SELECTED );
1005  }
1006 
1007  if( !item->IsSelected() )
1008  ++item;
1009  else
1010  item = m_drawings.erase( item );
1011  }
1012 }
1013 
1014 
1015 void LIB_PART::CopySelectedItems( const wxPoint& aOffset )
1016 {
1017  std::vector< LIB_ITEM* > tmp;
1018 
1019  for( LIB_ITEM& item : m_drawings )
1020  {
1021  // We *do not* copy fields because they are unique for the whole component
1022  // so skip them (do not duplicate) if they are flagged selected.
1023  if( item.Type() == LIB_FIELD_T )
1024  item.ClearFlags( SELECTED );
1025 
1026  if( !item.IsSelected() )
1027  continue;
1028 
1029  item.ClearFlags( SELECTED );
1030  LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
1031  newItem->SetFlags( SELECTED );
1032 
1033  // When push_back elements in buffer, a memory reallocation can happen
1034  // and will break pointers.
1035  // So, push_back later.
1036  tmp.push_back( newItem );
1037  }
1038 
1039  for( auto item : tmp )
1040  m_drawings.push_back( item );
1041 
1042  MoveSelectedItems( aOffset );
1043 }
1044 
1045 
1047 {
1048  for( LIB_ITEM& item : m_drawings )
1049  {
1050  if( !item.IsSelected() )
1051  continue;
1052 
1053  item.MirrorHorizontal( aCenter );
1054  item.m_Flags = 0;
1055  }
1056 }
1057 
1058 
1060 {
1061  for( LIB_ITEM& item : m_drawings )
1062  {
1063  if( !item.IsSelected() )
1064  continue;
1065 
1066  item.MirrorVertical( aCenter );
1067  item.m_Flags = 0;
1068  }
1069 }
1070 
1071 
1073 {
1074  for( LIB_ITEM& item : m_drawings )
1075  {
1076  if( !item.IsSelected() )
1077  continue;
1078 
1079  item.Rotate( aCenter );
1080  item.m_Flags = 0;
1081  }
1082 }
1083 
1084 
1085 LIB_ITEM* LIB_PART::LocateDrawItem( int aUnit, int aConvert,
1086  KICAD_T aType, const wxPoint& aPoint )
1087 {
1088  for( LIB_ITEM& item : m_drawings )
1089  {
1090  if( ( aUnit && item.m_Unit && ( aUnit != item.m_Unit) )
1091  || ( aConvert && item.m_Convert && ( aConvert != item.m_Convert ) )
1092  || ( ( item.Type() != aType ) && ( aType != TYPE_NOT_INIT ) ) )
1093  continue;
1094 
1095  if( item.HitTest( aPoint ) )
1096  return &item;
1097  }
1098 
1099  return NULL;
1100 }
1101 
1102 
1103 LIB_ITEM* LIB_PART::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
1104  const wxPoint& aPoint, const TRANSFORM& aTransform )
1105 {
1106  /* we use LocateDrawItem( int aUnit, int convert, KICAD_T type, const
1107  * wxPoint& pt ) to search items.
1108  * because this function uses DefaultTransform as orient/mirror matrix
1109  * we temporary copy aTransform in DefaultTransform
1110  */
1111  LIB_ITEM* item;
1112  TRANSFORM transform = DefaultTransform;
1113  DefaultTransform = aTransform;
1114 
1115  item = LocateDrawItem( aUnit, aConvert, aType, aPoint );
1116 
1117  // Restore matrix
1118  DefaultTransform = transform;
1119 
1120  return item;
1121 }
1122 
1123 
1124 void LIB_PART::SetUnitCount( int aCount )
1125 {
1126  if( m_unitCount == aCount )
1127  return;
1128 
1129  if( aCount < m_unitCount )
1130  {
1132 
1133  while( i != m_drawings.end() )
1134  {
1135  if( i->m_Unit > aCount )
1136  i = m_drawings.erase( i );
1137  else
1138  ++i;
1139  }
1140  }
1141  else
1142  {
1143  int prevCount = m_unitCount;
1144 
1145  // Temporary storage for new items, as adding new items directly to
1146  // m_drawings may cause the buffer reallocation which invalidates the
1147  // iterators
1148  std::vector< LIB_ITEM* > tmp;
1149 
1150  for( LIB_ITEM& item : m_drawings )
1151  {
1152  if( item.m_Unit != 1 )
1153  continue;
1154 
1155  for( int j = prevCount + 1; j <= aCount; j++ )
1156  {
1157  LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
1158  newItem->m_Unit = j;
1159  tmp.push_back( newItem );
1160  }
1161  }
1162 
1163  for( auto item : tmp )
1164  m_drawings.push_back( item );
1165  }
1166 
1167  m_unitCount = aCount;
1168 }
1169 
1170 
1171 void LIB_PART::SetConversion( bool aSetConvert )
1172 {
1173  if( aSetConvert == HasConversion() )
1174  return;
1175 
1176  // Duplicate items to create the converted shape
1177  if( aSetConvert )
1178  {
1179  std::vector< LIB_ITEM* > tmp; // Temporarily store the duplicated pins here.
1180 
1181  for( LIB_ITEM& item : m_drawings )
1182  {
1183  // Only pins are duplicated.
1184  if( item.Type() != LIB_PIN_T )
1185  continue;
1186 
1187  if( item.m_Convert == 1 )
1188  {
1189  LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
1190  newItem->m_Convert = 2;
1191  tmp.push_back( newItem );
1192  }
1193  }
1194 
1195  // Transfer the new pins to the LIB_PART.
1196  for( unsigned i = 0; i < tmp.size(); i++ )
1197  m_drawings.push_back( tmp[i] );
1198  }
1199  else
1200  {
1201  // Delete converted shape items because the converted shape does
1202  // not exist
1204 
1205  while( i != m_drawings.end() )
1206  {
1207  if( i->m_Convert > 1 )
1208  i = m_drawings.erase( i );
1209  else
1210  ++i;
1211  }
1212  }
1213 }
1214 
1215 
1216 wxArrayString LIB_PART::GetAliasNames( bool aIncludeRoot ) const
1217 {
1218  wxArrayString names;
1219 
1220  LIB_ALIASES::const_iterator it;
1221 
1222  for( it=m_aliases.begin(); it != m_aliases.end(); ++it )
1223  {
1224  if( !aIncludeRoot && (*it)->IsRoot() )
1225  continue;
1226 
1227  names.Add( (*it)->GetName() );
1228  }
1229 
1230  return names;
1231 }
1232 
1233 
1234 bool LIB_PART::HasAlias( const wxString& aName ) const
1235 {
1236  wxCHECK2_MSG( !aName.IsEmpty(), return false,
1237  wxT( "Cannot get alias with an empty name, bad programmer." ) );
1238 
1239  for( size_t i = 0; i < m_aliases.size(); i++ )
1240  {
1241  if( aName == m_aliases[i]->GetName() )
1242  return true;
1243  }
1244 
1245  return false;
1246 }
1247 
1248 
1249 void LIB_PART::SetAliases( const wxArrayString& aAliasList )
1250 {
1251  wxCHECK_RET( !m_library,
1252  wxT( "Symbol aliases cannot be changed when they are owned by a library." ) );
1253  wxCHECK_RET( !aAliasList.IsEmpty(), wxT( "Alias list cannot be empty" ) );
1254 
1255  if( aAliasList == GetAliasNames() )
1256  return;
1257 
1258  // Add names not existing in the current component alias list.
1259  for( size_t i = 0; i < aAliasList.GetCount(); i++ )
1260  {
1261  if( HasAlias( aAliasList[ i ] ) )
1262  continue;
1263 
1264  m_aliases.push_back( new LIB_ALIAS( aAliasList[ i ], this ) );
1265  }
1266 
1267  // Remove names in the current component that are not in the new alias list.
1268  LIB_ALIASES::iterator it = m_aliases.begin();
1269 
1270  while( it != m_aliases.end() )
1271  {
1272  int index = aAliasList.Index( (*it)->GetName(), false );
1273 
1274  if( index != wxNOT_FOUND || (*it)->IsRoot() )
1275  ++it;
1276  else
1277  it = m_aliases.erase( it );
1278  }
1279 }
1280 
1281 
1282 void LIB_PART::RemoveAlias( const wxString& aName )
1283 {
1284  LIB_ALIAS* a = GetAlias( aName );
1285 
1286  if( a )
1287  RemoveAlias( a );
1288 }
1289 
1290 
1292 {
1293  wxCHECK_MSG( aAlias, NULL, wxT( "Cannot remove alias by NULL pointer." ) );
1294 
1295  LIB_ALIAS* nextAlias = NULL;
1296 
1297  LIB_ALIASES::iterator it = find( m_aliases.begin(), m_aliases.end(), aAlias );
1298 
1299  if( it != m_aliases.end() )
1300  {
1301  bool rename = aAlias->IsRoot();
1302 
1303  wxLogTrace( traceSchLibMem,
1304  wxT( "%s: symbol:'%s', alias:'%s', alias count %llu, reference count %ld." ),
1305  GetChars( wxString::FromAscii( __WXFUNCTION__ ) ),
1306  GetChars( GetName() ),
1307  GetChars( aAlias->GetName() ),
1308  (long long unsigned) m_aliases.size(),
1309  m_me.use_count() );
1310 
1311  it = m_aliases.erase( it );
1312 
1313  if( !m_aliases.empty() )
1314  {
1315  if( it == m_aliases.end() )
1316  it = m_aliases.begin();
1317 
1318  nextAlias = *it;
1319 
1320  if( rename )
1321  SetName( nextAlias->GetName() );
1322  }
1323  }
1324 
1325  return nextAlias;
1326 }
1327 
1328 
1330 {
1331  // Remove all of the aliases except the root alias.
1332  while( m_aliases.size() > 1 )
1333  m_aliases.pop_back();
1334 }
1335 
1336 
1337 LIB_ALIAS* LIB_PART::GetAlias( const wxString& aName )
1338 {
1339  wxCHECK2_MSG( !aName.IsEmpty(), return NULL,
1340  wxT( "Cannot get alias with an empty name. Bad programmer!" ) );
1341 
1342  for( size_t i = 0; i < m_aliases.size(); i++ )
1343  {
1344  if( aName == m_aliases[i]->GetName() )
1345  return m_aliases[i];
1346  }
1347 
1348  return NULL;
1349 }
1350 
1351 
1353 {
1354  wxCHECK2_MSG( aIndex < m_aliases.size(), return NULL,
1355  wxT( "Illegal alias list index, bad programmer." ) );
1356 
1357  return m_aliases[aIndex];
1358 }
1359 
1360 
1361 void LIB_PART::AddAlias( const wxString& aName )
1362 {
1363  wxCHECK_RET( !HasAlias( aName ),
1364  wxT( "Symbol <" ) + GetName() + wxT( "> already has an alias <" ) +
1365  aName + wxT( ">. Bad programmer." ) );
1366 
1367  m_aliases.push_back( new LIB_ALIAS( aName, this ) );
1368 }
1369 
1370 
1371 void LIB_PART::SetSubpartIdNotation( int aSep, int aFirstId )
1372 {
1373  m_subpartFirstId = 'A';
1375 
1376  if( aSep == '.' || aSep == '-' || aSep == '_' )
1377  m_subpartIdSeparator = aSep;
1378 
1379  if( aFirstId == '1' && aSep != 0 )
1380  m_subpartFirstId = aFirstId;
1381 }
timestamp_t m_dateLastEdition
Date of the last modification.
LIB_ALIASES m_aliases
List of alias object pointers associated with the part.
PART_LIB * GetLib()
virtual ~LIB_ALIAS()
LIB_FIELD & GetFootprintField()
Return reference to the footprint field.
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:73
void SetLib(PART_LIB *aLibrary)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
LIB_FIELD * GetField(int aId)
Return pointer to the requested field.
bool PinsConflictWith(LIB_PART &aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength)
Return true if this part&#39;s pins do not match another part&#39;s pins.
void SetModified()
static int m_subpartIdSeparator
the separator char between the subpart id and the reference like U1A ( m_subpartIdSeparator = 0 ) or ...
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDc, const wxPoint &aOffset, int aMulti, int aConvert, const PART_DRAW_OPTIONS &aOpts)
Draw part.
const EDA_RECT GetUnitBoundingBox(int aUnit, int aConvert) const
Get the bounding box for the symbol.
Part library alias object definition.
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:183
bool PinIsDangling(size_t aPin) const
void Move(const wxPoint &aMoveVector)
Function Move moves the rectangle by the aMoveVector.
void SetConversion(bool aSetConvert)
Set or clear the alternate body style (DeMorgan) for the part.
virtual ~LIB_PART()
name of datasheet
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect...
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
bool m_showPinNumbers
Determines if part pin numbers are visible.
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:318
wxString description
documentation for info
int LibraryEntryCompare(const LIB_ALIAS *aItem1, const LIB_ALIAS *aItem2)
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
bool IsPower() const
LIB_ALIAS * GetAlias(size_t aIndex)
bool IsNew() const
Definition: base_struct.h:216
virtual void SetColor(COLOR4D color)=0
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
int m_unitCount
Number of units (parts) per package.
const wxString GetLibraryName()
LIB_ITEM * GetNextDrawItem(LIB_ITEM *aItem=NULL, KICAD_T aType=TYPE_NOT_INIT)
Return the next draw object pointer.
PART_LIB * m_library
Library the part belongs to if any.
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:224
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
Field object used in symbol libraries.
Definition: lib_field.h:59
static int m_subpartFirstId
the ascii char value to calculate the subpart symbol id from the part number: only &#39;A&#39;...
void unique()
Remove duplicate elements in list.
Definition: multivector.h:238
const EDA_RECT GetBodyBoundingBox(int aUnit, int aConvert) const
Get the symbol bounding box excluding fields.
bool HasAlias(const wxString &aName) const
Test if alias aName is in part alias list.
LIB_ITEMS_CONTAINER m_drawings
Drawing items of this part.
LIB_FIELD & GetValueField()
Return reference to the value field.
int m_Unit
Unit identification for multiple parts per package.
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
LIB_ALIAS(const wxString &aName, LIB_PART *aRootComponent)
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:356
void ClearSelectedItems()
Clears all the draw items marked by a block select.
void AddAlias(const wxString &aName)
Add an alias aName to the part.
LIBRENTRYOPTIONS m_options
Special part features such as POWER or NORMAL.)
COLOR4D GetLayerColor(SCH_LAYER_ID aLayer)
Definition: eeschema.cpp:167
PART_LIB * GetLib()
void RevertYAxis()
Function RevertYAxis Mirror the rectangle from the X axis (negate Y pos and size) ...
Definition: eda_rect.h:144
void operator()(void const *) const
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
bool draw_hidden_fields
Whether to draw "hidden" fields.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
bool m_unitsLocked
True if part has multiple units and changing one unit does not automatically change another unit...
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
LIB_ITEMS_CONTAINER::ITEM_PTR_VECTOR LIB_ITEMS
void MirrorSelectedItemsH(const wxPoint &aCenter)
Horizontally (X axis) mirror selected draw items about a point.
This file contains miscellaneous commonly used macros and functions.
wxString name
void PlotLibFields(PLOTTER *aPlotter, int aUnit, int aConvert, const wxPoint &aOffset, const TRANSFORM &aTransform)
Plot Lib Fields only of the part to plotter.
void SetOffset(const wxPoint &aOffset)
Move the part aOffset.
void MirrorSelectedItemsV(const wxPoint &aCenter)
Vertically (Y axis) mirror selected draw items about a point.
bool LoadDateAndTime(char *aLine)
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:189
void AddDrawItem(LIB_ITEM *aItem)
Add a new draw aItem to the draw object list.
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:133
int m_pinNameOffset
The offset in mils to draw the pin name.
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41
void deleteAllFields()
#define SELECTED
Definition: base_struct.h:118
bool IsRoot() const
void SetName(const wxString &aName)
void GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1098
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
void Plot(PLOTTER *aPlotter, int aUnit, int aConvert, const wxPoint &aOffset, const TRANSFORM &aTransform)
Plot lib part to plotter.
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
LIB_FIELD * FindField(const wxString &aFieldName)
Findd a field within this part matching aFieldName and returns it or NULL if not found.
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:502
void SetUnitCount(int count)
Set the units per part count.
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:213
int GetId() const
Definition: lib_field.h:138
wxString docFileName
Associate doc file name.
void CopySelectedItems(const wxPoint &aOffset)
Make a copy of the selected draw items marked by a block select.
LIB_PART * shared
Actual LIB_PART referenced by [multiple] aliases.
void RotateSelectedItems(const wxPoint &aCenter)
Rotate CCW selected draw items about a point.
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
void push_back(T *aItem)
Definition: multivector.h:169
Class LIB_ITEM definition.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
const wxString GetName() const
Return the file name without path or extension.
int SelectItems(EDA_RECT &aRect, int aUnit, int aConvert, bool aSyncPinEdit)
Checks all draw objects of part to see if they are with block.
bool operator==(const wxChar *aName) const
KEEPCASE sensitive comparison of the part entry name.
Define a library symbol object.
EDA_RECT * GetClipBox()
wxLogTrace helper definitions.
void RemoveDuplicateDrawItems()
Remove duplicate draw items from list.
wxArrayString m_FootprintList
List of suitable footprint names for the part (wild card names accepted).
bool GetColorMode() const
Definition: plotter.h:131
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:380
LIB_PART(const wxString &aName, PART_LIB *aLibrary=NULL)
bool m_IsPrinting
Definition: base_screen.h:220
LIB_ID m_libId
const wxChar *const traceSchLibMem
Flag to enable schematic library memory deletion debug output.
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:232
wxString GetName(bool aTranslate=true) const
Returns the field name.
Definition: lib_field.cpp:432
const wxString GetLibraryName()
ITERATOR erase(const ITERATOR &aIterator)
Definition: multivector.h:174
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared ...
ITERATOR_BASE< LIB_ITEM, MULTIVECTOR< LIB_ITEM, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The non-const iterator
Definition: multivector.h:160
Definitions for the Eeschema program SCH_SCREEN class.
Base plotter engine class.
Definition: plotter.h:97
void SetAliases(const wxArrayString &aAliasList)
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:60
void ClearStatus()
Clears the status flag all draw objects in this part.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
TRANSFORM DefaultTransform
Definition: eeschema.cpp:58
GR_DRAWMODE draw_mode
Device context drawing mode, see wxDC.
COLOR4D color
Color to draw part in.
void RemoveAlias(const wxString &aName)
void RemoveAllAliases()
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, GR_DRAWMODE aDrawMode, void *aData, const TRANSFORM &aTransform)
Draw an item.
const wxString & GetName() const
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
bool IsVisible() const
Definition: lib_field.h:164
static void SetSubpartIdNotation(int aSep, int aFirstId)
Set the separator char between the subpart id and the reference 0 (no separator) or &#39;...
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:257
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
size_t i
Definition: json11.cpp:597
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
static wxString SubReference(int aUnit, bool aAddSeparator=true)
bool show_pin_text
Whether to show pin texts.
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:176
void RemoveDrawItem(LIB_ITEM *aItem, EDA_DRAW_PANEL *aPanel=NULL, wxDC *aDc=NULL)
Remove draw aItem from list.
bool only_selected
Draws only the body items that are selected, for block moves.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores &#39;_&#39;.
Definition: lib_id.cpp:374
bool show_elec_type
Whether to show the pin electrical type.
int m_Convert
Shape identification for alternate body styles.
const wxString & GetName() const
void MoveSelectedItems(const wxPoint &aOffset)
Move the selected draw items marked by a block select.
bool IsPowerConnection() const
Return whether this pin forms an implicit power connection: i.e., is hidden and of type POWER_IN...
Definition: lib_pin.h:368
LIB_ITEM * LocateDrawItem(int aUnit, int aConvert, KICAD_T aType, const wxPoint &aPoint)
Locate a draw object.
virtual void SetName(const wxString &aName)
Definition for part library class.
bool draw_visible_fields
Whether to draw "visible" fields.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
bool GetGRForceBlackPenState(void)
Function GetGRForceBlackPenState.
Definition: gr_basic.cpp:309
void DeleteSelectedItems()
Deletes the select draw items marked by a block select.
bool m_showPinNames
Determines if part pin names are visible.
void SetFields(const std::vector< LIB_FIELD > &aFieldsList)
Overwrite all the existing fields in this symbol with fields supplied in aFieldsList.
#define VALUE
Object used to load, save, search, and otherwise manipulate symbol library files. ...
TRANSFORM transform
Coordinate adjustment settings.
wxString keyWords
keyword list (used for search for parts by keyword)
void GetFields(LIB_FIELDS &aList)
Return a list of fields withing this part.
LIB_PIN * GetPin(const wxString &aNumber, int aUnit=0, int aConvert=0)
Return pin object with the requested pin aNumber.
#define min(a, b)
Definition: auxiliary.h:85
bool SaveDateAndTime(OUTPUTFORMATTER &aFormatter)
Write the date and time of part to aFile in the format: "Ti yy/mm/jj hh:mm:ss".
#define IS_MOVED
Item being moved.
Definition: base_struct.h:110
PART_SPTR m_me
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared ...