KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN_CACHE Class Reference

A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLUGIN, so therefore is private to this implementation file, i.e. More...

Public Member Functions

 SCH_LEGACY_PLUGIN_CACHE (const wxString &aLibraryPath)
 
 ~SCH_LEGACY_PLUGIN_CACHE ()
 
int GetModifyHash () const
 
void Save (bool aSaveDocFile=true)
 Save the entire library to file m_libFileName;. More...
 
void Load ()
 
void AddSymbol (const LIB_PART *aPart)
 
void DeleteSymbol (const wxString &aName)
 
wxFileName GetRealFile () const
 
wxDateTime GetLibModificationTime ()
 
bool IsFile (const wxString &aFullPathAndFileName) const
 
bool IsFileChanged () const
 
void SetModified (bool aModified=true)
 
wxString GetLogicalName () const
 
void SetFileName (const wxString &aFileName)
 
wxString GetFileName () const
 

Static Public Member Functions

static LIB_PARTLoadPart (LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_PART_MAP *aMap=nullptr)
 
static void SaveSymbol (LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_PART_MAP *aMap=nullptr)
 

Private Member Functions

void loadHeader (FILE_LINE_READER &aReader)
 
void loadDocs ()
 
LIB_PARTremoveSymbol (LIB_PART *aAlias)
 
void saveDocFile ()
 

Static Private Member Functions

static void loadAliases (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, LIB_PART_MAP *aMap=nullptr)
 
static void loadField (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static void loadDrawEntries (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
 
static void loadFootprintFilters (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_ARCloadArc (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_CIRCLEloadCircle (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_TEXTloadText (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
 
static LIB_RECTANGLEloadRectangle (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_PINloadPin (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_POLYLINEloadPolyLine (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_BEZIERloadBezier (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static FILL_T parseFillMode (LINE_READER &aReader, const char *aLine, const char **aOutput)
 
static void saveArc (LIB_ARC *aArc, OUTPUTFORMATTER &aFormatter)
 
static void saveBezier (LIB_BEZIER *aBezier, OUTPUTFORMATTER &aFormatter)
 
static void saveCircle (LIB_CIRCLE *aCircle, OUTPUTFORMATTER &aFormatter)
 
static void saveField (LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter)
 
static void savePin (LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter)
 
static void savePolyLine (LIB_POLYLINE *aPolyLine, OUTPUTFORMATTER &aFormatter)
 
static void saveRectangle (LIB_RECTANGLE *aRectangle, OUTPUTFORMATTER &aFormatter)
 
static void saveText (LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter)
 

Private Attributes

wxString m_fileName
 
wxFileName m_libFileName
 
wxDateTime m_fileModTime
 
LIB_PART_MAP m_symbols
 
bool m_isWritable
 
bool m_isModified
 
int m_versionMajor
 
int m_versionMinor
 
int m_libType
 
friend SCH_LEGACY_PLUGIN
 

Static Private Attributes

static int m_modHash = 1
 

Detailed Description

A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLUGIN, so therefore is private to this implementation file, i.e.

not placed into a header.

Definition at line 475 of file sch_legacy_plugin.cpp.

Constructor & Destructor Documentation

◆ SCH_LEGACY_PLUGIN_CACHE()

SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN_CACHE ( const wxString &  aLibraryPath)

Definition at line 2401 of file sch_legacy_plugin.cpp.

2401  :
2402  m_fileName( aFullPathAndFileName ),
2403  m_libFileName( aFullPathAndFileName ),
2404  m_isWritable( true ),
2405  m_isModified( false )
2406 {
2407  m_versionMajor = -1;
2408  m_versionMinor = -1;
2410 }

References LIBRARY_TYPE_EESCHEMA, m_libType, m_versionMajor, and m_versionMinor.

◆ ~SCH_LEGACY_PLUGIN_CACHE()

SCH_LEGACY_PLUGIN_CACHE::~SCH_LEGACY_PLUGIN_CACHE ( )

Definition at line 2413 of file sch_legacy_plugin.cpp.

2414 {
2415  std::vector< LIB_PART* > rootParts;
2416 
2417  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2418  for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); ++it )
2419  delete it->second;
2420 
2421  m_symbols.clear();
2422 }

References m_symbols.

Member Function Documentation

◆ AddSymbol()

void SCH_LEGACY_PLUGIN_CACHE::AddSymbol ( const LIB_PART aPart)

Definition at line 2543 of file sch_legacy_plugin.cpp.

2544 {
2545  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2546  wxString name = aPart->GetName();
2547  LIB_PART_MAP::iterator it = m_symbols.find( name );
2548 
2549  if( it != m_symbols.end() )
2550  {
2551  removeSymbol( it->second );
2552  }
2553 
2554  m_symbols[ name ] = const_cast< LIB_PART* >( aPart );
2555  m_isModified = true;
2556  ++m_modHash;
2557 }
wxString GetName() const override
const char * name
Definition: DXF_plotter.cpp:60
LIB_PART * removeSymbol(LIB_PART *aAlias)

References LIB_PART::GetName(), m_isModified, m_modHash, m_symbols, name, and removeSymbol().

Referenced by SCH_LEGACY_PLUGIN::SaveSymbol().

◆ DeleteSymbol()

void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol ( const wxString &  aName)

Definition at line 4274 of file sch_legacy_plugin.cpp.

4275 {
4276  LIB_PART_MAP::iterator it = m_symbols.find( aSymbolName );
4277 
4278  if( it == m_symbols.end() )
4279  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
4280  m_libFileName.GetFullName(), aSymbolName ) );
4281 
4282  LIB_PART* part = it->second;
4283 
4284  if( part->IsRoot() )
4285  {
4286  LIB_PART* rootPart = part;
4287 
4288  // Remove the root symbol and all it's children.
4289  m_symbols.erase( it );
4290 
4291  LIB_PART_MAP::iterator it1 = m_symbols.begin();
4292 
4293  while( it1 != m_symbols.end() )
4294  {
4295  if( it1->second->IsAlias() && it1->second->GetParent().lock() == rootPart->SharedPtr() )
4296  {
4297  delete it1->second;
4298  it1 = m_symbols.erase( it1 );
4299  }
4300  else
4301  {
4302  it1++;
4303  }
4304  }
4305 
4306  delete rootPart;
4307  }
4308  else
4309  {
4310  // Just remove the alias.
4311  m_symbols.erase( it );
4312  delete part;
4313  }
4314 
4315  ++m_modHash;
4316  m_isModified = true;
4317 }
PART_SPTR SharedPtr()
Define a library symbol object.
#define THROW_IO_ERROR(msg)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.

References _, Format(), LIB_PART::IsRoot(), m_isModified, m_libFileName, m_modHash, m_symbols, LIB_PART::SharedPtr(), and THROW_IO_ERROR.

Referenced by SCH_LEGACY_PLUGIN::DeleteSymbol().

◆ GetFileName()

wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 558 of file sch_legacy_plugin.cpp.

558 { return m_libFileName.GetFullPath(); }

References m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

◆ GetLibModificationTime()

wxDateTime SCH_LEGACY_PLUGIN_CACHE::GetLibModificationTime ( )

Definition at line 2449 of file sch_legacy_plugin.cpp.

2450 {
2451  wxFileName fn = GetRealFile();
2452 
2453  // update the writable flag while we have a wxFileName, in a network this
2454  // is possibly quite dynamic anyway.
2455  m_isWritable = fn.IsFileWritable();
2456 
2457  return fn.GetModificationTime();
2458 }
wxFileName GetRealFile() const

References GetRealFile(), and m_isWritable.

Referenced by Load().

◆ GetLogicalName()

wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 554 of file sch_legacy_plugin.cpp.

554 { return m_libFileName.GetName(); }

References m_libFileName.

◆ GetModifyHash()

int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( ) const
inline

Definition at line 528 of file sch_legacy_plugin.cpp.

528 { return m_modHash; }

References m_modHash.

Referenced by SCH_LEGACY_PLUGIN::GetModifyHash().

◆ GetRealFile()

wxFileName SCH_LEGACY_PLUGIN_CACHE::GetRealFile ( ) const

Definition at line 2426 of file sch_legacy_plugin.cpp.

2427 {
2428  wxFileName fn( m_libFileName );
2429 
2430 #ifndef __WINDOWS__
2431  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2432  {
2433  char buffer[ PATH_MAX + 1 ];
2434  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2435 
2436  if( pathLen > 0 )
2437  {
2438  buffer[ pathLen ] = '\0';
2439  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2440  fn.Normalize();
2441  }
2442  }
2443 #endif
2444 
2445  return fn;
2446 }
#define TO_UTF8(wxstring)

References m_libFileName, and TO_UTF8.

Referenced by GetLibModificationTime(), IsFileChanged(), and Save().

◆ IsFile()

bool SCH_LEGACY_PLUGIN_CACHE::IsFile ( const wxString &  aFullPathAndFileName) const

Definition at line 2461 of file sch_legacy_plugin.cpp.

2462 {
2463  return m_fileName == aFullPathAndFileName;
2464 }

References m_fileName.

Referenced by SCH_LEGACY_PLUGIN::cacheLib(), SCH_LEGACY_PLUGIN::DeleteSymbolLib(), and SCH_LEGACY_PLUGIN::SaveLibrary().

◆ IsFileChanged()

bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 2467 of file sch_legacy_plugin.cpp.

2468 {
2469  wxFileName fn = GetRealFile();
2470 
2471  if( m_fileModTime.IsValid() && fn.IsOk() && fn.FileExists() )
2472  return fn.GetModificationTime() != m_fileModTime;
2473 
2474  return false;
2475 }
wxFileName GetRealFile() const

References GetRealFile(), and m_fileModTime.

Referenced by SCH_LEGACY_PLUGIN::cacheLib().

◆ Load()

void SCH_LEGACY_PLUGIN_CACHE::Load ( )
Todo:
Probably should check for a valid date and time stamp even though it's not used.

Definition at line 2560 of file sch_legacy_plugin.cpp.

2561 {
2562  if( !m_libFileName.FileExists() )
2563  {
2564  THROW_IO_ERROR( wxString::Format( _( "Library file \"%s\" not found." ),
2565  m_libFileName.GetFullPath() ) );
2566  }
2567 
2568  wxCHECK_RET( m_libFileName.IsAbsolute(),
2569  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2570  "open library \"%s\".", m_libFileName.GetFullPath() ) );
2571 
2572  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file \"%s\"",
2573  m_libFileName.GetFullPath() );
2574 
2575  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2576 
2577  if( !reader.ReadLine() )
2578  THROW_IO_ERROR( _( "unexpected end of file" ) );
2579 
2580  const char* line = reader.Line();
2581 
2582  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2583  {
2584  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2585  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2586  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2587  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2588  }
2589 
2590  m_versionMajor = parseInt( reader, line, &line );
2591 
2592  if( *line != '.' )
2593  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2594 
2595  line++;
2596 
2597  m_versionMinor = parseInt( reader, line, &line );
2598 
2599  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2600  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2601 
2602  // Check if this is a symbol library which is the same as a component library but without
2603  // any alias, documentation, footprint filters, etc.
2604  if( strCompare( "SYMBOL", line, &line ) )
2605  {
2606  // Symbol files add date and time stamp info to the header.
2608 
2610  }
2611  else
2612  {
2614  }
2615 
2616  while( reader.ReadLine() )
2617  {
2618  line = reader.Line();
2619 
2620  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2621  continue;
2622 
2623  // Headers where only supported in older library file formats.
2624  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2625  loadHeader( reader );
2626 
2627  if( strCompare( "DEF", line ) )
2628  {
2629  // Read one DEF/ENDDEF part entry from library:
2631 
2632  m_symbols[ part->GetName() ] = part;
2633  }
2634  }
2635 
2636  ++m_modHash;
2637 
2638  // Remember the file modification time of library file when the
2639  // cache snapshot was made, so that in a networked environment we will
2640  // reload the cache as needed.
2642 
2644  loadDocs();
2645 }
wxString GetName() const override
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
void loadHeader(FILE_LINE_READER &aReader)
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
Define a library symbol object.
#define THROW_IO_ERROR(msg)
#define USE_OLD_DOC_FILE_FORMAT(major, minor)
Definition: class_library.h:74
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static LIB_PART * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_PART_MAP *aMap=nullptr)
#define SCH_PARSE_ERROR(text, reader, pos)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References _, Format(), GetLibModificationTime(), LIB_PART::GetName(), LIBRARY_TYPE_EESCHEMA, LIBRARY_TYPE_SYMBOL, loadDocs(), loadHeader(), LoadPart(), m_fileModTime, m_libFileName, m_libType, m_modHash, m_symbols, m_versionMajor, m_versionMinor, parseInt(), SCH_PARSE_ERROR, strCompare(), THROW_IO_ERROR, traceSchLegacyPlugin, and USE_OLD_DOC_FILE_FORMAT.

Referenced by SCH_LEGACY_PLUGIN::cacheLib(), and SCH_LEGACY_PLUGIN::CreateSymbolLib().

◆ loadAliases()

void SCH_LEGACY_PLUGIN_CACHE::loadAliases ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader,
LIB_PART_MAP aMap = nullptr 
)
staticprivate

Definition at line 2947 of file sch_legacy_plugin.cpp.

2950 {
2951  wxString newAliasName;
2952  const char* line = aReader.Line();
2953 
2954  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2955 
2956  wxString utf8Line = wxString::FromUTF8( line );
2957  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2958 
2959  // Parse the ALIAS list.
2960  while( tokens.HasMoreTokens() )
2961  {
2962  newAliasName = tokens.GetNextToken();
2963 
2964  if( aMap )
2965  {
2966  LIB_PART* newPart = new LIB_PART( newAliasName );
2967 
2968  newPart->SetParent( aPart.get() );
2969 
2970  // This will prevent duplicate aliases.
2971  (*aMap)[ newPart->GetName() ] = newPart;
2972  }
2973  }
2974 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
wxString GetName() const override
void SetParent(LIB_PART *aParent=nullptr)
Define a library symbol object.
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LIB_PART::GetName(), LINE_READER::Line(), LIB_PART::SetParent(), and strCompare().

Referenced by LoadPart().

◆ loadArc()

LIB_ARC * SCH_LEGACY_PLUGIN_CACHE::loadArc ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3208 of file sch_legacy_plugin.cpp.

3210 {
3211  const char* line = aReader.Line();
3212 
3213  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
3214 
3215  LIB_ARC* arc = new LIB_ARC( aPart.get() );
3216 
3217  wxPoint center;
3218 
3219  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3220  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3221 
3222  arc->SetPosition( center );
3223  arc->SetRadius( Mils2Iu( parseInt( aReader, line, &line ) ) );
3224 
3225  int angle1 = parseInt( aReader, line, &line );
3226  int angle2 = parseInt( aReader, line, &line );
3227 
3228  NORMALIZE_ANGLE_POS( angle1 );
3229  NORMALIZE_ANGLE_POS( angle2 );
3230  arc->SetFirstRadiusAngle( angle1 );
3231  arc->SetSecondRadiusAngle( angle2 );
3232 
3233  arc->SetUnit( parseInt( aReader, line, &line ) );
3234  arc->SetConvert( parseInt( aReader, line, &line ) );
3235  arc->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3236 
3237  // Old libraries (version <= 2.2) do not have always this FILL MODE param
3238  // when fill mode is no fill (default mode).
3239  if( *line != 0 )
3240  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
3241 
3242  // Actual Coordinates of arc ends are read from file
3243  if( *line != 0 )
3244  {
3245  wxPoint arcStart, arcEnd;
3246 
3247  arcStart.x = Mils2Iu( parseInt( aReader, line, &line ) );
3248  arcStart.y = Mils2Iu( parseInt( aReader, line, &line ) );
3249  arcEnd.x = Mils2Iu( parseInt( aReader, line, &line ) );
3250  arcEnd.y = Mils2Iu( parseInt( aReader, line, &line ) );
3251 
3252  arc->SetStart( arcStart );
3253  arc->SetEnd( arcEnd );
3254  }
3255  else
3256  {
3257  // Actual Coordinates of arc ends are not read from file
3258  // (old library), calculate them
3259  wxPoint arcStart( arc->GetRadius(), 0 );
3260  wxPoint arcEnd( arc->GetRadius(), 0 );
3261 
3262  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
3263  arcStart += arc->GetPosition();
3264  arc->SetStart( arcStart );
3265  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
3266  arcEnd += arc->GetPosition();
3267  arc->SetEnd( arcEnd );
3268  }
3269 
3270  return arc;
3271 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:248
void SetFirstRadiusAngle(int aAngle)
Definition: lib_arc.h:105
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:257
#define Mils2Iu(x)
void SetWidth(int aWidth) override
Definition: lib_arc.h:100
void SetEnd(const wxPoint &aPoint)
Definition: lib_arc.h:115
#define NULL
const wxPoint GetPosition() const override
Definition: lib_arc.h:90
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:300
void SetSecondRadiusAngle(int aAngle)
Definition: lib_arc.h:108
int GetRadius() const
Definition: lib_arc.h:103
void SetConvert(int aConvert)
Definition: lib_item.h:297
void SetUnit(int aUnit)
Definition: lib_item.h:294
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetRadius(int aRadius)
Definition: lib_arc.h:102
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetStart(const wxPoint &aPoint)
Definition: lib_arc.h:112

References LIB_ARC::GetPosition(), LIB_ARC::GetRadius(), LINE_READER::Line(), Mils2Iu, NORMALIZE_ANGLE_POS(), NULL, parseFillMode(), parseInt(), RotatePoint(), LIB_ITEM::SetConvert(), LIB_ARC::SetEnd(), LIB_ITEM::SetFillMode(), LIB_ARC::SetFirstRadiusAngle(), LIB_ITEM::SetPosition(), LIB_ARC::SetRadius(), LIB_ARC::SetSecondRadiusAngle(), LIB_ARC::SetStart(), LIB_ITEM::SetUnit(), LIB_ARC::SetWidth(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ loadBezier()

LIB_BEZIER * SCH_LEGACY_PLUGIN_CACHE::loadBezier ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3681 of file sch_legacy_plugin.cpp.

3683 {
3684  const char* line = aReader.Line();
3685 
3686  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3687 
3688  LIB_BEZIER* bezier = new LIB_BEZIER( aPart.get() );
3689 
3690  int points = parseInt( aReader, line, &line );
3691  bezier->SetUnit( parseInt( aReader, line, &line ) );
3692  bezier->SetConvert( parseInt( aReader, line, &line ) );
3693  bezier->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3694 
3695  wxPoint pt;
3696  bezier->Reserve( points );
3697 
3698  for( int i = 0; i < points; i++ )
3699  {
3700  pt.x = Mils2Iu( parseInt( aReader, line, &line ) );
3701  pt.y = Mils2Iu( parseInt( aReader, line, &line ) );
3702  bezier->AddPoint( pt );
3703  }
3704 
3705  if( *line != 0 )
3706  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3707 
3708  return bezier;
3709 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define Mils2Iu(x)
void Reserve(size_t aCount)
Definition: lib_bezier.h:57
#define NULL
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:300
void SetConvert(int aConvert)
Definition: lib_item.h:297
void SetUnit(int aUnit)
Definition: lib_item.h:294
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetWidth(int aWidth) override
Definition: lib_bezier.h:87
void AddPoint(const wxPoint &aPoint)
Definition: lib_bezier.h:58
Define a bezier curve graphic body item.
Definition: lib_bezier.h:34

References LIB_BEZIER::AddPoint(), LINE_READER::Line(), Mils2Iu, NULL, parseFillMode(), parseInt(), LIB_BEZIER::Reserve(), LIB_ITEM::SetConvert(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetUnit(), LIB_BEZIER::SetWidth(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ loadCircle()

LIB_CIRCLE * SCH_LEGACY_PLUGIN_CACHE::loadCircle ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3274 of file sch_legacy_plugin.cpp.

3276 {
3277  const char* line = aReader.Line();
3278 
3279  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
3280 
3281  LIB_CIRCLE* circle = new LIB_CIRCLE( aPart.get() );
3282 
3283  wxPoint center;
3284 
3285  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3286  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3287 
3288  circle->SetPosition( center );
3289  circle->SetRadius( Mils2Iu( parseInt( aReader, line, &line ) ) );
3290  circle->SetUnit( parseInt( aReader, line, &line ) );
3291  circle->SetConvert( parseInt( aReader, line, &line ) );
3292  circle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3293 
3294  if( *line != 0 )
3295  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3296 
3297  return circle;
3298 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:248
#define Mils2Iu(x)
#define NULL
void SetRadius(int aRadius)
Definition: lib_circle.h:86
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:300
void SetConvert(int aConvert)
Definition: lib_item.h:297
void SetUnit(int aUnit)
Definition: lib_item.h:294
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetWidth(int aWidth) override
Definition: lib_circle.h:84

References LINE_READER::Line(), Mils2Iu, NULL, parseFillMode(), parseInt(), LIB_ITEM::SetConvert(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetPosition(), LIB_CIRCLE::SetRadius(), LIB_ITEM::SetUnit(), LIB_CIRCLE::SetWidth(), strCompare(), and wxPoint::x.

Referenced by loadDrawEntries().

◆ loadDocs()

void SCH_LEGACY_PLUGIN_CACHE::loadDocs ( )
private

Definition at line 2648 of file sch_legacy_plugin.cpp.

2649 {
2650  const char* line;
2651  wxString text;
2652  wxString aliasName;
2653  wxFileName fn = m_libFileName;
2654  LIB_PART* symbol = NULL;;
2655 
2656  fn.SetExt( DOC_EXT );
2657 
2658  // Not all libraries will have a document file.
2659  if( !fn.FileExists() )
2660  return;
2661 
2662  if( !fn.IsFileReadable() )
2663  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2664  "document file \"%s\"" ), fn.GetFullPath() ) );
2665 
2666  FILE_LINE_READER reader( fn.GetFullPath() );
2667 
2668  line = reader.ReadLine();
2669 
2670  if( !line )
2671  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2672 
2673  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2674  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2675  reader, line );
2676 
2677  while( reader.ReadLine() )
2678  {
2679  line = reader.Line();
2680 
2681  if( *line == '#' ) // Comment line.
2682  continue;
2683 
2684  if( !strCompare( "$CMP", line, &line ) != 0 )
2685  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2686 
2687  aliasName = wxString::FromUTF8( line );
2688  aliasName.Trim();
2689  aliasName = LIB_ID::FixIllegalChars( aliasName, LIB_ID::ID_SCH );
2690 
2691  LIB_PART_MAP::iterator it = m_symbols.find( aliasName );
2692 
2693  if( it == m_symbols.end() )
2694  wxLogWarning( "Symbol '%s' not found in library:\n\n"
2695  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2696  reader.LineNumber(), (int) (line - reader.Line() ) );
2697  else
2698  symbol = it->second;
2699 
2700  // Read the curent alias associated doc.
2701  // if the alias does not exist, just skip the description
2702  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2703  while( reader.ReadLine() )
2704  {
2705  line = reader.Line();
2706 
2707  if( !line )
2708  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2709 
2710  if( strCompare( "$ENDCMP", line, &line ) )
2711  break;
2712 
2713  text = FROM_UTF8( line + 2 );
2714  // Remove spaces at eol, and eol chars:
2715  text = text.Trim();
2716 
2717  switch( line[0] )
2718  {
2719  case 'D':
2720  if( symbol )
2721  symbol->SetDescription( text );
2722  break;
2723 
2724  case 'K':
2725  if( symbol )
2726  symbol->SetKeyWords( text );
2727  break;
2728 
2729  case 'F':
2730  if( symbol )
2731  {
2732  symbol->SetDocFileName( text );
2733  symbol->GetField( DATASHEET )->SetText( text );
2734  }
2735  break;
2736 
2737  case 0:
2738  case '\n':
2739  case '\r':
2740  case '#':
2741  // Empty line or commment
2742  break;
2743 
2744  default:
2745  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2746  }
2747  }
2748  }
2749 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
name of datasheet
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:114
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define DOCFILE_IDENT
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:116
#define NULL
void SetDescription(const wxString &aDescription)
void SetDocFileName(const wxString &aDocFileName)
Define a library symbol object.
#define DOC_EXT
Definition: class_library.h:49
#define THROW_IO_ERROR(msg)
#define SCH_PARSE_ERROR(text, reader, pos)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
void SetKeyWords(const wxString &aKeyWords)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:352
LIB_FIELD * GetField(int aId) const
Return pointer to the requested field.

References _, DATASHEET, DOC_EXT, DOCFILE_IDENT, LIB_ID::FixIllegalChars(), Format(), FROM_UTF8(), LIB_PART::GetField(), LIB_ID::ID_SCH, m_libFileName, m_symbols, NULL, FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_PART::SetDescription(), LIB_PART::SetDocFileName(), LIB_PART::SetKeyWords(), EDA_TEXT::SetText(), strCompare(), and THROW_IO_ERROR.

Referenced by Load().

◆ loadDrawEntries()

void SCH_LEGACY_PLUGIN_CACHE::loadDrawEntries ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader,
int  aMajorVersion,
int  aMinorVersion 
)
staticprivate

Definition at line 3125 of file sch_legacy_plugin.cpp.

3129 {
3130  const char* line = aReader.Line();
3131 
3132  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
3133 
3134  line = aReader.ReadLine();
3135 
3136  while( line )
3137  {
3138  if( strCompare( "ENDDRAW", line, &line ) )
3139  return;
3140 
3141  switch( line[0] )
3142  {
3143  case 'A': // Arc
3144  aPart->AddDrawItem( loadArc( aPart, aReader ) );
3145  break;
3146 
3147  case 'C': // Circle
3148  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
3149  break;
3150 
3151  case 'T': // Text
3152  aPart->AddDrawItem( loadText( aPart, aReader, aMajorVersion, aMinorVersion ) );
3153  break;
3154 
3155  case 'S': // Square
3156  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
3157  break;
3158 
3159  case 'X': // Pin Description
3160  aPart->AddDrawItem( loadPin( aPart, aReader ) );
3161  break;
3162 
3163  case 'P': // Polyline
3164  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
3165  break;
3166 
3167  case 'B': // Bezier Curves
3168  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
3169  break;
3170 
3171  case '#': // Comment
3172  case '\n': // Empty line
3173  case '\r':
3174  case 0:
3175  break;
3176 
3177  default:
3178  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
3179  }
3180 
3181  line = aReader.ReadLine();
3182  }
3183 
3184  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
3185 }
static LIB_POLYLINE * loadPolyLine(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_TEXT * loadText(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static LIB_CIRCLE * loadCircle(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_RECTANGLE * loadRectangle(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_BEZIER * loadBezier(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static LIB_PIN * loadPin(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_ARC * loadArc(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)

References LINE_READER::Line(), loadArc(), loadBezier(), loadCircle(), loadPin(), loadPolyLine(), loadRectangle(), loadText(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by LoadPart().

◆ loadField()

void SCH_LEGACY_PLUGIN_CACHE::loadField ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 2977 of file sch_legacy_plugin.cpp.

2979 {
2980  const char* line = aReader.Line();
2981 
2982  wxCHECK_RET( *line == 'F', "Invalid field line" );
2983 
2984  wxString text;
2985  int id;
2986 
2987  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2988  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
2989 
2990  LIB_FIELD* field;
2991 
2992  if( id >= 0 && id < MANDATORY_FIELDS )
2993  {
2994  field = aPart->GetField( id );
2995 
2996  // this will fire only if somebody broke a constructor or editor.
2997  // MANDATORY_FIELDS are always present in ram resident components, no
2998  // exceptions, and they always have their names set, even fixed fields.
2999  wxASSERT( field );
3000  }
3001  else
3002  {
3003  field = new LIB_FIELD( aPart.get(), id );
3004  aPart->AddDrawItem( field );
3005  }
3006 
3007  // Skip to the first double quote.
3008  while( *line != '"' && *line != 0 )
3009  line++;
3010 
3011  if( *line == 0 )
3012  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
3013 
3014  parseQuotedString( text, aReader, line, &line, true );
3015 
3016  field->SetText( text );
3017 
3018  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
3019  // not save like this.
3020  if( text.size() == 1 && text[0] == '~' )
3021  field->SetText( wxEmptyString );
3022  else
3023  field->SetText( text );
3024 
3025  wxPoint pos;
3026 
3027  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
3028  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
3029  field->SetPosition( pos );
3030 
3031  wxSize textSize;
3032 
3033  textSize.x = textSize.y = Mils2Iu( parseInt( aReader, line, &line ) );
3034  field->SetTextSize( textSize );
3035 
3036  char textOrient = parseChar( aReader, line, &line );
3037 
3038  if( textOrient == 'H' )
3039  field->SetTextAngle( TEXT_ANGLE_HORIZ );
3040  else if( textOrient == 'V' )
3041  field->SetTextAngle( TEXT_ANGLE_VERT );
3042  else
3043  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
3044 
3045  char textVisible = parseChar( aReader, line, &line );
3046 
3047  if( textVisible == 'V' )
3048  field->SetVisible( true );
3049  else if ( textVisible == 'I' )
3050  field->SetVisible( false );
3051  else
3052  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
3053 
3054  // It may be technically correct to use the library version to determine if the field text
3055  // attributes are present. If anyone knows if that is valid and what version that would be,
3056  // please change this to test the library version rather than an EOL or the quoted string
3057  // of the field name.
3058  if( *line != 0 && *line != '"' )
3059  {
3060  char textHJustify = parseChar( aReader, line, &line );
3061 
3062  if( textHJustify == 'C' )
3064  else if( textHJustify == 'L' )
3066  else if( textHJustify == 'R' )
3068  else
3069  SCH_PARSE_ERROR( "invalid field text horizontal justification", aReader, line );
3070 
3071  wxString attributes;
3072 
3073  parseUnquotedString( attributes, aReader, line, &line );
3074 
3075  size_t attrSize = attributes.size();
3076 
3077  if( !(attrSize == 3 || attrSize == 1 ) )
3078  SCH_PARSE_ERROR( "invalid field text attributes size", aReader, line );
3079 
3080  switch( (wxChar) attributes[0] )
3081  {
3082  case 'C': field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3083  case 'B': field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3084  case 'T': field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3085  default: SCH_PARSE_ERROR( "invalid field text vertical justification", aReader, line );
3086  }
3087 
3088  if( attrSize == 3 )
3089  {
3090  wxChar attr_1 = attributes[1];
3091  wxChar attr_2 = attributes[2];
3092 
3093  if( attr_1 == 'I' ) // Italic
3094  field->SetItalic( true );
3095  else if( attr_1 != 'N' ) // No italics is default, check for error.
3096  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
3097 
3098  if ( attr_2 == 'B' ) // Bold
3099  field->SetBold( true );
3100  else if( attr_2 != 'N' ) // No bold is default, check for error.
3101  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
3102  }
3103  }
3104 
3105  // Fields in RAM must always have names.
3106  if( id >= 0 && id < MANDATORY_FIELDS )
3107  {
3108  // Fields in RAM must always have names, because we are trying to get
3109  // less dependent on field ids and more dependent on names.
3110  // Plus assumptions are made in the field editors.
3112 
3113  // Ensure the VALUE field = the part name (can be not the case
3114  // with malformed libraries: edited by hand, or converted from other tools)
3115  if( id == VALUE )
3116  field->SetText( aPart->GetName() );
3117  }
3118  else
3119  {
3120  parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
3121  }
3122 }
#define TEXT_ANGLE_HORIZ
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:248
#define TEXT_ANGLE_VERT
void SetItalic(bool isItalic)
Definition: eda_text.h:178
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
void SetVisible(bool aVisible)
Definition: eda_text.h:184
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
#define Mils2Iu(x)
#define VALUE
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:116
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:202
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define SCH_PARSE_ERROR(text, reader, pos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:201
#define _(s)
Definition: 3d_actions.cpp:33
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:166
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
void SetBold(bool aBold)
Definition: eda_text.h:181

References _, TEMPLATE_FIELDNAME::GetDefaultFieldName(), GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, LINE_READER::Line(), LIB_FIELD::m_name, MANDATORY_FIELDS, Mils2Iu, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, EDA_TEXT::SetBold(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), LIB_ITEM::SetPosition(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, VALUE, wxPoint::x, and wxPoint::y.

Referenced by LoadPart().

◆ loadFootprintFilters()

void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3712 of file sch_legacy_plugin.cpp.

3714 {
3715  const char* line = aReader.Line();
3716 
3717  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3718 
3719  line = aReader.ReadLine();
3720 
3721  wxArrayString footprintFilters;
3722 
3723  while( line )
3724  {
3725  if( strCompare( "$ENDFPLIST", line, &line ) )
3726  {
3727  aPart->SetFootprintFilters( footprintFilters );
3728  return;
3729  }
3730 
3731  wxString footprint;
3732 
3733  parseUnquotedString( footprint, aReader, line, &line );
3734  footprintFilters.Add( footprint );
3735  line = aReader.ReadLine();
3736  }
3737 
3738  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3739 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), parseUnquotedString(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by LoadPart().

◆ loadHeader()

void SCH_LEGACY_PLUGIN_CACHE::loadHeader ( FILE_LINE_READER aReader)
private

Definition at line 2752 of file sch_legacy_plugin.cpp.

2753 {
2754  const char* line = aReader.Line();
2755 
2756  wxASSERT( strCompare( "$HEADER", line, &line ) );
2757 
2758  while( aReader.ReadLine() )
2759  {
2760  line = (char*) aReader;
2761 
2762  // The time stamp saved in old library files is not used or saved in the latest
2763  // library file version.
2764  if( strCompare( "TimeStamp", line, &line ) )
2765  continue;
2766  else if( strCompare( "$ENDHEADER", line, &line ) )
2767  return;
2768  }
2769 
2770  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2771 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by Load().

◆ LoadPart()

LIB_PART * SCH_LEGACY_PLUGIN_CACHE::LoadPart ( LINE_READER aReader,
int  aMajorVersion,
int  aMinorVersion,
LIB_PART_MAP aMap = nullptr 
)
static

Definition at line 2774 of file sch_legacy_plugin.cpp.

2776 {
2777  const char* line = aReader.Line();
2778 
2779  while( *line == '#' )
2780  aReader.ReadLine();
2781 
2782  if( !strCompare( "DEF", line, &line ) )
2783  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2784 
2785  long num;
2786  size_t pos = 4; // "DEF" plus the first space.
2787  wxString utf8Line = wxString::FromUTF8( line );
2788  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2789 
2790  if( tokens.CountTokens() < 8 )
2791  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2792 
2793  // Read DEF line:
2794  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2795 
2796  wxString name, prefix, tmp;
2797 
2798  name = tokens.GetNextToken();
2799  pos += name.size() + 1;
2800 
2801  prefix = tokens.GetNextToken();
2802  pos += prefix.size() + 1;
2803 
2804  tmp = tokens.GetNextToken();
2805  pos += tmp.size() + 1; // NumOfPins, unused.
2806 
2807  tmp = tokens.GetNextToken(); // Pin name offset.
2808 
2809  if( !tmp.ToLong( &num ) )
2810  THROW_PARSE_ERROR( "invalid pin offset", aReader.GetSource(), aReader.Line(),
2811  aReader.LineNumber(), pos );
2812 
2813  pos += tmp.size() + 1;
2814  part->SetPinNameOffset( Mils2Iu( (int)num ) );
2815 
2816  tmp = tokens.GetNextToken(); // Show pin numbers.
2817 
2818  if( !( tmp == "Y" || tmp == "N") )
2819  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2820  aReader.LineNumber(), pos );
2821 
2822  pos += tmp.size() + 1;
2823  part->SetShowPinNumbers( ( tmp == "N" ) ? false : true );
2824 
2825  tmp = tokens.GetNextToken(); // Show pin names.
2826 
2827  if( !( tmp == "Y" || tmp == "N") )
2828  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2829  aReader.LineNumber(), pos );
2830 
2831  pos += tmp.size() + 1;
2832  part->SetShowPinNames( ( tmp == "N" ) ? false : true );
2833 
2834  tmp = tokens.GetNextToken(); // Number of units.
2835 
2836  if( !tmp.ToLong( &num ) )
2837  THROW_PARSE_ERROR( "invalid unit count", aReader.GetSource(), aReader.Line(),
2838  aReader.LineNumber(), pos );
2839 
2840  pos += tmp.size() + 1;
2841  part->SetUnitCount( (int)num );
2842 
2843  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2844  if( part->GetUnitCount() < 1 )
2845  part->SetUnitCount( 1 );
2846 
2847  // Copy part name and prefix.
2848 
2849  // The root alias is added to the alias list by SetName() which is called by SetText().
2850  if( name.IsEmpty() )
2851  {
2852  part->SetName( "~" );
2853  }
2854  else if( name[0] != '~' )
2855  {
2856  part->SetName( name );
2857  }
2858  else
2859  {
2860  part->SetName( name.Right( name.Length() - 1 ) );
2861  part->GetValueField().SetVisible( false );
2862  }
2863 
2864  // Don't set the library alias, this is determined by the symbol library table.
2865  part->SetLibId( LIB_ID( wxEmptyString, part->GetName() ) );
2866 
2867  LIB_FIELD& reference = part->GetReferenceField();
2868 
2869  if( prefix == "~" )
2870  {
2871  reference.Empty();
2872  reference.SetVisible( false );
2873  }
2874  else
2875  {
2876  reference.SetText( prefix );
2877  }
2878 
2879  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2880  // The was no concept of interchangeable multiple unit symbols.
2881  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
2882  && LIB_VERSION( aMajorVersion, aMinorVersion ) <= LIB_VERSION( 2, 2 ) )
2883  {
2884  // Nothing needs to be set since the default setting for symbols with multiple
2885  // units were never interchangeable. Just parse the 0 an move on.
2886  tmp = tokens.GetNextToken();
2887  pos += tmp.size() + 1;
2888  }
2889  else
2890  {
2891  tmp = tokens.GetNextToken();
2892 
2893  if( tmp == "L" )
2894  part->LockUnits( true );
2895  else if( tmp == "F" || tmp == "0" )
2896  part->LockUnits( false );
2897  else
2898  THROW_PARSE_ERROR( "expected L, F, or 0", aReader.GetSource(), aReader.Line(),
2899  aReader.LineNumber(), pos );
2900 
2901  pos += tmp.size() + 1;
2902  }
2903 
2904  // There is the optional power component flag.
2905  if( tokens.HasMoreTokens() )
2906  {
2907  tmp = tokens.GetNextToken();
2908 
2909  if( tmp == "P" )
2910  part->SetPower();
2911  else if( tmp == "N" )
2912  part->SetNormal();
2913  else
2914  THROW_PARSE_ERROR( "expected P or N", aReader.GetSource(), aReader.Line(),
2915  aReader.LineNumber(), pos );
2916  }
2917 
2918  line = aReader.ReadLine();
2919 
2920  // Read lines until "ENDDEF" is found.
2921  while( line )
2922  {
2923  if( *line == '#' ) // Comment
2924  ;
2925  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2926  continue;
2927  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2928  loadAliases( part, aReader, aMap );
2929  else if( *line == 'F' ) // Fields
2930  loadField( part, aReader );
2931  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2932  loadDrawEntries( part, aReader, aMajorVersion, aMinorVersion );
2933  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2934  loadFootprintFilters( part, aReader );
2935  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2936  {
2937  return part.release();
2938  }
2939 
2940  line = aReader.ReadLine();
2941  }
2942 
2943  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2944 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
static void loadDrawEntries(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:184
#define LIB_VERSION(major, minor)
Definition: class_library.h:60
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
#define Mils2Iu(x)
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:116
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
static void loadField(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
void Empty()
Definition: eda_text.h:254
Define a library symbol object.
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
static void loadAliases(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, LIB_PART_MAP *aMap=nullptr)
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static void loadFootprintFilters(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
const char * name
Definition: DXF_plotter.cpp:60
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References EDA_TEXT::Empty(), LINE_READER::GetSource(), LIB_VERSION, LINE_READER::Line(), LINE_READER::LineNumber(), loadAliases(), loadDrawEntries(), loadField(), loadFootprintFilters(), Mils2Iu, name, LINE_READER::ReadLine(), SCH_PARSE_ERROR, EDA_TEXT::SetText(), EDA_TEXT::SetVisible(), strCompare(), and THROW_PARSE_ERROR.

Referenced by Load(), and SCH_LEGACY_PLUGIN::ParsePart().

◆ loadPin()

LIB_PIN * SCH_LEGACY_PLUGIN_CACHE::loadPin ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3426 of file sch_legacy_plugin.cpp.

3428 {
3429  const char* line = aReader.Line();
3430 
3431  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3432 
3433  LIB_PIN* pin = new LIB_PIN( aPart.get() );
3434 
3435  size_t pos = 2; // "X" plus ' ' space character.
3436  wxString tmp;
3437  wxString utf8Line = wxString::FromUTF8( line );
3438  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
3439 
3440  if( tokens.CountTokens() < 11 )
3441  SCH_PARSE_ERROR( "invalid pin definition", aReader, line );
3442 
3443  pin->m_name = tokens.GetNextToken();
3444  pos += pin->m_name.size() + 1;
3445  pin->m_number = tokens.GetNextToken();
3446  pos += pin->m_number.size() + 1;
3447 
3448  long num;
3449  wxPoint position;
3450 
3451  tmp = tokens.GetNextToken();
3452 
3453  if( !tmp.ToLong( &num ) )
3454  THROW_PARSE_ERROR( "invalid pin X coordinate", aReader.GetSource(), aReader.Line(),
3455  aReader.LineNumber(), pos );
3456 
3457  pos += tmp.size() + 1;
3458  position.x = Mils2Iu( (int) num );
3459 
3460  tmp = tokens.GetNextToken();
3461 
3462  if( !tmp.ToLong( &num ) )
3463  THROW_PARSE_ERROR( "invalid pin Y coordinate", aReader.GetSource(), aReader.Line(),
3464  aReader.LineNumber(), pos );
3465 
3466  pos += tmp.size() + 1;
3467  position.y = Mils2Iu( (int) num );
3468  pin->m_position = position;
3469 
3470  tmp = tokens.GetNextToken();
3471 
3472  if( !tmp.ToLong( &num ) )
3473  THROW_PARSE_ERROR( "invalid pin length", aReader.GetSource(), aReader.Line(),
3474  aReader.LineNumber(), pos );
3475 
3476  pos += tmp.size() + 1;
3477  pin->m_length = Mils2Iu( (int) num );
3478 
3479 
3480  tmp = tokens.GetNextToken();
3481 
3482  if( tmp.size() > 1 )
3483  THROW_PARSE_ERROR( "invalid pin orientation", aReader.GetSource(), aReader.Line(),
3484  aReader.LineNumber(), pos );
3485 
3486  pos += tmp.size() + 1;
3487  pin->m_orientation = tmp[0];
3488 
3489  tmp = tokens.GetNextToken();
3490 
3491  if( !tmp.ToLong( &num ) )
3492  THROW_PARSE_ERROR( "invalid pin number text size", aReader.GetSource(), aReader.Line(),
3493  aReader.LineNumber(), pos );
3494 
3495  pos += tmp.size() + 1;
3496  pin->m_numTextSize = Mils2Iu( (int) num );
3497 
3498  tmp = tokens.GetNextToken();
3499 
3500  if( !tmp.ToLong( &num ) )
3501  THROW_PARSE_ERROR( "invalid pin name text size", aReader.GetSource(), aReader.Line(),
3502  aReader.LineNumber(), pos );
3503 
3504  pos += tmp.size() + 1;
3505  pin->m_nameTextSize = Mils2Iu( (int) num );
3506 
3507  tmp = tokens.GetNextToken();
3508 
3509  if( !tmp.ToLong( &num ) )
3510  THROW_PARSE_ERROR( "invalid pin unit", aReader.GetSource(), aReader.Line(),
3511  aReader.LineNumber(), pos );
3512 
3513  pos += tmp.size() + 1;
3514  pin->m_Unit = (int) num;
3515 
3516  tmp = tokens.GetNextToken();
3517 
3518  if( !tmp.ToLong( &num ) )
3519  THROW_PARSE_ERROR( "invalid pin alternate body type", aReader.GetSource(), aReader.Line(),
3520  aReader.LineNumber(), pos );
3521 
3522  pos += tmp.size() + 1;
3523  pin->m_Convert = (int) num;
3524 
3525  tmp = tokens.GetNextToken();
3526 
3527  if( tmp.size() != 1 )
3528  THROW_PARSE_ERROR( "invalid pin type", aReader.GetSource(), aReader.Line(),
3529  aReader.LineNumber(), pos );
3530 
3531  pos += tmp.size() + 1;
3532  char type = tmp[0];
3533 
3534  wxString attributes;
3535 
3536  switch( type )
3537  {
3538  case 'I':
3540  break;
3541  case 'O':
3543  break;
3544  case 'B':
3546  break;
3547  case 'T':
3549  break;
3550  case 'P':
3552  break;
3553  case 'U':
3555  break;
3556  case 'W':
3558  break;
3559  case 'w':
3561  break;
3562  case 'C':
3564  break;
3565  case 'E':
3567  break;
3568  case 'N':
3570  break;
3571  default:
3572  THROW_PARSE_ERROR( "unknown pin type", aReader.GetSource(), aReader.Line(),
3573  aReader.LineNumber(), pos );
3574  }
3575 
3576  // Optional
3577  if( tokens.HasMoreTokens() ) /* Special Symbol defined */
3578  {
3579  tmp = tokens.GetNextToken();
3580 
3581  enum
3582  {
3583  INVERTED = 1 << 0,
3584  CLOCK = 1 << 1,
3585  LOWLEVEL_IN = 1 << 2,
3586  LOWLEVEL_OUT = 1 << 3,
3587  FALLING_EDGE = 1 << 4,
3588  NONLOGIC = 1 << 5
3589  };
3590 
3591  int flags = 0;
3592 
3593  for( int j = tmp.size(); j > 0; )
3594  {
3595  switch( tmp[--j].GetValue() )
3596  {
3597  case '~': break;
3598  case 'N': pin->m_attributes |= PIN_INVISIBLE; break;
3599  case 'I': flags |= INVERTED; break;
3600  case 'C': flags |= CLOCK; break;
3601  case 'L': flags |= LOWLEVEL_IN; break;
3602  case 'V': flags |= LOWLEVEL_OUT; break;
3603  case 'F': flags |= FALLING_EDGE; break;
3604  case 'X': flags |= NONLOGIC; break;
3605  default: THROW_PARSE_ERROR( "invalid pin attribut", aReader.GetSource(),
3606  aReader.Line(), aReader.LineNumber(), pos );
3607  }
3608 
3609  pos += 1;
3610  }
3611 
3612  switch( flags )
3613  {
3614  case 0:
3616  break;
3617  case INVERTED:
3619  break;
3620  case CLOCK:
3622  break;
3623  case INVERTED | CLOCK:
3625  break;
3626  case LOWLEVEL_IN:
3628  break;
3629  case LOWLEVEL_IN | CLOCK:
3631  break;
3632  case LOWLEVEL_OUT:
3634  break;
3635  case FALLING_EDGE:
3637  break;
3638  case NONLOGIC:
3640  break;
3641  default:
3642  SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3643  }
3644  }
3645 
3646  return pin;
3647 }
power input (GND, VCC for ICs). Must be connected to a power output.
int m_nameTextSize
Definition: lib_pin.h:80
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
GRAPHIC_PINSHAPE m_shape
Definition: lib_pin.h:73
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
int m_numTextSize
Definition: lib_pin.h:79
pin for passive components: must be connected, and can be connected to any pin
unknown electrical properties: creates always a warning when connected
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_item.h:81
wxString m_name
Definition: lib_pin.h:77
int m_length
Definition: lib_pin.h:71
std::chrono::steady_clock CLOCK
#define Mils2Iu(x)
int m_orientation
Definition: lib_pin.h:72
wxString m_number
Definition: lib_pin.h:78
#define NULL
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
#define PIN_INVISIBLE
Definition: lib_pin.h:49
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
int m_attributes
Definition: lib_pin.h:76
wxPoint m_position
Definition: lib_pin.h:70
#define SCH_PARSE_ERROR(text, reader, pos)
usual pin input: must be connected
ELECTRICAL_PINTYPE m_type
Definition: lib_pin.h:75
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
int m_Convert
Shape identification for alternate body styles.
Definition: lib_item.h:87
input or output (like port for a microprocessor)
not connected (must be left open)
output of a regulator: intended to be connected to power input pins

References CLOCK, CLOCK_LOW, FALLING_EDGE_CLOCK, LINE_READER::GetSource(), INPUT_LOW, INVERTED, INVERTED_CLOCK, LINE, LINE_READER::Line(), LINE_READER::LineNumber(), LIB_PIN::m_attributes, LIB_ITEM::m_Convert, LIB_PIN::m_length, LIB_PIN::m_name, LIB_PIN::m_nameTextSize, LIB_PIN::m_number, LIB_PIN::m_numTextSize, LIB_PIN::m_orientation, LIB_PIN::m_position, LIB_PIN::m_shape, LIB_PIN::m_type, LIB_ITEM::m_Unit, Mils2Iu, NONLOGIC, NULL, OUTPUT_LOW, PIN_INVISIBLE, PT_BIDI, PT_INPUT, PT_NC, PT_OPENCOLLECTOR, PT_OPENEMITTER, PT_OUTPUT, PT_PASSIVE, PT_POWER_IN, PT_POWER_OUT, PT_TRISTATE, PT_UNSPECIFIED, SCH_PARSE_ERROR, strCompare(), THROW_PARSE_ERROR, wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ loadPolyLine()

LIB_POLYLINE * SCH_LEGACY_PLUGIN_CACHE::loadPolyLine ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3650 of file sch_legacy_plugin.cpp.

3652 {
3653  const char* line = aReader.Line();
3654 
3655  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3656 
3657  LIB_POLYLINE* polyLine = new LIB_POLYLINE( aPart.get() );
3658 
3659  int points = parseInt( aReader, line, &line );
3660  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3661  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3662  polyLine->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3663  polyLine->Reserve( points );
3664 
3665  wxPoint pt;
3666 
3667  for( int i = 0; i < points; i++ )
3668  {
3669  pt.x = Mils2Iu( parseInt( aReader, line, &line ) );
3670  pt.y = Mils2Iu( parseInt( aReader, line, &line ) );
3671  polyLine->AddPoint( pt );
3672  }
3673 
3674  if( *line != 0 )
3675  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3676 
3677  return polyLine;
3678 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetWidth(int aWidth) override
Definition: lib_polyline.h:103
#define Mils2Iu(x)
#define NULL
void Reserve(size_t aPointCount)
Definition: lib_polyline.h:57
void AddPoint(const wxPoint &aPoint)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:300
void SetConvert(int aConvert)
Definition: lib_item.h:297
void SetUnit(int aUnit)
Definition: lib_item.h:294
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LIB_POLYLINE::AddPoint(), LINE_READER::Line(), Mils2Iu, NULL, parseFillMode(), parseInt(), LIB_POLYLINE::Reserve(), LIB_ITEM::SetConvert(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetUnit(), LIB_POLYLINE::SetWidth(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ loadRectangle()

LIB_RECTANGLE * SCH_LEGACY_PLUGIN_CACHE::loadRectangle ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3394 of file sch_legacy_plugin.cpp.

3396 {
3397  const char* line = aReader.Line();
3398 
3399  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
3400 
3401  LIB_RECTANGLE* rectangle = new LIB_RECTANGLE( aPart.get() );
3402 
3403  wxPoint pos;
3404 
3405  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
3406  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
3407  rectangle->SetPosition( pos );
3408 
3409  wxPoint end;
3410 
3411  end.x = Mils2Iu( parseInt( aReader, line, &line ) );
3412  end.y = Mils2Iu( parseInt( aReader, line, &line ) );
3413  rectangle->SetEnd( end );
3414 
3415  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3416  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3417  rectangle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3418 
3419  if( *line != 0 )
3420  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3421 
3422  return rectangle;
3423 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:248
#define Mils2Iu(x)
#define NULL
void SetWidth(int aWidth) override
Definition: lib_rectangle.h:84
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:300
void SetConvert(int aConvert)
Definition: lib_item.h:297
void SetUnit(int aUnit)
Definition: lib_item.h:294
void SetEnd(const wxPoint &aEnd)
Definition: lib_rectangle.h:86
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), Mils2Iu, NULL, parseFillMode(), parseInt(), LIB_ITEM::SetConvert(), LIB_RECTANGLE::SetEnd(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetPosition(), LIB_ITEM::SetUnit(), LIB_RECTANGLE::SetWidth(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ loadText()

LIB_TEXT * SCH_LEGACY_PLUGIN_CACHE::loadText ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader,
int  aMajorVersion,
int  aMinorVersion 
)
staticprivate

Definition at line 3301 of file sch_legacy_plugin.cpp.

3305 {
3306  const char* line = aReader.Line();
3307 
3308  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
3309 
3310  LIB_TEXT* text = new LIB_TEXT( aPart.get() );
3311 
3312  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3313 
3314  wxPoint center;
3315 
3316  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3317  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3318  text->SetPosition( center );
3319 
3320  wxSize size;
3321 
3322  size.x = size.y = Mils2Iu( parseInt( aReader, line, &line ) );
3323  text->SetTextSize( size );
3324  text->SetVisible( !parseInt( aReader, line, &line ) );
3325  text->SetUnit( parseInt( aReader, line, &line ) );
3326  text->SetConvert( parseInt( aReader, line, &line ) );
3327 
3328  wxString str;
3329 
3330  // If quoted string loading fails, load as not quoted string.
3331  if( *line == '"' )
3332  parseQuotedString( str, aReader, line, &line );
3333  else
3334  {
3335  parseUnquotedString( str, aReader, line, &line );
3336 
3337  // In old libs, "spaces" are replaced by '~' in unquoted strings:
3338  str.Replace( "~", " " );
3339  }
3340 
3341  if( !str.IsEmpty() )
3342  {
3343  // convert two apostrophes back to double quote
3344  str.Replace( "''", "\"" );
3345  }
3346 
3347  text->SetText( str );
3348 
3349  // Here things are murky and not well defined. At some point it appears the format
3350  // was changed to add text properties. However rather than add the token to the end of
3351  // the text definition, it was added after the string and no mention if the file
3352  // verion was bumped or not so this code make break on very old component libraries.
3353  //
3354  // Update: apparently even in the latest version this can be different so added a test
3355  // for end of line before checking for the text properties.
3356  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
3357  && LIB_VERSION( aMajorVersion, aMinorVersion ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3358  {
3359  if( strCompare( "Italic", line, &line ) )
3360  text->SetItalic( true );
3361  else if( !strCompare( "Normal", line, &line ) )
3362  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );
3363 
3364  if( parseInt( aReader, line, &line ) > 0 )
3365  text->SetBold( true );
3366 
3367  // Some old libaries version > 2.0 do not have these options for text justification:
3368  if( !is_eol( *line ) )
3369  {
3370  switch( parseChar( aReader, line, &line ) )
3371  {
3372  case 'L': text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
3373  case 'C': text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
3374  case 'R': text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
3375  default: SCH_PARSE_ERROR( "invalid horizontal text justication; expected L, C, or R",
3376  aReader, line );
3377  }
3378 
3379  switch( parseChar( aReader, line, &line ) )
3380  {
3381  case 'T': text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3382  case 'C': text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3383  case 'B': text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3384  default: SCH_PARSE_ERROR( "invalid vertical text justication; expected T, C, or B",
3385  aReader, line );
3386  }
3387  }
3388  }
3389 
3390  return text;
3391 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:248
Define a symbol library graphical text item.
Definition: lib_text.h:40
void SetItalic(bool isItalic)
Definition: eda_text.h:178
void SetVisible(bool aVisible)
Definition: eda_text.h:184
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
#define LIB_VERSION(major, minor)
Definition: class_library.h:60
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
#define Mils2Iu(x)
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:116
#define NULL
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:202
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
static bool is_eol(char c)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetConvert(int aConvert)
Definition: lib_item.h:297
void SetUnit(int aUnit)
Definition: lib_item.h:294
#define SCH_PARSE_ERROR(text, reader, pos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:201
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:166
void SetBold(bool aBold)
Definition: eda_text.h:181

References GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, is_eol(), LIB_VERSION, LINE_READER::Line(), Mils2Iu, NULL, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, EDA_TEXT::SetBold(), LIB_ITEM::SetConvert(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), LIB_ITEM::SetPosition(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextSize(), LIB_ITEM::SetUnit(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

◆ parseFillMode()

FILL_T SCH_LEGACY_PLUGIN_CACHE::parseFillMode ( LINE_READER aReader,
const char *  aLine,
const char **  aOutput 
)
staticprivate

Definition at line 3188 of file sch_legacy_plugin.cpp.

3190 {
3191  switch ( parseChar( aReader, aLine, aOutput ) )
3192  {
3193  case 'F':
3194  return FILLED_SHAPE;
3195  case 'f':
3196  return FILLED_WITH_BG_BODYCOLOR;
3197  case 'N':
3198  return NO_FILL;
3199  default:
3200  SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
3201  }
3202 
3203  // This will never be reached but quiets the compiler warnings
3204  return NO_FILL;
3205 }
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
#define SCH_PARSE_ERROR(text, reader, pos)

References FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR, NO_FILL, parseChar(), and SCH_PARSE_ERROR.

Referenced by loadArc(), loadBezier(), loadCircle(), loadPolyLine(), and loadRectangle().

◆ removeSymbol()

LIB_PART * SCH_LEGACY_PLUGIN_CACHE::removeSymbol ( LIB_PART aAlias)
private

Definition at line 2478 of file sch_legacy_plugin.cpp.

2479 {
2480  wxCHECK_MSG( aPart != NULL, NULL, "NULL pointer cannot be removed from library." );
2481 
2482  LIB_PART* firstChild = NULL;
2483  LIB_PART_MAP::iterator it = m_symbols.find( aPart->GetName() );
2484 
2485  if( it == m_symbols.end() )
2486  return NULL;
2487 
2488  // If the entry pointer doesn't match the name it is mapped to in the library, we
2489  // have done something terribly wrong.
2490  wxCHECK_MSG( *it->second == aPart, NULL,
2491  "Pointer mismatch while attempting to remove alias entry <" + aPart->GetName() +
2492  "> from library cache <" + m_libFileName.GetName() + ">." );
2493 
2494  // If the symbol is a root symbol used by other symbols find the first alias that uses
2495  // the root part and make it the new root.
2496  if( aPart->IsRoot() )
2497  {
2498  for( auto entry : m_symbols )
2499  {
2500  if( entry.second->IsAlias()
2501  && entry.second->GetParent().lock() == aPart->SharedPtr() )
2502  {
2503  firstChild = entry.second;
2504  break;
2505  }
2506  }
2507 
2508  if( firstChild )
2509  {
2510  for( LIB_ITEM& drawItem : aPart->GetDrawItems() )
2511  {
2512  if( drawItem.Type() == LIB_FIELD_T )
2513  {
2514  LIB_FIELD& field = static_cast<LIB_FIELD&>( drawItem );
2515 
2516  if( firstChild->FindField( field.GetCanonicalName() ) )
2517  continue;
2518  }
2519 
2520  LIB_ITEM* newItem = (LIB_ITEM*) drawItem.Clone();
2521  drawItem.SetParent( firstChild );
2522  firstChild->AddDrawItem( newItem );
2523  }
2524 
2525  // Reparent the remaining aliases.
2526  for( auto entry : m_symbols )
2527  {
2528  if( entry.second->IsAlias()
2529  && entry.second->GetParent().lock() == aPart->SharedPtr() )
2530  entry.second->SetParent( firstChild );
2531  }
2532  }
2533  }
2534 
2535  m_symbols.erase( it );
2536  delete aPart;
2537  m_isModified = true;
2538  ++m_modHash;
2539  return firstChild;
2540 }
Field object used in symbol libraries.
Definition: lib_field.h:59
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:200
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
The base class for drawable items used by schematic library components.
Definition: lib_item.h:61
void AddDrawItem(LIB_ITEM *aItem)
Add a new draw aItem to the draw object list.
LIB_FIELD * FindField(const wxString &aFieldName)
Find a field within this part matching aFieldName and returns it or NULL if not found.
#define NULL
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: lib_field.cpp:375
Define a library symbol object.

References LIB_PART::AddDrawItem(), EDA_ITEM::Clone(), LIB_PART::FindField(), LIB_FIELD::GetCanonicalName(), LIB_PART::GetDrawItems(), LIB_PART::GetName(), LIB_PART::IsRoot(), LIB_FIELD_T, m_isModified, m_libFileName, m_modHash, m_symbols, NULL, EDA_ITEM::SetParent(), and LIB_PART::SharedPtr().

Referenced by AddSymbol().

◆ Save()

void SCH_LEGACY_PLUGIN_CACHE::Save ( bool  aSaveDocFile = true)

Save the entire library to file m_libFileName;.

Definition at line 3742 of file sch_legacy_plugin.cpp.

3743 {
3744  if( !m_isModified )
3745  return;
3746 
3747  // Write through symlinks, don't replace them
3748  wxFileName fn = GetRealFile();
3749 
3750  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( fn.GetFullPath() ) );
3751  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3752  formatter->Print( 0, "#encoding utf-8\n");
3753 
3754  for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); it++ )
3755  {
3756  if( !it->second->IsRoot() )
3757  continue;
3758 
3759  SaveSymbol( it->second, *formatter.get(), &m_symbols );
3760  }
3761 
3762  formatter->Print( 0, "#\n#End Library\n" );
3763  formatter.reset();
3764 
3765  m_fileModTime = fn.GetModificationTime();
3766  m_isModified = false;
3767 
3768  if( aSaveDocFile )
3769  saveDocFile();
3770 }
#define LIBFILE_IDENT
Definition: class_library.h:58
#define LIB_VERSION_MINOR
Definition: class_library.h:55
#define LIB_VERSION_MAJOR
Definition: class_library.h:54
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_PART_MAP *aMap=nullptr)
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
wxFileName GetRealFile() const

References GetRealFile(), LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIBFILE_IDENT, m_fileModTime, m_isModified, m_symbols, saveDocFile(), and SaveSymbol().

Referenced by SCH_LEGACY_PLUGIN::CreateSymbolLib(), SCH_LEGACY_PLUGIN::DeleteSymbol(), SCH_LEGACY_PLUGIN::SaveLibrary(), and SCH_LEGACY_PLUGIN::SaveSymbol().

◆ saveArc()

void SCH_LEGACY_PLUGIN_CACHE::saveArc ( LIB_ARC aArc,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 3946 of file sch_legacy_plugin.cpp.

3948 {
3949  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
3950 
3951  int x1 = aArc->GetFirstRadiusAngle();
3952 
3953  if( x1 > 1800 )
3954  x1 -= 3600;
3955 
3956  int x2 = aArc->GetSecondRadiusAngle();
3957 
3958  if( x2 > 1800 )
3959  x2 -= 3600;
3960 
3961  aFormatter.Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
3962  Iu2Mils( aArc->GetPosition().x ), Iu2Mils( aArc->GetPosition().y ),
3963  Iu2Mils( aArc->GetRadius() ), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
3964  Iu2Mils( aArc->GetWidth() ), fill_tab[aArc->GetFillMode()],
3965  Iu2Mils( aArc->GetStart().x ), Iu2Mils( aArc->GetStart().y ),
3966  Iu2Mils( aArc->GetEnd().x ), Iu2Mils( aArc->GetEnd().y ) );
3967 }
FILL_T GetFillMode() const
Definition: lib_item.h:301
int GetSecondRadiusAngle() const
Definition: lib_arc.h:109
int GetUnit() const
Definition: lib_item.h:295
const wxPoint GetPosition() const override
Definition: lib_arc.h:90
wxPoint GetStart() const
Definition: lib_arc.h:111
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetConvert() const
Definition: lib_item.h:298
int GetRadius() const
Definition: lib_arc.h:103
int GetWidth() const override
Definition: lib_arc.h:99
wxPoint GetEnd() const
Definition: lib_arc.h:114
int GetFirstRadiusAngle() const
Definition: lib_arc.h:106
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

References fill_tab, LIB_ITEM::GetConvert(), LIB_ARC::GetEnd(), LIB_ITEM::GetFillMode(), LIB_ARC::GetFirstRadiusAngle(), LIB_ARC::GetPosition(), LIB_ARC::GetRadius(), LIB_ARC::GetSecondRadiusAngle(), LIB_ARC::GetStart(), LIB_ITEM::GetUnit(), LIB_ARC::GetWidth(), LIB_ARC_T, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ saveBezier()

void SCH_LEGACY_PLUGIN_CACHE::saveBezier ( LIB_BEZIER aBezier,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 3970 of file sch_legacy_plugin.cpp.

3972 {
3973  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
3974 
3975  aFormatter.Print( 0, "B %u %d %d %d", (unsigned)aBezier->GetPoints().size(),
3976  aBezier->GetUnit(), aBezier->GetConvert(), Iu2Mils( aBezier->GetWidth() ) );
3977 
3978  for( const auto& pt : aBezier->GetPoints() )
3979  aFormatter.Print( 0, " %d %d", Iu2Mils( pt.x ), Iu2Mils( pt.y ) );
3980 
3981  aFormatter.Print( 0, " %c\n", fill_tab[aBezier->GetFillMode()] );
3982 }
FILL_T GetFillMode() const
Definition: lib_item.h:301
int GetWidth() const override
Definition: lib_bezier.h:86
int GetUnit() const
Definition: lib_item.h:295
const int fill_tab[3]
Definition: lib_item.cpp:34
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:68
int GetConvert() const
Definition: lib_item.h:298
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

References fill_tab, LIB_ITEM::GetConvert(), LIB_ITEM::GetFillMode(), LIB_BEZIER::GetPoints(), LIB_ITEM::GetUnit(), LIB_BEZIER::GetWidth(), LIB_BEZIER_T, OUTPUTFORMATTER::Print(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ saveCircle()

void SCH_LEGACY_PLUGIN_CACHE::saveCircle ( LIB_CIRCLE aCircle,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 3985 of file sch_legacy_plugin.cpp.

3987 {
3988  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
3989 
3990  aFormatter.Print( 0, "C %d %d %d %d %d %d %c\n",
3991  Iu2Mils( aCircle->GetPosition().x ), Iu2Mils( aCircle->GetPosition().y ),
3992  Iu2Mils( aCircle->GetRadius() ), aCircle->GetUnit(), aCircle->GetConvert(),
3993  Iu2Mils( aCircle->GetWidth() ), fill_tab[aCircle->GetFillMode()] );
3994 }
FILL_T GetFillMode() const
Definition: lib_item.h:301
int GetWidth() const override
Definition: lib_circle.h:83
int GetUnit() const
Definition: lib_item.h:295
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetRadius() const
Definition: lib_circle.h:87
int GetConvert() const
Definition: lib_item.h:298
const wxPoint GetPosition() const override
Definition: lib_circle.h:71
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

References fill_tab, LIB_ITEM::GetConvert(), LIB_ITEM::GetFillMode(), LIB_CIRCLE::GetPosition(), LIB_CIRCLE::GetRadius(), LIB_ITEM::GetUnit(), LIB_CIRCLE::GetWidth(), LIB_CIRCLE_T, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ saveDocFile()

void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 4238 of file sch_legacy_plugin.cpp.

4239 {
4240  wxFileName fileName = m_libFileName;
4241 
4242  fileName.SetExt( DOC_EXT );
4243  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
4244 
4245  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
4246 
4247  for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); ++it )
4248  {
4249  wxString description = it->second->GetDescription();
4250  wxString keyWords = it->second->GetKeyWords();
4251  wxString docFileName = it->second->GetDocFileName();
4252 
4253  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
4254  continue;
4255 
4256  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
4257 
4258  if( !description.IsEmpty() )
4259  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
4260 
4261  if( !keyWords.IsEmpty() )
4262  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
4263 
4264  if( !docFileName.IsEmpty() )
4265  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
4266 
4267  formatter.Print( 0, "$ENDCMP\n" );
4268  }
4269 
4270  formatter.Print( 0, "#\n#End Doc Library\n" );
4271 }
#define DOCFILE_IDENT
#define DOC_EXT
Definition: class_library.h:49
#define TO_UTF8(wxstring)
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References DOC_EXT, DOCFILE_IDENT, m_libFileName, m_symbols, OUTPUTFORMATTER::Print(), and TO_UTF8.

Referenced by Save().

◆ saveField()

void SCH_LEGACY_PLUGIN_CACHE::saveField ( LIB_FIELD aField,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 3997 of file sch_legacy_plugin.cpp.

3999 {
4000  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
4001 
4002  int hjustify, vjustify;
4003  int id = aField->GetId();
4004  wxString text = aField->GetText();
4005 
4006  hjustify = 'C';
4007 
4008  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
4009  hjustify = 'L';
4010  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
4011  hjustify = 'R';
4012 
4013  vjustify = 'C';
4014 
4015  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
4016  vjustify = 'B';
4017  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
4018  vjustify = 'T';
4019 
4020  aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
4021  id,
4022  EscapedUTF8( text ).c_str(), // wraps in quotes
4023  Iu2Mils( aField->GetTextPos().x ), Iu2Mils( aField->GetTextPos().y ),
4024  Iu2Mils( aField->GetTextWidth() ),
4025  aField->GetTextAngle() == 0 ? 'H' : 'V',
4026  aField->IsVisible() ? 'V' : 'I',
4027  hjustify, vjustify,
4028  aField->IsItalic() ? 'I' : 'N',
4029  aField->IsBold() ? 'B' : 'N' );
4030 
4031  /* Save field name, if necessary
4032  * Field name is saved only if it is not the default name.
4033  * Just because default name depends on the language and can change from
4034  * a country to another
4035  */
4036  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
4037 
4038  if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
4039  aFormatter.Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
4040 
4041  aFormatter.Print( 0, "\n" );
4042 }
bool IsBold() const
Definition: eda_text.h:182
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
bool IsVisible() const
Definition: eda_text.h:185
double GetTextAngle() const
Definition: eda_text.h:173
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
int GetId() const
Definition: lib_field.h:138
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:283
bool IsItalic() const
Definition: eda_text.h:179
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
int GetTextWidth() const
Definition: eda_text.h:241
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

References EscapedUTF8(), FIELD1, TEMPLATE_FIELDNAME::GetDefaultFieldName(), EDA_TEXT::GetHorizJustify(), LIB_FIELD::GetId(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetTextWidth(), EDA_TEXT::GetVertJustify(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, EDA_TEXT::IsBold(), EDA_TEXT::IsItalic(), EDA_TEXT::IsVisible(), LIB_FIELD_T, LIB_FIELD::m_name, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ savePin()

void SCH_LEGACY_PLUGIN_CACHE::savePin ( LIB_PIN aPin,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4045 of file sch_legacy_plugin.cpp.

4047 {
4048  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
4049 
4050  int Etype;
4051 
4052  switch( aPin->GetType() )
4053  {
4054  default:
4056  Etype = 'I';
4057  break;
4058 
4060  Etype = 'O';
4061  break;
4062 
4064  Etype = 'B';
4065  break;
4066 
4068  Etype = 'T';
4069  break;
4070 
4072  Etype = 'P';
4073  break;
4074 
4076  Etype = 'U';
4077  break;
4078 
4080  Etype = 'W';
4081  break;
4082 
4084  Etype = 'w';
4085  break;
4086 
4088  Etype = 'C';
4089  break;
4090 
4092  Etype = 'E';
4093  break;
4094 
4096  Etype = 'N';
4097  break;
4098  }
4099 
4100  if( !aPin->GetName().IsEmpty() )
4101  aFormatter.Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
4102  else
4103  aFormatter.Print( 0, "X ~" );
4104 
4105  aFormatter.Print( 0, " %s %d %d %d %c %d %d %d %d %c",
4106  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
4107  Iu2Mils( aPin->GetPosition().x ), Iu2Mils( aPin->GetPosition().y ),
4108  Iu2Mils( (int) aPin->GetLength() ), (int) aPin->GetOrientation(),
4109  Iu2Mils( aPin->GetNumberTextSize() ), Iu2Mils( aPin->GetNameTextSize() ),
4110  aPin->GetUnit(), aPin->GetConvert(), Etype );
4111 
4112  if( aPin->GetShape() != GRAPHIC_PINSHAPE::LINE || !aPin->IsVisible() )
4113  aFormatter.Print( 0, " " );
4114 
4115  if( !aPin->IsVisible() )
4116  aFormatter.Print( 0, "N" );
4117 
4118  switch( aPin->GetShape() )
4119  {
4121  break;
4122 
4124  aFormatter.Print( 0, "I" );
4125  break;
4126 
4128  aFormatter.Print( 0, "C" );
4129  break;
4130 
4132  aFormatter.Print( 0, "IC" );
4133  break;
4134 
4136  aFormatter.Print( 0, "L" );
4137  break;
4138 
4140  aFormatter.Print( 0, "CL" );
4141  break;
4142 
4144  aFormatter.Print( 0, "V" );
4145  break;
4146 
4148  aFormatter.Print( 0, "F" );
4149  break;
4150 
4152  aFormatter.Print( 0, "X" );
4153  break;
4154 
4155  default:
4156  assert( !"Invalid pin shape" );
4157  }
4158 
4159  aFormatter.Print( 0, "\n" );
4160 
4161  aPin->ClearFlags( IS_CHANGED );
4162 }
power input (GND, VCC for ICs). Must be connected to a power output.
int GetOrientation() const
Definition: lib_pin.h:206
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:218
pin for passive components: must be connected, and can be connected to any pin
unknown electrical properties: creates always a warning when connected
int GetUnit() const
Definition: lib_item.h:295
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:113
const wxString & GetName() const
Definition: lib_pin.h:151
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:345
int GetNameTextSize() const
Definition: lib_pin.h:177
const wxPoint GetPosition() const override
Definition: lib_pin.h:430
int GetConvert() const
Definition: lib_item.h:298
const wxString & GetNumber() const
Definition: lib_pin.h:179
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:234
int GetNumberTextSize() const
Definition: lib_pin.h:204
usual pin input: must be connected
#define TO_UTF8(wxstring)
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:240
input or output (like port for a microprocessor)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
not connected (must be left open)
int GetLength()
Definition: lib_pin.h:284
output of a regulator: intended to be connected to power input pins
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

References EDA_ITEM::ClearFlags(), CLOCK, CLOCK_LOW, FALLING_EDGE_CLOCK, LIB_ITEM::GetConvert(), LIB_PIN::GetLength(), LIB_PIN::GetName(), LIB_PIN::GetNameTextSize(), LIB_PIN::GetNumber(), LIB_PIN::GetNumberTextSize(), LIB_PIN::GetOrientation(), LIB_PIN::GetPosition(), LIB_PIN::GetShape(), LIB_PIN::GetType(), LIB_ITEM::GetUnit(), INPUT_LOW, INVERTED, INVERTED_CLOCK, IS_CHANGED, LIB_PIN::IsVisible(), LIB_PIN_T, LINE, NONLOGIC, OUTPUT_LOW, OUTPUTFORMATTER::Print(), PT_BIDI, PT_INPUT, PT_NC, PT_OPENCOLLECTOR, PT_OPENEMITTER, PT_OUTPUT, PT_PASSIVE, PT_POWER_IN, PT_POWER_OUT, PT_TRISTATE, PT_UNSPECIFIED, TO_UTF8, EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ savePolyLine()

void SCH_LEGACY_PLUGIN_CACHE::savePolyLine ( LIB_POLYLINE aPolyLine,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4165 of file sch_legacy_plugin.cpp.

4167 {
4168  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
4169 
4170  int ccount = aPolyLine->GetCornerCount();
4171 
4172  aFormatter.Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
4173  Iu2Mils( aPolyLine->GetWidth() ) );
4174 
4175  for( const auto& pt : aPolyLine->GetPolyPoints() )
4176  {
4177  aFormatter.Print( 0, " %d %d", Iu2Mils( pt.x ), Iu2Mils( pt.y ) );
4178  }
4179 
4180  aFormatter.Print( 0, " %c\n", fill_tab[aPolyLine->GetFillMode()] );
4181 }
FILL_T GetFillMode() const
Definition: lib_item.h:301
int GetWidth() const override
Definition: lib_polyline.h:102
unsigned GetCornerCount() const
Definition: lib_polyline.h:73
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:60
int GetUnit() const
Definition: lib_item.h:295
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetConvert() const
Definition: lib_item.h:298
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

References fill_tab, LIB_ITEM::GetConvert(), LIB_POLYLINE::GetCornerCount(), LIB_ITEM::GetFillMode(), LIB_POLYLINE::GetPolyPoints(), LIB_ITEM::GetUnit(), LIB_POLYLINE::GetWidth(), LIB_POLYLINE_T, OUTPUTFORMATTER::Print(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ saveRectangle()

void SCH_LEGACY_PLUGIN_CACHE::saveRectangle ( LIB_RECTANGLE aRectangle,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4184 of file sch_legacy_plugin.cpp.

4186 {
4187  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
4188  "Invalid LIB_RECTANGLE object." );
4189 
4190  aFormatter.Print( 0, "S %d %d %d %d %d %d %d %c\n",
4191  Iu2Mils( aRectangle->GetPosition().x ),
4192  Iu2Mils( aRectangle->GetPosition().y ),
4193  Iu2Mils( aRectangle->GetEnd().x ), Iu2Mils( aRectangle->GetEnd().y ),
4194  aRectangle->GetUnit(), aRectangle->GetConvert(),
4195  Iu2Mils( aRectangle->GetWidth() ), fill_tab[aRectangle->GetFillMode()] );
4196 }
wxPoint GetEnd() const
Definition: lib_rectangle.h:87
FILL_T GetFillMode() const
Definition: lib_item.h:301
const wxPoint GetPosition() const override
Definition: lib_rectangle.h:74
int GetUnit() const
Definition: lib_item.h:295
int GetWidth() const override
Definition: lib_rectangle.h:83
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetConvert() const
Definition: lib_item.h:298
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

References fill_tab, LIB_ITEM::GetConvert(), LIB_RECTANGLE::GetEnd(), LIB_ITEM::GetFillMode(), LIB_RECTANGLE::GetPosition(), LIB_ITEM::GetUnit(), LIB_RECTANGLE::GetWidth(), LIB_RECTANGLE_T, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ SaveSymbol()

void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol ( LIB_PART aSymbol,
OUTPUTFORMATTER aFormatter,
LIB_PART_MAP aMap = nullptr 
)
static

Definition at line 3773 of file sch_legacy_plugin.cpp.

3775 {
3776  wxCHECK_RET( aSymbol && aSymbol->IsRoot(), "Invalid LIB_PART pointer." );
3777 
3778  // LIB_ALIAS objects are deprecated but we still need to gather up the derived symbols
3779  // and save their names for the old file format.
3780  wxArrayString aliasNames;
3781 
3782  if( aMap )
3783  {
3784  for( auto entry : *aMap )
3785  {
3786  LIB_PART* part = entry.second;
3787 
3788  if( part->IsAlias() && part->GetParent().lock() == aSymbol->SharedPtr() )
3789  aliasNames.Add( part->GetName() );
3790  }
3791  }
3792 
3793  LIB_FIELD& value = aSymbol->GetValueField();
3794 
3795  // First line: it s a comment (component name for readers)
3796  aFormatter.Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3797 
3798  // Save data
3799  aFormatter.Print( 0, "DEF" );
3800  aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) );
3801 
3802  LIB_FIELD& reference = aSymbol->GetReferenceField();
3803 
3804  if( !reference.GetText().IsEmpty() )
3805  {
3806  aFormatter.Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3807  }
3808  else
3809  {
3810  aFormatter.Print( 0, " ~" );
3811  }
3812 
3813  aFormatter.Print( 0, " %d %d %c %c %d %c %c\n",
3814  0, Iu2Mils( aSymbol->GetPinNameOffset() ),
3815  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3816  aSymbol->ShowPinNames() ? 'Y' : 'N',
3817  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3818  aSymbol->IsPower() ? 'P' : 'N' );
3819 
3820  timestamp_t dateModified = aSymbol->GetDateLastEdition();
3821 
3822  if( dateModified != 0 )
3823  {
3824  int sec = dateModified & 63;
3825  int min = ( dateModified >> 6 ) & 63;
3826  int hour = ( dateModified >> 12 ) & 31;
3827  int day = ( dateModified >> 17 ) & 31;
3828  int mon = ( dateModified >> 22 ) & 15;
3829  int year = ( dateModified >> 26 ) + 1990;
3830 
3831  aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3832  }
3833 
3834  LIB_FIELDS fields;
3835  aSymbol->GetFields( fields );
3836 
3837  // Mandatory fields:
3838  // may have their own save policy so there is a separate loop for them.
3839  // Empty fields are saved, because the user may have set visibility,
3840  // size and orientation
3841  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3842  {
3843  saveField( &fields[i], aFormatter );
3844  }
3845 
3846  // User defined fields:
3847  // may have their own save policy so there is a separate loop for them.
3848 
3849  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3850 
3851  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3852  {
3853  // There is no need to save empty fields, i.e. no reason to preserve field
3854  // names now that fields names come in dynamically through the template
3855  // fieldnames.
3856  if( !fields[i].GetText().IsEmpty() )
3857  {
3858  fields[i].SetId( fieldId++ );
3859  saveField( &fields[i], aFormatter );
3860  }
3861  }
3862 
3863  // Save the alias list: a line starting by "ALIAS".
3864  if( !aliasNames.IsEmpty() )
3865  {
3866  aFormatter.Print( 0, "ALIAS" );
3867 
3868  for( unsigned i = 0; i < aliasNames.GetCount(); i++ )
3869  {
3870  aFormatter.Print( 0, " %s", TO_UTF8( aliasNames[i] ) );
3871  }
3872 
3873  aFormatter.Print( 0, "\n" );
3874  }
3875 
3876  wxArrayString footprints = aSymbol->GetFootprints();
3877 
3878  // Write the footprint filter list
3879  if( footprints.GetCount() != 0 )
3880  {
3881  aFormatter.Print( 0, "$FPLIST\n" );
3882 
3883  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3884  {
3885  aFormatter.Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3886  }
3887 
3888  aFormatter.Print( 0, "$ENDFPLIST\n" );
3889  }
3890 
3891  // Save graphics items (including pins)
3892  if( !aSymbol->GetDrawItems().empty() )
3893  {
3894  // Sort the draw items in order to editing a file editing by hand.
3895  aSymbol->GetDrawItems().sort();
3896 
3897  aFormatter.Print( 0, "DRAW\n" );
3898 
3899  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3900  {
3901  switch( item.Type() )
3902  {
3903  case LIB_FIELD_T: // Fields have already been saved above.
3904  continue;
3905 
3906  case LIB_ARC_T:
3907  saveArc( (LIB_ARC*) &item, aFormatter );
3908  break;
3909 
3910  case LIB_BEZIER_T:
3911  saveBezier( (LIB_BEZIER*) &item, aFormatter );
3912  break;
3913 
3914  case LIB_CIRCLE_T:
3915  saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
3916  break;
3917 
3918  case LIB_PIN_T:
3919  savePin( (LIB_PIN* ) &item, aFormatter );
3920  break;
3921 
3922  case LIB_POLYLINE_T:
3923  savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
3924  break;
3925 
3926  case LIB_RECTANGLE_T:
3927  saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
3928  break;
3929 
3930  case LIB_TEXT_T:
3931  saveText( ( LIB_TEXT* ) &item, aFormatter );
3932  break;
3933 
3934  default:
3935  ;
3936  }
3937  }
3938 
3939  aFormatter.Print( 0, "ENDDRAW\n" );
3940  }
3941 
3942  aFormatter.Print( 0, "ENDDEF\n" );
3943 }
static void saveCircle(LIB_CIRCLE *aCircle, OUTPUTFORMATTER &aFormatter)
int GetPinNameOffset()
wxString GetName() const override
Define a symbol library graphical text item.
Definition: lib_text.h:40
timestamp_t GetDateLastEdition() const
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:237
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
void sort()
Definition: multivector.h:242
LIB_FIELD & GetValueField()
Return reference to the value field.
static void savePin(LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter)
static void saveBezier(LIB_BEZIER *aBezier, OUTPUTFORMATTER &aFormatter)
static void saveField(LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter)
The base class for drawable items used by schematic library components.
Definition: lib_item.h:61
bool ShowPinNames()
bool ShowPinNumbers()
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
int GetUnitCount() const override
For items with units, return the number of units.
static void saveText(LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter)
static void saveRectangle(LIB_RECTANGLE *aRectangle, OUTPUTFORMATTER &aFormatter)
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
wxString GetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_shape.cpp:58
PART_SPTR SharedPtr()
PART_REF & GetParent()
static void savePolyLine(LIB_POLYLINE *aPolyLine, OUTPUTFORMATTER &aFormatter)
Define a library symbol object.
wxArrayString GetFootprints() const
bool IsPower() const
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:218
bool IsAlias() const
static void saveArc(LIB_ARC *aArc, OUTPUTFORMATTER &aFormatter)
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
#define TO_UTF8(wxstring)
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:56
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
bool UnitsLocked() const
Check whether part units are interchangeable.
void GetFields(LIB_FIELDS &aList)
Return a list of fields within this part.
Define a bezier curve graphic body item.
Definition: lib_bezier.h:34

References MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::empty(), LIB_PART::GetDateLastEdition(), LIB_PART::GetDrawItems(), LIB_PART::GetFields(), LIB_PART::GetFootprints(), LIB_PART::GetName(), LIB_PART::GetParent(), LIB_PART::GetPinNameOffset(), LIB_PART::GetReferenceField(), GetText(), EDA_TEXT::GetText(), LIB_PART::GetUnitCount(), LIB_PART::GetValueField(), LIB_PART::IsAlias(), LIB_PART::IsPower(), LIB_PART::IsRoot(), LIB_ARC_T, LIB_BEZIER_T, LIB_CIRCLE_T, LIB_FIELD_T, LIB_PIN_T, LIB_POLYLINE_T, LIB_RECTANGLE_T, LIB_TEXT_T, MANDATORY_FIELDS, OUTPUTFORMATTER::Print(), saveArc(), saveBezier(), saveCircle(), saveField(), savePin(), savePolyLine(), saveRectangle(), saveText(), LIB_PART::SharedPtr(), LIB_PART::ShowPinNames(), LIB_PART::ShowPinNumbers(), MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::sort(), TO_UTF8, and LIB_PART::UnitsLocked().

Referenced by SCH_LEGACY_PLUGIN::FormatPart(), and Save().

◆ saveText()

void SCH_LEGACY_PLUGIN_CACHE::saveText ( LIB_TEXT aText,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4199 of file sch_legacy_plugin.cpp.

4201 {
4202  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
4203 
4204  wxString text = aText->GetText();
4205 
4206  if( text.Contains( wxT( " " ) ) || text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
4207  {
4208  // convert double quote to similar-looking two apostrophes
4209  text.Replace( wxT( "\"" ), wxT( "''" ) );
4210  text = wxT( "\"" ) + text + wxT( "\"" );
4211  }
4212 
4213  aFormatter.Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
4214  Iu2Mils( aText->GetTextPos().x ), Iu2Mils( aText->GetTextPos().y ),
4215  Iu2Mils( aText->GetTextWidth() ), !aText->IsVisible(),
4216  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
4217 
4218  aFormatter.Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
4219 
4220  char hjustify = 'C';
4221 
4222  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
4223  hjustify = 'L';
4224  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
4225  hjustify = 'R';
4226 
4227  char vjustify = 'C';
4228 
4229  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
4230  vjustify = 'B';
4231  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
4232  vjustify = 'T';
4233 
4234  aFormatter.Print( 0, " %c %c\n", hjustify, vjustify );
4235 }
bool IsBold() const
Definition: eda_text.h:182
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
bool IsVisible() const
Definition: eda_text.h:185
double GetTextAngle() const
Definition: eda_text.h:173
bool IsItalic() const
Definition: eda_text.h:179
int GetUnit() const
Definition: lib_item.h:295
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
int GetConvert() const
Definition: lib_item.h:298
int GetTextWidth() const
Definition: eda_text.h:241
#define TO_UTF8(wxstring)
const wxPoint & GetTextPos() const
Definition: eda_text.h:247
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

References LIB_ITEM::GetConvert(), EDA_TEXT::GetHorizJustify(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextPos(), EDA_TEXT::GetTextWidth(), LIB_ITEM::GetUnit(), EDA_TEXT::GetVertJustify(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, EDA_TEXT::IsBold(), EDA_TEXT::IsItalic(), EDA_TEXT::IsVisible(), LIB_TEXT_T, OUTPUTFORMATTER::Print(), TO_UTF8, EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by SaveSymbol().

◆ SetFileName()

void SCH_LEGACY_PLUGIN_CACHE::SetFileName ( const wxString &  aFileName)
inline

Definition at line 556 of file sch_legacy_plugin.cpp.

556 { m_libFileName = aFileName; }

References m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

◆ SetModified()

void SCH_LEGACY_PLUGIN_CACHE::SetModified ( bool  aModified = true)
inline

Member Data Documentation

◆ m_fileModTime

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

Definition at line 481 of file sch_legacy_plugin.cpp.

Referenced by IsFileChanged(), Load(), and Save().

◆ m_fileName

wxString SCH_LEGACY_PLUGIN_CACHE::m_fileName
private

Definition at line 479 of file sch_legacy_plugin.cpp.

Referenced by IsFile().

◆ m_isModified

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 484 of file sch_legacy_plugin.cpp.

Referenced by AddSymbol(), DeleteSymbol(), removeSymbol(), Save(), and SetModified().

◆ m_isWritable

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

Definition at line 483 of file sch_legacy_plugin.cpp.

Referenced by GetLibModificationTime().

◆ m_libFileName

wxFileName SCH_LEGACY_PLUGIN_CACHE::m_libFileName
private

◆ m_libType

int SCH_LEGACY_PLUGIN_CACHE::m_libType
private

Definition at line 487 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ m_modHash

int SCH_LEGACY_PLUGIN_CACHE::m_modHash = 1
staticprivate

Definition at line 477 of file sch_legacy_plugin.cpp.

Referenced by AddSymbol(), DeleteSymbol(), GetModifyHash(), Load(), and removeSymbol().

◆ m_symbols

◆ m_versionMajor

int SCH_LEGACY_PLUGIN_CACHE::m_versionMajor
private

Definition at line 485 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ m_versionMinor

int SCH_LEGACY_PLUGIN_CACHE::m_versionMinor
private

Definition at line 486 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ SCH_LEGACY_PLUGIN

friend SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN
private

Definition at line 522 of file sch_legacy_plugin.cpp.


The documentation for this class was generated from the following file: