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 479 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 2043 of file sch_legacy_plugin.cpp.

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

2044 {
2045  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2046  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); ++it )
2047  {
2048  wxLogTrace( traceSchLegacyPlugin, wxT( "Removing alias %s from library %s." ),
2049  GetChars( it->second->GetName() ), GetChars( GetLogicalName() ) );
2050  LIB_PART* part = it->second->GetPart();
2051  LIB_ALIAS* alias = it->second;
2052  delete alias;
2053 
2054  // When the last alias of a part is destroyed, the part is no longer required and it
2055  // too is destroyed.
2056  if( part && part->GetAliasCount() == 0 )
2057  delete part;
2058  }
2059 
2060  m_aliases.clear();
2061 }
Part library alias object definition.
size_t GetAliasCount() const
const wxChar traceSchLegacyPlugin[]
Flag to enable legacy schematic plugin debug output.
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 2132 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().

2133 {
2134  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2135  wxArrayString aliasNames = aPart->GetAliasNames();
2136 
2137  for( size_t i = 0; i < aliasNames.size(); i++ )
2138  {
2139  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasNames[i] );
2140 
2141  if( it != m_aliases.end() )
2142  removeAlias( it->second );
2143 
2144  LIB_ALIAS* alias = const_cast< LIB_PART* >( aPart )->GetAlias( aliasNames[i] );
2145 
2146  wxASSERT_MSG( alias != NULL, "No alias <" + aliasNames[i] + "> found in symbol <" +
2147  aPart->GetName() +">." );
2148 
2149  m_aliases[ aliasNames[i] ] = alias;
2150  }
2151 
2152  m_isModified = true;
2153  ++m_modHash;
2154 }
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 2500 of file sch_legacy_plugin.cpp.

References m_aliases.

Referenced by loadAliases().

2501 {
2502  wxCHECK_MSG( !aAliasName.IsEmpty(), false, "alias name cannot be empty" );
2503 
2504  // The alias name is not a duplicate so don't change it.
2505  if( m_aliases.find( aAliasName ) == m_aliases.end() )
2506  return false;
2507 
2508  int dupCounter = 1;
2509  wxString newAlias = aAliasName;
2510 
2511  // If the alias is already loaded, the library is broken. It may have been possible in
2512  // the past that this could happen so we assign a new alias name to prevent any conflicts
2513  // rather than throw an exception.
2514  while( m_aliases.find( newAlias ) != m_aliases.end() )
2515  {
2516  newAlias = aAliasName << dupCounter;
2517  dupCounter++;
2518  }
2519 
2520  aAliasName = newAlias;
2521 
2522  return true;
2523 }
void SCH_LEGACY_PLUGIN_CACHE::DeleteAlias ( const wxString &  aAliasName)

Definition at line 3333 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().

3334 {
3335  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3336 
3337  if( it == m_aliases.end() )
3338  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3339  m_libFileName.GetFullName(), aAliasName ) );
3340 
3341  LIB_ALIAS* alias = it->second;
3342  LIB_PART* part = alias->GetPart();
3343 
3344  alias = part->RemoveAlias( alias );
3345 
3346  if( !alias )
3347  {
3348  delete part;
3349 
3350  if( m_aliases.size() > 1 )
3351  {
3352  LIB_ALIAS_MAP::iterator next = it;
3353  next++;
3354 
3355  if( next == m_aliases.end() )
3356  next = m_aliases.begin();
3357 
3358  alias = next->second;
3359  }
3360  }
3361 
3362  m_aliases.erase( it );
3363  ++m_modHash;
3364  m_isModified = true;
3365 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Class LIB_PART defines a library part object.
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol ( const wxString &  aAliasName)

Definition at line 3368 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().

3369 {
3370  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3371 
3372  if( it == m_aliases.end() )
3373  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3374  m_libFileName.GetFullName(), aAliasName ) );
3375 
3376  LIB_ALIAS* alias = it->second;
3377  LIB_PART* part = alias->GetPart();
3378 
3379  wxArrayString aliasNames = part->GetAliasNames();
3380 
3381  // Deleting all of the aliases deletes the symbol from the library.
3382  for( size_t i = 0; i < aliasNames.Count(); i++ )
3383  DeleteAlias( aliasNames[i] );
3384 }
Part library alias object definition.
void DeleteAlias(const wxString &aAliasName)
Class LIB_PART defines a library part object.
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 550 of file sch_legacy_plugin.cpp.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

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

Definition at line 2064 of file sch_legacy_plugin.cpp.

References m_isWritable, and m_libFileName.

Referenced by Load().

2065 {
2066  // update the writable flag while we have a wxFileName, in a network this
2067  // is possibly quite dynamic anyway.
2068  m_isWritable = m_libFileName.IsFileWritable();
2069 
2070  return m_libFileName.GetModificationTime();
2071 }
wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 546 of file sch_legacy_plugin.cpp.

Referenced by ~SCH_LEGACY_PLUGIN_CACHE().

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

Definition at line 521 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 2074 of file sch_legacy_plugin.cpp.

References m_libFileName.

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

2075 {
2076  return m_libFileName == aFullPathAndFileName;
2077 }
bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 2080 of file sch_legacy_plugin.cpp.

References m_fileModTime, and m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::cacheLib().

2081 {
2082  if( m_fileModTime.IsValid() && m_libFileName.IsOk() && m_libFileName.FileExists() )
2083  return m_libFileName.GetModificationTime() != m_fileModTime;
2084 
2085  return false;
2086 }
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 2157 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().

2158 {
2159  wxCHECK_RET( m_libFileName.IsAbsolute(),
2160  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2161  "open library '%s'.", m_libFileName.GetFullPath() ) );
2162 
2163  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file '%s'",
2164  m_libFileName.GetFullPath() );
2165 
2166  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2167 
2168  if( !reader.ReadLine() )
2169  THROW_IO_ERROR( _( "unexpected end of file" ) );
2170 
2171  const char* line = reader.Line();
2172 
2173  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2174  {
2175  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2176  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2177  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2178  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2179  }
2180 
2181  m_versionMajor = parseInt( reader, line, &line );
2182 
2183  if( *line != '.' )
2184  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2185 
2186  line++;
2187 
2188  m_versionMinor = parseInt( reader, line, &line );
2189 
2190  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2191  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2192 
2193  // Check if this is a symbol library which is the same as a component library but without
2194  // any alias, documentation, footprint filters, etc.
2195  if( strCompare( "SYMBOL", line, &line ) )
2196  {
2197  // Symbol files add date and time stamp info to the header.
2199 
2201  }
2202  else
2203  {
2205  }
2206 
2207  while( reader.ReadLine() )
2208  {
2209  line = reader.Line();
2210 
2211  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2212  continue;
2213 
2214  // Headers where only supported in older library file formats.
2215  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2216  loadHeader( reader );
2217 
2218  if( strCompare( "DEF", line ) )
2219  {
2220  // Read one DEF/ENDDEF part entry from library:
2221  loadPart( reader );
2222 
2223  }
2224  }
2225 
2226  ++m_modHash;
2227 
2228  // Remember the file modification time of library file when the
2229  // cache snapshot was made, so that in a networked environment we will
2230  // reload the cache as needed.
2232 
2234  loadDocs();
2235 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
void loadHeader(FILE_LINE_READER &aReader)
const wxChar traceSchLegacyPlugin[]
Flag to enable legacy schematic plugin debug output.
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#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.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SCH_LEGACY_PLUGIN_CACHE::loadAliases ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2526 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

2528 {
2529  wxString newAlias;
2530  const char* line = aReader.Line();
2531 
2532  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2533 
2534  // Parse the ALIAS list.
2535  wxString alias;
2536  parseUnquotedString( alias, aReader, line, &line );
2537 
2538  while( !alias.IsEmpty() )
2539  {
2540  newAlias = alias;
2541  checkForDuplicates( newAlias );
2542  aPart->AddAlias( newAlias );
2543  alias.clear();
2544  parseUnquotedString( alias, aReader, line, &line, true );
2545  }
2546 }
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 2783 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().

2785 {
2786  const char* line = aReader.Line();
2787 
2788  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
2789 
2790  std::unique_ptr< LIB_ARC > arc( new LIB_ARC( aPart.get() ) );
2791 
2792  wxPoint center;
2793 
2794  center.x = parseInt( aReader, line, &line );
2795  center.y = parseInt( aReader, line, &line );
2796 
2797  arc->SetPosition( center );
2798  arc->SetRadius( parseInt( aReader, line, &line ) );
2799 
2800  int angle1 = parseInt( aReader, line, &line );
2801  int angle2 = parseInt( aReader, line, &line );
2802 
2803  NORMALIZE_ANGLE_POS( angle1 );
2804  NORMALIZE_ANGLE_POS( angle2 );
2805  arc->SetFirstRadiusAngle( angle1 );
2806  arc->SetSecondRadiusAngle( angle2 );
2807 
2808  arc->SetUnit( parseInt( aReader, line, &line ) );
2809  arc->SetConvert( parseInt( aReader, line, &line ) );
2810  arc->SetWidth( parseInt( aReader, line, &line ) );
2811 
2812  // Old libraries (version <= 2.2) do not have always this FILL MODE param
2813  // when fill mode is no fill (default mode).
2814  if( *line != 0 )
2815  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
2816 
2817  // Actual Coordinates of arc ends are read from file
2818  if( *line != 0 )
2819  {
2820  wxPoint arcStart, arcEnd;
2821 
2822  arcStart.x = parseInt( aReader, line, &line );
2823  arcStart.y = parseInt( aReader, line, &line );
2824  arcEnd.x = parseInt( aReader, line, &line );
2825  arcEnd.y = parseInt( aReader, line, &line );
2826 
2827  arc->SetStart( arcStart );
2828  arc->SetEnd( arcEnd );
2829  }
2830  else
2831  {
2832  // Actual Coordinates of arc ends are not read from file
2833  // (old library), calculate them
2834  wxPoint arcStart( arc->GetRadius(), 0 );
2835  wxPoint arcEnd( arc->GetRadius(), 0 );
2836 
2837  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
2838  arcStart += arc->GetPosition();
2839  arc->SetStart( arcStart );
2840  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
2841  arcEnd += arc->GetPosition();
2842  arc->SetEnd( arcEnd );
2843  }
2844 
2845  return arc.release();
2846 }
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 3232 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3234 {
3235  const char* line = aReader.Line();
3236 
3237  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3238 
3239  std::unique_ptr< LIB_BEZIER > bezier( new LIB_BEZIER( aPart.get() ) );
3240 
3241  int points = parseInt( aReader, line, &line );
3242  bezier->SetUnit( parseInt( aReader, line, &line ) );
3243  bezier->SetConvert( parseInt( aReader, line, &line ) );
3244  bezier->SetWidth( parseInt( aReader, line, &line ) );
3245 
3246  wxPoint pt;
3247 
3248  for( int i = 0; i < points; i++ )
3249  {
3250  pt.x = parseInt( aReader, line, &line );
3251  pt.y = parseInt( aReader, line, &line );
3252  bezier->AddPoint( pt );
3253  }
3254 
3255  if( *line != 0 )
3256  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3257 
3258  return bezier.release();
3259 }
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 2849 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

2851 {
2852  const char* line = aReader.Line();
2853 
2854  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
2855 
2856  std::unique_ptr< LIB_CIRCLE > circle( new LIB_CIRCLE( aPart.get() ) );
2857 
2858  wxPoint center;
2859 
2860  center.x = parseInt( aReader, line, &line );
2861  center.y = parseInt( aReader, line, &line );
2862 
2863  circle->SetPosition( center );
2864  circle->SetRadius( parseInt( aReader, line, &line ) );
2865  circle->SetUnit( parseInt( aReader, line, &line ) );
2866  circle->SetConvert( parseInt( aReader, line, &line ) );
2867  circle->SetWidth( parseInt( aReader, line, &line ) );
2868 
2869  if( *line != 0 )
2870  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
2871 
2872  return circle.release();
2873 }
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 2238 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().

2239 {
2240  const char* line;
2241  wxString text;
2242  wxString aliasName;
2243  wxFileName fn = m_libFileName;
2244  LIB_ALIAS* alias = NULL;;
2245 
2246  fn.SetExt( DOC_EXT );
2247 
2248  // Not all libraries will have a document file.
2249  if( !fn.FileExists() )
2250  return;
2251 
2252  if( !fn.IsFileReadable() )
2253  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2254  "document file '%s'" ), fn.GetFullPath() ) );
2255 
2256  FILE_LINE_READER reader( fn.GetFullPath() );
2257 
2258  line = reader.ReadLine();
2259 
2260  if( !line )
2261  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2262 
2263  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2264  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2265  reader, line );
2266 
2267  while( reader.ReadLine() )
2268  {
2269  line = reader.Line();
2270 
2271  if( *line == '#' ) // Comment line.
2272  continue;
2273 
2274  if( !strCompare( "$CMP", line, &line ) != 0 )
2275  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2276 
2277  parseUnquotedString( aliasName, reader, line, &line ); // Alias name.
2278 
2279  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
2280 
2281  if( it == m_aliases.end() )
2282  wxLogWarning( "Alias '%s' not found in library:\n\n"
2283  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2284  reader.LineNumber(), (int) (line - reader.Line() ) );
2285  else
2286  alias = it->second;
2287 
2288  // Read the curent alias associated doc.
2289  // if the alias does not exist, just skip the description
2290  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2291  while( reader.ReadLine() )
2292  {
2293  line = reader.Line();
2294 
2295  if( !line )
2296  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2297 
2298  if( strCompare( "$ENDCMP", line, &line ) )
2299  break;
2300 
2301  text = FROM_UTF8( line + 2 );
2302  text = text.Trim();
2303 
2304  switch( line[0] )
2305  {
2306  case 'D':
2307  if( alias )
2308  alias->SetDescription( text );
2309  break;
2310 
2311  case 'K':
2312  if( alias )
2313  alias->SetKeyWords( text );
2314  break;
2315 
2316  case 'F':
2317  if( alias )
2318  alias->SetDocFileName( text );
2319  break;
2320 
2321  case '#':
2322  break;
2323 
2324  default:
2325  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2326  }
2327  }
2328  }
2329 }
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
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.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SCH_LEGACY_PLUGIN_CACHE::loadDrawEntries ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2695 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().

2697 {
2698  const char* line = aReader.Line();
2699 
2700  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
2701 
2702  line = aReader.ReadLine();
2703 
2704  while( line )
2705  {
2706  if( strCompare( "ENDDRAW", line, &line ) )
2707  return;
2708 
2709  switch( line[0] )
2710  {
2711  case 'A': // Arc
2712  aPart->AddDrawItem( loadArc( aPart, aReader ) );
2713  break;
2714 
2715  case 'C': // Circle
2716  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
2717  break;
2718 
2719  case 'T': // Text
2720  aPart->AddDrawItem( loadText( aPart, aReader ) );
2721  break;
2722 
2723  case 'S': // Square
2724  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
2725  break;
2726 
2727  case 'X': // Pin Description
2728  aPart->AddDrawItem( loadPin( aPart, aReader ) );
2729  break;
2730 
2731  case 'P': // Polyline
2732  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
2733  break;
2734 
2735  case 'B': // Bezier Curves
2736  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
2737  break;
2738 
2739  case '#': // Comment
2740  case '\n': // Empty line
2741  case '\r':
2742  case 0:
2743  break;
2744 
2745  default:
2746  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
2747  }
2748 
2749  line = aReader.ReadLine();
2750  }
2751 
2752  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
2753 }
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 2549 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, name, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, VALUE, wxPoint::x, and wxPoint::y.

Referenced by loadPart().

2551 {
2552  const char* line = aReader.Line();
2553 
2554  wxCHECK_RET( *line == 'F', "Invalid field line" );
2555 
2556  int id;
2557 
2558  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2559  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
2560 
2561  std::unique_ptr< LIB_FIELD > field( new LIB_FIELD( aPart.get(), id ) );
2562 
2563  // Skip to the first double quote.
2564  while( *line != '"' && *line != 0 )
2565  line++;
2566 
2567  if( *line == 0 )
2568  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
2569 
2570  wxString text;
2571  parseQuotedString( text, aReader, line, &line, true );
2572 
2573  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
2574  // not save like this.
2575  if( text.size() == 1 && text[0] == '~' )
2576  text.clear();
2577 
2578  field->m_Text = text;
2579 
2580  wxPoint pos;
2581 
2582  pos.x = parseInt( aReader, line, &line );
2583  pos.y = parseInt( aReader, line, &line );
2584  field->SetPosition( pos );
2585 
2586  wxSize textSize;
2587 
2588  textSize.x = textSize.y = parseInt( aReader, line, &line );
2589  field->SetTextSize( textSize );
2590 
2591  char textOrient = parseChar( aReader, line, &line );
2592 
2593  if( textOrient == 'H' )
2594  field->SetTextAngle( TEXT_ANGLE_HORIZ );
2595  else if( textOrient == 'V' )
2596  field->SetTextAngle( TEXT_ANGLE_VERT );
2597  else
2598  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
2599 
2600  char textVisible = parseChar( aReader, line, &line );
2601 
2602  if( textVisible == 'V' )
2603  field->SetVisible( true );
2604  else if ( textVisible == 'I' )
2605  field->SetVisible( false );
2606  else
2607  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
2608 
2609  // It may be technically correct to use the library version to determine if the field text
2610  // attributes are present. If anyone knows if that is valid and what version that would be,
2611  // please change this to test the library version rather than an EOL or the quoted string
2612  // of the field name.
2613  if( *line != 0 && *line != '"' )
2614  {
2615  char textHJustify = parseChar( aReader, line, &line );
2616 
2617  if( textHJustify == 'C' )
2618  field->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
2619  else if( textHJustify == 'L' )
2620  field->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
2621  else if( textHJustify == 'R' )
2622  field->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
2623  else
2624  SCH_PARSE_ERROR( "invalid field text horizontal justification parameter",
2625  aReader, line );
2626 
2627  wxString attributes;
2628 
2629  parseUnquotedString( attributes, aReader, line, &line );
2630 
2631  if( !(attributes.size() == 3 || attributes.size() == 1 ) )
2632  SCH_PARSE_ERROR( "invalid field text attributes size",
2633  aReader, line );
2634 
2635  if( attributes[0] == 'C' )
2636  field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
2637  else if( attributes[0] == 'B' )
2638  field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
2639  else if( attributes[0] == 'T' )
2640  field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
2641  else
2642  SCH_PARSE_ERROR( "invalid field text vertical justification parameter",
2643  aReader, line );
2644 
2645  if( attributes.size() == 3 )
2646  {
2647  if( attributes[1] == 'I' ) // Italic
2648  field->SetItalic( true );
2649  else if( attributes[1] != 'N' ) // No italics is default, check for error.
2650  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
2651 
2652  if ( attributes[2] == 'B' ) // Bold
2653  field->SetBold( true );
2654  else if( attributes[2] != 'N' ) // No bold is default, check for error.
2655  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
2656  }
2657  }
2658 
2659  // Fields in RAM must always have names.
2660  if( id < MANDATORY_FIELDS )
2661  {
2662  // Fields in RAM must always have names, because we are trying to get
2663  // less dependent on field ids and more dependent on names.
2664  // Plus assumptions are made in the field editors.
2665  field->m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
2666 
2667  LIB_FIELD* fixedField = aPart->GetField( field->GetId() );
2668 
2669  // this will fire only if somebody broke a constructor or editor.
2670  // MANDATORY_FIELDS are always present in ram resident components, no
2671  // exceptions, and they always have their names set, even fixed fields.
2672  wxASSERT( fixedField );
2673 
2674  *fixedField = *field;
2675 
2676  // Ensure the VALUE field = the part name (can be not the case
2677  // with malformed libraries: edited by hand, or converted from other tools)
2678  if( fixedField->GetId() == VALUE )
2679  fixedField->m_Text = aPart->m_name;
2680  }
2681  else
2682  {
2683  wxString name;
2684 
2685  parseQuotedString( name, aReader, line, &line, true ); // Optional.
2686 
2687  if( !name.IsEmpty() )
2688  field->m_name = name;
2689 
2690  aPart->AddDrawItem( field.release() ); // LIB_FIELD* is now owned by the LIB_PART.
2691  }
2692 }
#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:346
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.
const char * name
void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3262 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

3264 {
3265  const char* line = aReader.Line();
3266 
3267  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3268 
3269  line = aReader.ReadLine();
3270 
3271  while( line )
3272  {
3273  if( strCompare( "$ENDFPLIST", line, &line ) )
3274  return;
3275 
3276  wxString footprint;
3277 
3278  parseUnquotedString( footprint, aReader, line, &line );
3279  aPart->GetFootPrints().Add( footprint );
3280  line = aReader.ReadLine();
3281  }
3282 
3283  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3284 }
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 2332 of file sch_legacy_plugin.cpp.

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

Referenced by Load().

2333 {
2334  const char* line = aReader.Line();
2335 
2336  wxASSERT( strCompare( "$HEADER", line, &line ) );
2337 
2338  while( aReader.ReadLine() )
2339  {
2340  line = (char*) aReader;
2341 
2342  // The time stamp saved in old library files is not used or saved in the latest
2343  // library file version.
2344  if( strCompare( "TimeStamp", line, &line ) )
2345  continue;
2346  else if( strCompare( "$ENDHEADER", line, &line ) )
2347  return;
2348  }
2349 
2350  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2351 }
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 2354 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, name, parseChar(), parseInt(), parseUnquotedString(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_FIELD::SetText(), EDA_TEXT::SetVisible(), and strCompare().

Referenced by Load().

2355 {
2356  const char* line = aReader.Line();
2357 
2358  wxCHECK( strCompare( "DEF", line, &line ), NULL );
2359 
2360  // Read DEF line:
2361  char yes_no = 0;
2362 
2363  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2364 
2365  wxString name, prefix;
2366 
2367  parseUnquotedString( name, aReader, line, &line ); // Part name.
2368  parseUnquotedString( prefix, aReader, line, &line ); // Prefix name
2369  parseInt( aReader, line, &line ); // NumOfPins, unused.
2370  part->SetPinNameOffset( parseInt( aReader, line, &line ) ); // Pin name offset.
2371  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2372 
2373  if( !( yes_no == 'Y' || yes_no == 'N') )
2374  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2375 
2376  part->SetShowPinNumbers( ( yes_no == 'N' ) ? false : true );
2377 
2378  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2379 
2380  if( !( yes_no == 'Y' || yes_no == 'N') )
2381  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2382 
2383  part->SetShowPinNames( ( yes_no == 'N' ) ? false : true ); // Show pin names.
2384 
2385  part->SetUnitCount( parseInt( aReader, line, &line ) ); // Number of units.
2386 
2387  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2388  if( part->GetUnitCount() < 1 )
2389  part->SetUnitCount( 1 );
2390 
2391  // Copy part name and prefix.
2392  LIB_FIELD& value = part->GetValueField();
2393 
2394  // The root alias is added to the alias list by SetName() which is called by SetText().
2395  if( name.IsEmpty() )
2396  {
2397  part->m_name = "~";
2398  value.SetText( "~" );
2399  }
2400  else if( name[0] != '~' )
2401  {
2402  part->m_name = name;
2403  value.SetText( name );
2404  }
2405  else
2406  {
2407  name = name.Right( name.Length() - 1 );
2408  part->m_name = name;
2409  value.SetText( name );
2410  value.SetVisible( false );
2411  }
2412 
2413  // There are some code paths in SetText() that do not set the root alias to the
2414  // alias list so add it here if it didn't get added by SetText().
2415  if( !part->HasAlias( part->GetName() ) )
2416  part->AddAlias( part->GetName() );
2417 
2418  LIB_FIELD& reference = part->GetReferenceField();
2419 
2420  if( prefix == "~" )
2421  {
2422  reference.Empty();
2423  reference.SetVisible( false );
2424  }
2425  else
2426  {
2427  reference.SetText( prefix );
2428  }
2429 
2430  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2431  // The was no concept of interchangeable multiple unit symbols.
2433  {
2434  // Nothing needs to be set since the default setting for symbols with multiple
2435  // units were never interchangeable. Just parse the 0 an move on.
2436  parseInt( aReader, line, &line );
2437  }
2438  else
2439  {
2440  char locked = parseChar( aReader, line, &line );
2441 
2442  if( locked == 'L' )
2443  part->LockUnits( true );
2444  else if( locked == 'F' || locked == '0' )
2445  part->LockUnits( false );
2446  else
2447  SCH_PARSE_ERROR( "expected L, F, or 0", aReader, line );
2448  }
2449 
2450 
2451  // There is the optional power component flag.
2452  if( *line )
2453  {
2454  char power = parseChar( aReader, line, &line );
2455 
2456  if( power == 'P' )
2457  part->SetPower();
2458  else if( power == 'N' )
2459  part->SetNormal();
2460  else
2461  SCH_PARSE_ERROR( "expected P or N", aReader, line );
2462  }
2463 
2464  line = aReader.ReadLine();
2465 
2466  // Read lines until "ENDDEF" is found.
2467  while( line )
2468  {
2469  if( *line == '#' ) // Comment
2470  ;
2471  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2472  continue;
2473  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2474  loadAliases( part, aReader );
2475  else if( *line == 'F' ) // Fields
2476  loadField( part, aReader );
2477  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2478  loadDrawEntries( part, aReader );
2479  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2480  loadFootprintFilters( part, aReader );
2481  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2482  {
2483  // Now all is good, Add the root alias to the cache alias list.
2484  m_aliases[ part->GetName() ] = part->GetAlias( part->GetName() );
2485 
2486  // Add aliases when exist
2487  for( size_t ii = 0; ii < part->GetAliasCount(); ++ii )
2488  m_aliases[ part->GetAlias( ii )->GetName() ] = part->GetAlias( ii );
2489 
2490  return part.release();
2491  }
2492 
2493  line = aReader.ReadLine();
2494  }
2495 
2496  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2497 }
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:675
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.
const char * name
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 3015 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), name, 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().

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

Definition at line 3202 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3204 {
3205  const char* line = aReader.Line();
3206 
3207  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3208 
3209  std::unique_ptr< LIB_POLYLINE > polyLine( new LIB_POLYLINE( aPart.get() ) );
3210 
3211  int points = parseInt( aReader, line, &line );
3212  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3213  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3214  polyLine->SetWidth( parseInt( aReader, line, &line ) );
3215 
3216  wxPoint pt;
3217 
3218  for( int i = 0; i < points; i++ )
3219  {
3220  pt.x = parseInt( aReader, line, &line );
3221  pt.y = parseInt( aReader, line, &line );
3222  polyLine->AddPoint( pt );
3223  }
3224 
3225  if( *line != 0 )
3226  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3227 
3228  return polyLine.release();
3229 }
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 2983 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

2985 {
2986  const char* line = aReader.Line();
2987 
2988  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
2989 
2990  std::unique_ptr< LIB_RECTANGLE > rectangle( new LIB_RECTANGLE( aPart.get() ) );
2991 
2992  wxPoint pos;
2993 
2994  pos.x = parseInt( aReader, line, &line );
2995  pos.y = parseInt( aReader, line, &line );
2996  rectangle->SetPosition( pos );
2997 
2998  wxPoint end;
2999 
3000  end.x = parseInt( aReader, line, &line );
3001  end.y = parseInt( aReader, line, &line );
3002  rectangle->SetEnd( end );
3003 
3004  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3005  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3006  rectangle->SetWidth( parseInt( aReader, line, &line ) );
3007 
3008  if( *line != 0 )
3009  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3010 
3011  return rectangle.release();
3012 }
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 2876 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().

2878 {
2879  const char* line = aReader.Line();
2880 
2881  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
2882 
2883  std::unique_ptr< LIB_TEXT > text( new LIB_TEXT( aPart.get() ) );
2884 
2885  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
2886 
2887  wxPoint center;
2888 
2889  center.x = parseInt( aReader, line, &line );
2890  center.y = parseInt( aReader, line, &line );
2891  text->SetPosition( center );
2892 
2893  wxSize size;
2894 
2895  size.x = size.y = parseInt( aReader, line, &line );
2896  text->SetTextSize( size );
2897  text->SetVisible( !parseInt( aReader, line, &line ) );
2898  text->SetUnit( parseInt( aReader, line, &line ) );
2899  text->SetConvert( parseInt( aReader, line, &line ) );
2900 
2901  wxString str;
2902 
2903  // If quoted string loading fails, load as not quoted string.
2904  if( *line == '"' )
2905  parseQuotedString( str, aReader, line, &line );
2906  else
2907  parseUnquotedString( str, aReader, line, &line );
2908 
2909  if( !str.IsEmpty() )
2910  {
2911  // convert two apostrophes back to double quote
2912  str.Replace( "''", "\"" );
2913  str.Replace( wxT( "~" ), wxT( " " ) );
2914  }
2915 
2916  text->SetText( str );
2917 
2918  // Here things are murky and not well defined. At some point it appears the format
2919  // was changed to add text properties. However rather than add the token to the end of
2920  // the text definition, it was added after the string and no mention if the file
2921  // verion was bumped or not so this code make break on very old component libraries.
2922  //
2923  // Update: apparently even in the latest version this can be different so added a test
2924  // for end of line before checking for the text properties.
2925  if( LIB_VERSION( m_versionMajor, m_versionMinor ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
2926  {
2927  if( strCompare( "Italic", line, &line ) )
2928  text->SetItalic( true );
2929  else if( !strCompare( "Normal", line, &line ) )
2930  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'",
2931  aReader, line );
2932 
2933  if( parseInt( aReader, line, &line ) > 0 )
2934  text->SetBold( true );
2935 
2936  // Some old libaries version > 2.0 do not have these options for text justification:
2937  if( !is_eol( *line ) )
2938  {
2939  switch( parseChar( aReader, line, &line ) )
2940  {
2941  case 'L':
2942  text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
2943  break;
2944 
2945  case 'C':
2946  text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
2947  break;
2948 
2949  case 'R':
2950  text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
2951  break;
2952 
2953  default:
2954  SCH_PARSE_ERROR( "invalid horizontal text justication parameter, expected L, C, or R",
2955  aReader, line );
2956  }
2957 
2958  switch( parseChar( aReader, line, &line ) )
2959  {
2960  case 'T':
2961  text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
2962  break;
2963 
2964  case 'C':
2965  text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
2966  break;
2967 
2968  case 'B':
2969  text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
2970  break;
2971 
2972  default:
2973  SCH_PARSE_ERROR( "invalid vertical text justication parameter, expected T, C, or B",
2974  aReader, line );
2975  }
2976  }
2977  }
2978 
2979  return text.release();
2980 }
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 2756 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().

2758 {
2759  FILL_T mode;
2760 
2761  switch( parseChar( aReader, aLine, aOutput ) )
2762  {
2763  case 'F':
2764  mode = FILLED_SHAPE;
2765  break;
2766 
2767  case 'f':
2768  mode = FILLED_WITH_BG_BODYCOLOR;
2769  break;
2770 
2771  case 'N':
2772  mode = NO_FILL;
2773  break;
2774 
2775  default:
2776  SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
2777  }
2778 
2779  return mode;
2780 }
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:70
LIB_ALIAS * SCH_LEGACY_PLUGIN_CACHE::removeAlias ( LIB_ALIAS aAlias)
private

Definition at line 2089 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().

2090 {
2091  wxCHECK_MSG( aAlias != NULL, NULL, "NULL pointer cannot be removed from library." );
2092 
2093  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAlias->GetName() );
2094 
2095  if( it == m_aliases.end() )
2096  return NULL;
2097 
2098  // If the entry pointer doesn't match the name it is mapped to in the library, we
2099  // have done something terribly wrong.
2100  wxCHECK_MSG( *it->second == aAlias, NULL,
2101  "Pointer mismatch while attempting to remove alias entry <" + aAlias->GetName() +
2102  "> from library cache <" + m_libFileName.GetName() + ">." );
2103 
2104  LIB_ALIAS* alias = aAlias;
2105  LIB_PART* part = alias->GetPart();
2106 
2107  alias = part->RemoveAlias( alias );
2108 
2109  if( !alias )
2110  {
2111  delete part;
2112 
2113  if( m_aliases.size() > 1 )
2114  {
2115  LIB_ALIAS_MAP::iterator next = it;
2116  next++;
2117 
2118  if( next == m_aliases.end() )
2119  next = m_aliases.begin();
2120 
2121  alias = next->second;
2122  }
2123  }
2124 
2125  m_aliases.erase( it );
2126  m_isModified = true;
2127  ++m_modHash;
2128  return alias;
2129 }
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 3287 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().

3288 {
3289  if( !m_isModified )
3290  return;
3291 
3292  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( m_libFileName.GetFullPath() ) );
3293  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3294  formatter->Print( 0, "#encoding utf-8\n");
3295 
3296  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3297  {
3298  if( !it->second->IsRoot() )
3299  continue;
3300 
3301  it->second->GetPart()->Save( *formatter.get() );
3302  }
3303 
3304  formatter->Print( 0, "#\n#End Library\n" );
3305  formatter.reset();
3306 
3307  m_fileModTime = m_libFileName.GetModificationTime();
3308  m_isModified = false;
3309 
3310  if( aSaveDocFile )
3311  saveDocFile();
3312 }
#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 3315 of file sch_legacy_plugin.cpp.

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

Referenced by Save().

3316 {
3317  wxFileName docFileName = m_libFileName;
3318 
3319  docFileName.SetExt( DOC_EXT );
3320  FILE_OUTPUTFORMATTER formatter( docFileName.GetFullPath() );
3321 
3322  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
3323 
3324  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3325  {
3326  it->second->SaveDoc( formatter );
3327  }
3328 
3329  formatter.Print( 0, "#\n#End Doc Library\n" );
3330 }
#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 548 of file sch_legacy_plugin.cpp.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

548 { 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 482 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 485 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

Definition at line 484 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 489 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 486 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 487 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 488 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 515 of file sch_legacy_plugin.cpp.


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