KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN_CACHE Class Reference

Class SCH_LEGACY_PLUGIN_CACHE is 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 DeleteAlias (const wxString &aAliasName)
 
void DeleteSymbol (const wxString &aAliasName)
 
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
 

Private Member Functions

LIB_PARTloadPart (FILE_LINE_READER &aReader)
 
void loadHeader (FILE_LINE_READER &aReader)
 
void loadAliases (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
void loadField (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
void loadDrawEntries (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
void loadFootprintFilters (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
void loadDocs ()
 
LIB_ARCloadArc (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_CIRCLEloadCircle (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_TEXTloadText (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_RECTANGLEloadRectangle (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_PINloadPin (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_POLYLINEloadPolyLine (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
LIB_BEZIERloadBezier (std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
 
FILL_T parseFillMode (FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
 
bool checkForDuplicates (wxString &aAliasName)
 
LIB_ALIASremoveAlias (LIB_ALIAS *aAlias)
 
void saveDocFile ()
 

Private Attributes

wxFileName m_libFileName
 
wxDateTime m_fileModTime
 
LIB_ALIAS_MAP m_aliases
 
bool m_isWritable
 
bool m_isModified
 
int m_modHash
 
int m_versionMajor
 
int m_versionMinor
 
int m_libType
 
friend SCH_LEGACY_PLUGIN
 

Detailed Description

Class SCH_LEGACY_PLUGIN_CACHE is 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 473 of file sch_legacy_plugin.cpp.

Constructor & Destructor Documentation

SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN_CACHE ( const wxString &  aLibraryPath)
SCH_LEGACY_PLUGIN_CACHE::~SCH_LEGACY_PLUGIN_CACHE ( )

Definition at line 2024 of file sch_legacy_plugin.cpp.

References LIB_PART::GetAliasCount(), GetChars(), GetLogicalName(), m_aliases, and traceSchLegacyPlugin.

2025 {
2026  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2027  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); ++it )
2028  {
2029  wxLogTrace( traceSchLegacyPlugin, wxT( "Removing alias %s from library %s." ),
2030  GetChars( it->second->GetName() ), GetChars( GetLogicalName() ) );
2031  LIB_PART* part = it->second->GetPart();
2032  LIB_ALIAS* alias = it->second;
2033  delete alias;
2034 
2035  // When the last alias of a part is destroyed, the part is no longer required and it
2036  // too is destroyed.
2037  if( part && part->GetAliasCount() == 0 )
2038  delete part;
2039  }
2040 
2041  m_aliases.clear();
2042 }
Part library alias object definition.
const wxChar traceSchLegacyPlugin[]
size_t GetAliasCount() const
Class LIB_PART defines a library part object.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
wxString GetLogicalName() const

Member Function Documentation

void SCH_LEGACY_PLUGIN_CACHE::AddSymbol ( const LIB_PART aPart)

Definition at line 2113 of file sch_legacy_plugin.cpp.

References LIB_PART::GetAliasNames(), LIB_PART::GetName(), m_aliases, m_isModified, m_modHash, and removeAlias().

Referenced by SCH_LEGACY_PLUGIN::SaveSymbol().

2114 {
2115  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2116  wxArrayString aliasNames = aPart->GetAliasNames();
2117 
2118  for( size_t i = 0; i < aliasNames.size(); i++ )
2119  {
2120  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasNames[i] );
2121 
2122  if( it != m_aliases.end() )
2123  removeAlias( it->second );
2124 
2125  LIB_ALIAS* alias = const_cast< LIB_PART* >( aPart )->GetAlias( aliasNames[i] );
2126 
2127  wxASSERT_MSG( alias != NULL, "No alias <" + aliasNames[i] + "> found in symbol <" +
2128  aPart->GetName() +">." );
2129 
2130  m_aliases[ aliasNames[i] ] = alias;
2131  }
2132 
2133  m_isModified = true;
2134  ++m_modHash;
2135 }
Part library alias object definition.
const wxString & GetName() const
Class LIB_PART defines a library part object.
LIB_ALIAS * removeAlias(LIB_ALIAS *aAlias)
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
bool SCH_LEGACY_PLUGIN_CACHE::checkForDuplicates ( wxString &  aAliasName)
private

Definition at line 2481 of file sch_legacy_plugin.cpp.

References m_aliases.

Referenced by loadAliases().

2482 {
2483  wxCHECK_MSG( !aAliasName.IsEmpty(), false, "alias name cannot be empty" );
2484 
2485  // The alias name is not a duplicate so don't change it.
2486  if( m_aliases.find( aAliasName ) == m_aliases.end() )
2487  return false;
2488 
2489  int dupCounter = 1;
2490  wxString newAlias = aAliasName;
2491 
2492  // If the alias is already loaded, the library is broken. It may have been possible in
2493  // the past that this could happen so we assign a new alias name to prevent any conflicts
2494  // rather than throw an exception.
2495  while( m_aliases.find( newAlias ) != m_aliases.end() )
2496  {
2497  newAlias = aAliasName << dupCounter;
2498  dupCounter++;
2499  }
2500 
2501  aAliasName = newAlias;
2502 
2503  return true;
2504 }
void SCH_LEGACY_PLUGIN_CACHE::DeleteAlias ( const wxString &  aAliasName)

Definition at line 3314 of file sch_legacy_plugin.cpp.

References Format(), LIB_ALIAS::GetPart(), m_aliases, m_isModified, m_libFileName, m_modHash, next(), LIB_PART::RemoveAlias(), and THROW_IO_ERROR.

Referenced by SCH_LEGACY_PLUGIN::DeleteAlias(), and DeleteSymbol().

3315 {
3316  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3317 
3318  if( it == m_aliases.end() )
3319  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3320  m_libFileName.GetFullName(), aAliasName ) );
3321 
3322  LIB_ALIAS* alias = it->second;
3323  LIB_PART* part = alias->GetPart();
3324 
3325  alias = part->RemoveAlias( alias );
3326 
3327  if( !alias )
3328  {
3329  delete part;
3330 
3331  if( m_aliases.size() > 1 )
3332  {
3333  LIB_ALIAS_MAP::iterator next = it;
3334  next++;
3335 
3336  if( next == m_aliases.end() )
3337  next = m_aliases.begin();
3338 
3339  alias = next->second;
3340  }
3341  }
3342 
3343  m_aliases.erase( it );
3344  ++m_modHash;
3345  m_isModified = true;
3346 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Class LIB_PART defines a library part object.
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
LIB_PART * GetPart() const
Function GetPart gets the shared LIB_PART.
void RemoveAlias(const wxString &aName)
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
void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol ( const wxString &  aAliasName)

Definition at line 3349 of file sch_legacy_plugin.cpp.

References DeleteAlias(), Format(), LIB_PART::GetAliasNames(), LIB_ALIAS::GetPart(), m_aliases, m_libFileName, and THROW_IO_ERROR.

Referenced by SCH_LEGACY_PLUGIN::DeleteSymbol().

3350 {
3351  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3352 
3353  if( it == m_aliases.end() )
3354  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3355  m_libFileName.GetFullName(), aAliasName ) );
3356 
3357  LIB_ALIAS* alias = it->second;
3358  LIB_PART* part = alias->GetPart();
3359 
3360  wxArrayString aliasNames = part->GetAliasNames();
3361 
3362  // Deleting all of the aliases deletes the symbol from the library.
3363  for( size_t i = 0; i < aliasNames.Count(); i++ )
3364  DeleteAlias( aliasNames[i] );
3365 }
Part library alias object definition.
void DeleteAlias(const wxString &aAliasName)
Class LIB_PART defines a library part object.
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
LIB_PART * GetPart() const
Function GetPart gets the shared LIB_PART.
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
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 544 of file sch_legacy_plugin.cpp.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

544 { return m_libFileName.GetFullPath(); }
wxDateTime SCH_LEGACY_PLUGIN_CACHE::GetLibModificationTime ( )

Definition at line 2045 of file sch_legacy_plugin.cpp.

References m_isWritable, and m_libFileName.

Referenced by Load().

2046 {
2047  // update the writable flag while we have a wxFileName, in a network this
2048  // is possibly quite dynamic anyway.
2049  m_isWritable = m_libFileName.IsFileWritable();
2050 
2051  return m_libFileName.GetModificationTime();
2052 }
wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 540 of file sch_legacy_plugin.cpp.

Referenced by ~SCH_LEGACY_PLUGIN_CACHE().

540 { return m_libFileName.GetName(); }
int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( ) const
inline

Definition at line 515 of file sch_legacy_plugin.cpp.

References m_modHash.

Referenced by SCH_LEGACY_PLUGIN::GetModifyHash().

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

Definition at line 2055 of file sch_legacy_plugin.cpp.

References m_libFileName.

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

2056 {
2057  return m_libFileName == aFullPathAndFileName;
2058 }
bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 2061 of file sch_legacy_plugin.cpp.

References m_fileModTime, and m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::cacheLib().

2062 {
2063  if( m_fileModTime.IsValid() && m_libFileName.IsOk() && m_libFileName.FileExists() )
2064  return m_libFileName.GetModificationTime() != m_fileModTime;
2065 
2066  return false;
2067 }
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 2138 of file sch_legacy_plugin.cpp.

References Format(), GetLibModificationTime(), LIBRARY_TYPE_EESCHEMA, LIBRARY_TYPE_SYMBOL, loadDocs(), loadHeader(), loadPart(), m_fileModTime, m_libFileName, m_libType, m_modHash, 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().

2139 {
2140  wxCHECK_RET( m_libFileName.IsAbsolute(),
2141  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2142  "open library '%s'.", m_libFileName.GetFullPath() ) );
2143 
2144  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file '%s'",
2145  m_libFileName.GetFullPath() );
2146 
2147  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2148 
2149  if( !reader.ReadLine() )
2150  THROW_IO_ERROR( _( "unexpected end of file" ) );
2151 
2152  const char* line = reader.Line();
2153 
2154  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2155  {
2156  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2157  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2158  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2159  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2160  }
2161 
2162  m_versionMajor = parseInt( reader, line, &line );
2163 
2164  if( *line != '.' )
2165  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2166 
2167  line++;
2168 
2169  m_versionMinor = parseInt( reader, line, &line );
2170 
2171  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2172  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2173 
2174  // Check if this is a symbol library which is the same as a component library but without
2175  // any alias, documentation, footprint filters, etc.
2176  if( strCompare( "SYMBOL", line, &line ) )
2177  {
2178  // Symbol files add date and time stamp info to the header.
2180 
2182  }
2183  else
2184  {
2186  }
2187 
2188  while( reader.ReadLine() )
2189  {
2190  line = reader.Line();
2191 
2192  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2193  continue;
2194 
2195  // Headers where only supported in older library file formats.
2196  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2197  loadHeader( reader );
2198 
2199  if( strCompare( "DEF", line ) )
2200  {
2201  // Read one DEF/ENDDEF part entry from library:
2202  loadPart( reader );
2203 
2204  }
2205  }
2206 
2207  ++m_modHash;
2208 
2209  // Remember the file modification time of library file when the
2210  // cache snapshot was made, so that in a networked environment we will
2211  // reload the cache as needed.
2213 
2215  loadDocs();
2216 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
const wxChar traceSchLegacyPlugin[]
void loadHeader(FILE_LINE_READER &aReader)
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
#define USE_OLD_DOC_FILE_FORMAT(major, minor)
Definition: class_library.h:75
#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
LIB_PART * loadPart(FILE_LINE_READER &aReader)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
void SCH_LEGACY_PLUGIN_CACHE::loadAliases ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2507 of file sch_legacy_plugin.cpp.

References checkForDuplicates(), LINE_READER::Line(), parseUnquotedString(), and strCompare().

Referenced by loadPart().

2509 {
2510  wxString newAlias;
2511  const char* line = aReader.Line();
2512 
2513  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2514 
2515  // Parse the ALIAS list.
2516  wxString alias;
2517  parseUnquotedString( alias, aReader, line, &line );
2518 
2519  while( !alias.IsEmpty() )
2520  {
2521  newAlias = alias;
2522  checkForDuplicates( newAlias );
2523  aPart->AddAlias( newAlias );
2524  alias.clear();
2525  parseUnquotedString( alias, aReader, line, &line, true );
2526  }
2527 }
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseUnquotedString.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
bool checkForDuplicates(wxString &aAliasName)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
LIB_ARC * SCH_LEGACY_PLUGIN_CACHE::loadArc ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2764 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), NORMALIZE_ANGLE_POS(), parseFillMode(), parseInt(), RotatePoint(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

2766 {
2767  const char* line = aReader.Line();
2768 
2769  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
2770 
2771  std::unique_ptr< LIB_ARC > arc( new LIB_ARC( aPart.get() ) );
2772 
2773  wxPoint center;
2774 
2775  center.x = parseInt( aReader, line, &line );
2776  center.y = parseInt( aReader, line, &line );
2777 
2778  arc->SetPosition( center );
2779  arc->SetRadius( parseInt( aReader, line, &line ) );
2780 
2781  int angle1 = parseInt( aReader, line, &line );
2782  int angle2 = parseInt( aReader, line, &line );
2783 
2784  NORMALIZE_ANGLE_POS( angle1 );
2785  NORMALIZE_ANGLE_POS( angle2 );
2786  arc->SetFirstRadiusAngle( angle1 );
2787  arc->SetSecondRadiusAngle( angle2 );
2788 
2789  arc->SetUnit( parseInt( aReader, line, &line ) );
2790  arc->SetConvert( parseInt( aReader, line, &line ) );
2791  arc->SetWidth( parseInt( aReader, line, &line ) );
2792 
2793  // Old libraries (version <= 2.2) do not have always this FILL MODE param
2794  // when fill mode is no fill (default mode).
2795  if( *line != 0 )
2796  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
2797 
2798  // Actual Coordinates of arc ends are read from file
2799  if( *line != 0 )
2800  {
2801  wxPoint arcStart, arcEnd;
2802 
2803  arcStart.x = parseInt( aReader, line, &line );
2804  arcStart.y = parseInt( aReader, line, &line );
2805  arcEnd.x = parseInt( aReader, line, &line );
2806  arcEnd.y = parseInt( aReader, line, &line );
2807 
2808  arc->SetStart( arcStart );
2809  arc->SetEnd( arcEnd );
2810  }
2811  else
2812  {
2813  // Actual Coordinates of arc ends are not read from file
2814  // (old library), calculate them
2815  wxPoint arcStart( arc->GetRadius(), 0 );
2816  wxPoint arcEnd( arc->GetRadius(), 0 );
2817 
2818  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
2819  arcStart += arc->GetPosition();
2820  arc->SetStart( arcStart );
2821  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
2822  arcEnd += arc->GetPosition();
2823  arc->SetEnd( arcEnd );
2824  }
2825 
2826  return arc.release();
2827 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:317
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:222
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
LIB_BEZIER * SCH_LEGACY_PLUGIN_CACHE::loadBezier ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3213 of file sch_legacy_plugin.cpp.

References bezier(), LINE_READER::Line(), parseFillMode(), parseInt(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

3215 {
3216  const char* line = aReader.Line();
3217 
3218  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3219 
3220  std::unique_ptr< LIB_BEZIER > bezier( new LIB_BEZIER( aPart.get() ) );
3221 
3222  int points = parseInt( aReader, line, &line );
3223  bezier->SetUnit( parseInt( aReader, line, &line ) );
3224  bezier->SetConvert( parseInt( aReader, line, &line ) );
3225  bezier->SetWidth( parseInt( aReader, line, &line ) );
3226 
3227  wxPoint pt;
3228 
3229  for( int i = 0; i < points; i++ )
3230  {
3231  pt.x = parseInt( aReader, line, &line );
3232  pt.y = parseInt( aReader, line, &line );
3233  bezier->AddPoint( pt );
3234  }
3235 
3236  if( *line != 0 )
3237  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3238 
3239  return bezier.release();
3240 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
static dpoint_t bezier(double t, dpoint_t p0, dpoint_t p1, dpoint_t p2, dpoint_t p3)
Definition: trace.cpp:259
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
Class LIB_BEZIER defines bezier curve graphic body item.
Definition: lib_bezier.h:39
LIB_CIRCLE * SCH_LEGACY_PLUGIN_CACHE::loadCircle ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2830 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), parseFillMode(), parseInt(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

2832 {
2833  const char* line = aReader.Line();
2834 
2835  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
2836 
2837  std::unique_ptr< LIB_CIRCLE > circle( new LIB_CIRCLE( aPart.get() ) );
2838 
2839  wxPoint center;
2840 
2841  center.x = parseInt( aReader, line, &line );
2842  center.y = parseInt( aReader, line, &line );
2843 
2844  circle->SetPosition( center );
2845  circle->SetRadius( parseInt( aReader, line, &line ) );
2846  circle->SetUnit( parseInt( aReader, line, &line ) );
2847  circle->SetConvert( parseInt( aReader, line, &line ) );
2848  circle->SetWidth( parseInt( aReader, line, &line ) );
2849 
2850  if( *line != 0 )
2851  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
2852 
2853  return circle.release();
2854 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
void SCH_LEGACY_PLUGIN_CACHE::loadDocs ( )
private

Definition at line 2219 of file sch_legacy_plugin.cpp.

References DOC_EXT, DOCFILE_IDENT, Format(), FROM_UTF8(), m_aliases, m_libFileName, parseUnquotedString(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_ALIAS::SetDescription(), LIB_ALIAS::SetDocFileName(), LIB_ALIAS::SetKeyWords(), strCompare(), and THROW_IO_ERROR.

Referenced by Load().

2220 {
2221  const char* line;
2222  wxString text;
2223  wxString aliasName;
2224  wxFileName fn = m_libFileName;
2225  LIB_ALIAS* alias = NULL;;
2226 
2227  fn.SetExt( DOC_EXT );
2228 
2229  // Not all libraries will have a document file.
2230  if( !fn.FileExists() )
2231  return;
2232 
2233  if( !fn.IsFileReadable() )
2234  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2235  "document file '%s'" ), fn.GetFullPath() ) );
2236 
2237  FILE_LINE_READER reader( fn.GetFullPath() );
2238 
2239  line = reader.ReadLine();
2240 
2241  if( !line )
2242  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2243 
2244  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2245  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2246  reader, line );
2247 
2248  while( reader.ReadLine() )
2249  {
2250  line = reader.Line();
2251 
2252  if( *line == '#' ) // Comment line.
2253  continue;
2254 
2255  if( !strCompare( "$CMP", line, &line ) != 0 )
2256  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2257 
2258  parseUnquotedString( aliasName, reader, line, &line ); // Alias name.
2259 
2260  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
2261 
2262  if( it == m_aliases.end() )
2263  wxLogWarning( "Alias '%s' not found in library:\n\n"
2264  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2265  reader.LineNumber(), (int) (line - reader.Line() ) );
2266  else
2267  alias = it->second;
2268 
2269  // Read the curent alias associated doc.
2270  // if the alias does not exist, just skip the description
2271  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2272  while( reader.ReadLine() )
2273  {
2274  line = reader.Line();
2275 
2276  if( !line )
2277  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2278 
2279  if( strCompare( "$ENDCMP", line, &line ) )
2280  break;
2281 
2282  text = FROM_UTF8( line + 2 );
2283  text = text.Trim();
2284 
2285  switch( line[0] )
2286  {
2287  case 'D':
2288  if( alias )
2289  alias->SetDescription( text );
2290  break;
2291 
2292  case 'K':
2293  if( alias )
2294  alias->SetKeyWords( text );
2295  break;
2296 
2297  case 'F':
2298  if( alias )
2299  alias->SetDocFileName( text );
2300  break;
2301 
2302  case '#':
2303  break;
2304 
2305  default:
2306  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2307  }
2308  }
2309  }
2310 }
Part library alias object definition.
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
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:53
void SetDocFileName(const wxString &aDocFileName)
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define DOCFILE_IDENT
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseUnquotedString.
#define DOC_EXT
Definition: class_library.h:50
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
void SetDescription(const wxString &aDescription)
#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
void SetKeyWords(const wxString &aKeyWords)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
void SCH_LEGACY_PLUGIN_CACHE::loadDrawEntries ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2676 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

2678 {
2679  const char* line = aReader.Line();
2680 
2681  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
2682 
2683  line = aReader.ReadLine();
2684 
2685  while( line )
2686  {
2687  if( strCompare( "ENDDRAW", line, &line ) )
2688  return;
2689 
2690  switch( line[0] )
2691  {
2692  case 'A': // Arc
2693  aPart->AddDrawItem( loadArc( aPart, aReader ) );
2694  break;
2695 
2696  case 'C': // Circle
2697  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
2698  break;
2699 
2700  case 'T': // Text
2701  aPart->AddDrawItem( loadText( aPart, aReader ) );
2702  break;
2703 
2704  case 'S': // Square
2705  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
2706  break;
2707 
2708  case 'X': // Pin Description
2709  aPart->AddDrawItem( loadPin( aPart, aReader ) );
2710  break;
2711 
2712  case 'P': // Polyline
2713  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
2714  break;
2715 
2716  case 'B': // Bezier Curves
2717  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
2718  break;
2719 
2720  case '#': // Comment
2721  case '\n': // Empty line
2722  case '\r':
2723  case 0:
2724  break;
2725 
2726  default:
2727  SCH_PARSE_ERROR( _( "undefined DRAW entry" ), aReader, line );
2728  }
2729 
2730  line = aReader.ReadLine();
2731  }
2732 
2733  SCH_PARSE_ERROR( _( "file ended prematurely loading component draw element" ), aReader, line );
2734 }
LIB_PIN * loadPin(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
LIB_BEZIER * loadBezier(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
LIB_CIRCLE * loadCircle(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
LIB_ARC * loadArc(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
LIB_TEXT * loadText(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
LIB_POLYLINE * loadPolyLine(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
#define SCH_PARSE_ERROR(text, reader, pos)
LIB_RECTANGLE * loadRectangle(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
void SCH_LEGACY_PLUGIN_CACHE::loadField ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2530 of file sch_legacy_plugin.cpp.

References TEMPLATE_FIELDNAME::GetDefaultFieldName(), LIB_FIELD::GetId(), 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(), EDA_TEXT::m_Text, MANDATORY_FIELDS, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, VALUE, wxPoint::x, and wxPoint::y.

Referenced by loadPart().

2532 {
2533  const char* line = aReader.Line();
2534 
2535  wxCHECK_RET( *line == 'F', "Invalid field line" );
2536 
2537  int id;
2538 
2539  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2540  SCH_PARSE_ERROR( _( "invalid field ID" ), aReader, line + 1 );
2541 
2542  std::unique_ptr< LIB_FIELD > field( new LIB_FIELD( aPart.get(), id ) );
2543 
2544  // Skip to the first double quote.
2545  while( *line != '"' && *line != 0 )
2546  line++;
2547 
2548  if( *line == 0 )
2549  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
2550 
2551  wxString text;
2552  parseQuotedString( text, aReader, line, &line, true );
2553 
2554  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
2555  // not save like this.
2556  if( text.size() == 1 && text[0] == '~' )
2557  text.clear();
2558 
2559  field->m_Text = text;
2560 
2561  wxPoint pos;
2562 
2563  pos.x = parseInt( aReader, line, &line );
2564  pos.y = parseInt( aReader, line, &line );
2565  field->SetPosition( pos );
2566 
2567  wxSize textSize;
2568 
2569  textSize.x = textSize.y = parseInt( aReader, line, &line );
2570  field->SetTextSize( textSize );
2571 
2572  char textOrient = parseChar( aReader, line, &line );
2573 
2574  if( textOrient == 'H' )
2575  field->SetTextAngle( TEXT_ANGLE_HORIZ );
2576  else if( textOrient == 'V' )
2577  field->SetTextAngle( TEXT_ANGLE_VERT );
2578  else
2579  SCH_PARSE_ERROR( _( "invalid field text orientation parameter" ), aReader, line );
2580 
2581  char textVisible = parseChar( aReader, line, &line );
2582 
2583  if( textVisible == 'V' )
2584  field->SetVisible( true );
2585  else if ( textVisible == 'I' )
2586  field->SetVisible( false );
2587  else
2588  SCH_PARSE_ERROR( _( "invalid field text visibility parameter" ), aReader, line );
2589 
2590  // It may be technically correct to use the library version to determine if the field text
2591  // attributes are present. If anyone knows if that is valid and what version that would be,
2592  // please change this to test the library version rather than an EOL or the quoted string
2593  // of the field name.
2594  if( *line != 0 && *line != '"' )
2595  {
2596  char textHJustify = parseChar( aReader, line, &line );
2597 
2598  if( textHJustify == 'C' )
2599  field->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
2600  else if( textHJustify == 'L' )
2601  field->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
2602  else if( textHJustify == 'R' )
2603  field->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
2604  else
2605  SCH_PARSE_ERROR( _( "invalid field text horizontal justification parameter" ),
2606  aReader, line );
2607 
2608  wxString attributes;
2609 
2610  parseUnquotedString( attributes, aReader, line, &line );
2611 
2612  if( !(attributes.size() == 3 || attributes.size() == 1 ) )
2613  SCH_PARSE_ERROR( _( "invalid field text attributes size" ),
2614  aReader, line );
2615 
2616  if( attributes[0] == 'C' )
2617  field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
2618  else if( attributes[0] == 'B' )
2619  field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
2620  else if( attributes[0] == 'T' )
2621  field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
2622  else
2623  SCH_PARSE_ERROR( _( "invalid field text vertical justification parameter" ),
2624  aReader, line );
2625 
2626  if( attributes.size() == 3 )
2627  {
2628  if( attributes[1] == 'I' ) // Italic
2629  field->SetItalic( true );
2630  else if( attributes[1] != 'N' ) // No italics is default, check for error.
2631  SCH_PARSE_ERROR( _( "invalid field text italic parameter" ), aReader, line );
2632 
2633  if ( attributes[2] == 'B' ) // Bold
2634  field->SetBold( true );
2635  else if( attributes[2] != 'N' ) // No bold is default, check for error.
2636  SCH_PARSE_ERROR( _( "invalid field text bold parameter" ), aReader, line );
2637  }
2638  }
2639 
2640  // Fields in RAM must always have names.
2641  if( id < MANDATORY_FIELDS )
2642  {
2643  // Fields in RAM must always have names, because we are trying to get
2644  // less dependent on field ids and more dependent on names.
2645  // Plus assumptions are made in the field editors.
2646  field->m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
2647 
2648  LIB_FIELD* fixedField = aPart->GetField( field->GetId() );
2649 
2650  // this will fire only if somebody broke a constructor or editor.
2651  // MANDATORY_FIELDS are always present in ram resident components, no
2652  // exceptions, and they always have their names set, even fixed fields.
2653  wxASSERT( fixedField );
2654 
2655  *fixedField = *field;
2656 
2657  // Ensure the VALUE field = the part name (can be not the case
2658  // with malformed libraries: edited by hand, or converted from other tools)
2659  if( fixedField->GetId() == VALUE )
2660  fixedField->m_Text = aPart->m_name;
2661  }
2662  else
2663  {
2664  wxString name;
2665 
2666  parseQuotedString( name, aReader, line, &line, true ); // Optional.
2667 
2668  if( !name.IsEmpty() )
2669  field->m_name = name;
2670 
2671  aPart->AddDrawItem( field.release() ); // LIB_FIELD* is now owned by the LIB_PART.
2672  }
2673 }
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
wxString m_Text
Definition: eda_text.h:348
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
static char parseChar(FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Function parseChar.
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
Class LIB_FIELD is used in symbol libraries.
Definition: lib_field.h:60
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
#define TEXT_ANGLE_VERT
Definition: common.h:92
int GetId() const
Definition: lib_field.h:136
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseUnquotedString.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
Field Value of part, i.e. "3.3K".
#define SCH_PARSE_ERROR(text, reader, pos)
static void parseQuotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseQuotedString.
void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3243 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

3245 {
3246  const char* line = aReader.Line();
3247 
3248  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3249 
3250  line = aReader.ReadLine();
3251 
3252  while( line )
3253  {
3254  if( strCompare( "$ENDFPLIST", line, &line ) )
3255  return;
3256 
3257  wxString footprint;
3258 
3259  parseUnquotedString( footprint, aReader, line, &line );
3260  aPart->GetFootPrints().Add( footprint );
3261  line = aReader.ReadLine();
3262  }
3263 
3264  SCH_PARSE_ERROR( _( "file ended prematurely while loading footprint filters" ), aReader, line );
3265 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseUnquotedString.
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)
Function strCompare.
void SCH_LEGACY_PLUGIN_CACHE::loadHeader ( FILE_LINE_READER aReader)
private

Definition at line 2313 of file sch_legacy_plugin.cpp.

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

Referenced by Load().

2314 {
2315  const char* line = aReader.Line();
2316 
2317  wxASSERT( strCompare( "$HEADER", line, &line ) );
2318 
2319  while( aReader.ReadLine() )
2320  {
2321  line = (char*) aReader;
2322 
2323  // The time stamp saved in old library files is not used or saved in the latest
2324  // library file version.
2325  if( strCompare( "TimeStamp", line, &line ) )
2326  continue;
2327  else if( strCompare( "$ENDHEADER", line, &line ) )
2328  return;
2329  }
2330 
2331  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2332 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
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)
Function strCompare.
LIB_PART * SCH_LEGACY_PLUGIN_CACHE::loadPart ( FILE_LINE_READER aReader)
private

Definition at line 2335 of file sch_legacy_plugin.cpp.

References EDA_TEXT::Empty(), LIB_VERSION, LINE_READER::Line(), loadAliases(), loadDrawEntries(), loadField(), loadFootprintFilters(), m_aliases, LIB_FIELD::m_name, m_versionMajor, m_versionMinor, parseChar(), parseInt(), parseUnquotedString(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_FIELD::SetText(), EDA_TEXT::SetVisible(), and strCompare().

Referenced by Load().

2336 {
2337  const char* line = aReader.Line();
2338 
2339  wxCHECK( strCompare( "DEF", line, &line ), NULL );
2340 
2341  // Read DEF line:
2342  char yes_no = 0;
2343 
2344  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2345 
2346  wxString name, prefix;
2347 
2348  parseUnquotedString( name, aReader, line, &line ); // Part name.
2349  parseUnquotedString( prefix, aReader, line, &line ); // Prefix name
2350  parseInt( aReader, line, &line ); // NumOfPins, unused.
2351  part->SetPinNameOffset( parseInt( aReader, line, &line ) ); // Pin name offset.
2352  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2353 
2354  if( !( yes_no == 'Y' || yes_no == 'N') )
2355  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2356 
2357  part->SetShowPinNumbers( ( yes_no == 'N' ) ? false : true );
2358 
2359  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2360 
2361  if( !( yes_no == 'Y' || yes_no == 'N') )
2362  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2363 
2364  part->SetShowPinNames( ( yes_no == 'N' ) ? false : true ); // Show pin names.
2365 
2366  part->SetUnitCount( parseInt( aReader, line, &line ) ); // Number of units.
2367 
2368  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2369  if( part->GetUnitCount() < 1 )
2370  part->SetUnitCount( 1 );
2371 
2372  // Copy part name and prefix.
2373  LIB_FIELD& value = part->GetValueField();
2374 
2375  // The root alias is added to the alias list by SetName() which is called by SetText().
2376  if( name.IsEmpty() )
2377  {
2378  part->m_name = "~";
2379  value.SetText( "~" );
2380  }
2381  else if( name[0] != '~' )
2382  {
2383  part->m_name = name;
2384  value.SetText( name );
2385  }
2386  else
2387  {
2388  name = name.Right( name.Length() - 1 );
2389  part->m_name = name;
2390  value.SetText( name );
2391  value.SetVisible( false );
2392  }
2393 
2394  // There are some code paths in SetText() that do not set the root alias to the
2395  // alias list so add it here if it didn't get added by SetText().
2396  if( !part->HasAlias( part->GetName() ) )
2397  part->AddAlias( part->GetName() );
2398 
2399  LIB_FIELD& reference = part->GetReferenceField();
2400 
2401  if( prefix == "~" )
2402  {
2403  reference.Empty();
2404  reference.SetVisible( false );
2405  }
2406  else
2407  {
2408  reference.SetText( prefix );
2409  }
2410 
2411  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2412  // The was no concept of interchangeable multiple unit symbols.
2414  {
2415  // Nothing needs to be set since the default setting for symbols with multiple
2416  // units were never interchangeable. Just parse the 0 an move on.
2417  parseInt( aReader, line, &line );
2418  }
2419  else
2420  {
2421  char locked = parseChar( aReader, line, &line );
2422 
2423  if( locked == 'L' )
2424  part->LockUnits( true );
2425  else if( locked == 'F' || locked == '0' )
2426  part->LockUnits( false );
2427  else
2428  SCH_PARSE_ERROR( "expected L, F, or 0", aReader, line );
2429  }
2430 
2431 
2432  // There is the optional power component flag.
2433  if( *line )
2434  {
2435  char power = parseChar( aReader, line, &line );
2436 
2437  if( power == 'P' )
2438  part->SetPower();
2439  else if( power == 'N' )
2440  part->SetNormal();
2441  else
2442  SCH_PARSE_ERROR( "expected P or N", aReader, line );
2443  }
2444 
2445  line = aReader.ReadLine();
2446 
2447  // Read lines until "ENDDEF" is found.
2448  while( line )
2449  {
2450  if( *line == '#' ) // Comment
2451  ;
2452  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2453  continue;
2454  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2455  loadAliases( part, aReader );
2456  else if( *line == 'F' ) // Fields
2457  loadField( part, aReader );
2458  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2459  loadDrawEntries( part, aReader );
2460  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2461  loadFootprintFilters( part, aReader );
2462  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2463  {
2464  // Now all is good, Add the root alias to the cache alias list.
2465  m_aliases[ part->GetName() ] = part->GetAlias( part->GetName() );
2466 
2467  // Add aliases when exist
2468  for( size_t ii = 0; ii < part->GetAliasCount(); ++ii )
2469  m_aliases[ part->GetAlias( ii )->GetName() ] = part->GetAlias( ii );
2470 
2471  return part.release();
2472  }
2473 
2474  line = aReader.ReadLine();
2475  }
2476 
2477  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2478 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
static char parseChar(FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Function parseChar.
Class LIB_FIELD is used in symbol libraries.
Definition: lib_field.h:60
void SetVisible(bool aVisible)
Definition: eda_text.h:175
#define LIB_VERSION(major, minor)
Definition: class_library.h:61
void loadAliases(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:679
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseUnquotedString.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void Empty()
Definition: eda_text.h:231
Class LIB_PART defines a library part object.
void loadField(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
void loadDrawEntries(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:63
void loadFootprintFilters(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
LIB_PIN * SCH_LEGACY_PLUGIN_CACHE::loadPin ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2996 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), parseChar(), parseInt(), parseUnquotedString(), PIN_BIDI, PIN_INPUT, PIN_NC, PIN_OPENCOLLECTOR, PIN_OPENEMITTER, PIN_OUTPUT, PIN_PASSIVE, PIN_POWER_IN, PIN_POWER_OUT, PIN_TRISTATE, PIN_UNSPECIFIED, PINSHAPE_CLOCK, PINSHAPE_CLOCK_LOW, PINSHAPE_FALLING_EDGE_CLOCK, PINSHAPE_INPUT_LOW, PINSHAPE_INVERTED, PINSHAPE_INVERTED_CLOCK, PINSHAPE_LINE, PINSHAPE_NONLOGIC, PINSHAPE_OUTPUT_LOW, SCH_PARSE_ERROR, strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

2998 {
2999  const char* line = aReader.Line();
3000 
3001  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3002 
3003  std::unique_ptr< LIB_PIN > pin( new LIB_PIN( aPart.get() ) );
3004 
3005  wxString name, number;
3006 
3007  parseUnquotedString( name, aReader, line, &line );
3008  parseUnquotedString( number, aReader, line, &line );
3009 
3010  pin->SetName( name );
3011  pin->SetPinNumFromString( number );
3012 
3013  wxPoint pos;
3014 
3015  pos.x = parseInt( aReader, line, &line );
3016  pos.y = parseInt( aReader, line, &line );
3017  pin->SetPosition( pos );
3018  pin->SetLength( parseInt( aReader, line, &line ) );
3019  pin->SetOrientation( parseChar( aReader, line, &line ) );
3020  pin->SetNumberTextSize( parseInt( aReader, line, &line ) );
3021  pin->SetNameTextSize( parseInt( aReader, line, &line ) );
3022  pin->SetUnit( parseInt( aReader, line, &line ) );
3023  pin->SetConvert( parseInt( aReader, line, &line ) );
3024 
3025  char type = parseChar( aReader, line, &line );
3026 
3027  wxString attributes;
3028 
3029  // Optional
3030  parseUnquotedString( attributes, aReader, line, &line, true );
3031 
3032  switch( type )
3033  {
3034  case 'I':
3035  pin->SetType( PIN_INPUT );
3036  break;
3037 
3038  case 'O':
3039  pin->SetType( PIN_OUTPUT );
3040  break;
3041 
3042  case 'B':
3043  pin->SetType( PIN_BIDI );
3044  break;
3045 
3046  case 'T':
3047  pin->SetType( PIN_TRISTATE );
3048  break;
3049 
3050  case 'P':
3051  pin->SetType( PIN_PASSIVE );
3052  break;
3053 
3054  case 'U':
3055  pin->SetType( PIN_UNSPECIFIED );
3056  break;
3057 
3058  case 'W':
3059  pin->SetType( PIN_POWER_IN );
3060  break;
3061 
3062  case 'w':
3063  pin->SetType( PIN_POWER_OUT );
3064  break;
3065 
3066  case 'C':
3067  pin->SetType( PIN_OPENCOLLECTOR );
3068  break;
3069 
3070  case 'E':
3071  pin->SetType( PIN_OPENEMITTER );
3072  break;
3073 
3074  case 'N':
3075  pin->SetType( PIN_NC );
3076  break;
3077 
3078  default:
3079  SCH_PARSE_ERROR( _( "unknown pin type" ), aReader, line );
3080  }
3081 
3082  if( !attributes.IsEmpty() ) /* Special Symbol defined */
3083  {
3084  enum
3085  {
3086  INVERTED = 1 << 0,
3087  CLOCK = 1 << 1,
3088  LOWLEVEL_IN = 1 << 2,
3089  LOWLEVEL_OUT = 1 << 3,
3090  FALLING_EDGE = 1 << 4,
3091  NONLOGIC = 1 << 5
3092  };
3093 
3094  int flags = 0;
3095 
3096  for( int j = attributes.size(); j > 0; )
3097  {
3098  switch( attributes[--j].GetValue() )
3099  {
3100  case '~':
3101  break;
3102 
3103  case 'N':
3104  pin->SetVisible( false );
3105  break;
3106 
3107  case 'I':
3108  flags |= INVERTED;
3109  break;
3110 
3111  case 'C':
3112  flags |= CLOCK;
3113  break;
3114 
3115  case 'L':
3116  flags |= LOWLEVEL_IN;
3117  break;
3118 
3119  case 'V':
3120  flags |= LOWLEVEL_OUT;
3121  break;
3122 
3123  case 'F':
3124  flags |= FALLING_EDGE;
3125  break;
3126 
3127  case 'X':
3128  flags |= NONLOGIC;
3129  break;
3130 
3131  default:
3132  SCH_PARSE_ERROR( _( "unknown pin attribute" ), aReader, line );
3133  }
3134  }
3135 
3136  switch( flags )
3137  {
3138  case 0:
3139  pin->SetShape( PINSHAPE_LINE );
3140  break;
3141 
3142  case INVERTED:
3143  pin->SetShape( PINSHAPE_INVERTED );
3144  break;
3145 
3146  case CLOCK:
3147  pin->SetShape( PINSHAPE_CLOCK );
3148  break;
3149 
3150  case INVERTED | CLOCK:
3151  pin->SetShape( PINSHAPE_INVERTED_CLOCK );
3152  break;
3153 
3154  case LOWLEVEL_IN:
3155  pin->SetShape( PINSHAPE_INPUT_LOW );
3156  break;
3157 
3158  case LOWLEVEL_IN | CLOCK:
3159  pin->SetShape( PINSHAPE_CLOCK_LOW );
3160  break;
3161 
3162  case LOWLEVEL_OUT:
3163  pin->SetShape( PINSHAPE_OUTPUT_LOW );
3164  break;
3165 
3166  case FALLING_EDGE:
3167  pin->SetShape( PINSHAPE_FALLING_EDGE_CLOCK );
3168  break;
3169 
3170  case NONLOGIC:
3171  pin->SetShape( PINSHAPE_NONLOGIC );
3172  break;
3173 
3174  default:
3175  SCH_PARSE_ERROR( _( "pin attributes do not define a valid pin shape" ), aReader, line );
3176  }
3177  }
3178 
3179  return pin.release();
3180 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
static char parseChar(FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Function parseChar.
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseUnquotedString.
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)
Function strCompare.
LIB_POLYLINE * SCH_LEGACY_PLUGIN_CACHE::loadPolyLine ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3183 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), parseFillMode(), parseInt(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

3185 {
3186  const char* line = aReader.Line();
3187 
3188  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3189 
3190  std::unique_ptr< LIB_POLYLINE > polyLine( new LIB_POLYLINE( aPart.get() ) );
3191 
3192  int points = parseInt( aReader, line, &line );
3193  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3194  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3195  polyLine->SetWidth( parseInt( aReader, line, &line ) );
3196 
3197  wxPoint pt;
3198 
3199  for( int i = 0; i < points; i++ )
3200  {
3201  pt.x = parseInt( aReader, line, &line );
3202  pt.y = parseInt( aReader, line, &line );
3203  polyLine->AddPoint( pt );
3204  }
3205 
3206  if( *line != 0 )
3207  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3208 
3209  return polyLine.release();
3210 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
LIB_RECTANGLE * SCH_LEGACY_PLUGIN_CACHE::loadRectangle ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2964 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), parseFillMode(), parseInt(), strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

2966 {
2967  const char* line = aReader.Line();
2968 
2969  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
2970 
2971  std::unique_ptr< LIB_RECTANGLE > rectangle( new LIB_RECTANGLE( aPart.get() ) );
2972 
2973  wxPoint pos;
2974 
2975  pos.x = parseInt( aReader, line, &line );
2976  pos.y = parseInt( aReader, line, &line );
2977  rectangle->SetPosition( pos );
2978 
2979  wxPoint end;
2980 
2981  end.x = parseInt( aReader, line, &line );
2982  end.y = parseInt( aReader, line, &line );
2983  rectangle->SetEnd( end );
2984 
2985  rectangle->SetUnit( parseInt( aReader, line, &line ) );
2986  rectangle->SetConvert( parseInt( aReader, line, &line ) );
2987  rectangle->SetWidth( parseInt( aReader, line, &line ) );
2988 
2989  if( *line != 0 )
2990  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
2991 
2992  return rectangle.release();
2993 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
FILL_T parseFillMode(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
LIB_TEXT * SCH_LEGACY_PLUGIN_CACHE::loadText ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2857 of file sch_legacy_plugin.cpp.

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(), m_versionMajor, m_versionMinor, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries().

2859 {
2860  const char* line = aReader.Line();
2861 
2862  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
2863 
2864  std::unique_ptr< LIB_TEXT > text( new LIB_TEXT( aPart.get() ) );
2865 
2866  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
2867 
2868  wxPoint center;
2869 
2870  center.x = parseInt( aReader, line, &line );
2871  center.y = parseInt( aReader, line, &line );
2872  text->SetPosition( center );
2873 
2874  wxSize size;
2875 
2876  size.x = size.y = parseInt( aReader, line, &line );
2877  text->SetTextSize( size );
2878  text->SetVisible( !parseInt( aReader, line, &line ) );
2879  text->SetUnit( parseInt( aReader, line, &line ) );
2880  text->SetConvert( parseInt( aReader, line, &line ) );
2881 
2882  wxString str;
2883 
2884  // If quoted string loading fails, load as not quoted string.
2885  if( *line == '"' )
2886  parseQuotedString( str, aReader, line, &line );
2887  else
2888  parseUnquotedString( str, aReader, line, &line );
2889 
2890  if( !str.IsEmpty() )
2891  {
2892  // convert two apostrophes back to double quote
2893  str.Replace( "''", "\"" );
2894  str.Replace( wxT( "~" ), wxT( " " ) );
2895  }
2896 
2897  text->SetText( str );
2898 
2899  // Here things are murky and not well defined. At some point it appears the format
2900  // was changed to add text properties. However rather than add the token to the end of
2901  // the text definition, it was added after the string and no mention if the file
2902  // verion was bumped or not so this code make break on very old component libraries.
2903  //
2904  // Update: apparently even in the latest version this can be different so added a test
2905  // for end of line before checking for the text properties.
2906  if( LIB_VERSION( m_versionMajor, m_versionMinor ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
2907  {
2908  if( strCompare( "Italic", line, &line ) )
2909  text->SetItalic( true );
2910  else if( !strCompare( "Normal", line, &line ) )
2911  SCH_PARSE_ERROR( _( "invalid text stype, expected 'Normal' or 'Italic'" ),
2912  aReader, line );
2913 
2914  if( parseInt( aReader, line, &line ) > 0 )
2915  text->SetBold( true );
2916 
2917  // Some old libaries version > 2.0 do not have these options for text justification:
2918  if( !is_eol( *line ) )
2919  {
2920  switch( parseChar( aReader, line, &line ) )
2921  {
2922  case 'L':
2923  text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
2924  break;
2925 
2926  case 'C':
2927  text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
2928  break;
2929 
2930  case 'R':
2931  text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
2932  break;
2933 
2934  default:
2935  SCH_PARSE_ERROR( _( "invalid horizontal text justication parameter, expected L, C, or R" ),
2936  aReader, line );
2937  }
2938 
2939  switch( parseChar( aReader, line, &line ) )
2940  {
2941  case 'T':
2942  text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
2943  break;
2944 
2945  case 'C':
2946  text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
2947  break;
2948 
2949  case 'B':
2950  text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
2951  break;
2952 
2953  default:
2954  SCH_PARSE_ERROR( _( "invalid vertical text justication parameter, expected T, C, or B" ),
2955  aReader, line );
2956  }
2957  }
2958  }
2959 
2960  return text.release();
2961 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
Class LIB_TEXT defines a component library graphical text item.
Definition: lib_text.h:45
static char parseChar(FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Function parseChar.
#define LIB_VERSION(major, minor)
Definition: class_library.h:61
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseUnquotedString.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static bool is_eol(char c)
#define SCH_PARSE_ERROR(text, reader, pos)
static void parseQuotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseQuotedString.
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
FILL_T SCH_LEGACY_PLUGIN_CACHE::parseFillMode ( FILE_LINE_READER aReader,
const char *  aLine,
const char **  aOutput 
)
private

Definition at line 2737 of file sch_legacy_plugin.cpp.

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

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

2739 {
2740  FILL_T mode;
2741 
2742  switch( parseChar( aReader, aLine, aOutput ) )
2743  {
2744  case 'F':
2745  mode = FILLED_SHAPE;
2746  break;
2747 
2748  case 'f':
2749  mode = FILLED_WITH_BG_BODYCOLOR;
2750  break;
2751 
2752  case 'N':
2753  mode = NO_FILL;
2754  break;
2755 
2756  default:
2757  SCH_PARSE_ERROR( _( "invalid fill type, expected f, F, or N" ), aReader, aLine );
2758  }
2759 
2760  return mode;
2761 }
static char parseChar(FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Function parseChar.
#define SCH_PARSE_ERROR(text, reader, pos)
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:56
LIB_ALIAS * SCH_LEGACY_PLUGIN_CACHE::removeAlias ( LIB_ALIAS aAlias)
private

Definition at line 2070 of file sch_legacy_plugin.cpp.

References LIB_ALIAS::GetName(), m_aliases, m_isModified, m_libFileName, m_modHash, next(), and LIB_PART::RemoveAlias().

Referenced by AddSymbol().

2071 {
2072  wxCHECK_MSG( aAlias != NULL, NULL, "NULL pointer cannot be removed from library." );
2073 
2074  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAlias->GetName() );
2075 
2076  if( it == m_aliases.end() )
2077  return NULL;
2078 
2079  // If the entry pointer doesn't match the name it is mapped to in the library, we
2080  // have done something terribly wrong.
2081  wxCHECK_MSG( *it->second == aAlias, NULL,
2082  "Pointer mismatch while attempting to remove alias entry <" + aAlias->GetName() +
2083  "> from library cache <" + m_libFileName.GetName() + ">." );
2084 
2085  LIB_ALIAS* alias = aAlias;
2086  LIB_PART* part = alias->GetPart();
2087 
2088  alias = part->RemoveAlias( alias );
2089 
2090  if( !alias )
2091  {
2092  delete part;
2093 
2094  if( m_aliases.size() > 1 )
2095  {
2096  LIB_ALIAS_MAP::iterator next = it;
2097  next++;
2098 
2099  if( next == m_aliases.end() )
2100  next = m_aliases.begin();
2101 
2102  alias = next->second;
2103  }
2104  }
2105 
2106  m_aliases.erase( it );
2107  m_isModified = true;
2108  ++m_modHash;
2109  return alias;
2110 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Class LIB_PART defines a library part object.
void RemoveAlias(const wxString &aName)
const wxString & GetName() const
void SCH_LEGACY_PLUGIN_CACHE::Save ( bool  aSaveDocFile = true)

Save the entire library to file m_libFileName;.

Definition at line 3268 of file sch_legacy_plugin.cpp.

References LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIBFILE_IDENT, m_aliases, m_fileModTime, m_isModified, m_libFileName, and saveDocFile().

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

3269 {
3270  if( !m_isModified )
3271  return;
3272 
3273  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( m_libFileName.GetFullPath() ) );
3274  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3275  formatter->Print( 0, "#encoding utf-8\n");
3276 
3277  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3278  {
3279  if( !it->second->IsRoot() )
3280  continue;
3281 
3282  it->second->GetPart()->Save( *formatter.get() );
3283  }
3284 
3285  formatter->Print( 0, "#\n#End Library\n" );
3286  formatter.reset();
3287 
3288  m_fileModTime = m_libFileName.GetModificationTime();
3289  m_isModified = false;
3290 
3291  if( aSaveDocFile )
3292  saveDocFile();
3293 }
#define LIBFILE_IDENT
Definition: class_library.h:59
#define LIB_VERSION_MINOR
Definition: class_library.h:56
#define LIB_VERSION_MAJOR
Definition: class_library.h:55
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 3296 of file sch_legacy_plugin.cpp.

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

Referenced by Save().

3297 {
3298  wxFileName docFileName = m_libFileName;
3299 
3300  docFileName.SetExt( DOC_EXT );
3301  FILE_OUTPUTFORMATTER formatter( docFileName.GetFullPath() );
3302 
3303  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
3304 
3305  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3306  {
3307  it->second->SaveDoc( formatter );
3308  }
3309 
3310  formatter.Print( 0, "#\n#End Doc Library\n" );
3311 }
#define DOCFILE_IDENT
#define DOC_EXT
Definition: class_library.h:50
Class 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:408
void SCH_LEGACY_PLUGIN_CACHE::SetFileName ( const wxString &  aFileName)
inline

Definition at line 542 of file sch_legacy_plugin.cpp.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

542 { m_libFileName = aFileName; }
void SCH_LEGACY_PLUGIN_CACHE::SetModified ( bool  aModified = true)
inline

Member Data Documentation

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

Definition at line 476 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 479 of file sch_legacy_plugin.cpp.

Referenced by AddSymbol(), DeleteAlias(), removeAlias(), and Save().

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

Definition at line 478 of file sch_legacy_plugin.cpp.

Referenced by GetLibModificationTime().

wxFileName SCH_LEGACY_PLUGIN_CACHE::m_libFileName
private
int SCH_LEGACY_PLUGIN_CACHE::m_libType
private

Definition at line 483 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

int SCH_LEGACY_PLUGIN_CACHE::m_modHash
private

Definition at line 480 of file sch_legacy_plugin.cpp.

Referenced by AddSymbol(), DeleteAlias(), GetModifyHash(), Load(), and removeAlias().

int SCH_LEGACY_PLUGIN_CACHE::m_versionMajor
private

Definition at line 481 of file sch_legacy_plugin.cpp.

Referenced by Load(), loadPart(), loadText(), and SCH_LEGACY_PLUGIN_CACHE().

int SCH_LEGACY_PLUGIN_CACHE::m_versionMinor
private

Definition at line 482 of file sch_legacy_plugin.cpp.

Referenced by Load(), loadPart(), loadText(), and SCH_LEGACY_PLUGIN_CACHE().

friend SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN
private

Definition at line 509 of file sch_legacy_plugin.cpp.


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