KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN_CACHE Class Reference

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

Public Member Functions

 SCH_LEGACY_PLUGIN_CACHE (const wxString &aLibraryPath)
 
 ~SCH_LEGACY_PLUGIN_CACHE ()
 
int GetModifyHash () const
 
void Save (bool aSaveDocFile=true)
 Save the entire library to file m_libFileName;. More...
 
void Load ()
 
void AddSymbol (const LIB_PART *aPart)
 
void 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 ()
 
void saveSymbol (LIB_PART *aSymbol, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveArc (LIB_ARC *aArc, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveBezier (LIB_BEZIER *aBezier, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveCircle (LIB_CIRCLE *aCircle, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveField (LIB_FIELD *aField, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void savePin (LIB_PIN *aPin, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void savePolyLine (LIB_POLYLINE *aPolyLine, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveRectangle (LIB_RECTANGLE *aRectangle, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 
void saveText (LIB_TEXT *aText, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
 

Private Attributes

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

Static Private Attributes

static int m_modHash = 1
 

Detailed Description

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

not placed into a header.

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

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

2194 {
2195  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2196  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); ++it )
2197  {
2198  wxLogTrace( traceSchLegacyPlugin, wxT( "Removing alias %s from library %s." ),
2199  GetChars( it->second->GetName() ), GetChars( GetLogicalName() ) );
2200  LIB_PART* part = it->second->GetPart();
2201  LIB_ALIAS* alias = it->second;
2202  delete alias;
2203 
2204  // When the last alias of a part is destroyed, the part is no longer required and it
2205  // too is destroyed.
2206  if( part && part->GetAliasCount() == 0 )
2207  delete part;
2208  }
2209 
2210  m_aliases.clear();
2211 }
Part library alias object definition.
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
size_t GetAliasCount() const
Define a library symbol 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 2282 of file sch_legacy_plugin.cpp.

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

Referenced by GetModifyHash().

2283 {
2284  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2285  wxArrayString aliasNames = aPart->GetAliasNames();
2286 
2287  for( size_t i = 0; i < aliasNames.size(); i++ )
2288  {
2289  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasNames[i] );
2290 
2291  if( it != m_aliases.end() )
2292  removeAlias( it->second );
2293 
2294  LIB_ALIAS* alias = const_cast< LIB_PART* >( aPart )->GetAlias( aliasNames[i] );
2295 
2296  wxASSERT_MSG( alias != NULL, "No alias <" + aliasNames[i] + "> found in symbol <" +
2297  aPart->GetName() +">." );
2298 
2299  m_aliases[ aliasNames[i] ] = alias;
2300  }
2301 
2302  m_isModified = true;
2303  ++m_modHash;
2304 }
Part library alias object definition.
Define a library symbol object.
LIB_ALIAS * removeAlias(LIB_ALIAS *aAlias)
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
size_t i
Definition: json11.cpp:597
const wxString & GetName() const
bool SCH_LEGACY_PLUGIN_CACHE::checkForDuplicates ( wxString &  aAliasName)
private

Definition at line 2679 of file sch_legacy_plugin.cpp.

References m_aliases.

Referenced by loadAliases().

2680 {
2681  wxCHECK_MSG( !aAliasName.IsEmpty(), false, "alias name cannot be empty" );
2682 
2683  // The alias name is not a duplicate so don't change it.
2684  if( m_aliases.find( aAliasName ) == m_aliases.end() )
2685  return false;
2686 
2687  int dupCounter = 1;
2688  wxString newAlias = aAliasName;
2689 
2690  // If the alias is already loaded, the library is broken. It may have been possible in
2691  // the past that this could happen so we assign a new alias name to prevent any conflicts
2692  // rather than throw an exception.
2693  while( m_aliases.find( newAlias ) != m_aliases.end() )
2694  {
2695  newAlias = aAliasName << dupCounter;
2696  dupCounter++;
2697  }
2698 
2699  aAliasName = newAlias;
2700 
2701  return true;
2702 }
void SCH_LEGACY_PLUGIN_CACHE::DeleteAlias ( const wxString &  aAliasName)

Definition at line 4000 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 DeleteSymbol(), and GetModifyHash().

4001 {
4002  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
4003 
4004  if( it == m_aliases.end() )
4005  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
4006  m_libFileName.GetFullName(), aAliasName ) );
4007 
4008  LIB_ALIAS* alias = it->second;
4009  LIB_PART* part = alias->GetPart();
4010 
4011  alias = part->RemoveAlias( alias );
4012 
4013  if( !alias )
4014  {
4015  delete part;
4016 
4017  if( m_aliases.size() > 1 )
4018  {
4019  LIB_ALIAS_MAP::iterator next = it;
4020  next++;
4021 
4022  if( next == m_aliases.end() )
4023  next = m_aliases.begin();
4024 
4025  alias = next->second;
4026  }
4027  }
4028 
4029  m_aliases.erase( it );
4030  ++m_modHash;
4031  m_isModified = true;
4032 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Define a library symbol object.
LIB_PART * GetPart() const
Get the shared LIB_PART.
void RemoveAlias(const wxString &aName)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol ( const wxString &  aAliasName)

Definition at line 4035 of file sch_legacy_plugin.cpp.

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

Referenced by GetModifyHash().

4036 {
4037  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
4038 
4039  if( it == m_aliases.end() )
4040  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
4041  m_libFileName.GetFullName(), aAliasName ) );
4042 
4043  LIB_ALIAS* alias = it->second;
4044  LIB_PART* part = alias->GetPart();
4045 
4046  wxArrayString aliasNames = part->GetAliasNames();
4047 
4048  // Deleting all of the aliases deletes the symbol from the library.
4049  for( size_t i = 0; i < aliasNames.Count(); i++ )
4050  DeleteAlias( aliasNames[i] );
4051 }
Part library alias object definition.
void DeleteAlias(const wxString &aAliasName)
Define a library symbol object.
LIB_PART * GetPart() const
Get 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
size_t i
Definition: json11.cpp:597
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 553 of file sch_legacy_plugin.cpp.

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

Definition at line 2214 of file sch_legacy_plugin.cpp.

References m_isWritable, and m_libFileName.

Referenced by GetModifyHash(), and Load().

2215 {
2216  // update the writable flag while we have a wxFileName, in a network this
2217  // is possibly quite dynamic anyway.
2218  m_isWritable = m_libFileName.IsFileWritable();
2219 
2220  return m_libFileName.GetModificationTime();
2221 }
wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 549 of file sch_legacy_plugin.cpp.

Referenced by ~SCH_LEGACY_PLUGIN_CACHE().

549 { return m_libFileName.GetName(); }
int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( ) const
inline
bool SCH_LEGACY_PLUGIN_CACHE::IsFile ( const wxString &  aFullPathAndFileName) const

Definition at line 2224 of file sch_legacy_plugin.cpp.

References m_fileName.

Referenced by GetModifyHash().

2225 {
2226  return m_fileName == aFullPathAndFileName;
2227 }
bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 2230 of file sch_legacy_plugin.cpp.

References m_fileModTime, and m_libFileName.

Referenced by GetModifyHash().

2231 {
2232  if( m_fileModTime.IsValid() && m_libFileName.IsOk() && m_libFileName.FileExists() )
2233  return m_libFileName.GetModificationTime() != m_fileModTime;
2234 
2235  return false;
2236 }
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 2307 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 GetModifyHash().

2308 {
2309  wxCHECK_RET( m_libFileName.IsAbsolute(),
2310  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2311  "open library \"%s\".", m_libFileName.GetFullPath() ) );
2312 
2313  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file \"%s\"",
2314  m_libFileName.GetFullPath() );
2315 
2316  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2317 
2318  if( !reader.ReadLine() )
2319  THROW_IO_ERROR( _( "unexpected end of file" ) );
2320 
2321  const char* line = reader.Line();
2322 
2323  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2324  {
2325  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2326  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2327  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2328  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2329  }
2330 
2331  m_versionMajor = parseInt( reader, line, &line );
2332 
2333  if( *line != '.' )
2334  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2335 
2336  line++;
2337 
2338  m_versionMinor = parseInt( reader, line, &line );
2339 
2340  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2341  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2342 
2343  // Check if this is a symbol library which is the same as a component library but without
2344  // any alias, documentation, footprint filters, etc.
2345  if( strCompare( "SYMBOL", line, &line ) )
2346  {
2347  // Symbol files add date and time stamp info to the header.
2349 
2351  }
2352  else
2353  {
2355  }
2356 
2357  while( reader.ReadLine() )
2358  {
2359  line = reader.Line();
2360 
2361  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2362  continue;
2363 
2364  // Headers where only supported in older library file formats.
2365  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2366  loadHeader( reader );
2367 
2368  if( strCompare( "DEF", line ) )
2369  {
2370  // Read one DEF/ENDDEF part entry from library:
2371  loadPart( reader );
2372  }
2373  }
2374 
2375  ++m_modHash;
2376 
2377  // Remember the file modification time of library file when the
2378  // cache snapshot was made, so that in a networked environment we will
2379  // reload the cache as needed.
2381 
2383  loadDocs();
2384 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
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 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)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SCH_LEGACY_PLUGIN_CACHE::loadAliases ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 2705 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

2707 {
2708  wxString newAlias;
2709  const char* line = aReader.Line();
2710 
2711  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2712 
2713  // Parse the ALIAS list.
2714  wxString alias;
2715  parseUnquotedString( alias, aReader, line, &line );
2716 
2717  while( !alias.IsEmpty() )
2718  {
2719  newAlias = alias;
2720  checkForDuplicates( newAlias );
2721  aPart->AddAlias( newAlias );
2722  alias.clear();
2723  parseUnquotedString( alias, aReader, line, &line, true );
2724  }
2725 }
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
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)
Compare aString to the string starting at aLine and advances the character point to the end of String...
LIB_ARC * SCH_LEGACY_PLUGIN_CACHE::loadArc ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

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

2964 {
2965  const char* line = aReader.Line();
2966 
2967  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
2968 
2969  std::unique_ptr< LIB_ARC > arc( new LIB_ARC( aPart.get() ) );
2970 
2971  wxPoint center;
2972 
2973  center.x = parseInt( aReader, line, &line );
2974  center.y = parseInt( aReader, line, &line );
2975 
2976  arc->SetPosition( center );
2977  arc->SetRadius( parseInt( aReader, line, &line ) );
2978 
2979  int angle1 = parseInt( aReader, line, &line );
2980  int angle2 = parseInt( aReader, line, &line );
2981 
2982  NORMALIZE_ANGLE_POS( angle1 );
2983  NORMALIZE_ANGLE_POS( angle2 );
2984  arc->SetFirstRadiusAngle( angle1 );
2985  arc->SetSecondRadiusAngle( angle2 );
2986 
2987  arc->SetUnit( parseInt( aReader, line, &line ) );
2988  arc->SetConvert( parseInt( aReader, line, &line ) );
2989  arc->SetWidth( parseInt( aReader, line, &line ) );
2990 
2991  // Old libraries (version <= 2.2) do not have always this FILL MODE param
2992  // when fill mode is no fill (default mode).
2993  if( *line != 0 )
2994  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
2995 
2996  // Actual Coordinates of arc ends are read from file
2997  if( *line != 0 )
2998  {
2999  wxPoint arcStart, arcEnd;
3000 
3001  arcStart.x = parseInt( aReader, line, &line );
3002  arcStart.y = parseInt( aReader, line, &line );
3003  arcEnd.x = parseInt( aReader, line, &line );
3004  arcEnd.y = parseInt( aReader, line, &line );
3005 
3006  arc->SetStart( arcStart );
3007  arc->SetEnd( arcEnd );
3008  }
3009  else
3010  {
3011  // Actual Coordinates of arc ends are not read from file
3012  // (old library), calculate them
3013  wxPoint arcStart( arc->GetRadius(), 0 );
3014  wxPoint arcEnd( arc->GetRadius(), 0 );
3015 
3016  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
3017  arcStart += arc->GetPosition();
3018  arc->SetStart( arcStart );
3019  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
3020  arcEnd += arc->GetPosition();
3021  arc->SetEnd( arcEnd );
3022  }
3023 
3024  return arc.release();
3025 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:241
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)
Compare aString to the string starting at aLine and advances the character point to the end of String...
LIB_BEZIER * SCH_LEGACY_PLUGIN_CACHE::loadBezier ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3415 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3417 {
3418  const char* line = aReader.Line();
3419 
3420  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3421 
3422  std::unique_ptr< LIB_BEZIER > bezier( new LIB_BEZIER( aPart.get() ) );
3423 
3424  int points = parseInt( aReader, line, &line );
3425  bezier->SetUnit( parseInt( aReader, line, &line ) );
3426  bezier->SetConvert( parseInt( aReader, line, &line ) );
3427  bezier->SetWidth( parseInt( aReader, line, &line ) );
3428 
3429  wxPoint pt;
3430 
3431  for( int i = 0; i < points; i++ )
3432  {
3433  pt.x = parseInt( aReader, line, &line );
3434  pt.y = parseInt( aReader, line, &line );
3435  bezier->AddPoint( pt );
3436  }
3437 
3438  if( *line != 0 )
3439  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3440 
3441  return bezier.release();
3442 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static dpoint_t bezier(double t, dpoint_t p0, dpoint_t p1, dpoint_t p2, dpoint_t p3)
Definition: trace.cpp:260
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)
size_t i
Definition: json11.cpp:597
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
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 3028 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3030 {
3031  const char* line = aReader.Line();
3032 
3033  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
3034 
3035  std::unique_ptr< LIB_CIRCLE > circle( new LIB_CIRCLE( aPart.get() ) );
3036 
3037  wxPoint center;
3038 
3039  center.x = parseInt( aReader, line, &line );
3040  center.y = parseInt( aReader, line, &line );
3041 
3042  circle->SetPosition( center );
3043  circle->SetRadius( parseInt( aReader, line, &line ) );
3044  circle->SetUnit( parseInt( aReader, line, &line ) );
3045  circle->SetConvert( parseInt( aReader, line, &line ) );
3046  circle->SetWidth( parseInt( aReader, line, &line ) );
3047 
3048  if( *line != 0 )
3049  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3050 
3051  return circle.release();
3052 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
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)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SCH_LEGACY_PLUGIN_CACHE::loadDocs ( )
private

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

2388 {
2389  const char* line;
2390  wxString text;
2391  wxString aliasName;
2392  wxFileName fn = m_libFileName;
2393  LIB_ALIAS* alias = NULL;;
2394 
2395  fn.SetExt( DOC_EXT );
2396 
2397  // Not all libraries will have a document file.
2398  if( !fn.FileExists() )
2399  return;
2400 
2401  if( !fn.IsFileReadable() )
2402  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2403  "document file \"%s\"" ), fn.GetFullPath() ) );
2404 
2405  FILE_LINE_READER reader( fn.GetFullPath() );
2406 
2407  line = reader.ReadLine();
2408 
2409  if( !line )
2410  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2411 
2412  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2413  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2414  reader, line );
2415 
2416  while( reader.ReadLine() )
2417  {
2418  line = reader.Line();
2419 
2420  if( *line == '#' ) // Comment line.
2421  continue;
2422 
2423  if( !strCompare( "$CMP", line, &line ) != 0 )
2424  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2425 
2426  parseUnquotedString( aliasName, reader, line, &line ); // Alias name.
2427 
2428  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
2429 
2430  if( it == m_aliases.end() )
2431  wxLogWarning( "Alias '%s' not found in library:\n\n"
2432  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2433  reader.LineNumber(), (int) (line - reader.Line() ) );
2434  else
2435  alias = it->second;
2436 
2437  // Read the curent alias associated doc.
2438  // if the alias does not exist, just skip the description
2439  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2440  while( reader.ReadLine() )
2441  {
2442  line = reader.Line();
2443 
2444  if( !line )
2445  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2446 
2447  if( strCompare( "$ENDCMP", line, &line ) )
2448  break;
2449 
2450  text = FROM_UTF8( line + 2 );
2451  text = text.Trim();
2452 
2453  switch( line[0] )
2454  {
2455  case 'D':
2456  if( alias )
2457  alias->SetDescription( text );
2458  break;
2459 
2460  case 'K':
2461  if( alias )
2462  alias->SetKeyWords( text );
2463  break;
2464 
2465  case 'F':
2466  if( alias )
2467  alias->SetDocFileName( text );
2468  break;
2469 
2470  case '#':
2471  break;
2472 
2473  default:
2474  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2475  }
2476  }
2477  }
2478 }
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:194
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)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
#define DOC_EXT
Definition: class_library.h:50
void SetDescription(const wxString &aDescription)
#define SCH_PARSE_ERROR(text, reader, pos)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void SetKeyWords(const wxString &aKeyWords)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SCH_LEGACY_PLUGIN_CACHE::loadDrawEntries ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

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

2876 {
2877  const char* line = aReader.Line();
2878 
2879  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
2880 
2881  line = aReader.ReadLine();
2882 
2883  while( line )
2884  {
2885  if( strCompare( "ENDDRAW", line, &line ) )
2886  return;
2887 
2888  switch( line[0] )
2889  {
2890  case 'A': // Arc
2891  aPart->AddDrawItem( loadArc( aPart, aReader ) );
2892  break;
2893 
2894  case 'C': // Circle
2895  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
2896  break;
2897 
2898  case 'T': // Text
2899  aPart->AddDrawItem( loadText( aPart, aReader ) );
2900  break;
2901 
2902  case 'S': // Square
2903  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
2904  break;
2905 
2906  case 'X': // Pin Description
2907  aPart->AddDrawItem( loadPin( aPart, aReader ) );
2908  break;
2909 
2910  case 'P': // Polyline
2911  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
2912  break;
2913 
2914  case 'B': // Bezier Curves
2915  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
2916  break;
2917 
2918  case '#': // Comment
2919  case '\n': // Empty line
2920  case '\r':
2921  case 0:
2922  break;
2923 
2924  default:
2925  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
2926  }
2927 
2928  line = aReader.ReadLine();
2929  }
2930 
2931  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
2932 }
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:194
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)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SCH_LEGACY_PLUGIN_CACHE::loadField ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

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

2730 {
2731  const char* line = aReader.Line();
2732 
2733  wxCHECK_RET( *line == 'F', "Invalid field line" );
2734 
2735  int id;
2736 
2737  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2738  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
2739 
2740  std::unique_ptr< LIB_FIELD > field( new LIB_FIELD( aPart.get(), id ) );
2741 
2742  // Skip to the first double quote.
2743  while( *line != '"' && *line != 0 )
2744  line++;
2745 
2746  if( *line == 0 )
2747  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
2748 
2749  wxString text;
2750  parseQuotedString( text, aReader, line, &line, true );
2751 
2752  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
2753  // not save like this.
2754  if( text.size() == 1 && text[0] == '~' )
2755  text.clear();
2756 
2757  field->m_Text = text;
2758 
2759  wxPoint pos;
2760 
2761  pos.x = parseInt( aReader, line, &line );
2762  pos.y = parseInt( aReader, line, &line );
2763  field->SetPosition( pos );
2764 
2765  wxSize textSize;
2766 
2767  textSize.x = textSize.y = parseInt( aReader, line, &line );
2768  field->SetTextSize( textSize );
2769 
2770  char textOrient = parseChar( aReader, line, &line );
2771 
2772  if( textOrient == 'H' )
2773  field->SetTextAngle( TEXT_ANGLE_HORIZ );
2774  else if( textOrient == 'V' )
2775  field->SetTextAngle( TEXT_ANGLE_VERT );
2776  else
2777  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
2778 
2779  char textVisible = parseChar( aReader, line, &line );
2780 
2781  if( textVisible == 'V' )
2782  field->SetVisible( true );
2783  else if ( textVisible == 'I' )
2784  field->SetVisible( false );
2785  else
2786  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
2787 
2788  // It may be technically correct to use the library version to determine if the field text
2789  // attributes are present. If anyone knows if that is valid and what version that would be,
2790  // please change this to test the library version rather than an EOL or the quoted string
2791  // of the field name.
2792  if( *line != 0 && *line != '"' )
2793  {
2794  char textHJustify = parseChar( aReader, line, &line );
2795 
2796  if( textHJustify == 'C' )
2797  field->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
2798  else if( textHJustify == 'L' )
2799  field->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
2800  else if( textHJustify == 'R' )
2801  field->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
2802  else
2803  SCH_PARSE_ERROR( "invalid field text horizontal justification parameter",
2804  aReader, line );
2805 
2806  wxString attributes;
2807 
2808  parseUnquotedString( attributes, aReader, line, &line );
2809 
2810  if( !(attributes.size() == 3 || attributes.size() == 1 ) )
2811  SCH_PARSE_ERROR( "invalid field text attributes size",
2812  aReader, line );
2813 
2814  if( attributes[0] == 'C' )
2815  field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
2816  else if( attributes[0] == 'B' )
2817  field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
2818  else if( attributes[0] == 'T' )
2819  field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
2820  else
2821  SCH_PARSE_ERROR( "invalid field text vertical justification parameter",
2822  aReader, line );
2823 
2824  if( attributes.size() == 3 )
2825  {
2826  if( attributes[1] == 'I' ) // Italic
2827  field->SetItalic( true );
2828  else if( attributes[1] != 'N' ) // No italics is default, check for error.
2829  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
2830 
2831  if ( attributes[2] == 'B' ) // Bold
2832  field->SetBold( true );
2833  else if( attributes[2] != 'N' ) // No bold is default, check for error.
2834  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
2835  }
2836  }
2837 
2838  // Fields in RAM must always have names.
2839  if( (unsigned) id < MANDATORY_FIELDS )
2840  {
2841  // Fields in RAM must always have names, because we are trying to get
2842  // less dependent on field ids and more dependent on names.
2843  // Plus assumptions are made in the field editors.
2844  field->m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
2845 
2846  LIB_FIELD* fixedField = aPart->GetField( field->GetId() );
2847 
2848  // this will fire only if somebody broke a constructor or editor.
2849  // MANDATORY_FIELDS are always present in ram resident components, no
2850  // exceptions, and they always have their names set, even fixed fields.
2851  wxASSERT( fixedField );
2852 
2853  *fixedField = *field;
2854 
2855  // Ensure the VALUE field = the part name (can be not the case
2856  // with malformed libraries: edited by hand, or converted from other tools)
2857  if( fixedField->GetId() == VALUE )
2858  fixedField->m_Text = aPart->GetName();
2859  }
2860  else
2861  {
2862  wxString name;
2863 
2864  parseQuotedString( name, aReader, line, &line, true ); // Optional.
2865 
2866  if( !name.IsEmpty() )
2867  field->m_name = name;
2868 
2869  aPart->AddDrawItem( field.release() ); // LIB_FIELD* is now owned by the LIB_PART.
2870  }
2871 }
#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:344
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static char parseChar(FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
Field object used in symbol libraries.
Definition: lib_field.h:59
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:138
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
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)
const char * name
Definition: DXF_plotter.cpp:61
static void parseQuotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
#define VALUE
void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3445 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

3447 {
3448  const char* line = aReader.Line();
3449 
3450  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3451 
3452  line = aReader.ReadLine();
3453 
3454  while( line )
3455  {
3456  if( strCompare( "$ENDFPLIST", line, &line ) )
3457  return;
3458 
3459  wxString footprint;
3460 
3461  parseUnquotedString( footprint, aReader, line, &line );
3462  aPart->GetFootprints().Add( footprint );
3463  line = aReader.ReadLine();
3464  }
3465 
3466  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3467 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SCH_LEGACY_PLUGIN_CACHE::loadHeader ( FILE_LINE_READER aReader)
private

Definition at line 2481 of file sch_legacy_plugin.cpp.

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

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

2482 {
2483  const char* line = aReader.Line();
2484 
2485  wxASSERT( strCompare( "$HEADER", line, &line ) );
2486 
2487  while( aReader.ReadLine() )
2488  {
2489  line = (char*) aReader;
2490 
2491  // The time stamp saved in old library files is not used or saved in the latest
2492  // library file version.
2493  if( strCompare( "TimeStamp", line, &line ) )
2494  continue;
2495  else if( strCompare( "$ENDHEADER", line, &line ) )
2496  return;
2497  }
2498 
2499  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2500 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
LIB_PART * SCH_LEGACY_PLUGIN_CACHE::loadPart ( FILE_LINE_READER aReader)
private

Definition at line 2503 of file sch_legacy_plugin.cpp.

References EDA_TEXT::Empty(), Format(), LIB_ALIAS::GetName(), LIB_ALIAS::IsRoot(), LIB_VERSION, LINE_READER::Line(), loadAliases(), loadDrawEntries(), loadField(), loadFootprintFilters(), m_aliases, m_fileName, m_versionMajor, m_versionMinor, name, parseChar(), parseInt(), parseUnquotedString(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_ALIAS::SetName(), LIB_FIELD::SetText(), EDA_TEXT::SetVisible(), and strCompare().

Referenced by Load().

2504 {
2505  const char* line = aReader.Line();
2506 
2507  wxCHECK( strCompare( "DEF", line, &line ), NULL );
2508 
2509  // Read DEF line:
2510  char yes_no = 0;
2511 
2512  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2513 
2514  wxString name, prefix;
2515 
2516  parseUnquotedString( name, aReader, line, &line ); // Part name.
2517  parseUnquotedString( prefix, aReader, line, &line ); // Prefix name
2518  parseInt( aReader, line, &line ); // NumOfPins, unused.
2519  part->SetPinNameOffset( parseInt( aReader, line, &line ) ); // Pin name offset.
2520  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2521 
2522  if( !( yes_no == 'Y' || yes_no == 'N') )
2523  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2524 
2525  part->SetShowPinNumbers( ( yes_no == 'N' ) ? false : true );
2526 
2527  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2528 
2529  if( !( yes_no == 'Y' || yes_no == 'N') )
2530  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2531 
2532  part->SetShowPinNames( ( yes_no == 'N' ) ? false : true ); // Show pin names.
2533 
2534  part->SetUnitCount( parseInt( aReader, line, &line ) ); // Number of units.
2535 
2536  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2537  if( part->GetUnitCount() < 1 )
2538  part->SetUnitCount( 1 );
2539 
2540  // Copy part name and prefix.
2541 
2542  // The root alias is added to the alias list by SetName() which is called by SetText().
2543  if( name.IsEmpty() )
2544  {
2545  part->SetName( "~" );
2546  }
2547  else if( name[0] != '~' )
2548  {
2549  part->SetName( name );
2550  }
2551  else
2552  {
2553  part->SetName( name.Right( name.Length() - 1 ) );
2554  part->GetValueField().SetVisible( false );
2555  }
2556 
2557  // Don't set the library alias, this is determined by the symbol library table.
2558  part->SetLibId( LIB_ID( wxEmptyString, part->GetName() ) );
2559 
2560  // There are some code paths in SetText() that do not set the root alias to the
2561  // alias list so add it here if it didn't get added by SetText().
2562  if( !part->HasAlias( part->GetName() ) )
2563  part->AddAlias( part->GetName() );
2564 
2565  LIB_FIELD& reference = part->GetReferenceField();
2566 
2567  if( prefix == "~" )
2568  {
2569  reference.Empty();
2570  reference.SetVisible( false );
2571  }
2572  else
2573  {
2574  reference.SetText( prefix );
2575  }
2576 
2577  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2578  // The was no concept of interchangeable multiple unit symbols.
2580  {
2581  // Nothing needs to be set since the default setting for symbols with multiple
2582  // units were never interchangeable. Just parse the 0 an move on.
2583  parseInt( aReader, line, &line );
2584  }
2585  else
2586  {
2587  char locked = parseChar( aReader, line, &line );
2588 
2589  if( locked == 'L' )
2590  part->LockUnits( true );
2591  else if( locked == 'F' || locked == '0' )
2592  part->LockUnits( false );
2593  else
2594  SCH_PARSE_ERROR( "expected L, F, or 0", aReader, line );
2595  }
2596 
2597 
2598  // There is the optional power component flag.
2599  if( *line )
2600  {
2601  char power = parseChar( aReader, line, &line );
2602 
2603  if( power == 'P' )
2604  part->SetPower();
2605  else if( power == 'N' )
2606  part->SetNormal();
2607  else
2608  SCH_PARSE_ERROR( "expected P or N", aReader, line );
2609  }
2610 
2611  line = aReader.ReadLine();
2612 
2613  // Read lines until "ENDDEF" is found.
2614  while( line )
2615  {
2616  if( *line == '#' ) // Comment
2617  ;
2618  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2619  continue;
2620  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2621  loadAliases( part, aReader );
2622  else if( *line == 'F' ) // Fields
2623  loadField( part, aReader );
2624  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2625  loadDrawEntries( part, aReader );
2626  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2627  loadFootprintFilters( part, aReader );
2628  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2629  {
2630  // Add aliases
2631  for( size_t ii = 0; ii < part->GetAliasCount(); ++ii )
2632  {
2633  LIB_ALIAS* alias = part->GetAlias( ii );
2634  const wxString& aliasName = alias->GetName();
2635  auto it = m_aliases.find( aliasName );
2636 
2637  if( it != m_aliases.end() )
2638  {
2639  // Find a new name for the alias
2640  wxString newName;
2641  int idx = 0;
2642  LIB_ALIAS_MAP::const_iterator jt;
2643 
2644  do
2645  {
2646  newName = wxString::Format( "%s_%d", aliasName, idx );
2647  jt = m_aliases.find( newName );
2648  ++idx;
2649  }
2650  while( jt != m_aliases.end() );
2651 
2652  wxLogWarning( "Symbol name conflict in library:\n%s\n"
2653  "'%s' has been renamed to '%s'",
2654  m_fileName, aliasName, newName );
2655 
2656  if( alias->IsRoot() )
2657  part->SetName( newName );
2658  else
2659  alias->SetName( newName );
2660 
2661  m_aliases[newName] = alias;
2662  }
2663  else
2664  {
2665  m_aliases[aliasName] = alias;
2666  }
2667  }
2668 
2669  return part.release();
2670  }
2671 
2672  line = aReader.ReadLine();
2673  }
2674 
2675  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2676 }
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:194
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static char parseChar(FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:173
#define LIB_VERSION(major, minor)
Definition: class_library.h:61
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void loadAliases(std::unique_ptr< LIB_PART > &aPart, FILE_LINE_READER &aReader)
bool IsRoot() const
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
Sets the field text to aText.
Definition: lib_field.cpp:502
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
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:229
Define a library symbol 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)
const wxString & GetName() const
const char * name
Definition: DXF_plotter.cpp:61
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
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void 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 3194 of file sch_legacy_plugin.cpp.

References LINE_READER::Line(), name, parseChar(), parseInt(), parseUnquotedString(), PIN_BIDI, PIN_INPUT, PIN_INVISIBLE, 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().

3196 {
3197  const char* line = aReader.Line();
3198 
3199  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3200 
3201  std::unique_ptr< LIB_PIN > pin( new LIB_PIN( aPart.get() ) );
3202 
3203  wxString name, number;
3204 
3205  parseUnquotedString( name, aReader, line, &line );
3206  parseUnquotedString( number, aReader, line, &line );
3207 
3208  // Unlike most of the other LIB_ITEMs, the SetXXX() routines on LIB_PINs are at the UI
3209  // level, performing additional pin checking, multi-pin editing, and setting the modified
3210  // flag. So we must set the member fields directly.
3211 
3212  pin->m_name = name;
3213  pin->m_number = number;
3214 
3215  wxPoint pos;
3216 
3217  pos.x = parseInt( aReader, line, &line );
3218  pos.y = parseInt( aReader, line, &line );
3219  pin->m_position = pos;
3220  pin->m_length = parseInt( aReader, line, &line );
3221  pin->m_orientation = parseChar( aReader, line, &line );
3222  pin->m_numTextSize = parseInt( aReader, line, &line );
3223  pin->m_nameTextSize = parseInt( aReader, line, &line );
3224  pin->m_Unit = parseInt( aReader, line, &line );
3225  pin->m_Convert = parseInt( aReader, line, &line );
3226 
3227  char type = parseChar( aReader, line, &line );
3228 
3229  wxString attributes;
3230 
3231  // Optional
3232  parseUnquotedString( attributes, aReader, line, &line, true );
3233 
3234  switch( type )
3235  {
3236  case 'I':
3237  pin->m_type = PIN_INPUT;
3238  break;
3239 
3240  case 'O':
3241  pin->m_type = PIN_OUTPUT;
3242  break;
3243 
3244  case 'B':
3245  pin->m_type = PIN_BIDI;
3246  break;
3247 
3248  case 'T':
3249  pin->m_type = PIN_TRISTATE;
3250  break;
3251 
3252  case 'P':
3253  pin->m_type = PIN_PASSIVE;
3254  break;
3255 
3256  case 'U':
3257  pin->m_type = PIN_UNSPECIFIED;
3258  break;
3259 
3260  case 'W':
3261  pin->m_type = PIN_POWER_IN;
3262  break;
3263 
3264  case 'w':
3265  pin->m_type = PIN_POWER_OUT;
3266  break;
3267 
3268  case 'C':
3269  pin->m_type = PIN_OPENCOLLECTOR;
3270  break;
3271 
3272  case 'E':
3273  pin->m_type = PIN_OPENEMITTER;
3274  break;
3275 
3276  case 'N':
3277  pin->m_type = PIN_NC;
3278  break;
3279 
3280  default:
3281  SCH_PARSE_ERROR( "unknown pin type", aReader, line );
3282  }
3283 
3284  if( !attributes.IsEmpty() ) /* Special Symbol defined */
3285  {
3286  enum
3287  {
3288  INVERTED = 1 << 0,
3289  CLOCK = 1 << 1,
3290  LOWLEVEL_IN = 1 << 2,
3291  LOWLEVEL_OUT = 1 << 3,
3292  FALLING_EDGE = 1 << 4,
3293  NONLOGIC = 1 << 5
3294  };
3295 
3296  int flags = 0;
3297 
3298  for( int j = attributes.size(); j > 0; )
3299  {
3300  switch( attributes[--j].GetValue() )
3301  {
3302  case '~':
3303  break;
3304 
3305  case 'N':
3306  pin->m_attributes |= PIN_INVISIBLE;
3307  break;
3308 
3309  case 'I':
3310  flags |= INVERTED;
3311  break;
3312 
3313  case 'C':
3314  flags |= CLOCK;
3315  break;
3316 
3317  case 'L':
3318  flags |= LOWLEVEL_IN;
3319  break;
3320 
3321  case 'V':
3322  flags |= LOWLEVEL_OUT;
3323  break;
3324 
3325  case 'F':
3326  flags |= FALLING_EDGE;
3327  break;
3328 
3329  case 'X':
3330  flags |= NONLOGIC;
3331  break;
3332 
3333  default:
3334  SCH_PARSE_ERROR( "unknown pin attribute", aReader, line );
3335  }
3336  }
3337 
3338  switch( flags )
3339  {
3340  case 0:
3341  pin->m_shape = PINSHAPE_LINE;
3342  break;
3343 
3344  case INVERTED:
3345  pin->m_shape = PINSHAPE_INVERTED;
3346  break;
3347 
3348  case CLOCK:
3349  pin->m_shape = PINSHAPE_CLOCK;
3350  break;
3351 
3352  case INVERTED | CLOCK:
3353  pin->m_shape = PINSHAPE_INVERTED_CLOCK;
3354  break;
3355 
3356  case LOWLEVEL_IN:
3357  pin->m_shape = PINSHAPE_INPUT_LOW;
3358  break;
3359 
3360  case LOWLEVEL_IN | CLOCK:
3361  pin->m_shape = PINSHAPE_CLOCK_LOW;
3362  break;
3363 
3364  case LOWLEVEL_OUT:
3365  pin->m_shape = PINSHAPE_OUTPUT_LOW;
3366  break;
3367 
3368  case FALLING_EDGE:
3369  pin->m_shape = PINSHAPE_FALLING_EDGE_CLOCK;
3370  break;
3371 
3372  case NONLOGIC:
3373  pin->m_shape = PINSHAPE_NONLOGIC;
3374  break;
3375 
3376  default:
3377  SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3378  }
3379  }
3380 
3381  return pin.release();
3382 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static char parseChar(FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define PIN_INVISIBLE
Definition: lib_pin.h:46
#define SCH_PARSE_ERROR(text, reader, pos)
const char * name
Definition: DXF_plotter.cpp:61
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
LIB_POLYLINE * SCH_LEGACY_PLUGIN_CACHE::loadPolyLine ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3385 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3387 {
3388  const char* line = aReader.Line();
3389 
3390  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3391 
3392  std::unique_ptr< LIB_POLYLINE > polyLine( new LIB_POLYLINE( aPart.get() ) );
3393 
3394  int points = parseInt( aReader, line, &line );
3395  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3396  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3397  polyLine->SetWidth( parseInt( aReader, line, &line ) );
3398 
3399  wxPoint pt;
3400 
3401  for( int i = 0; i < points; i++ )
3402  {
3403  pt.x = parseInt( aReader, line, &line );
3404  pt.y = parseInt( aReader, line, &line );
3405  polyLine->AddPoint( pt );
3406  }
3407 
3408  if( *line != 0 )
3409  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3410 
3411  return polyLine.release();
3412 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
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)
size_t i
Definition: json11.cpp:597
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
LIB_RECTANGLE * SCH_LEGACY_PLUGIN_CACHE::loadRectangle ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3162 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3164 {
3165  const char* line = aReader.Line();
3166 
3167  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
3168 
3169  std::unique_ptr< LIB_RECTANGLE > rectangle( new LIB_RECTANGLE( aPart.get() ) );
3170 
3171  wxPoint pos;
3172 
3173  pos.x = parseInt( aReader, line, &line );
3174  pos.y = parseInt( aReader, line, &line );
3175  rectangle->SetPosition( pos );
3176 
3177  wxPoint end;
3178 
3179  end.x = parseInt( aReader, line, &line );
3180  end.y = parseInt( aReader, line, &line );
3181  rectangle->SetEnd( end );
3182 
3183  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3184  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3185  rectangle->SetWidth( parseInt( aReader, line, &line ) );
3186 
3187  if( *line != 0 )
3188  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3189 
3190  return rectangle.release();
3191 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
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)
Compare aString to the string starting at aLine and advances the character point to the end of String...
LIB_TEXT * SCH_LEGACY_PLUGIN_CACHE::loadText ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3055 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, str, strCompare(), wxPoint::x, and wxPoint::y.

Referenced by loadDrawEntries(), and SCH_LEGACY_PLUGIN::loadFile().

3057 {
3058  const char* line = aReader.Line();
3059 
3060  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
3061 
3062  std::unique_ptr< LIB_TEXT > text( new LIB_TEXT( aPart.get() ) );
3063 
3064  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3065 
3066  wxPoint center;
3067 
3068  center.x = parseInt( aReader, line, &line );
3069  center.y = parseInt( aReader, line, &line );
3070  text->SetPosition( center );
3071 
3072  wxSize size;
3073 
3074  size.x = size.y = parseInt( aReader, line, &line );
3075  text->SetTextSize( size );
3076  text->SetVisible( !parseInt( aReader, line, &line ) );
3077  text->SetUnit( parseInt( aReader, line, &line ) );
3078  text->SetConvert( parseInt( aReader, line, &line ) );
3079 
3080  wxString str;
3081 
3082  // If quoted string loading fails, load as not quoted string.
3083  if( *line == '"' )
3084  parseQuotedString( str, aReader, line, &line );
3085  else
3086  parseUnquotedString( str, aReader, line, &line );
3087 
3088  if( !str.IsEmpty() )
3089  {
3090  // convert two apostrophes back to double quote
3091  str.Replace( "''", "\"" );
3092  str.Replace( wxT( "~" ), wxT( " " ) );
3093  }
3094 
3095  text->SetText( str );
3096 
3097  // Here things are murky and not well defined. At some point it appears the format
3098  // was changed to add text properties. However rather than add the token to the end of
3099  // the text definition, it was added after the string and no mention if the file
3100  // verion was bumped or not so this code make break on very old component libraries.
3101  //
3102  // Update: apparently even in the latest version this can be different so added a test
3103  // for end of line before checking for the text properties.
3104  if( LIB_VERSION( m_versionMajor, m_versionMinor ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3105  {
3106  if( strCompare( "Italic", line, &line ) )
3107  text->SetItalic( true );
3108  else if( !strCompare( "Normal", line, &line ) )
3109  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'",
3110  aReader, line );
3111 
3112  if( parseInt( aReader, line, &line ) > 0 )
3113  text->SetBold( true );
3114 
3115  // Some old libaries version > 2.0 do not have these options for text justification:
3116  if( !is_eol( *line ) )
3117  {
3118  switch( parseChar( aReader, line, &line ) )
3119  {
3120  case 'L':
3121  text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
3122  break;
3123 
3124  case 'C':
3125  text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
3126  break;
3127 
3128  case 'R':
3129  text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
3130  break;
3131 
3132  default:
3133  SCH_PARSE_ERROR( "invalid horizontal text justication parameter, expected L, C, or R",
3134  aReader, line );
3135  }
3136 
3137  switch( parseChar( aReader, line, &line ) )
3138  {
3139  case 'T':
3140  text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
3141  break;
3142 
3143  case 'C':
3144  text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
3145  break;
3146 
3147  case 'B':
3148  text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
3149  break;
3150 
3151  default:
3152  SCH_PARSE_ERROR( "invalid vertical text justication parameter, expected T, C, or B",
3153  aReader, line );
3154  }
3155  }
3156  }
3157 
3158  return text.release();
3159 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
Define a symbol library graphical text item.
Definition: lib_text.h:44
static char parseChar(FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
#define LIB_VERSION(major, minor)
Definition: class_library.h:61
const string & str
Definition: json11.cpp:596
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
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)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
FILL_T SCH_LEGACY_PLUGIN_CACHE::parseFillMode ( FILE_LINE_READER aReader,
const char *  aLine,
const char **  aOutput 
)
private

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

2937 {
2938  FILL_T mode;
2939 
2940  switch( parseChar( aReader, aLine, aOutput ) )
2941  {
2942  case 'F':
2943  mode = FILLED_SHAPE;
2944  break;
2945 
2946  case 'f':
2947  mode = FILLED_WITH_BG_BODYCOLOR;
2948  break;
2949 
2950  case 'N':
2951  mode = NO_FILL;
2952  break;
2953 
2954  default:
2955  SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
2956  }
2957 
2958  return mode;
2959 }
static char parseChar(FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
#define SCH_PARSE_ERROR(text, reader, pos)
FILL_T
Enum FILL_T is the set of fill types used in plotting or drawing enclosed areas.
Definition: base_struct.h:52
LIB_ALIAS * SCH_LEGACY_PLUGIN_CACHE::removeAlias ( LIB_ALIAS aAlias)
private

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

2240 {
2241  wxCHECK_MSG( aAlias != NULL, NULL, "NULL pointer cannot be removed from library." );
2242 
2243  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAlias->GetName() );
2244 
2245  if( it == m_aliases.end() )
2246  return NULL;
2247 
2248  // If the entry pointer doesn't match the name it is mapped to in the library, we
2249  // have done something terribly wrong.
2250  wxCHECK_MSG( *it->second == aAlias, NULL,
2251  "Pointer mismatch while attempting to remove alias entry <" + aAlias->GetName() +
2252  "> from library cache <" + m_libFileName.GetName() + ">." );
2253 
2254  LIB_ALIAS* alias = aAlias;
2255  LIB_PART* part = alias->GetPart();
2256 
2257  alias = part->RemoveAlias( alias );
2258 
2259  if( !alias )
2260  {
2261  delete part;
2262 
2263  if( m_aliases.size() > 1 )
2264  {
2265  LIB_ALIAS_MAP::iterator next = it;
2266  next++;
2267 
2268  if( next == m_aliases.end() )
2269  next = m_aliases.begin();
2270 
2271  alias = next->second;
2272  }
2273  }
2274 
2275  m_aliases.erase( it );
2276  m_isModified = true;
2277  ++m_modHash;
2278  return alias;
2279 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Define a library symbol 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 3470 of file sch_legacy_plugin.cpp.

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

Referenced by GetModifyHash().

3471 {
3472  if( !m_isModified )
3473  return;
3474 
3475  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( m_libFileName.GetFullPath() ) );
3476  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3477  formatter->Print( 0, "#encoding utf-8\n");
3478 
3479  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3480  {
3481  if( !it->second->IsRoot() )
3482  continue;
3483 
3484  saveSymbol( it->second->GetPart(), formatter );
3485  }
3486 
3487  formatter->Print( 0, "#\n#End Library\n" );
3488  formatter.reset();
3489 
3490  m_fileModTime = m_libFileName.GetModificationTime();
3491  m_isModified = false;
3492 
3493  if( aSaveDocFile )
3494  saveDocFile();
3495 }
#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 saveSymbol(LIB_PART *aSymbol, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void SCH_LEGACY_PLUGIN_CACHE::saveArc ( LIB_ARC aArc,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3668 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3670 {
3671  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
3672 
3673  int x1 = aArc->GetFirstRadiusAngle();
3674 
3675  if( x1 > 1800 )
3676  x1 -= 3600;
3677 
3678  int x2 = aArc->GetSecondRadiusAngle();
3679 
3680  if( x2 > 1800 )
3681  x2 -= 3600;
3682 
3683  aFormatter->Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
3684  aArc->GetPosition().x, aArc->GetPosition().y,
3685  aArc->GetRadius(), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
3686  aArc->GetWidth(), fill_tab[aArc->GetFillMode()],
3687  aArc->GetStart().x, aArc->GetStart().y,
3688  aArc->GetEnd().x, aArc->GetEnd().y );
3689 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
FILL_T GetFillMode() const
int GetSecondRadiusAngle() const
Definition: lib_arc.h:146
wxPoint GetStart() const
Definition: lib_arc.h:148
int GetUnit() const
int GetFirstRadiusAngle() const
Definition: lib_arc.h:142
wxPoint GetEnd() const
Definition: lib_arc.h:152
int GetRadius() const
Definition: lib_arc.h:138
int GetWidth() const override
Return the width of the draw item.
Definition: lib_arc.h:132
const int fill_tab[3]
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_arc.h:121
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveBezier ( LIB_BEZIER aBezier,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3692 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3694 {
3695  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
3696 
3697  aFormatter->Print( 0, "B %u %d %d %d", (unsigned)aBezier->GetPoints().size(),
3698  aBezier->GetUnit(), aBezier->GetConvert(), aBezier->GetWidth() );
3699 
3700  for( const auto& pt : aBezier->GetPoints() )
3701  aFormatter->Print( 0, " %d %d", pt.x, pt.y );
3702 
3703  aFormatter->Print( 0, " %c\n", fill_tab[aBezier->GetFillMode()] );
3704 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
FILL_T GetFillMode() const
int GetUnit() const
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:75
int GetWidth() const override
Return the width of the draw item.
Definition: lib_bezier.h:101
const int fill_tab[3]
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveCircle ( LIB_CIRCLE aCircle,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3707 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3709 {
3710  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
3711 
3712  aFormatter->Print( 0, "C %d %d %d %d %d %d %c\n",
3713  aCircle->GetPosition().x, aCircle->GetPosition().y,
3714  aCircle->GetRadius(), aCircle->GetUnit(), aCircle->GetConvert(),
3715  aCircle->GetWidth(), fill_tab[aCircle->GetFillMode()] );
3716 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
FILL_T GetFillMode() const
int GetUnit() const
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_circle.h:86
int GetWidth() const override
Return the width of the draw item.
Definition: lib_circle.h:97
int GetRadius() const
Definition: lib_circle.h:103
const int fill_tab[3]
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 3964 of file sch_legacy_plugin.cpp.

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

Referenced by Save().

3965 {
3966  wxFileName fileName = m_libFileName;
3967 
3968  fileName.SetExt( DOC_EXT );
3969  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
3970 
3971  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
3972 
3973  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3974  {
3975  wxString description = it->second->GetDescription();
3976  wxString keyWords = it->second->GetKeyWords();
3977  wxString docFileName = it->second->GetDocFileName();
3978 
3979  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
3980  continue;
3981 
3982  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
3983 
3984  if( !description.IsEmpty() )
3985  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
3986 
3987  if( !keyWords.IsEmpty() )
3988  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
3989 
3990  if( !docFileName.IsEmpty() )
3991  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
3992 
3993  formatter.Print( 0, "$ENDCMP\n" );
3994  }
3995 
3996  formatter.Print( 0, "#\n#End Doc Library\n" );
3997 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
#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:404
void SCH_LEGACY_PLUGIN_CACHE::saveField ( LIB_FIELD aField,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3719 of file sch_legacy_plugin.cpp.

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

Referenced by SCH_LEGACY_PLUGIN::saveComponent(), and saveSymbol().

3721 {
3722  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
3723 
3724  int hjustify, vjustify;
3725  int id = aField->GetId();
3726  wxString text = aField->m_Text;
3727 
3728  hjustify = 'C';
3729 
3730  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3731  hjustify = 'L';
3732  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3733  hjustify = 'R';
3734 
3735  vjustify = 'C';
3736 
3737  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3738  vjustify = 'B';
3739  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3740  vjustify = 'T';
3741 
3742  aFormatter->Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
3743  id,
3744  EscapedUTF8( text ).c_str(), // wraps in quotes
3745  aField->GetTextPos().x, aField->GetTextPos().y, aField->GetTextWidth(),
3746  aField->GetTextAngle() == 0 ? 'H' : 'V',
3747  aField->IsVisible() ? 'V' : 'I',
3748  hjustify, vjustify,
3749  aField->IsItalic() ? 'I' : 'N',
3750  aField->IsBold() ? 'B' : 'N' );
3751 
3752  /* Save field name, if necessary
3753  * Field name is saved only if it is not the default name.
3754  * Just because default name depends on the language and can change from
3755  * a country to another
3756  */
3757  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
3758 
3759  if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
3760  aFormatter->Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
3761 
3762  aFormatter->Print( 0, "\n" );
3763 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
wxString m_Text
Definition: eda_text.h:344
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
bool IsItalic() const
Definition: eda_text.h:168
int GetTextWidth() const
Definition: eda_text.h:216
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:188
bool IsBold() const
Definition: eda_text.h:171
double GetTextAngle() const
Definition: eda_text.h:162
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:137
int GetId() const
Definition: lib_field.h:138
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:189
bool IsVisible() const
Definition: lib_field.h:164
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
void SCH_LEGACY_PLUGIN_CACHE::savePin ( LIB_PIN aPin,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3766 of file sch_legacy_plugin.cpp.

References EDA_ITEM::ClearFlags(), LIB_ITEM::GetConvert(), LIB_PIN::GetLength(), LIB_PIN::GetName(), LIB_PIN::GetNameTextSize(), LIB_PIN::GetNumber(), LIB_PIN::GetNumberTextSize(), LIB_PIN::GetOrientation(), LIB_PIN::GetPosition(), LIB_PIN::GetShape(), LIB_PIN::GetType(), LIB_ITEM::GetUnit(), IS_CHANGED, LIB_PIN::IsVisible(), LIB_PIN_T, 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, TO_UTF8, EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by saveSymbol().

3768 {
3769  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
3770 
3771  int Etype;
3772 
3773  switch( aPin->GetType() )
3774  {
3775  default:
3776  case PIN_INPUT:
3777  Etype = 'I';
3778  break;
3779 
3780  case PIN_OUTPUT:
3781  Etype = 'O';
3782  break;
3783 
3784  case PIN_BIDI:
3785  Etype = 'B';
3786  break;
3787 
3788  case PIN_TRISTATE:
3789  Etype = 'T';
3790  break;
3791 
3792  case PIN_PASSIVE:
3793  Etype = 'P';
3794  break;
3795 
3796  case PIN_UNSPECIFIED:
3797  Etype = 'U';
3798  break;
3799 
3800  case PIN_POWER_IN:
3801  Etype = 'W';
3802  break;
3803 
3804  case PIN_POWER_OUT:
3805  Etype = 'w';
3806  break;
3807 
3808  case PIN_OPENCOLLECTOR:
3809  Etype = 'C';
3810  break;
3811 
3812  case PIN_OPENEMITTER:
3813  Etype = 'E';
3814  break;
3815 
3816  case PIN_NC:
3817  Etype = 'N';
3818  break;
3819  }
3820 
3821  if( !aPin->GetName().IsEmpty() )
3822  aFormatter->Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
3823  else
3824  aFormatter->Print( 0, "X ~" );
3825 
3826  aFormatter->Print( 0, " %s %d %d %d %c %d %d %d %d %c",
3827  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
3828  aPin->GetPosition().x, aPin->GetPosition().y,
3829  (int) aPin->GetLength(), (int) aPin->GetOrientation(),
3830  aPin->GetNumberTextSize(), aPin->GetNameTextSize(),
3831  aPin->GetUnit(), aPin->GetConvert(), Etype );
3832 
3833  if( aPin->GetShape() || !aPin->IsVisible() )
3834  aFormatter->Print( 0, " " );
3835 
3836  if( !aPin->IsVisible() )
3837  aFormatter->Print( 0, "N" );
3838 
3839  switch( aPin->GetShape() )
3840  {
3841  case PINSHAPE_LINE:
3842  break;
3843 
3844  case PINSHAPE_INVERTED:
3845  aFormatter->Print( 0, "I" );
3846  break;
3847 
3848  case PINSHAPE_CLOCK:
3849  aFormatter->Print( 0, "C" );
3850  break;
3851 
3853  aFormatter->Print( 0, "IC" );
3854  break;
3855 
3856  case PINSHAPE_INPUT_LOW:
3857  aFormatter->Print( 0, "L" );
3858  break;
3859 
3860  case PINSHAPE_CLOCK_LOW:
3861  aFormatter->Print( 0, "CL" );
3862  break;
3863 
3864  case PINSHAPE_OUTPUT_LOW:
3865  aFormatter->Print( 0, "V" );
3866  break;
3867 
3869  aFormatter->Print( 0, "F" );
3870  break;
3871 
3872  case PINSHAPE_NONLOGIC:
3873  aFormatter->Print( 0, "X" );
3874  break;
3875 
3876  default:
3877  assert( !"Invalid pin shape" );
3878  }
3879 
3880  aFormatter->Print( 0, "\n" );
3881 
3882  aPin->ClearFlags( IS_CHANGED );
3883 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
int GetUnit() const
int GetNameTextSize() const
Definition: lib_pin.h:191
int GetOrientation() const
Definition: lib_pin.h:220
int GetNumberTextSize() const
Definition: lib_pin.h:218
const wxString & GetNumber() const
Definition: lib_pin.h:193
const wxString & GetName() const
Definition: lib_pin.h:165
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:105
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:250
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:361
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_pin.h:462
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:265
int GetLength()
Definition: lib_pin.h:300
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:234
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::savePolyLine ( LIB_POLYLINE aPolyLine,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3886 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3888 {
3889  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
3890 
3891  int ccount = aPolyLine->GetCornerCount();
3892 
3893  aFormatter->Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
3894  aPolyLine->GetWidth() );
3895 
3896  for( const auto& pt : aPolyLine->GetPolyPoints() )
3897  {
3898  aFormatter->Print( 0, " %d %d", pt.x, pt.y );
3899  }
3900 
3901  aFormatter->Print( 0, " %c\n", fill_tab[aPolyLine->GetFillMode()] );
3902 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
FILL_T GetFillMode() const
int GetUnit() const
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:67
unsigned GetCornerCount() const
Definition: lib_polyline.h:77
int GetWidth() const override
Return the width of the draw item.
Definition: lib_polyline.h:112
const int fill_tab[3]
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveRectangle ( LIB_RECTANGLE aRectangle,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3905 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3907 {
3908  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
3909  "Invalid LIB_RECTANGLE object." );
3910 
3911  aFormatter->Print( 0, "S %d %d %d %d %d %d %d %c\n",
3912  aRectangle->GetPosition().x, aRectangle->GetPosition().y,
3913  aRectangle->GetEnd().x, aRectangle->GetEnd().y,
3914  aRectangle->GetUnit(), aRectangle->GetConvert(),
3915  aRectangle->GetWidth(), fill_tab[aRectangle->GetFillMode()] );
3916 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
FILL_T GetFillMode() const
int GetUnit() const
int GetWidth() const override
Return the width of the draw item.
wxPoint GetEnd() const
const int fill_tab[3]
wxPoint GetPosition() const override
Return the current draw object position.
Definition: lib_rectangle.h:91
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::saveSymbol ( LIB_PART aSymbol,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3498 of file sch_legacy_plugin.cpp.

References MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::empty(), LIB_PART::GetAliasCount(), LIB_PART::GetAliasNames(), LIB_PART::GetDateLastEdition(), LIB_PART::GetDrawItems(), LIB_PART::GetFields(), LIB_PART::GetFootprints(), LIB_PART::GetPinNameOffset(), LIB_PART::GetReferenceField(), GetText(), EDA_TEXT::GetText(), LIB_PART::GetUnitCount(), LIB_PART::GetValueField(), i, LIB_PART::IsPower(), LIB_FIELD::IsVisible(), LIB_ARC_T, LIB_BEZIER_T, LIB_CIRCLE_T, LIB_FIELD_T, LIB_PIN_T, LIB_POLYLINE_T, LIB_RECTANGLE_T, LIB_TEXT_T, MANDATORY_FIELDS, min, saveArc(), saveBezier(), saveCircle(), saveField(), savePin(), savePolyLine(), saveRectangle(), saveText(), LIB_PART::ShowPinNames(), LIB_PART::ShowPinNumbers(), MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::sort(), TO_UTF8, and LIB_PART::UnitsLocked().

Referenced by Save().

3500 {
3501  wxCHECK_RET( aSymbol, "Invalid LIB_PART pointer." );
3502 
3503  LIB_FIELD& value = aSymbol->GetValueField();
3504 
3505  // First line: it s a comment (component name for readers)
3506  aFormatter->Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3507 
3508  // Save data
3509  aFormatter->Print( 0, "DEF" );
3510 
3511  if( value.IsVisible() )
3512  {
3513  aFormatter->Print( 0, " %s", TO_UTF8( value.GetText() ) );
3514  }
3515  else
3516  {
3517  aFormatter->Print( 0, " ~%s", TO_UTF8( value.GetText() ) );
3518  }
3519 
3520  LIB_FIELD& reference = aSymbol->GetReferenceField();
3521 
3522  if( !reference.GetText().IsEmpty() )
3523  {
3524  aFormatter->Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3525  }
3526  else
3527  {
3528  aFormatter->Print( 0, " ~" );
3529  }
3530 
3531  aFormatter->Print( 0, " %d %d %c %c %d %c %c\n",
3532  0, aSymbol->GetPinNameOffset(),
3533  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3534  aSymbol->ShowPinNames() ? 'Y' : 'N',
3535  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3536  aSymbol->IsPower() ? 'P' : 'N' );
3537 
3538  timestamp_t dateModified = aSymbol->GetDateLastEdition();
3539 
3540  if( dateModified != 0 )
3541  {
3542  int sec = dateModified & 63;
3543  int min = ( dateModified >> 6 ) & 63;
3544  int hour = ( dateModified >> 12 ) & 31;
3545  int day = ( dateModified >> 17 ) & 31;
3546  int mon = ( dateModified >> 22 ) & 15;
3547  int year = ( dateModified >> 26 ) + 1990;
3548 
3549  aFormatter->Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3550  }
3551 
3552  LIB_FIELDS fields;
3553  aSymbol->GetFields( fields );
3554 
3555  // Mandatory fields:
3556  // may have their own save policy so there is a separate loop for them.
3557  // Empty fields are saved, because the user may have set visibility,
3558  // size and orientation
3559  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3560  {
3561  saveField( &fields[i], aFormatter );
3562  }
3563 
3564  // User defined fields:
3565  // may have their own save policy so there is a separate loop for them.
3566 
3567  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3568 
3569  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3570  {
3571  // There is no need to save empty fields, i.e. no reason to preserve field
3572  // names now that fields names come in dynamically through the template
3573  // fieldnames.
3574  if( !fields[i].GetText().IsEmpty() )
3575  {
3576  fields[i].SetId( fieldId++ );
3577  saveField( &fields[i], aFormatter );
3578  }
3579  }
3580 
3581  // Save the alias list: a line starting by "ALIAS". The first alias is the root
3582  // and has the same name as the component. In the old library file format this
3583  // alias does not get added to the alias list.
3584  if( aSymbol->GetAliasCount() > 1 )
3585  {
3586  wxArrayString aliases = aSymbol->GetAliasNames();
3587 
3588  aFormatter->Print( 0, "ALIAS" );
3589 
3590  for( unsigned i = 1; i < aliases.size(); i++ )
3591  {
3592  aFormatter->Print( 0, " %s", TO_UTF8( aliases[i] ) );
3593  }
3594 
3595  aFormatter->Print( 0, "\n" );
3596  }
3597 
3598  wxArrayString footprints = aSymbol->GetFootprints();
3599 
3600  // Write the footprint filter list
3601  if( footprints.GetCount() != 0 )
3602  {
3603  aFormatter->Print( 0, "$FPLIST\n" );
3604 
3605  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3606  {
3607  aFormatter->Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3608  }
3609 
3610  aFormatter->Print( 0, "$ENDFPLIST\n" );
3611  }
3612 
3613  // Save graphics items (including pins)
3614  if( !aSymbol->GetDrawItems().empty() )
3615  {
3616  // Sort the draw items in order to editing a file editing by hand.
3617  aSymbol->GetDrawItems().sort();
3618 
3619  aFormatter->Print( 0, "DRAW\n" );
3620 
3621  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3622  {
3623  switch( item.Type() )
3624  {
3625  case LIB_FIELD_T: // Fields have already been saved above.
3626  continue;
3627 
3628  case LIB_ARC_T:
3629  saveArc( (LIB_ARC*) &item, aFormatter );
3630  break;
3631 
3632  case LIB_BEZIER_T:
3633  saveBezier( (LIB_BEZIER*) &item, aFormatter );
3634  break;
3635 
3636  case LIB_CIRCLE_T:
3637  saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
3638  break;
3639 
3640  case LIB_PIN_T:
3641  savePin( (LIB_PIN* ) &item, aFormatter );
3642  break;
3643 
3644  case LIB_POLYLINE_T:
3645  savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
3646  break;
3647 
3648  case LIB_RECTANGLE_T:
3649  saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
3650  break;
3651 
3652  case LIB_TEXT_T:
3653  saveText( ( LIB_TEXT* ) &item, aFormatter );
3654  break;
3655 
3656  default:
3657  ;
3658  }
3659  }
3660 
3661  aFormatter->Print( 0, "ENDDRAW\n" );
3662  }
3663 
3664  aFormatter->Print( 0, "ENDDEF\n" );
3665 }
bool UnitsLocked() const
Check whether part units are interchangeable.
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: base_struct.h:155
int GetPinNameOffset()
bool IsPower() const
Define a symbol library graphical text item.
Definition: lib_text.h:44
void saveRectangle(LIB_RECTANGLE *aRectangle, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:224
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
Field object used in symbol libraries.
Definition: lib_field.h:59
void sort()
Definition: multivector.h:229
LIB_FIELD & GetValueField()
Return reference to the value field.
size_t GetAliasCount() const
void savePin(LIB_PIN *aPin, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveCircle(LIB_CIRCLE *aCircle, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
void saveText(LIB_TEXT *aText, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
bool ShowPinNames()
bool ShowPinNumbers()
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
timestamp_t GetDateLastEdition() const
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
wxArrayString & GetFootprints()
int GetUnitCount() const
bool IsVisible() const
Definition: lib_field.h:164
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:257
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
size_t i
Definition: json11.cpp:597
void savePolyLine(LIB_POLYLINE *aPolyLine, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveArc(LIB_ARC *aArc, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveField(LIB_FIELD *aField, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void saveBezier(LIB_BEZIER *aBezier, std::unique_ptr< FILE_OUTPUTFORMATTER > &aFormatter)
void GetFields(LIB_FIELDS &aList)
Return a list of fields withing this part.
#define min(a, b)
Definition: auxiliary.h:85
Class LIB_BEZIER defines bezier curve graphic body item.
Definition: lib_bezier.h:39
void SCH_LEGACY_PLUGIN_CACHE::saveText ( LIB_TEXT aText,
std::unique_ptr< FILE_OUTPUTFORMATTER > &  aFormatter 
)
private

Definition at line 3919 of file sch_legacy_plugin.cpp.

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

Referenced by SCH_LEGACY_PLUGIN::Format(), and saveSymbol().

3921 {
3922  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
3923 
3924  wxString text = aText->GetText();
3925 
3926  if( text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
3927  {
3928  // convert double quote to similar-looking two apostrophes
3929  text.Replace( wxT( "\"" ), wxT( "''" ) );
3930  text = wxT( "\"" ) + text + wxT( "\"" );
3931  }
3932  else
3933  {
3934  // Spaces are not allowed in text because it is not double quoted:
3935  // changed to '~'
3936  text.Replace( wxT( " " ), wxT( "~" ) );
3937  }
3938 
3939  aFormatter->Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
3940  aText->GetTextPos().x, aText->GetTextPos().y,
3941  aText->GetTextWidth(), !aText->IsVisible(),
3942  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
3943 
3944  aFormatter->Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
3945 
3946  char hjustify = 'C';
3947 
3948  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3949  hjustify = 'L';
3950  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3951  hjustify = 'R';
3952 
3953  char vjustify = 'C';
3954 
3955  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3956  vjustify = 'B';
3957  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3958  vjustify = 'T';
3959 
3960  aFormatter->Print( 0, " %c %c\n", hjustify, vjustify );
3961 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
bool IsItalic() const
Definition: eda_text.h:168
int GetUnit() const
int GetTextWidth() const
Definition: eda_text.h:216
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:188
bool IsBold() const
Definition: eda_text.h:171
double GetTextAngle() const
Definition: eda_text.h:162
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:189
bool IsVisible() const
Definition: eda_text.h:174
int GetConvert() const
void SCH_LEGACY_PLUGIN_CACHE::SetFileName ( const wxString &  aFileName)
inline

Definition at line 551 of file sch_legacy_plugin.cpp.

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

Definition at line 547 of file sch_legacy_plugin.cpp.

547 { m_isModified = aModified; }

Member Data Documentation

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

Definition at line 470 of file sch_legacy_plugin.cpp.

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

wxString SCH_LEGACY_PLUGIN_CACHE::m_fileName
private

Definition at line 468 of file sch_legacy_plugin.cpp.

Referenced by IsFile(), and loadPart().

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 473 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

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

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

int SCH_LEGACY_PLUGIN_CACHE::m_modHash = 1
staticprivate
int SCH_LEGACY_PLUGIN_CACHE::m_versionMajor
private

Definition at line 474 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 475 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 518 of file sch_legacy_plugin.cpp.


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