KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN_CACHE Class Reference

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

Public Member Functions

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

Private Member Functions

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

Private Attributes

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

Detailed Description

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

not placed into a header.

Definition at line 473 of file sch_legacy_plugin.cpp.

Constructor & Destructor Documentation

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

Definition at line 2037 of file sch_legacy_plugin.cpp.

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

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

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

References m_aliases.

Referenced by loadAliases().

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

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

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

3363 {
3364  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3365 
3366  if( it == m_aliases.end() )
3367  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3368  m_libFileName.GetFullName(), aAliasName ) );
3369 
3370  LIB_ALIAS* alias = it->second;
3371  LIB_PART* part = alias->GetPart();
3372 
3373  wxArrayString aliasNames = part->GetAliasNames();
3374 
3375  // Deleting all of the aliases deletes the symbol from the library.
3376  for( size_t i = 0; i < aliasNames.Count(); i++ )
3377  DeleteAlias( aliasNames[i] );
3378 }
Part library alias object definition.
void DeleteAlias(const wxString &aAliasName)
Class LIB_PART defines a library part object.
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
LIB_PART * GetPart() const
Function GetPart gets the shared LIB_PART.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 544 of file sch_legacy_plugin.cpp.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

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

Definition at line 2058 of file sch_legacy_plugin.cpp.

References m_isWritable, and m_libFileName.

Referenced by Load().

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

Definition at line 540 of file sch_legacy_plugin.cpp.

Referenced by ~SCH_LEGACY_PLUGIN_CACHE().

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

Definition at line 515 of file sch_legacy_plugin.cpp.

References m_modHash.

Referenced by SCH_LEGACY_PLUGIN::GetModifyHash().

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

Definition at line 2068 of file sch_legacy_plugin.cpp.

References m_libFileName.

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

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

Definition at line 2074 of file sch_legacy_plugin.cpp.

References m_fileModTime, and m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::cacheLib().

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

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

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

Referenced by loadPart().

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

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

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

Referenced by loadDrawEntries().

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

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

Referenced by loadDrawEntries().

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

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

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

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

Definition at line 3256 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

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

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

Referenced by Load().

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

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

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

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

Referenced by loadDrawEntries().

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

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

Referenced by loadDrawEntries().

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

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

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

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

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

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

Referenced by Save().

3310 {
3311  wxFileName docFileName = m_libFileName;
3312 
3313  docFileName.SetExt( DOC_EXT );
3314  FILE_OUTPUTFORMATTER formatter( docFileName.GetFullPath() );
3315 
3316  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
3317 
3318  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3319  {
3320  it->second->SaveDoc( formatter );
3321  }
3322 
3323  formatter.Print( 0, "#\n#End Doc Library\n" );
3324 }
#define DOCFILE_IDENT
#define DOC_EXT
Definition: class_library.h:50
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void SCH_LEGACY_PLUGIN_CACHE::SetFileName ( const wxString &  aFileName)
inline

Definition at line 542 of file sch_legacy_plugin.cpp.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

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

Member Data Documentation

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

Definition at line 476 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 479 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

Definition at line 478 of file sch_legacy_plugin.cpp.

Referenced by GetLibModificationTime().

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

Definition at line 483 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

int SCH_LEGACY_PLUGIN_CACHE::m_modHash
private

Definition at line 480 of file sch_legacy_plugin.cpp.

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

int SCH_LEGACY_PLUGIN_CACHE::m_versionMajor
private

Definition at line 481 of file sch_legacy_plugin.cpp.

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

int SCH_LEGACY_PLUGIN_CACHE::m_versionMinor
private

Definition at line 482 of file sch_legacy_plugin.cpp.

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

friend SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN
private

Definition at line 509 of file sch_legacy_plugin.cpp.


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