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 470 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 2194 of file sch_legacy_plugin.cpp.

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

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

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

Referenced by GetModifyHash().

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

Definition at line 2649 of file sch_legacy_plugin.cpp.

References m_aliases.

Referenced by loadAliases().

2650 {
2651  wxCHECK_MSG( !aAliasName.IsEmpty(), false, "alias name cannot be empty" );
2652 
2653  // The alias name is not a duplicate so don't change it.
2654  if( m_aliases.find( aAliasName ) == m_aliases.end() )
2655  return false;
2656 
2657  int dupCounter = 1;
2658  wxString newAlias = aAliasName;
2659 
2660  // If the alias is already loaded, the library is broken. It may have been possible in
2661  // the past that this could happen so we assign a new alias name to prevent any conflicts
2662  // rather than throw an exception.
2663  while( m_aliases.find( newAlias ) != m_aliases.end() )
2664  {
2665  newAlias = aAliasName << dupCounter;
2666  dupCounter++;
2667  }
2668 
2669  aAliasName = newAlias;
2670 
2671  return true;
2672 }
void SCH_LEGACY_PLUGIN_CACHE::DeleteAlias ( const wxString &  aAliasName)

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

3972 {
3973  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
3974 
3975  if( it == m_aliases.end() )
3976  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
3977  m_libFileName.GetFullName(), aAliasName ) );
3978 
3979  LIB_ALIAS* alias = it->second;
3980  LIB_PART* part = alias->GetPart();
3981 
3982  alias = part->RemoveAlias( alias );
3983 
3984  if( !alias )
3985  {
3986  delete part;
3987 
3988  if( m_aliases.size() > 1 )
3989  {
3990  LIB_ALIAS_MAP::iterator next = it;
3991  next++;
3992 
3993  if( next == m_aliases.end() )
3994  next = m_aliases.begin();
3995 
3996  alias = next->second;
3997  }
3998  }
3999 
4000  m_aliases.erase( it );
4001  ++m_modHash;
4002  m_isModified = true;
4003 }
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 4006 of file sch_legacy_plugin.cpp.

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

Referenced by GetModifyHash().

4007 {
4008  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
4009 
4010  if( it == m_aliases.end() )
4011  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
4012  m_libFileName.GetFullName(), aAliasName ) );
4013 
4014  LIB_ALIAS* alias = it->second;
4015  LIB_PART* part = alias->GetPart();
4016 
4017  wxArrayString aliasNames = part->GetAliasNames();
4018 
4019  // Deleting all of the aliases deletes the symbol from the library.
4020  for( size_t i = 0; i < aliasNames.Count(); i++ )
4021  DeleteAlias( aliasNames[i] );
4022 }
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
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 559 of file sch_legacy_plugin.cpp.

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

Definition at line 2215 of file sch_legacy_plugin.cpp.

References m_isWritable, and m_libFileName.

Referenced by GetModifyHash(), and Load().

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

Definition at line 555 of file sch_legacy_plugin.cpp.

Referenced by ~SCH_LEGACY_PLUGIN_CACHE().

555 { 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 2225 of file sch_legacy_plugin.cpp.

References m_fileName.

Referenced by GetModifyHash().

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

Definition at line 2231 of file sch_legacy_plugin.cpp.

References m_fileModTime, and m_libFileName.

Referenced by GetModifyHash().

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

2309 {
2310  wxCHECK_RET( m_libFileName.IsAbsolute(),
2311  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2312  "open library \"%s\".", m_libFileName.GetFullPath() ) );
2313 
2314  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file \"%s\"",
2315  m_libFileName.GetFullPath() );
2316 
2317  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2318 
2319  if( !reader.ReadLine() )
2320  THROW_IO_ERROR( _( "unexpected end of file" ) );
2321 
2322  const char* line = reader.Line();
2323 
2324  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2325  {
2326  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2327  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2328  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2329  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2330  }
2331 
2332  m_versionMajor = parseInt( reader, line, &line );
2333 
2334  if( *line != '.' )
2335  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2336 
2337  line++;
2338 
2339  m_versionMinor = parseInt( reader, line, &line );
2340 
2341  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2342  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2343 
2344  // Check if this is a symbol library which is the same as a component library but without
2345  // any alias, documentation, footprint filters, etc.
2346  if( strCompare( "SYMBOL", line, &line ) )
2347  {
2348  // Symbol files add date and time stamp info to the header.
2350 
2352  }
2353  else
2354  {
2356  }
2357 
2358  while( reader.ReadLine() )
2359  {
2360  line = reader.Line();
2361 
2362  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2363  continue;
2364 
2365  // Headers where only supported in older library file formats.
2366  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2367  loadHeader( reader );
2368 
2369  if( strCompare( "DEF", line ) )
2370  {
2371  // Read one DEF/ENDDEF part entry from library:
2372  loadPart( reader );
2373 
2374  }
2375  }
2376 
2377  ++m_modHash;
2378 
2379  // Remember the file modification time of library file when the
2380  // cache snapshot was made, so that in a networked environment we will
2381  // reload the cache as needed.
2383 
2385  loadDocs();
2386 }
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 loadHeader(FILE_LINE_READER &aReader)
const wxChar traceSchLegacyPlugin[]
Flag to enable legacy schematic plugin debug output.
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define USE_OLD_DOC_FILE_FORMAT(major, minor)
Definition: class_library.h:75
#define SCH_PARSE_ERROR(text, reader, pos)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
LIB_PART * loadPart(FILE_LINE_READER &aReader)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
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 2675 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

2677 {
2678  wxString newAlias;
2679  const char* line = aReader.Line();
2680 
2681  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2682 
2683  // Parse the ALIAS list.
2684  wxString alias;
2685  parseUnquotedString( alias, aReader, line, &line );
2686 
2687  while( !alias.IsEmpty() )
2688  {
2689  newAlias = alias;
2690  checkForDuplicates( newAlias );
2691  aPart->AddAlias( newAlias );
2692  alias.clear();
2693  parseUnquotedString( alias, aReader, line, &line, true );
2694  }
2695 }
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 2932 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().

2934 {
2935  const char* line = aReader.Line();
2936 
2937  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
2938 
2939  std::unique_ptr< LIB_ARC > arc( new LIB_ARC( aPart.get() ) );
2940 
2941  wxPoint center;
2942 
2943  center.x = parseInt( aReader, line, &line );
2944  center.y = parseInt( aReader, line, &line );
2945 
2946  arc->SetPosition( center );
2947  arc->SetRadius( parseInt( aReader, line, &line ) );
2948 
2949  int angle1 = parseInt( aReader, line, &line );
2950  int angle2 = parseInt( aReader, line, &line );
2951 
2952  NORMALIZE_ANGLE_POS( angle1 );
2953  NORMALIZE_ANGLE_POS( angle2 );
2954  arc->SetFirstRadiusAngle( angle1 );
2955  arc->SetSecondRadiusAngle( angle2 );
2956 
2957  arc->SetUnit( parseInt( aReader, line, &line ) );
2958  arc->SetConvert( parseInt( aReader, line, &line ) );
2959  arc->SetWidth( parseInt( aReader, line, &line ) );
2960 
2961  // Old libraries (version <= 2.2) do not have always this FILL MODE param
2962  // when fill mode is no fill (default mode).
2963  if( *line != 0 )
2964  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
2965 
2966  // Actual Coordinates of arc ends are read from file
2967  if( *line != 0 )
2968  {
2969  wxPoint arcStart, arcEnd;
2970 
2971  arcStart.x = parseInt( aReader, line, &line );
2972  arcStart.y = parseInt( aReader, line, &line );
2973  arcEnd.x = parseInt( aReader, line, &line );
2974  arcEnd.y = parseInt( aReader, line, &line );
2975 
2976  arc->SetStart( arcStart );
2977  arc->SetEnd( arcEnd );
2978  }
2979  else
2980  {
2981  // Actual Coordinates of arc ends are not read from file
2982  // (old library), calculate them
2983  wxPoint arcStart( arc->GetRadius(), 0 );
2984  wxPoint arcEnd( arc->GetRadius(), 0 );
2985 
2986  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
2987  arcStart += arc->GetPosition();
2988  arc->SetStart( arcStart );
2989  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
2990  arcEnd += arc->GetPosition();
2991  arc->SetEnd( arcEnd );
2992  }
2993 
2994  return arc.release();
2995 }
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:317
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 3385 of file sch_legacy_plugin.cpp.

References bezier(), 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( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3391 
3392  std::unique_ptr< LIB_BEZIER > bezier( new LIB_BEZIER( aPart.get() ) );
3393 
3394  int points = parseInt( aReader, line, &line );
3395  bezier->SetUnit( parseInt( aReader, line, &line ) );
3396  bezier->SetConvert( parseInt( aReader, line, &line ) );
3397  bezier->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  bezier->AddPoint( pt );
3406  }
3407 
3408  if( *line != 0 )
3409  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3410 
3411  return bezier.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...
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)
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 2998 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3000 {
3001  const char* line = aReader.Line();
3002 
3003  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
3004 
3005  std::unique_ptr< LIB_CIRCLE > circle( new LIB_CIRCLE( aPart.get() ) );
3006 
3007  wxPoint center;
3008 
3009  center.x = parseInt( aReader, line, &line );
3010  center.y = parseInt( aReader, line, &line );
3011 
3012  circle->SetPosition( center );
3013  circle->SetRadius( parseInt( aReader, line, &line ) );
3014  circle->SetUnit( parseInt( aReader, line, &line ) );
3015  circle->SetConvert( parseInt( aReader, line, &line ) );
3016  circle->SetWidth( parseInt( aReader, line, &line ) );
3017 
3018  if( *line != 0 )
3019  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3020 
3021  return circle.release();
3022 }
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 2389 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().

2390 {
2391  const char* line;
2392  wxString text;
2393  wxString aliasName;
2394  wxFileName fn = m_libFileName;
2395  LIB_ALIAS* alias = NULL;;
2396 
2397  fn.SetExt( DOC_EXT );
2398 
2399  // Not all libraries will have a document file.
2400  if( !fn.FileExists() )
2401  return;
2402 
2403  if( !fn.IsFileReadable() )
2404  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2405  "document file \"%s\"" ), fn.GetFullPath() ) );
2406 
2407  FILE_LINE_READER reader( fn.GetFullPath() );
2408 
2409  line = reader.ReadLine();
2410 
2411  if( !line )
2412  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2413 
2414  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2415  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2416  reader, line );
2417 
2418  while( reader.ReadLine() )
2419  {
2420  line = reader.Line();
2421 
2422  if( *line == '#' ) // Comment line.
2423  continue;
2424 
2425  if( !strCompare( "$CMP", line, &line ) != 0 )
2426  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2427 
2428  parseUnquotedString( aliasName, reader, line, &line ); // Alias name.
2429 
2430  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
2431 
2432  if( it == m_aliases.end() )
2433  wxLogWarning( "Alias '%s' not found in library:\n\n"
2434  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2435  reader.LineNumber(), (int) (line - reader.Line() ) );
2436  else
2437  alias = it->second;
2438 
2439  // Read the curent alias associated doc.
2440  // if the alias does not exist, just skip the description
2441  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2442  while( reader.ReadLine() )
2443  {
2444  line = reader.Line();
2445 
2446  if( !line )
2447  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2448 
2449  if( strCompare( "$ENDCMP", line, &line ) )
2450  break;
2451 
2452  text = FROM_UTF8( line + 2 );
2453  text = text.Trim();
2454 
2455  switch( line[0] )
2456  {
2457  case 'D':
2458  if( alias )
2459  alias->SetDescription( text );
2460  break;
2461 
2462  case 'K':
2463  if( alias )
2464  alias->SetKeyWords( text );
2465  break;
2466 
2467  case 'F':
2468  if( alias )
2469  alias->SetDocFileName( text );
2470  break;
2471 
2472  case '#':
2473  break;
2474 
2475  default:
2476  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2477  }
2478  }
2479  }
2480 }
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 2844 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().

2846 {
2847  const char* line = aReader.Line();
2848 
2849  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
2850 
2851  line = aReader.ReadLine();
2852 
2853  while( line )
2854  {
2855  if( strCompare( "ENDDRAW", line, &line ) )
2856  return;
2857 
2858  switch( line[0] )
2859  {
2860  case 'A': // Arc
2861  aPart->AddDrawItem( loadArc( aPart, aReader ) );
2862  break;
2863 
2864  case 'C': // Circle
2865  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
2866  break;
2867 
2868  case 'T': // Text
2869  aPart->AddDrawItem( loadText( aPart, aReader ) );
2870  break;
2871 
2872  case 'S': // Square
2873  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
2874  break;
2875 
2876  case 'X': // Pin Description
2877  aPart->AddDrawItem( loadPin( aPart, aReader ) );
2878  break;
2879 
2880  case 'P': // Polyline
2881  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
2882  break;
2883 
2884  case 'B': // Bezier Curves
2885  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
2886  break;
2887 
2888  case '#': // Comment
2889  case '\n': // Empty line
2890  case '\r':
2891  case 0:
2892  break;
2893 
2894  default:
2895  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
2896  }
2897 
2898  line = aReader.ReadLine();
2899  }
2900 
2901  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
2902 }
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 2698 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().

2700 {
2701  const char* line = aReader.Line();
2702 
2703  wxCHECK_RET( *line == 'F', "Invalid field line" );
2704 
2705  int id;
2706 
2707  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2708  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
2709 
2710  std::unique_ptr< LIB_FIELD > field( new LIB_FIELD( aPart.get(), id ) );
2711 
2712  // Skip to the first double quote.
2713  while( *line != '"' && *line != 0 )
2714  line++;
2715 
2716  if( *line == 0 )
2717  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
2718 
2719  wxString text;
2720  parseQuotedString( text, aReader, line, &line, true );
2721 
2722  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
2723  // not save like this.
2724  if( text.size() == 1 && text[0] == '~' )
2725  text.clear();
2726 
2727  field->m_Text = text;
2728 
2729  wxPoint pos;
2730 
2731  pos.x = parseInt( aReader, line, &line );
2732  pos.y = parseInt( aReader, line, &line );
2733  field->SetPosition( pos );
2734 
2735  wxSize textSize;
2736 
2737  textSize.x = textSize.y = parseInt( aReader, line, &line );
2738  field->SetTextSize( textSize );
2739 
2740  char textOrient = parseChar( aReader, line, &line );
2741 
2742  if( textOrient == 'H' )
2743  field->SetTextAngle( TEXT_ANGLE_HORIZ );
2744  else if( textOrient == 'V' )
2745  field->SetTextAngle( TEXT_ANGLE_VERT );
2746  else
2747  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
2748 
2749  char textVisible = parseChar( aReader, line, &line );
2750 
2751  if( textVisible == 'V' )
2752  field->SetVisible( true );
2753  else if ( textVisible == 'I' )
2754  field->SetVisible( false );
2755  else
2756  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
2757 
2758  // It may be technically correct to use the library version to determine if the field text
2759  // attributes are present. If anyone knows if that is valid and what version that would be,
2760  // please change this to test the library version rather than an EOL or the quoted string
2761  // of the field name.
2762  if( *line != 0 && *line != '"' )
2763  {
2764  char textHJustify = parseChar( aReader, line, &line );
2765 
2766  if( textHJustify == 'C' )
2767  field->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
2768  else if( textHJustify == 'L' )
2769  field->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
2770  else if( textHJustify == 'R' )
2771  field->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
2772  else
2773  SCH_PARSE_ERROR( "invalid field text horizontal justification parameter",
2774  aReader, line );
2775 
2776  wxString attributes;
2777 
2778  parseUnquotedString( attributes, aReader, line, &line );
2779 
2780  if( !(attributes.size() == 3 || attributes.size() == 1 ) )
2781  SCH_PARSE_ERROR( "invalid field text attributes size",
2782  aReader, line );
2783 
2784  if( attributes[0] == 'C' )
2785  field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
2786  else if( attributes[0] == 'B' )
2787  field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
2788  else if( attributes[0] == 'T' )
2789  field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
2790  else
2791  SCH_PARSE_ERROR( "invalid field text vertical justification parameter",
2792  aReader, line );
2793 
2794  if( attributes.size() == 3 )
2795  {
2796  if( attributes[1] == 'I' ) // Italic
2797  field->SetItalic( true );
2798  else if( attributes[1] != 'N' ) // No italics is default, check for error.
2799  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
2800 
2801  if ( attributes[2] == 'B' ) // Bold
2802  field->SetBold( true );
2803  else if( attributes[2] != 'N' ) // No bold is default, check for error.
2804  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
2805  }
2806  }
2807 
2808  // Fields in RAM must always have names.
2809  if( (unsigned) id < MANDATORY_FIELDS )
2810  {
2811  // Fields in RAM must always have names, because we are trying to get
2812  // less dependent on field ids and more dependent on names.
2813  // Plus assumptions are made in the field editors.
2814  field->m_name = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
2815 
2816  LIB_FIELD* fixedField = aPart->GetField( field->GetId() );
2817 
2818  // this will fire only if somebody broke a constructor or editor.
2819  // MANDATORY_FIELDS are always present in ram resident components, no
2820  // exceptions, and they always have their names set, even fixed fields.
2821  wxASSERT( fixedField );
2822 
2823  *fixedField = *field;
2824 
2825  // Ensure the VALUE field = the part name (can be not the case
2826  // with malformed libraries: edited by hand, or converted from other tools)
2827  if( fixedField->GetId() == VALUE )
2828  fixedField->m_Text = aPart->GetName();
2829  }
2830  else
2831  {
2832  wxString name;
2833 
2834  parseQuotedString( name, aReader, line, &line, true ); // Optional.
2835 
2836  if( !name.IsEmpty() )
2837  field->m_name = name;
2838 
2839  aPart->AddDrawItem( field.release() ); // LIB_FIELD* is now owned by the LIB_PART.
2840  }
2841 }
#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 3415 of file sch_legacy_plugin.cpp.

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

Referenced by loadPart().

3417 {
3418  const char* line = aReader.Line();
3419 
3420  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3421 
3422  line = aReader.ReadLine();
3423 
3424  while( line )
3425  {
3426  if( strCompare( "$ENDFPLIST", line, &line ) )
3427  return;
3428 
3429  wxString footprint;
3430 
3431  parseUnquotedString( footprint, aReader, line, &line );
3432  aPart->GetFootprints().Add( footprint );
3433  line = aReader.ReadLine();
3434  }
3435 
3436  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3437 }
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 2483 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().

2484 {
2485  const char* line = aReader.Line();
2486 
2487  wxASSERT( strCompare( "$HEADER", line, &line ) );
2488 
2489  while( aReader.ReadLine() )
2490  {
2491  line = (char*) aReader;
2492 
2493  // The time stamp saved in old library files is not used or saved in the latest
2494  // library file version.
2495  if( strCompare( "TimeStamp", line, &line ) )
2496  continue;
2497  else if( strCompare( "$ENDHEADER", line, &line ) )
2498  return;
2499  }
2500 
2501  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2502 }
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 2505 of file sch_legacy_plugin.cpp.

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

Referenced by Load().

2506 {
2507  const char* line = aReader.Line();
2508 
2509  wxCHECK( strCompare( "DEF", line, &line ), NULL );
2510 
2511  // Read DEF line:
2512  char yes_no = 0;
2513 
2514  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2515 
2516  wxString name, prefix;
2517 
2518  parseUnquotedString( name, aReader, line, &line ); // Part name.
2519  parseUnquotedString( prefix, aReader, line, &line ); // Prefix name
2520  parseInt( aReader, line, &line ); // NumOfPins, unused.
2521  part->SetPinNameOffset( parseInt( aReader, line, &line ) ); // Pin name offset.
2522  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2523 
2524  if( !( yes_no == 'Y' || yes_no == 'N') )
2525  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2526 
2527  part->SetShowPinNumbers( ( yes_no == 'N' ) ? false : true );
2528 
2529  yes_no = parseChar( aReader, line, &line ); // Show pin numbers.
2530 
2531  if( !( yes_no == 'Y' || yes_no == 'N') )
2532  SCH_PARSE_ERROR( "expected Y or N", aReader, line );
2533 
2534  part->SetShowPinNames( ( yes_no == 'N' ) ? false : true ); // Show pin names.
2535 
2536  part->SetUnitCount( parseInt( aReader, line, &line ) ); // Number of units.
2537 
2538  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2539  if( part->GetUnitCount() < 1 )
2540  part->SetUnitCount( 1 );
2541 
2542  // Copy part name and prefix.
2543 
2544  // The root alias is added to the alias list by SetName() which is called by SetText().
2545  if( name.IsEmpty() )
2546  {
2547  part->SetName( "~" );
2548  }
2549  else if( name[0] != '~' )
2550  {
2551  part->SetName( name );
2552  }
2553  else
2554  {
2555  part->SetName( name.Right( name.Length() - 1 ) );
2556  part->GetValueField().SetVisible( false );
2557  }
2558 
2559  // Don't set the library alias, this is determined by the symbol library table.
2560  part->SetLibId( LIB_ID( wxEmptyString, part->GetName() ) );
2561 
2562  // There are some code paths in SetText() that do not set the root alias to the
2563  // alias list so add it here if it didn't get added by SetText().
2564  if( !part->HasAlias( part->GetName() ) )
2565  part->AddAlias( part->GetName() );
2566 
2567  LIB_FIELD& reference = part->GetReferenceField();
2568 
2569  if( prefix == "~" )
2570  {
2571  reference.Empty();
2572  reference.SetVisible( false );
2573  }
2574  else
2575  {
2576  reference.SetText( prefix );
2577  }
2578 
2579  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2580  // The was no concept of interchangeable multiple unit symbols.
2582  {
2583  // Nothing needs to be set since the default setting for symbols with multiple
2584  // units were never interchangeable. Just parse the 0 an move on.
2585  parseInt( aReader, line, &line );
2586  }
2587  else
2588  {
2589  char locked = parseChar( aReader, line, &line );
2590 
2591  if( locked == 'L' )
2592  part->LockUnits( true );
2593  else if( locked == 'F' || locked == '0' )
2594  part->LockUnits( false );
2595  else
2596  SCH_PARSE_ERROR( "expected L, F, or 0", aReader, line );
2597  }
2598 
2599 
2600  // There is the optional power component flag.
2601  if( *line )
2602  {
2603  char power = parseChar( aReader, line, &line );
2604 
2605  if( power == 'P' )
2606  part->SetPower();
2607  else if( power == 'N' )
2608  part->SetNormal();
2609  else
2610  SCH_PARSE_ERROR( "expected P or N", aReader, line );
2611  }
2612 
2613  line = aReader.ReadLine();
2614 
2615  // Read lines until "ENDDEF" is found.
2616  while( line )
2617  {
2618  if( *line == '#' ) // Comment
2619  ;
2620  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2621  continue;
2622  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2623  loadAliases( part, aReader );
2624  else if( *line == 'F' ) // Fields
2625  loadField( part, aReader );
2626  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2627  loadDrawEntries( part, aReader );
2628  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2629  loadFootprintFilters( part, aReader );
2630  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2631  {
2632  // Now all is good, Add the root alias to the cache alias list.
2633  m_aliases[ part->GetName() ] = part->GetAlias( part->GetName() );
2634 
2635  // Add aliases when exist
2636  for( size_t ii = 0; ii < part->GetAliasCount(); ++ii )
2637  m_aliases[ part->GetAlias( ii )->GetName() ] = part->GetAlias( ii );
2638 
2639  return part.release();
2640  }
2641 
2642  line = aReader.ReadLine();
2643  }
2644 
2645  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2646 }
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)
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 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...
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 3164 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().

3166 {
3167  const char* line = aReader.Line();
3168 
3169  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3170 
3171  std::unique_ptr< LIB_PIN > pin( new LIB_PIN( aPart.get() ) );
3172 
3173  wxString name, number;
3174 
3175  parseUnquotedString( name, aReader, line, &line );
3176  parseUnquotedString( number, aReader, line, &line );
3177 
3178  // Unlike most of the other LIB_ITEMs, the SetXXX() routines on LIB_PINs are at the UI
3179  // level, performing additional pin checking, multi-pin editing, and setting the modified
3180  // flag. So we must set the member fields directly.
3181 
3182  pin->m_name = name;
3183  pin->m_number = number;
3184 
3185  wxPoint pos;
3186 
3187  pos.x = parseInt( aReader, line, &line );
3188  pos.y = parseInt( aReader, line, &line );
3189  pin->m_position = pos;
3190  pin->m_length = parseInt( aReader, line, &line );
3191  pin->m_orientation = parseChar( aReader, line, &line );
3192  pin->m_numTextSize = parseInt( aReader, line, &line );
3193  pin->m_nameTextSize = parseInt( aReader, line, &line );
3194  pin->m_Unit = parseInt( aReader, line, &line );
3195  pin->m_Convert = parseInt( aReader, line, &line );
3196 
3197  char type = parseChar( aReader, line, &line );
3198 
3199  wxString attributes;
3200 
3201  // Optional
3202  parseUnquotedString( attributes, aReader, line, &line, true );
3203 
3204  switch( type )
3205  {
3206  case 'I':
3207  pin->m_type = PIN_INPUT;
3208  break;
3209 
3210  case 'O':
3211  pin->m_type = PIN_OUTPUT;
3212  break;
3213 
3214  case 'B':
3215  pin->m_type = PIN_BIDI;
3216  break;
3217 
3218  case 'T':
3219  pin->m_type = PIN_TRISTATE;
3220  break;
3221 
3222  case 'P':
3223  pin->m_type = PIN_PASSIVE;
3224  break;
3225 
3226  case 'U':
3227  pin->m_type = PIN_UNSPECIFIED;
3228  break;
3229 
3230  case 'W':
3231  pin->m_type = PIN_POWER_IN;
3232  break;
3233 
3234  case 'w':
3235  pin->m_type = PIN_POWER_OUT;
3236  break;
3237 
3238  case 'C':
3239  pin->m_type = PIN_OPENCOLLECTOR;
3240  break;
3241 
3242  case 'E':
3243  pin->m_type = PIN_OPENEMITTER;
3244  break;
3245 
3246  case 'N':
3247  pin->m_type = PIN_NC;
3248  break;
3249 
3250  default:
3251  SCH_PARSE_ERROR( "unknown pin type", aReader, line );
3252  }
3253 
3254  if( !attributes.IsEmpty() ) /* Special Symbol defined */
3255  {
3256  enum
3257  {
3258  INVERTED = 1 << 0,
3259  CLOCK = 1 << 1,
3260  LOWLEVEL_IN = 1 << 2,
3261  LOWLEVEL_OUT = 1 << 3,
3262  FALLING_EDGE = 1 << 4,
3263  NONLOGIC = 1 << 5
3264  };
3265 
3266  int flags = 0;
3267 
3268  for( int j = attributes.size(); j > 0; )
3269  {
3270  switch( attributes[--j].GetValue() )
3271  {
3272  case '~':
3273  break;
3274 
3275  case 'N':
3276  pin->m_attributes |= PIN_INVISIBLE;
3277  break;
3278 
3279  case 'I':
3280  flags |= INVERTED;
3281  break;
3282 
3283  case 'C':
3284  flags |= CLOCK;
3285  break;
3286 
3287  case 'L':
3288  flags |= LOWLEVEL_IN;
3289  break;
3290 
3291  case 'V':
3292  flags |= LOWLEVEL_OUT;
3293  break;
3294 
3295  case 'F':
3296  flags |= FALLING_EDGE;
3297  break;
3298 
3299  case 'X':
3300  flags |= NONLOGIC;
3301  break;
3302 
3303  default:
3304  SCH_PARSE_ERROR( "unknown pin attribute", aReader, line );
3305  }
3306  }
3307 
3308  switch( flags )
3309  {
3310  case 0:
3311  pin->m_shape = PINSHAPE_LINE;
3312  break;
3313 
3314  case INVERTED:
3315  pin->m_shape = PINSHAPE_INVERTED;
3316  break;
3317 
3318  case CLOCK:
3319  pin->m_shape = PINSHAPE_CLOCK;
3320  break;
3321 
3322  case INVERTED | CLOCK:
3323  pin->m_shape = PINSHAPE_INVERTED_CLOCK;
3324  break;
3325 
3326  case LOWLEVEL_IN:
3327  pin->m_shape = PINSHAPE_INPUT_LOW;
3328  break;
3329 
3330  case LOWLEVEL_IN | CLOCK:
3331  pin->m_shape = PINSHAPE_CLOCK_LOW;
3332  break;
3333 
3334  case LOWLEVEL_OUT:
3335  pin->m_shape = PINSHAPE_OUTPUT_LOW;
3336  break;
3337 
3338  case FALLING_EDGE:
3339  pin->m_shape = PINSHAPE_FALLING_EDGE_CLOCK;
3340  break;
3341 
3342  case NONLOGIC:
3343  pin->m_shape = PINSHAPE_NONLOGIC;
3344  break;
3345 
3346  default:
3347  SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3348  }
3349  }
3350 
3351  return pin.release();
3352 }
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 3355 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3357 {
3358  const char* line = aReader.Line();
3359 
3360  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3361 
3362  std::unique_ptr< LIB_POLYLINE > polyLine( new LIB_POLYLINE( aPart.get() ) );
3363 
3364  int points = parseInt( aReader, line, &line );
3365  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3366  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3367  polyLine->SetWidth( parseInt( aReader, line, &line ) );
3368 
3369  wxPoint pt;
3370 
3371  for( int i = 0; i < points; i++ )
3372  {
3373  pt.x = parseInt( aReader, line, &line );
3374  pt.y = parseInt( aReader, line, &line );
3375  polyLine->AddPoint( pt );
3376  }
3377 
3378  if( *line != 0 )
3379  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3380 
3381  return polyLine.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...
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_RECTANGLE * SCH_LEGACY_PLUGIN_CACHE::loadRectangle ( std::unique_ptr< LIB_PART > &  aPart,
FILE_LINE_READER aReader 
)
private

Definition at line 3132 of file sch_legacy_plugin.cpp.

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

Referenced by loadDrawEntries().

3134 {
3135  const char* line = aReader.Line();
3136 
3137  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
3138 
3139  std::unique_ptr< LIB_RECTANGLE > rectangle( new LIB_RECTANGLE( aPart.get() ) );
3140 
3141  wxPoint pos;
3142 
3143  pos.x = parseInt( aReader, line, &line );
3144  pos.y = parseInt( aReader, line, &line );
3145  rectangle->SetPosition( pos );
3146 
3147  wxPoint end;
3148 
3149  end.x = parseInt( aReader, line, &line );
3150  end.y = parseInt( aReader, line, &line );
3151  rectangle->SetEnd( end );
3152 
3153  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3154  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3155  rectangle->SetWidth( parseInt( aReader, line, &line ) );
3156 
3157  if( *line != 0 )
3158  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3159 
3160  return rectangle.release();
3161 }
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 3025 of file sch_legacy_plugin.cpp.

References GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, is_eol(), LIB_VERSION, LINE_READER::Line(), m_versionMajor, m_versionMinor, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, strCompare(), wxPoint::x, and wxPoint::y.

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

3027 {
3028  const char* line = aReader.Line();
3029 
3030  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
3031 
3032  std::unique_ptr< LIB_TEXT > text( new LIB_TEXT( aPart.get() ) );
3033 
3034  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3035 
3036  wxPoint center;
3037 
3038  center.x = parseInt( aReader, line, &line );
3039  center.y = parseInt( aReader, line, &line );
3040  text->SetPosition( center );
3041 
3042  wxSize size;
3043 
3044  size.x = size.y = parseInt( aReader, line, &line );
3045  text->SetTextSize( size );
3046  text->SetVisible( !parseInt( aReader, line, &line ) );
3047  text->SetUnit( parseInt( aReader, line, &line ) );
3048  text->SetConvert( parseInt( aReader, line, &line ) );
3049 
3050  wxString str;
3051 
3052  // If quoted string loading fails, load as not quoted string.
3053  if( *line == '"' )
3054  parseQuotedString( str, aReader, line, &line );
3055  else
3056  parseUnquotedString( str, aReader, line, &line );
3057 
3058  if( !str.IsEmpty() )
3059  {
3060  // convert two apostrophes back to double quote
3061  str.Replace( "''", "\"" );
3062  str.Replace( wxT( "~" ), wxT( " " ) );
3063  }
3064 
3065  text->SetText( str );
3066 
3067  // Here things are murky and not well defined. At some point it appears the format
3068  // was changed to add text properties. However rather than add the token to the end of
3069  // the text definition, it was added after the string and no mention if the file
3070  // verion was bumped or not so this code make break on very old component libraries.
3071  //
3072  // Update: apparently even in the latest version this can be different so added a test
3073  // for end of line before checking for the text properties.
3074  if( LIB_VERSION( m_versionMajor, m_versionMinor ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3075  {
3076  if( strCompare( "Italic", line, &line ) )
3077  text->SetItalic( true );
3078  else if( !strCompare( "Normal", line, &line ) )
3079  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'",
3080  aReader, line );
3081 
3082  if( parseInt( aReader, line, &line ) > 0 )
3083  text->SetBold( true );
3084 
3085  // Some old libaries version > 2.0 do not have these options for text justification:
3086  if( !is_eol( *line ) )
3087  {
3088  switch( parseChar( aReader, line, &line ) )
3089  {
3090  case 'L':
3091  text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
3092  break;
3093 
3094  case 'C':
3095  text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
3096  break;
3097 
3098  case 'R':
3099  text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
3100  break;
3101 
3102  default:
3103  SCH_PARSE_ERROR( "invalid horizontal text justication parameter, expected L, C, or R",
3104  aReader, line );
3105  }
3106 
3107  switch( parseChar( aReader, line, &line ) )
3108  {
3109  case 'T':
3110  text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
3111  break;
3112 
3113  case 'C':
3114  text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
3115  break;
3116 
3117  case 'B':
3118  text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
3119  break;
3120 
3121  default:
3122  SCH_PARSE_ERROR( "invalid vertical text justication parameter, expected T, C, or B",
3123  aReader, line );
3124  }
3125  }
3126  }
3127 
3128  return text.release();
3129 }
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
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 2905 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().

2907 {
2908  FILL_T mode;
2909 
2910  switch( parseChar( aReader, aLine, aOutput ) )
2911  {
2912  case 'F':
2913  mode = FILLED_SHAPE;
2914  break;
2915 
2916  case 'f':
2917  mode = FILLED_WITH_BG_BODYCOLOR;
2918  break;
2919 
2920  case 'N':
2921  mode = NO_FILL;
2922  break;
2923 
2924  default:
2925  SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
2926  }
2927 
2928  return mode;
2929 }
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:70
LIB_ALIAS * SCH_LEGACY_PLUGIN_CACHE::removeAlias ( LIB_ALIAS aAlias)
private

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

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

3441 {
3442  if( !m_isModified )
3443  return;
3444 
3445  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( m_libFileName.GetFullPath() ) );
3446  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3447  formatter->Print( 0, "#encoding utf-8\n");
3448 
3449  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3450  {
3451  if( !it->second->IsRoot() )
3452  continue;
3453 
3454  saveSymbol( it->second->GetPart(), formatter );
3455  }
3456 
3457  formatter->Print( 0, "#\n#End Library\n" );
3458  formatter.reset();
3459 
3460  m_fileModTime = m_libFileName.GetModificationTime();
3461  m_isModified = false;
3462 
3463  if( aSaveDocFile )
3464  saveDocFile();
3465 }
#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 3639 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().

3641 {
3642  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
3643 
3644  int x1 = aArc->GetFirstRadiusAngle();
3645 
3646  if( x1 > 1800 )
3647  x1 -= 3600;
3648 
3649  int x2 = aArc->GetSecondRadiusAngle();
3650 
3651  if( x2 > 1800 )
3652  x2 -= 3600;
3653 
3654  aFormatter->Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
3655  aArc->GetPosition().x, aArc->GetPosition().y,
3656  aArc->GetRadius(), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
3657  aArc->GetWidth(), fill_tab[aArc->GetFillMode()],
3658  aArc->GetStart().x, aArc->GetStart().y,
3659  aArc->GetEnd().x, aArc->GetEnd().y );
3660 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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 3663 of file sch_legacy_plugin.cpp.

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

Referenced by saveSymbol().

3665 {
3666  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
3667 
3668  aFormatter->Print( 0, "B %lu %d %d %d", (unsigned long)aBezier->GetCornerCount(),
3669  aBezier->GetUnit(), aBezier->GetConvert(), aBezier->GetWidth() );
3670 
3671  for( const auto& pt : aBezier->GetPoints() )
3672  aFormatter->Print( 0, " %d %d", pt.x, pt.y );
3673 
3674  aFormatter->Print( 0, " %c\n", fill_tab[aBezier->GetFillMode()] );
3675 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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
unsigned GetCornerCount() const
Definition: lib_bezier.h:73
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 3678 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().

3680 {
3681  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
3682 
3683  aFormatter->Print( 0, "C %d %d %d %d %d %d %c\n",
3684  aCircle->GetPosition().x, aCircle->GetPosition().y,
3685  aCircle->GetRadius(), aCircle->GetUnit(), aCircle->GetConvert(),
3686  aCircle->GetWidth(), fill_tab[aCircle->GetFillMode()] );
3687 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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 3935 of file sch_legacy_plugin.cpp.

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

Referenced by Save().

3936 {
3937  wxFileName fileName = m_libFileName;
3938 
3939  fileName.SetExt( DOC_EXT );
3940  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
3941 
3942  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
3943 
3944  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3945  {
3946  wxString description = it->second->GetDescription();
3947  wxString keyWords = it->second->GetKeyWords();
3948  wxString docFileName = it->second->GetDocFileName();
3949 
3950  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
3951  continue;
3952 
3953  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
3954 
3955  if( !description.IsEmpty() )
3956  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
3957 
3958  if( !keyWords.IsEmpty() )
3959  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
3960 
3961  if( !docFileName.IsEmpty() )
3962  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
3963 
3964  formatter.Print( 0, "$ENDCMP\n" );
3965  }
3966 
3967  formatter.Print( 0, "#\n#End Doc Library\n" );
3968 }
#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 3690 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().

3692 {
3693  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
3694 
3695  int hjustify, vjustify;
3696  int id = aField->GetId();
3697  wxString text = aField->m_Text;
3698 
3699  hjustify = 'C';
3700 
3701  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3702  hjustify = 'L';
3703  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3704  hjustify = 'R';
3705 
3706  vjustify = 'C';
3707 
3708  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3709  vjustify = 'B';
3710  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3711  vjustify = 'T';
3712 
3713  aFormatter->Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
3714  id,
3715  EscapedUTF8( text ).c_str(), // wraps in quotes
3716  aField->GetTextPos().x, aField->GetTextPos().y, aField->GetTextWidth(),
3717  aField->GetTextAngle() == 0 ? 'H' : 'V',
3718  aField->IsVisible() ? 'V' : 'I',
3719  hjustify, vjustify,
3720  aField->IsItalic() ? 'I' : 'N',
3721  aField->IsBold() ? 'B' : 'N' );
3722 
3723  /* Save field name, if necessary
3724  * Field name is saved only if it is not the default name.
3725  * Just because default name depends on the language and can change from
3726  * a country to an other
3727  */
3728  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
3729 
3730  if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
3731  aFormatter->Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
3732 
3733  aFormatter->Print( 0, "\n" );
3734 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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 3737 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().

3739 {
3740  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
3741 
3742  int Etype;
3743 
3744  switch( aPin->GetType() )
3745  {
3746  default:
3747  case PIN_INPUT:
3748  Etype = 'I';
3749  break;
3750 
3751  case PIN_OUTPUT:
3752  Etype = 'O';
3753  break;
3754 
3755  case PIN_BIDI:
3756  Etype = 'B';
3757  break;
3758 
3759  case PIN_TRISTATE:
3760  Etype = 'T';
3761  break;
3762 
3763  case PIN_PASSIVE:
3764  Etype = 'P';
3765  break;
3766 
3767  case PIN_UNSPECIFIED:
3768  Etype = 'U';
3769  break;
3770 
3771  case PIN_POWER_IN:
3772  Etype = 'W';
3773  break;
3774 
3775  case PIN_POWER_OUT:
3776  Etype = 'w';
3777  break;
3778 
3779  case PIN_OPENCOLLECTOR:
3780  Etype = 'C';
3781  break;
3782 
3783  case PIN_OPENEMITTER:
3784  Etype = 'E';
3785  break;
3786 
3787  case PIN_NC:
3788  Etype = 'N';
3789  break;
3790  }
3791 
3792  if( !aPin->GetName().IsEmpty() )
3793  aFormatter->Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
3794  else
3795  aFormatter->Print( 0, "X ~" );
3796 
3797  aFormatter->Print( 0, " %s %d %d %d %c %d %d %d %d %c",
3798  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
3799  aPin->GetPosition().x, aPin->GetPosition().y,
3800  (int) aPin->GetLength(), (int) aPin->GetOrientation(),
3801  aPin->GetNumberTextSize(), aPin->GetNameTextSize(),
3802  aPin->GetUnit(), aPin->GetConvert(), Etype );
3803 
3804  if( aPin->GetShape() || !aPin->IsVisible() )
3805  aFormatter->Print( 0, " " );
3806 
3807  if( !aPin->IsVisible() )
3808  aFormatter->Print( 0, "N" );
3809 
3810  switch( aPin->GetShape() )
3811  {
3812  case PINSHAPE_LINE:
3813  break;
3814 
3815  case PINSHAPE_INVERTED:
3816  aFormatter->Print( 0, "I" );
3817  break;
3818 
3819  case PINSHAPE_CLOCK:
3820  aFormatter->Print( 0, "C" );
3821  break;
3822 
3824  aFormatter->Print( 0, "IC" );
3825  break;
3826 
3827  case PINSHAPE_INPUT_LOW:
3828  aFormatter->Print( 0, "L" );
3829  break;
3830 
3831  case PINSHAPE_CLOCK_LOW:
3832  aFormatter->Print( 0, "CL" );
3833  break;
3834 
3835  case PINSHAPE_OUTPUT_LOW:
3836  aFormatter->Print( 0, "V" );
3837  break;
3838 
3840  aFormatter->Print( 0, "F" );
3841  break;
3842 
3843  case PINSHAPE_NONLOGIC:
3844  aFormatter->Print( 0, "X" );
3845  break;
3846 
3847  default:
3848  assert( !"Invalid pin shape" );
3849  }
3850 
3851  aFormatter->Print( 0, "\n" );
3852 
3853  aPin->ClearFlags( IS_CHANGED );
3854 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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:123
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:283
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 3857 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().

3859 {
3860  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
3861 
3862  int ccount = aPolyLine->GetCornerCount();
3863 
3864  aFormatter->Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
3865  aPolyLine->GetWidth() );
3866 
3867  for( const auto& pt : aPolyLine->GetPolyPoints() )
3868  {
3869  aFormatter->Print( 0, " %d %d", pt.x, pt.y );
3870  }
3871 
3872  aFormatter->Print( 0, " %c\n", fill_tab[aPolyLine->GetFillMode()] );
3873 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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 3876 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().

3878 {
3879  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
3880  "Invalid LIB_RECTANGLE object." );
3881 
3882  aFormatter->Print( 0, "S %d %d %d %d %d %d %d %c\n",
3883  aRectangle->GetPosition().x, aRectangle->GetPosition().y,
3884  aRectangle->GetEnd().x, aRectangle->GetEnd().y,
3885  aRectangle->GetUnit(), aRectangle->GetConvert(),
3886  aRectangle->GetWidth(), fill_tab[aRectangle->GetFillMode()] );
3887 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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 3468 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(), 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().

3470 {
3471  wxCHECK_RET( aSymbol, "Invalid LIB_PART pointer." );
3472 
3473  LIB_FIELD& value = aSymbol->GetValueField();
3474 
3475  // First line: it s a comment (component name for readers)
3476  aFormatter->Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3477 
3478  // Save data
3479  aFormatter->Print( 0, "DEF" );
3480 
3481  if( value.IsVisible() )
3482  {
3483  aFormatter->Print( 0, " %s", TO_UTF8( value.GetText() ) );
3484  }
3485  else
3486  {
3487  aFormatter->Print( 0, " ~%s", TO_UTF8( value.GetText() ) );
3488  }
3489 
3490  LIB_FIELD& reference = aSymbol->GetReferenceField();
3491 
3492  if( !reference.GetText().IsEmpty() )
3493  {
3494  aFormatter->Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3495  }
3496  else
3497  {
3498  aFormatter->Print( 0, " ~" );
3499  }
3500 
3501  aFormatter->Print( 0, " %d %d %c %c %d %c %c\n",
3502  0, aSymbol->GetPinNameOffset(),
3503  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3504  aSymbol->ShowPinNames() ? 'Y' : 'N',
3505  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3506  aSymbol->IsPower() ? 'P' : 'N' );
3507 
3508  timestamp_t dateModified = aSymbol->GetDateLastEdition();
3509 
3510  if( dateModified != 0 )
3511  {
3512  int sec = dateModified & 63;
3513  int min = ( dateModified >> 6 ) & 63;
3514  int hour = ( dateModified >> 12 ) & 31;
3515  int day = ( dateModified >> 17 ) & 31;
3516  int mon = ( dateModified >> 22 ) & 15;
3517  int year = ( dateModified >> 26 ) + 1990;
3518 
3519  aFormatter->Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3520  }
3521 
3522  LIB_FIELDS fields;
3523  aSymbol->GetFields( fields );
3524 
3525  // Mandatory fields:
3526  // may have their own save policy so there is a separate loop for them.
3527  // Empty fields are saved, because the user may have set visibility,
3528  // size and orientation
3529  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3530  {
3531  saveField( &fields[i], aFormatter );
3532  }
3533 
3534  // User defined fields:
3535  // may have their own save policy so there is a separate loop for them.
3536 
3537  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3538 
3539  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3540  {
3541  // There is no need to save empty fields, i.e. no reason to preserve field
3542  // names now that fields names come in dynamically through the template
3543  // fieldnames.
3544  if( !fields[i].GetText().IsEmpty() )
3545  {
3546  fields[i].SetId( fieldId++ );
3547  saveField( &fields[i], aFormatter );
3548  }
3549  }
3550 
3551  // Save the alias list: a line starting by "ALIAS". The first alias is the root
3552  // and has the same name as the component. In the old library file format this
3553  // alias does not get added to the alias list.
3554  if( aSymbol->GetAliasCount() > 1 )
3555  {
3556  wxArrayString aliases = aSymbol->GetAliasNames();
3557 
3558  aFormatter->Print( 0, "ALIAS" );
3559 
3560  for( unsigned i = 1; i < aliases.size(); i++ )
3561  {
3562  aFormatter->Print( 0, " %s", TO_UTF8( aliases[i] ) );
3563  }
3564 
3565  aFormatter->Print( 0, "\n" );
3566  }
3567 
3568  wxArrayString footprints = aSymbol->GetFootprints();
3569 
3570  // Write the footprint filter list
3571  if( footprints.GetCount() != 0 )
3572  {
3573  aFormatter->Print( 0, "$FPLIST\n" );
3574 
3575  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3576  {
3577  aFormatter->Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3578  }
3579 
3580  aFormatter->Print( 0, "$ENDFPLIST\n" );
3581  }
3582 
3583  // Save graphics items (including pins)
3584  if( !aSymbol->GetDrawItems().empty() )
3585  {
3586  // Sort the draw items in order to editing a file editing by hand.
3587  aSymbol->GetDrawItems().sort();
3588 
3589  aFormatter->Print( 0, "DRAW\n" );
3590 
3591  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3592  {
3593  switch( item.Type() )
3594  {
3595  case LIB_FIELD_T: // Fields have already been saved above.
3596  continue;
3597 
3598  case LIB_ARC_T:
3599  saveArc( (LIB_ARC*) &item, aFormatter );
3600  break;
3601 
3602  case LIB_BEZIER_T:
3603  saveBezier( (LIB_BEZIER*) &item, aFormatter );
3604  break;
3605 
3606 
3607  case LIB_CIRCLE_T:
3608  saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
3609  break;
3610 
3611  case LIB_PIN_T:
3612  savePin( (LIB_PIN* ) &item, aFormatter );
3613  break;
3614 
3615  case LIB_POLYLINE_T:
3616  savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
3617  break;
3618 
3619  case LIB_RECTANGLE_T:
3620  saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
3621  break;
3622 
3623  case LIB_TEXT_T:
3624  saveText( ( LIB_TEXT* ) &item, aFormatter );
3625  break;
3626 
3627  default:
3628  ;
3629  }
3630  }
3631 
3632  aFormatter->Print( 0, "ENDDRAW\n" );
3633  }
3634 
3635  aFormatter->Print( 0, "ENDDEF\n" );
3636 }
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:173
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
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 3890 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().

3892 {
3893  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
3894 
3895  wxString text = aText->GetText();
3896 
3897  if( text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
3898  {
3899  // convert double quote to similar-looking two apostrophes
3900  text.Replace( wxT( "\"" ), wxT( "''" ) );
3901  text = wxT( "\"" ) + text + wxT( "\"" );
3902  }
3903  else
3904  {
3905  // Spaces are not allowed in text because it is not double quoted:
3906  // changed to '~'
3907  text.Replace( wxT( " " ), wxT( "~" ) );
3908  }
3909 
3910  aFormatter->Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
3911  aText->GetTextPos().x, aText->GetTextPos().y,
3912  aText->GetTextWidth(), !aText->IsVisible(),
3913  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
3914 
3915  aFormatter->Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
3916 
3917  char hjustify = 'C';
3918 
3919  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3920  hjustify = 'L';
3921  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3922  hjustify = 'R';
3923 
3924  char vjustify = 'C';
3925 
3926  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3927  vjustify = 'B';
3928  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3929  vjustify = 'T';
3930 
3931  aFormatter->Print( 0, " %c %c\n", hjustify, vjustify );
3932 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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 557 of file sch_legacy_plugin.cpp.

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

Definition at line 553 of file sch_legacy_plugin.cpp.

553 { m_isModified = aModified; }

Member Data Documentation

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

Definition at line 476 of file sch_legacy_plugin.cpp.

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

wxString SCH_LEGACY_PLUGIN_CACHE::m_fileName
private

Definition at line 474 of file sch_legacy_plugin.cpp.

Referenced by IsFile().

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 479 of file sch_legacy_plugin.cpp.

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

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

Definition at line 478 of file sch_legacy_plugin.cpp.

Referenced by GetLibModificationTime().

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

Definition at line 482 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 480 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 481 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 524 of file sch_legacy_plugin.cpp.


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