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 474 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 2038 of file sch_legacy_plugin.cpp.

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

2039 {
2040  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2041  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); ++it )
2042  {
2043  wxLogTrace( traceSchLegacyPlugin, wxT( "Removing alias %s from library %s." ),
2044  GetChars( it->second->GetName() ), GetChars( GetLogicalName() ) );
2045  LIB_PART* part = it->second->GetPart();
2046  LIB_ALIAS* alias = it->second;
2047  delete alias;
2048 
2049  // When the last alias of a part is destroyed, the part is no longer required and it
2050  // too is destroyed.
2051  if( part && part->GetAliasCount() == 0 )
2052  delete part;
2053  }
2054 
2055  m_aliases.clear();
2056 }
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 2127 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().

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

References m_aliases.

Referenced by loadAliases().

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

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

3329 {
3330  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3331 
3332  if( it == m_aliases.end() )
3333  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3334  m_libFileName.GetFullName(), aAliasName ) );
3335 
3336  LIB_ALIAS* alias = it->second;
3337  LIB_PART* part = alias->GetPart();
3338 
3339  alias = part->RemoveAlias( alias );
3340 
3341  if( !alias )
3342  {
3343  delete part;
3344 
3345  if( m_aliases.size() > 1 )
3346  {
3347  LIB_ALIAS_MAP::iterator next = it;
3348  next++;
3349 
3350  if( next == m_aliases.end() )
3351  next = m_aliases.begin();
3352 
3353  alias = next->second;
3354  }
3355  }
3356 
3357  m_aliases.erase( it );
3358  ++m_modHash;
3359  m_isModified = true;
3360 }
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 3363 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().

3364 {
3365  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3366 
3367  if( it == m_aliases.end() )
3368  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3369  m_libFileName.GetFullName(), aAliasName ) );
3370 
3371  LIB_ALIAS* alias = it->second;
3372  LIB_PART* part = alias->GetPart();
3373 
3374  wxArrayString aliasNames = part->GetAliasNames();
3375 
3376  // Deleting all of the aliases deletes the symbol from the library.
3377  for( size_t i = 0; i < aliasNames.Count(); i++ )
3378  DeleteAlias( aliasNames[i] );
3379 }
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 545 of file sch_legacy_plugin.cpp.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

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

Definition at line 2059 of file sch_legacy_plugin.cpp.

References m_isWritable, and m_libFileName.

Referenced by Load().

2060 {
2061  // update the writable flag while we have a wxFileName, in a network this
2062  // is possibly quite dynamic anyway.
2063  m_isWritable = m_libFileName.IsFileWritable();
2064 
2065  return m_libFileName.GetModificationTime();
2066 }
wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 541 of file sch_legacy_plugin.cpp.

Referenced by ~SCH_LEGACY_PLUGIN_CACHE().

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

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

References m_libFileName.

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

2070 {
2071  return m_libFileName == aFullPathAndFileName;
2072 }
bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 2075 of file sch_legacy_plugin.cpp.

References m_fileModTime, and m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::cacheLib().

2076 {
2077  if( m_fileModTime.IsValid() && m_libFileName.IsOk() && m_libFileName.FileExists() )
2078  return m_libFileName.GetModificationTime() != m_fileModTime;
2079 
2080  return false;
2081 }
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 2152 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().

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

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

Referenced by loadPart().

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

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

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

Referenced by loadDrawEntries().

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

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

Referenced by loadDrawEntries().

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

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

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

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

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

Referenced by loadPart().

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

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

Referenced by Load().

2328 {
2329  const char* line = aReader.Line();
2330 
2331  wxASSERT( strCompare( "$HEADER", line, &line ) );
2332 
2333  while( aReader.ReadLine() )
2334  {
2335  line = (char*) aReader;
2336 
2337  // The time stamp saved in old library files is not used or saved in the latest
2338  // library file version.
2339  if( strCompare( "TimeStamp", line, &line ) )
2340  continue;
2341  else if( strCompare( "$ENDHEADER", line, &line ) )
2342  return;
2343  }
2344 
2345  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2346 }
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 2349 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().

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

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

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

Referenced by loadDrawEntries().

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

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

Referenced by loadDrawEntries().

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

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

2753 {
2754  FILL_T mode;
2755 
2756  switch( parseChar( aReader, aLine, aOutput ) )
2757  {
2758  case 'F':
2759  mode = FILLED_SHAPE;
2760  break;
2761 
2762  case 'f':
2763  mode = FILLED_WITH_BG_BODYCOLOR;
2764  break;
2765 
2766  case 'N':
2767  mode = NO_FILL;
2768  break;
2769 
2770  default:
2771  SCH_PARSE_ERROR( _( "invalid fill type, expected f, F, or N" ), aReader, aLine );
2772  }
2773 
2774  return mode;
2775 }
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 2084 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().

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

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

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

Referenced by Save().

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

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

543 { 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 477 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 480 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

Definition at line 479 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 484 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 481 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 482 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 483 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 510 of file sch_legacy_plugin.cpp.


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