KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN_CACHE Class Reference

A cache assistant for the symbol 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 ()
 
void Save (bool aSaveDocFile=true)
 Save the entire library to file m_libFileName;. More...
 
void Load ()
 
void AddSymbol (const LIB_SYMBOL *aSymbol)
 
void DeleteSymbol (const wxString &aName)
 
wxFileName GetRealFile () const
 
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
 

Static Public Member Functions

static void IncrementModifyHash ()
 
static int GetModifyHash ()
 
static LIB_SYMBOLLoadPart (LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_SYMBOL_MAP *aMap=nullptr)
 
static void SaveSymbol (LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_SYMBOL_MAP *aMap=nullptr)
 

Private Member Functions

void loadHeader (FILE_LINE_READER &aReader)
 
void loadDocs ()
 
LIB_SYMBOLremoveSymbol (LIB_SYMBOL *aAlias)
 
void saveDocFile ()
 

Static Private Member Functions

static void loadAliases (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader, LIB_SYMBOL_MAP *aMap=nullptr)
 
static void loadField (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
 
static void loadDrawEntries (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
 
static void loadFootprintFilters (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
 
static LIB_SHAPEloadArc (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
 
static LIB_SHAPEloadCircle (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
 
static LIB_TEXTloadText (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
 
static LIB_SHAPEloadRect (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
 
static LIB_PINloadPin (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
 
static LIB_SHAPEloadPolyLine (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
 
static LIB_SHAPEloadBezier (std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
 
static FILL_T parseFillMode (LINE_READER &aReader, const char *aLine, const char **aOutput)
 

Private Attributes

wxString m_fileName
 
wxFileName m_libFileName
 
wxDateTime m_fileModTime
 
LIB_SYMBOL_MAP m_symbols
 
bool m_isWritable
 
bool m_isModified
 
int m_versionMajor
 
int m_versionMinor
 
SCH_LIB_TYPE m_libType
 
friend SCH_LEGACY_PLUGIN
 

Static Private Attributes

static int s_modHash = 1
 
static std::mutex s_modHashMutex
 

Detailed Description

A cache assistant for the symbol 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 468 of file sch_legacy_plugin.cpp.

Constructor & Destructor Documentation

◆ SCH_LEGACY_PLUGIN_CACHE()

SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN_CACHE ( const wxString &  aLibraryPath)

Definition at line 2445 of file sch_legacy_plugin.cpp.

2445  :
2446  m_fileName( aFullPathAndFileName ),
2447  m_libFileName( aFullPathAndFileName ),
2448  m_isWritable( true ),
2449  m_isModified( false )
2450 {
2451  m_versionMajor = -1;
2452  m_versionMinor = -1;
2454 }

References LT_EESCHEMA, m_libType, m_versionMajor, and m_versionMinor.

◆ ~SCH_LEGACY_PLUGIN_CACHE()

SCH_LEGACY_PLUGIN_CACHE::~SCH_LEGACY_PLUGIN_CACHE ( )

Definition at line 2457 of file sch_legacy_plugin.cpp.

2458 {
2459  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2460  for( auto& symbol : m_symbols )
2461  delete symbol.second;
2462 
2463  m_symbols.clear();
2464 }

References m_symbols.

Member Function Documentation

◆ AddSymbol()

void SCH_LEGACY_PLUGIN_CACHE::AddSymbol ( const LIB_SYMBOL aSymbol)

Definition at line 2570 of file sch_legacy_plugin.cpp.

2571 {
2572  // aSymbol is cloned in SYMBOL_LIB::AddSymbol(). The cache takes ownership of aSymbol.
2573  wxString name = aSymbol->GetName();
2574  LIB_SYMBOL_MAP::iterator it = m_symbols.find( name );
2575 
2576  if( it != m_symbols.end() )
2577  {
2578  removeSymbol( it->second );
2579  }
2580 
2581  m_symbols[ name ] = const_cast< LIB_SYMBOL* >( aSymbol );
2582  m_isModified = true;
2584 }
wxString GetName() const override
Definition: lib_symbol.h:133
const char * name
Definition: DXF_plotter.cpp:56
LIB_SYMBOL * removeSymbol(LIB_SYMBOL *aAlias)

References LIB_SYMBOL::GetName(), IncrementModifyHash(), m_isModified, m_symbols, name, and removeSymbol().

Referenced by SCH_LEGACY_PLUGIN::SaveSymbol().

◆ DeleteSymbol()

void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol ( const wxString &  aName)

Definition at line 3829 of file sch_legacy_plugin.cpp.

3830 {
3831  LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbolName );
3832 
3833  if( it == m_symbols.end() )
3834  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
3835  m_libFileName.GetFullName(), aSymbolName ) );
3836 
3837  LIB_SYMBOL* symbol = it->second;
3838 
3839  if( symbol->IsRoot() )
3840  {
3841  LIB_SYMBOL* rootSymbol = symbol;
3842 
3843  // Remove the root symbol and all its children.
3844  m_symbols.erase( it );
3845 
3846  LIB_SYMBOL_MAP::iterator it1 = m_symbols.begin();
3847 
3848  while( it1 != m_symbols.end() )
3849  {
3850  if( it1->second->IsAlias()
3851  && it1->second->GetParent().lock() == rootSymbol->SharedPtr() )
3852  {
3853  delete it1->second;
3854  it1 = m_symbols.erase( it1 );
3855  }
3856  else
3857  {
3858  it1++;
3859  }
3860  }
3861 
3862  delete rootSymbol;
3863  }
3864  else
3865  {
3866  // Just remove the alias.
3867  m_symbols.erase( it );
3868  delete symbol;
3869  }
3870 
3872  m_isModified = true;
3873 }
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:107
Define a library symbol object.
Definition: lib_symbol.h:96
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:171
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), IncrementModifyHash(), LIB_SYMBOL::IsRoot(), m_isModified, m_libFileName, m_symbols, LIB_SYMBOL::SharedPtr(), and THROW_IO_ERROR.

Referenced by SCH_LEGACY_PLUGIN::DeleteSymbol().

◆ GetFileName()

wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( void  ) const
inline

Definition at line 552 of file sch_legacy_plugin.cpp.

552 { return m_libFileName.GetFullPath(); }

References m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

◆ GetLibModificationTime()

wxDateTime SCH_LEGACY_PLUGIN_CACHE::GetLibModificationTime ( )

Definition at line 2476 of file sch_legacy_plugin.cpp.

2477 {
2478  wxFileName fn = GetRealFile();
2479 
2480  // update the writable flag while we have a wxFileName, in a network this
2481  // is possibly quite dynamic anyway.
2482  m_isWritable = fn.IsFileWritable();
2483 
2484  return fn.GetModificationTime();
2485 }
wxFileName GetRealFile() const

References GetRealFile(), and m_isWritable.

Referenced by Load().

◆ GetLogicalName()

wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 548 of file sch_legacy_plugin.cpp.

548 { return m_libFileName.GetName(); }

References m_libFileName.

◆ GetModifyHash()

static int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( )
inlinestatic

Definition at line 518 of file sch_legacy_plugin.cpp.

519  {
520  std::lock_guard<std::mutex> mut( SCH_LEGACY_PLUGIN_CACHE::s_modHashMutex );
522  }
static std::mutex s_modHashMutex

References s_modHash, and s_modHashMutex.

Referenced by SCH_LEGACY_PLUGIN::GetModifyHash().

◆ GetRealFile()

wxFileName SCH_LEGACY_PLUGIN_CACHE::GetRealFile ( ) const

Definition at line 2468 of file sch_legacy_plugin.cpp.

2469 {
2470  wxFileName fn( m_libFileName );
2472  return fn;
2473 }
static void ResolvePossibleSymlinks(wxFileName &aFilename)
Definition: wx_filename.cpp:85

References m_libFileName, and WX_FILENAME::ResolvePossibleSymlinks().

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

◆ IncrementModifyHash()

static void SCH_LEGACY_PLUGIN_CACHE::IncrementModifyHash ( )
inlinestatic

Definition at line 512 of file sch_legacy_plugin.cpp.

513  {
514  std::lock_guard<std::mutex> mut( SCH_LEGACY_PLUGIN_CACHE::s_modHashMutex );
516  }
static std::mutex s_modHashMutex

References s_modHash, and s_modHashMutex.

Referenced by AddSymbol(), DeleteSymbol(), Load(), and removeSymbol().

◆ IsFile()

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

Definition at line 2488 of file sch_legacy_plugin.cpp.

2489 {
2490  return m_fileName == aFullPathAndFileName;
2491 }

References m_fileName.

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

◆ IsFileChanged()

bool SCH_LEGACY_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 2494 of file sch_legacy_plugin.cpp.

2495 {
2496  wxFileName fn = GetRealFile();
2497 
2498  if( m_fileModTime.IsValid() && fn.IsOk() && fn.FileExists() )
2499  return fn.GetModificationTime() != m_fileModTime;
2500 
2501  return false;
2502 }
wxFileName GetRealFile() const

References GetRealFile(), and m_fileModTime.

Referenced by SCH_LEGACY_PLUGIN::cacheLib().

◆ Load()

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

2588 {
2589  if( !m_libFileName.FileExists() )
2590  {
2591  THROW_IO_ERROR( wxString::Format( _( "Library file '%s' not found." ),
2592  m_libFileName.GetFullPath() ) );
2593  }
2594 
2595  wxCHECK_RET( m_libFileName.IsAbsolute(),
2596  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2597  "open library '%s'.", m_libFileName.GetFullPath() ) );
2598 
2599  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file '%s'",
2600  m_libFileName.GetFullPath() );
2601 
2602  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2603 
2604  if( !reader.ReadLine() )
2605  THROW_IO_ERROR( _( "Unexpected end of file." ) );
2606 
2607  const char* line = reader.Line();
2608 
2609  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2610  {
2611  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2612  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2613  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2614  SCH_PARSE_ERROR( "file is not a valid symbol or symbol library file", reader, line );
2615  }
2616 
2617  m_versionMajor = parseInt( reader, line, &line );
2618 
2619  if( *line != '.' )
2620  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2621 
2622  line++;
2623 
2624  m_versionMinor = parseInt( reader, line, &line );
2625 
2626  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2627  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2628 
2629  // Check if this is a symbol library which is the same as a symbol library but without
2630  // any alias, documentation, footprint filters, etc.
2631  if( strCompare( "SYMBOL", line, &line ) )
2632  {
2633  // Symbol files add date and time stamp info to the header.
2635 
2637  }
2638  else
2639  {
2641  }
2642 
2643  while( reader.ReadLine() )
2644  {
2645  line = reader.Line();
2646 
2647  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2648  continue;
2649 
2650  // Headers where only supported in older library file formats.
2651  if( m_libType == SCH_LIB_TYPE::LT_EESCHEMA && strCompare( "$HEADER", line ) )
2652  loadHeader( reader );
2653 
2654  if( strCompare( "DEF", line ) )
2655  {
2656  // Read one DEF/ENDDEF symbol entry from library:
2657  LIB_SYMBOL* symbol = LoadPart( reader, m_versionMajor, m_versionMinor, &m_symbols );
2658 
2659  m_symbols[ symbol->GetName() ] = symbol;
2660  }
2661  }
2662 
2664 
2665  // Remember the file modification time of library file when the
2666  // cache snapshot was made, so that in a networked environment we will
2667  // reload the cache as needed.
2669 
2671  loadDocs();
2672 }
static LIB_SYMBOL * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_SYMBOL_MAP *aMap=nullptr)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
wxString GetName() const override
Definition: lib_symbol.h:133
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
void loadHeader(FILE_LINE_READER &aReader)
Define a library symbol object.
Definition: lib_symbol.h:96
A LINE_READER that reads from an open file.
Definition: richio.h:172
#define _(s)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define USE_OLD_DOC_FILE_FORMAT(major, minor)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define SCH_PARSE_ERROR(text, reader, pos)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), GetLibModificationTime(), LIB_SYMBOL::GetName(), IncrementModifyHash(), loadDocs(), loadHeader(), LoadPart(), LT_EESCHEMA, LT_SYMBOL, m_fileModTime, m_libFileName, m_libType, m_symbols, m_versionMajor, m_versionMinor, parseInt(), SCH_PARSE_ERROR, strCompare(), THROW_IO_ERROR, traceSchLegacyPlugin, and USE_OLD_DOC_FILE_FORMAT.

Referenced by SCH_LEGACY_PLUGIN::cacheLib(), and SCH_LEGACY_PLUGIN::CreateSymbolLib().

◆ loadAliases()

void SCH_LEGACY_PLUGIN_CACHE::loadAliases ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader,
LIB_SYMBOL_MAP aMap = nullptr 
)
staticprivate

Definition at line 2973 of file sch_legacy_plugin.cpp.

2976 {
2977  wxString newAliasName;
2978  const char* line = aReader.Line();
2979 
2980  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2981 
2982  wxString utf8Line = wxString::FromUTF8( line );
2983  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2984 
2985  // Parse the ALIAS list.
2986  while( tokens.HasMoreTokens() )
2987  {
2988  newAliasName = tokens.GetNextToken();
2989 
2990  if( aMap )
2991  {
2992  LIB_SYMBOL* newSymbol = new LIB_SYMBOL( newAliasName );
2993 
2994  // Inherit the parent mandatory field attributes.
2995  for( int id = 0; id < MANDATORY_FIELDS; ++id )
2996  {
2997  LIB_FIELD* field = newSymbol->GetFieldById( id );
2998 
2999  // the MANDATORY_FIELDS are exactly that in RAM.
3000  wxASSERT( field );
3001 
3002  LIB_FIELD* parentField = aSymbol->GetFieldById( id );
3003 
3004  wxASSERT( parentField );
3005 
3006  *field = *parentField;
3007 
3008  if( id == VALUE_FIELD )
3009  field->SetText( newAliasName );
3010 
3011  field->SetParent( newSymbol );
3012  }
3013 
3014  newSymbol->SetParent( aSymbol.get() );
3015 
3016  // This will prevent duplicate aliases.
3017  (*aMap)[ newSymbol->GetName() ] = newSymbol;
3018  }
3019  }
3020 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
wxString GetName() const override
Definition: lib_symbol.h:133
Field object used in symbol libraries.
Definition: lib_field.h:59
Define a library symbol object.
Definition: lib_symbol.h:96
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
void SetParent(LIB_SYMBOL *aParent=nullptr)
Definition: lib_symbol.cpp:322
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
LIB_FIELD * GetFieldById(int aId) const
Return pointer to the requested field.
Definition: lib_symbol.cpp:963

References LIB_SYMBOL::GetFieldById(), LIB_SYMBOL::GetName(), LINE_READER::Line(), MANDATORY_FIELDS, EDA_ITEM::SetParent(), LIB_SYMBOL::SetParent(), EDA_TEXT::SetText(), strCompare(), and VALUE_FIELD.

Referenced by LoadPart().

◆ loadArc()

LIB_SHAPE * SCH_LEGACY_PLUGIN_CACHE::loadArc ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader 
)
staticprivate

This accounts for an oddity in the old library format, where the symbol is overdefined. The previous draw (based on wxwidgets) used start point and end point and always drew counter-clockwise. The new GAL draw takes center, radius and start/end angles. All of these points were stored in the file, so we need to mimic the swapping of start/end points rather than using the stored angles in order to properly map edge cases.

Definition at line 3252 of file sch_legacy_plugin.cpp.

3254 {
3255  const char* line = aReader.Line();
3256 
3257  wxCHECK_MSG( strCompare( "A", line, &line ), nullptr, "Invalid arc definition" );
3258 
3259  LIB_SHAPE* arc = new LIB_SHAPE( aSymbol.get(), SHAPE_T::ARC );
3260 
3261  wxPoint center;
3262 
3263  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3264  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3265 
3266  arc->SetPosition( center );
3267 
3268  int radius = Mils2Iu( parseInt( aReader, line, &line ) );
3269  int angle1 = parseInt( aReader, line, &line );
3270  int angle2 = parseInt( aReader, line, &line );
3271 
3272  NORMALIZE_ANGLE_POS( angle1 );
3273  NORMALIZE_ANGLE_POS( angle2 );
3274 
3275  arc->SetUnit( parseInt( aReader, line, &line ) );
3276  arc->SetConvert( parseInt( aReader, line, &line ) );
3277  arc->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3278 
3279  // Old libraries (version <= 2.2) do not have always this FILL MODE param
3280  // when fill mode is no fill (default mode).
3281  if( *line != 0 )
3282  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
3283 
3284  // Actual Coordinates of arc ends are read from file
3285  if( *line != 0 )
3286  {
3287  wxPoint arcStart, arcEnd;
3288 
3289  arcStart.x = Mils2Iu( parseInt( aReader, line, &line ) );
3290  arcStart.y = Mils2Iu( parseInt( aReader, line, &line ) );
3291  arcEnd.x = Mils2Iu( parseInt( aReader, line, &line ) );
3292  arcEnd.y = Mils2Iu( parseInt( aReader, line, &line ) );
3293 
3294  arc->SetStart( arcStart );
3295  arc->SetEnd( arcEnd );
3296  }
3297  else
3298  {
3299  // Actual Coordinates of arc ends are not read from file
3300  // (old library), calculate them
3301  wxPoint arcStart( radius, 0 );
3302  wxPoint arcEnd( radius, 0 );
3303 
3304  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
3305  arcStart += arc->GetCenter();
3306  arc->SetStart( arcStart );
3307  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
3308  arcEnd += arc->GetCenter();
3309  arc->SetEnd( arcEnd );
3310  }
3311 
3319  if( !TRANSFORM().MapAngles( &angle1, &angle2 ) )
3320  {
3321  wxPoint temp = arc->GetStart();
3322  arc->SetStart( arc->GetEnd() );
3323  arc->SetEnd( temp );
3324  }
3325 
3326  return arc;
3327 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:126
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:97
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:290
#define Mils2Iu(x)
void SetStart(const wxPoint &aStart)
Definition: eda_shape.h:101
void SetPosition(const wxPoint &aPosition) override
Definition: lib_shape.h:87
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:122
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetWidth(int aWidth)
Definition: eda_shape.h:88
wxPoint GetCenter() const
Definition: lib_shape.h:89
void SetConvert(int aConvert)
Definition: lib_item.h:260
void SetUnit(int aUnit)
Definition: lib_item.h:257
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:78

References ARC, LIB_SHAPE::GetCenter(), EDA_SHAPE::GetEnd(), EDA_SHAPE::GetStart(), LINE_READER::Line(), Mils2Iu, NORMALIZE_ANGLE_POS(), parseFillMode(), parseInt(), RotatePoint(), LIB_ITEM::SetConvert(), EDA_SHAPE::SetEnd(), EDA_SHAPE::SetFillMode(), LIB_SHAPE::SetPosition(), EDA_SHAPE::SetStart(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

◆ loadBezier()

LIB_SHAPE * SCH_LEGACY_PLUGIN_CACHE::loadBezier ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader 
)
staticprivate

Definition at line 3717 of file sch_legacy_plugin.cpp.

3719 {
3720  const char* line = aReader.Line();
3721 
3722  wxCHECK_MSG( strCompare( "B", line, &line ), nullptr, "Invalid Bezier definition" );
3723 
3724  int points = parseInt( aReader, line, &line );
3725 
3726  wxCHECK_MSG( points == 4, NULL, "Invalid Bezier curve definition" );
3727 
3728  LIB_SHAPE* bezier = new LIB_SHAPE( aSymbol.get(), SHAPE_T::BEZIER );
3729 
3730  bezier->SetUnit( parseInt( aReader, line, &line ) );
3731  bezier->SetConvert( parseInt( aReader, line, &line ) );
3732  bezier->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3733 
3734  bezier->SetStart( wxPoint( Mils2Iu( parseInt( aReader, line, &line ) ),
3735  Mils2Iu( parseInt( aReader, line, &line ) ) ) );
3736 
3737  bezier->SetBezierC1( wxPoint( Mils2Iu( parseInt( aReader, line, &line ) ),
3738  Mils2Iu( parseInt( aReader, line, &line ) ) ) );
3739 
3740  bezier->SetBezierC2( wxPoint( Mils2Iu( parseInt( aReader, line, &line ) ),
3741  Mils2Iu( parseInt( aReader, line, &line ) ) ) );
3742 
3743  bezier->SetEnd( wxPoint( Mils2Iu( parseInt( aReader, line, &line ) ),
3744  Mils2Iu( parseInt( aReader, line, &line ) ) ) );
3745 
3746  bezier->RebuildBezierToSegmentsPointsList( bezier->GetWidth() );
3747 
3748  if( *line != 0 )
3749  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3750 
3751  return bezier;
3752 }
int GetWidth() const
Definition: eda_shape.h:89
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:126
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define Mils2Iu(x)
void SetBezierC1(const wxPoint &aPt)
Definition: eda_shape.h:144
void SetStart(const wxPoint &aStart)
Definition: eda_shape.h:101
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetWidth(int aWidth)
Definition: eda_shape.h:88
void SetConvert(int aConvert)
Definition: lib_item.h:260
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_BezierPoints vertex list that approximate the Bezier curve by a list of segments.
Definition: eda_shape.cpp:365
void SetUnit(int aUnit)
Definition: lib_item.h:257
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetBezierC2(const wxPoint &aPt)
Definition: eda_shape.h:147
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:78

References BEZIER, EDA_SHAPE::GetWidth(), LINE_READER::Line(), Mils2Iu, parseFillMode(), parseInt(), EDA_SHAPE::RebuildBezierToSegmentsPointsList(), EDA_SHAPE::SetBezierC1(), EDA_SHAPE::SetBezierC2(), LIB_ITEM::SetConvert(), EDA_SHAPE::SetEnd(), EDA_SHAPE::SetFillMode(), EDA_SHAPE::SetStart(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

◆ loadCircle()

LIB_SHAPE * SCH_LEGACY_PLUGIN_CACHE::loadCircle ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader 
)
staticprivate

Definition at line 3330 of file sch_legacy_plugin.cpp.

3332 {
3333  const char* line = aReader.Line();
3334 
3335  wxCHECK_MSG( strCompare( "C", line, &line ), nullptr, "Invalid circle definition" );
3336 
3337  LIB_SHAPE* circle = new LIB_SHAPE( aSymbol.get(), SHAPE_T::CIRCLE );
3338 
3339  wxPoint center;
3340 
3341  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3342  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3343 
3344  int radius = Mils2Iu( parseInt( aReader, line, &line ) );
3345 
3346  circle->SetStart( center );
3347  circle->SetEnd( wxPoint( center.x + radius, center.y ) );
3348  circle->SetUnit( parseInt( aReader, line, &line ) );
3349  circle->SetConvert( parseInt( aReader, line, &line ) );
3350  circle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3351 
3352  if( *line != 0 )
3353  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3354 
3355  return circle;
3356 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:126
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define Mils2Iu(x)
void SetStart(const wxPoint &aStart)
Definition: eda_shape.h:101
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetWidth(int aWidth)
Definition: eda_shape.h:88
void SetConvert(int aConvert)
Definition: lib_item.h:260
void SetUnit(int aUnit)
Definition: lib_item.h:257
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:78

References CIRCLE, LINE_READER::Line(), Mils2Iu, parseFillMode(), parseInt(), LIB_ITEM::SetConvert(), EDA_SHAPE::SetEnd(), EDA_SHAPE::SetFillMode(), EDA_SHAPE::SetStart(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

◆ loadDocs()

void SCH_LEGACY_PLUGIN_CACHE::loadDocs ( )
private

Definition at line 2675 of file sch_legacy_plugin.cpp.

2676 {
2677  const char* line;
2678  wxString text;
2679  wxString aliasName;
2680  wxFileName fn = m_libFileName;
2681  LIB_SYMBOL* symbol = nullptr;;
2682 
2683  fn.SetExt( DOC_EXT );
2684 
2685  // Not all libraries will have a document file.
2686  if( !fn.FileExists() )
2687  return;
2688 
2689  if( !fn.IsFileReadable() )
2690  {
2691  THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to read library '%s'." ),
2692  fn.GetFullPath() ) );
2693  }
2694 
2695  FILE_LINE_READER reader( fn.GetFullPath() );
2696 
2697  line = reader.ReadLine();
2698 
2699  if( !line )
2700  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2701 
2702  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2703  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2704  reader, line );
2705 
2706  while( reader.ReadLine() )
2707  {
2708  line = reader.Line();
2709 
2710  if( *line == '#' ) // Comment line.
2711  continue;
2712 
2713  if( !strCompare( "$CMP", line, &line ) != 0 )
2714  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2715 
2716  aliasName = wxString::FromUTF8( line );
2717  aliasName.Trim();
2718  // aliasName = EscapeString( aliasName, CTX_LIBID );
2719 
2720  LIB_SYMBOL_MAP::iterator it = m_symbols.find( aliasName );
2721 
2722  if( it == m_symbols.end() )
2723  wxLogWarning( "Symbol '%s' not found in library:\n\n"
2724  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2725  reader.LineNumber(), (int) (line - reader.Line() ) );
2726  else
2727  symbol = it->second;
2728 
2729  // Read the current alias associated doc.
2730  // if the alias does not exist, just skip the description
2731  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2732  while( reader.ReadLine() )
2733  {
2734  line = reader.Line();
2735 
2736  if( !line )
2737  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2738 
2739  if( strCompare( "$ENDCMP", line, &line ) )
2740  break;
2741 
2742  text = FROM_UTF8( line + 2 );
2743  // Remove spaces at eol, and eol chars:
2744  text = text.Trim();
2745 
2746  switch( line[0] )
2747  {
2748  case 'D':
2749  if( symbol )
2750  symbol->SetDescription( text );
2751  break;
2752 
2753  case 'K':
2754  if( symbol )
2755  symbol->SetKeyWords( text );
2756  break;
2757 
2758  case 'F':
2759  if( symbol )
2760  symbol->GetFieldById( DATASHEET_FIELD )->SetText( text );
2761  break;
2762 
2763  case 0:
2764  case '\n':
2765  case '\r':
2766  case '#':
2767  // Empty line or commment
2768  break;
2769 
2770  default:
2771  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2772  }
2773  }
2774  }
2775 }
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:214
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
Define a library symbol object.
Definition: lib_symbol.h:96
name of datasheet
#define DOC_EXT
A LINE_READER that reads from an open file.
Definition: richio.h:172
#define DOCFILE_IDENT
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
void SetDescription(const wxString &aDescription)
Definition: lib_symbol.h:140
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
LIB_FIELD * GetFieldById(int aId) const
Return pointer to the requested field.
Definition: lib_symbol.cpp:963
#define SCH_PARSE_ERROR(text, reader, pos)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SetKeyWords(const wxString &aKeyWords)
Definition: lib_symbol.h:153

References _, DATASHEET_FIELD, DOC_EXT, DOCFILE_IDENT, Format(), FROM_UTF8(), LIB_SYMBOL::GetFieldById(), m_libFileName, m_symbols, FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_SYMBOL::SetDescription(), LIB_SYMBOL::SetKeyWords(), EDA_TEXT::SetText(), strCompare(), text, and THROW_IO_ERROR.

Referenced by Load().

◆ loadDrawEntries()

void SCH_LEGACY_PLUGIN_CACHE::loadDrawEntries ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader,
int  aMajorVersion,
int  aMinorVersion 
)
staticprivate

Definition at line 3169 of file sch_legacy_plugin.cpp.

3173 {
3174  const char* line = aReader.Line();
3175 
3176  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
3177 
3178  line = aReader.ReadLine();
3179 
3180  while( line )
3181  {
3182  if( strCompare( "ENDDRAW", line, &line ) )
3183  {
3184  aSymbol->GetDrawItems().sort();
3185  return;
3186  }
3187 
3188  switch( line[0] )
3189  {
3190  case 'A': // Arc
3191  aSymbol->AddDrawItem( loadArc( aSymbol, aReader ), false );
3192  break;
3193 
3194  case 'C': // Circle
3195  aSymbol->AddDrawItem( loadCircle( aSymbol, aReader ), false );
3196  break;
3197 
3198  case 'T': // Text
3199  aSymbol->AddDrawItem( loadText( aSymbol, aReader, aMajorVersion,
3200  aMinorVersion ), false );
3201  break;
3202 
3203  case 'S': // Square
3204  aSymbol->AddDrawItem( loadRect( aSymbol, aReader ), false );
3205  break;
3206 
3207  case 'X': // Pin Description
3208  aSymbol->AddDrawItem( loadPin( aSymbol, aReader ), false );
3209  break;
3210 
3211  case 'P': // Polyline
3212  aSymbol->AddDrawItem( loadPolyLine( aSymbol, aReader ), false );
3213  break;
3214 
3215  case 'B': // Bezier Curves
3216  aSymbol->AddDrawItem( loadBezier( aSymbol, aReader ), false );
3217  break;
3218 
3219  case '#': // Comment
3220  case '\n': // Empty line
3221  case '\r':
3222  case 0:
3223  break;
3224 
3225  default:
3226  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
3227  }
3228 
3229  line = aReader.ReadLine();
3230  }
3231 
3232  SCH_PARSE_ERROR( "File ended prematurely loading symbol draw element.", aReader, line );
3233 }
static LIB_TEXT * loadText(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static LIB_PIN * loadPin(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
static LIB_SHAPE * loadPolyLine(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
static LIB_SHAPE * loadCircle(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static LIB_SHAPE * loadRect(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
static LIB_SHAPE * loadArc(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
static LIB_SHAPE * loadBezier(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)

References LINE_READER::Line(), loadArc(), loadBezier(), loadCircle(), loadPin(), loadPolyLine(), loadRect(), loadText(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by LoadPart().

◆ loadField()

void SCH_LEGACY_PLUGIN_CACHE::loadField ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader 
)
staticprivate

Definition at line 3023 of file sch_legacy_plugin.cpp.

3025 {
3026  const char* line = aReader.Line();
3027 
3028  wxCHECK_RET( *line == 'F', "Invalid field line" );
3029 
3030  wxString text;
3031  int id;
3032 
3033  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
3034  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
3035 
3036  LIB_FIELD* field;
3037 
3038  if( id >= 0 && id < MANDATORY_FIELDS )
3039  {
3040  field = aSymbol->GetFieldById( id );
3041 
3042  // this will fire only if somebody broke a constructor or editor.
3043  // MANDATORY_FIELDS are always present in ram resident symbols, no
3044  // exceptions, and they always have their names set, even fixed fields.
3045  wxASSERT( field );
3046  }
3047  else
3048  {
3049  field = new LIB_FIELD( aSymbol.get(), id );
3050  aSymbol->AddDrawItem( field, false );
3051  }
3052 
3053  // Skip to the first double quote.
3054  while( *line != '"' && *line != 0 )
3055  line++;
3056 
3057  if( *line == 0 )
3058  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
3059 
3060  parseQuotedString( text, aReader, line, &line, true );
3061 
3062  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
3063  // not save like this.
3064  if( text.size() == 1 && text[0] == '~' )
3065  field->SetText( wxEmptyString );
3066  else
3068 
3069  wxPoint pos;
3070 
3071  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
3072  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
3073  field->SetPosition( pos );
3074 
3075  wxSize textSize;
3076 
3077  textSize.x = textSize.y = Mils2Iu( parseInt( aReader, line, &line ) );
3078  field->SetTextSize( textSize );
3079 
3080  char textOrient = parseChar( aReader, line, &line );
3081 
3082  if( textOrient == 'H' )
3083  field->SetTextAngle( TEXT_ANGLE_HORIZ );
3084  else if( textOrient == 'V' )
3085  field->SetTextAngle( TEXT_ANGLE_VERT );
3086  else
3087  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
3088 
3089  char textVisible = parseChar( aReader, line, &line );
3090 
3091  if( textVisible == 'V' )
3092  field->SetVisible( true );
3093  else if ( textVisible == 'I' )
3094  field->SetVisible( false );
3095  else
3096  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
3097 
3098  // It may be technically correct to use the library version to determine if the field text
3099  // attributes are present. If anyone knows if that is valid and what version that would be,
3100  // please change this to test the library version rather than an EOL or the quoted string
3101  // of the field name.
3102  if( *line != 0 && *line != '"' )
3103  {
3104  char textHJustify = parseChar( aReader, line, &line );
3105 
3106  if( textHJustify == 'C' )
3108  else if( textHJustify == 'L' )
3110  else if( textHJustify == 'R' )
3112  else
3113  SCH_PARSE_ERROR( "invalid field text horizontal justification", aReader, line );
3114 
3115  wxString attributes;
3116 
3117  parseUnquotedString( attributes, aReader, line, &line );
3118 
3119  size_t attrSize = attributes.size();
3120 
3121  if( !(attrSize == 3 || attrSize == 1 ) )
3122  SCH_PARSE_ERROR( "invalid field text attributes size", aReader, line );
3123 
3124  switch( (wxChar) attributes[0] )
3125  {
3126  case 'C': field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3127  case 'B': field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3128  case 'T': field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3129  default: SCH_PARSE_ERROR( "invalid field text vertical justification", aReader, line );
3130  }
3131 
3132  if( attrSize == 3 )
3133  {
3134  wxChar attr_1 = attributes[1];
3135  wxChar attr_2 = attributes[2];
3136 
3137  if( attr_1 == 'I' ) // Italic
3138  field->SetItalic( true );
3139  else if( attr_1 != 'N' ) // No italics is default, check for error.
3140  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
3141 
3142  if ( attr_2 == 'B' ) // Bold
3143  field->SetBold( true );
3144  else if( attr_2 != 'N' ) // No bold is default, check for error.
3145  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
3146  }
3147  }
3148 
3149  // Fields in RAM must always have names.
3150  if( id >= 0 && id < MANDATORY_FIELDS )
3151  {
3152  // Fields in RAM must always have names, because we are trying to get
3153  // less dependent on field ids and more dependent on names.
3154  // Plus assumptions are made in the field editors.
3156 
3157  // Ensure the VALUE field = the symbol name (can be not the case
3158  // with malformed libraries: edited by hand, or converted from other tools)
3159  if( id == VALUE_FIELD )
3160  field->SetText( aSymbol->GetName() );
3161  }
3162  else
3163  {
3164  parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
3165  }
3166 }
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:71
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
void SetItalic(bool isItalic)
Definition: eda_text.h:200
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:258
#define Mils2Iu(x)
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:206
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:223
#define _(s)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
#define SCH_PARSE_ERROR(text, reader, pos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:222
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
void SetPosition(const wxPoint &aPosition) override
Definition: lib_item.h:222
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
#define TEXT_ANGLE_VERT
Definition: eda_text.h:72
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:188
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:210
void SetBold(bool aBold)
Definition: eda_text.h:203

References _, ConvertToNewOverbarNotation(), TEMPLATE_FIELDNAME::GetDefaultFieldName(), 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(), LIB_FIELD::m_name, MANDATORY_FIELDS, Mils2Iu, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, EDA_TEXT::SetBold(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), LIB_ITEM::SetPosition(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), text, TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, and VALUE_FIELD.

Referenced by LoadPart().

◆ loadFootprintFilters()

void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader 
)
staticprivate

Definition at line 3755 of file sch_legacy_plugin.cpp.

3757 {
3758  const char* line = aReader.Line();
3759 
3760  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3761 
3762  line = aReader.ReadLine();
3763 
3764  wxArrayString footprintFilters;
3765 
3766  while( line )
3767  {
3768  if( strCompare( "$ENDFPLIST", line, &line ) )
3769  {
3770  aSymbol->SetFPFilters( footprintFilters );
3771  return;
3772  }
3773 
3774  wxString footprint;
3775 
3776  parseUnquotedString( footprint, aReader, line, &line );
3777  footprintFilters.Add( footprint );
3778  line = aReader.ReadLine();
3779  }
3780 
3781  SCH_PARSE_ERROR( "File ended prematurely while loading footprint filters.", aReader, line );
3782 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)

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

Referenced by LoadPart().

◆ loadHeader()

void SCH_LEGACY_PLUGIN_CACHE::loadHeader ( FILE_LINE_READER aReader)
private

Definition at line 2778 of file sch_legacy_plugin.cpp.

2779 {
2780  const char* line = aReader.Line();
2781 
2782  wxASSERT( strCompare( "$HEADER", line, &line ) );
2783 
2784  while( aReader.ReadLine() )
2785  {
2786  line = (char*) aReader;
2787 
2788  // The time stamp saved in old library files is not used or saved in the latest
2789  // library file version.
2790  if( strCompare( "TimeStamp", line, &line ) )
2791  continue;
2792  else if( strCompare( "$ENDHEADER", line, &line ) )
2793  return;
2794  }
2795 
2796  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2797 }
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:214
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define SCH_PARSE_ERROR(text, reader, pos)

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

Referenced by Load().

◆ LoadPart()

LIB_SYMBOL * SCH_LEGACY_PLUGIN_CACHE::LoadPart ( LINE_READER aReader,
int  aMajorVersion,
int  aMinorVersion,
LIB_SYMBOL_MAP aMap = nullptr 
)
static

Definition at line 2800 of file sch_legacy_plugin.cpp.

2802 {
2803  const char* line = aReader.Line();
2804 
2805  while( *line == '#' )
2806  aReader.ReadLine();
2807 
2808  if( !strCompare( "DEF", line, &line ) )
2809  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2810 
2811  long num;
2812  size_t pos = 4; // "DEF" plus the first space.
2813  wxString utf8Line = wxString::FromUTF8( line );
2814  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2815 
2816  if( tokens.CountTokens() < 8 )
2817  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2818 
2819  // Read DEF line:
2820  std::unique_ptr<LIB_SYMBOL> symbol = std::make_unique<LIB_SYMBOL>( wxEmptyString );
2821 
2822  wxString name, prefix, tmp;
2823 
2824  name = tokens.GetNextToken();
2825  pos += name.size() + 1;
2826 
2827  prefix = tokens.GetNextToken();
2828  pos += prefix.size() + 1;
2829 
2830  tmp = tokens.GetNextToken();
2831  pos += tmp.size() + 1; // NumOfPins, unused.
2832 
2833  tmp = tokens.GetNextToken(); // Pin name offset.
2834 
2835  if( !tmp.ToLong( &num ) )
2836  THROW_PARSE_ERROR( "invalid pin offset", aReader.GetSource(), aReader.Line(),
2837  aReader.LineNumber(), pos );
2838 
2839  pos += tmp.size() + 1;
2840  symbol->SetPinNameOffset( Mils2Iu( (int)num ) );
2841 
2842  tmp = tokens.GetNextToken(); // Show pin numbers.
2843 
2844  if( !( tmp == "Y" || tmp == "N") )
2845  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2846  aReader.LineNumber(), pos );
2847 
2848  pos += tmp.size() + 1;
2849  symbol->SetShowPinNumbers( ( tmp == "N" ) ? false : true );
2850 
2851  tmp = tokens.GetNextToken(); // Show pin names.
2852 
2853  if( !( tmp == "Y" || tmp == "N") )
2854  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2855  aReader.LineNumber(), pos );
2856 
2857  pos += tmp.size() + 1;
2858  symbol->SetShowPinNames( ( tmp == "N" ) ? false : true );
2859 
2860  tmp = tokens.GetNextToken(); // Number of units.
2861 
2862  if( !tmp.ToLong( &num ) )
2863  THROW_PARSE_ERROR( "invalid unit count", aReader.GetSource(), aReader.Line(),
2864  aReader.LineNumber(), pos );
2865 
2866  pos += tmp.size() + 1;
2867  symbol->SetUnitCount( (int)num );
2868 
2869  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2870  if( symbol->GetUnitCount() < 1 )
2871  symbol->SetUnitCount( 1 );
2872 
2873  // Copy symbol name and prefix.
2874 
2875  // The root alias is added to the alias list by SetName() which is called by SetText().
2876  if( name.IsEmpty() )
2877  {
2878  symbol->SetName( "~" );
2879  }
2880  else if( name[0] != '~' )
2881  {
2882  symbol->SetName( name );
2883  }
2884  else
2885  {
2886  symbol->SetName( name.Right( name.Length() - 1 ) );
2887  symbol->GetValueField().SetVisible( false );
2888  }
2889 
2890  // Don't set the library alias, this is determined by the symbol library table.
2891  symbol->SetLibId( LIB_ID( wxEmptyString, symbol->GetName() ) );
2892 
2893  LIB_FIELD& reference = symbol->GetReferenceField();
2894 
2895  if( prefix == "~" )
2896  {
2897  reference.Empty();
2898  reference.SetVisible( false );
2899  }
2900  else
2901  {
2902  reference.SetText( prefix );
2903  }
2904 
2905  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2906  // The was no concept of interchangeable multiple unit symbols.
2907  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
2908  && LIB_VERSION( aMajorVersion, aMinorVersion ) <= LIB_VERSION( 2, 2 ) )
2909  {
2910  // Nothing needs to be set since the default setting for symbols with multiple
2911  // units were never interchangeable. Just parse the 0 an move on.
2912  tmp = tokens.GetNextToken();
2913  pos += tmp.size() + 1;
2914  }
2915  else
2916  {
2917  tmp = tokens.GetNextToken();
2918 
2919  if( tmp == "L" )
2920  symbol->LockUnits( true );
2921  else if( tmp == "F" || tmp == "0" )
2922  symbol->LockUnits( false );
2923  else
2924  THROW_PARSE_ERROR( "expected L, F, or 0", aReader.GetSource(), aReader.Line(),
2925  aReader.LineNumber(), pos );
2926 
2927  pos += tmp.size() + 1;
2928  }
2929 
2930  // There is the optional power symbol flag.
2931  if( tokens.HasMoreTokens() )
2932  {
2933  tmp = tokens.GetNextToken();
2934 
2935  if( tmp == "P" )
2936  symbol->SetPower();
2937  else if( tmp == "N" )
2938  symbol->SetNormal();
2939  else
2940  THROW_PARSE_ERROR( "expected P or N", aReader.GetSource(), aReader.Line(),
2941  aReader.LineNumber(), pos );
2942  }
2943 
2944  line = aReader.ReadLine();
2945 
2946  // Read lines until "ENDDEF" is found.
2947  while( line )
2948  {
2949  if( *line == '#' ) // Comment
2950  ;
2951  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2952  continue;
2953  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2954  loadAliases( symbol, aReader, aMap );
2955  else if( *line == 'F' ) // Fields
2956  loadField( symbol, aReader );
2957  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2958  loadDrawEntries( symbol, aReader, aMajorVersion, aMinorVersion );
2959  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2960  loadFootprintFilters( symbol, aReader );
2961  else if( strCompare( "ENDDEF", line, &line ) ) // End of symbol description
2962  {
2963  return symbol.release();
2964  }
2965 
2966  line = aReader.ReadLine();
2967  }
2968 
2969  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2970 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
Definition: richio.h:109
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static void loadAliases(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader, LIB_SYMBOL_MAP *aMap=nullptr)
Field object used in symbol libraries.
Definition: lib_field.h:59
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
#define Mils2Iu(x)
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:206
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
static void loadDrawEntries(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition: richio.h:135
void Empty()
Definition: eda_text.h:275
static void loadField(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
const char * name
Definition: DXF_plotter.cpp:56
static void loadFootprintFilters(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
#define LIB_VERSION(major, minor)

References EDA_TEXT::Empty(), LINE_READER::GetSource(), LIB_VERSION, LINE_READER::Line(), LINE_READER::LineNumber(), loadAliases(), loadDrawEntries(), loadField(), loadFootprintFilters(), Mils2Iu, name, LINE_READER::ReadLine(), SCH_PARSE_ERROR, EDA_TEXT::SetText(), EDA_TEXT::SetVisible(), strCompare(), and THROW_PARSE_ERROR.

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

◆ loadPin()

LIB_PIN * SCH_LEGACY_PLUGIN_CACHE::loadPin ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader 
)
staticprivate

Definition at line 3488 of file sch_legacy_plugin.cpp.

3490 {
3491  const char* line = aReader.Line();
3492 
3493  wxCHECK_MSG( strCompare( "X", line, &line ), nullptr, "Invalid LIB_PIN definition" );
3494 
3495  wxString name;
3496  wxString number;
3497 
3498  size_t pos = 2; // "X" plus ' ' space character.
3499  wxString tmp;
3500  wxString utf8Line = wxString::FromUTF8( line );
3501  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
3502 
3503  if( tokens.CountTokens() < 11 )
3504  SCH_PARSE_ERROR( "invalid pin definition", aReader, line );
3505 
3506  tmp = tokens.GetNextToken();
3507  name = tmp;
3508  pos += tmp.size() + 1;
3509 
3510  tmp = tokens.GetNextToken();
3511  number = tmp ;
3512  pos += tmp.size() + 1;
3513 
3514  long num;
3515  wxPoint position;
3516 
3517  tmp = tokens.GetNextToken();
3518 
3519  if( !tmp.ToLong( &num ) )
3520  THROW_PARSE_ERROR( "invalid pin X coordinate", aReader.GetSource(), aReader.Line(),
3521  aReader.LineNumber(), pos );
3522 
3523  pos += tmp.size() + 1;
3524  position.x = Mils2Iu( (int) num );
3525 
3526  tmp = tokens.GetNextToken();
3527 
3528  if( !tmp.ToLong( &num ) )
3529  THROW_PARSE_ERROR( "invalid pin Y coordinate", aReader.GetSource(), aReader.Line(),
3530  aReader.LineNumber(), pos );
3531 
3532  pos += tmp.size() + 1;
3533  position.y = Mils2Iu( (int) num );
3534 
3535  tmp = tokens.GetNextToken();
3536 
3537  if( !tmp.ToLong( &num ) )
3538  THROW_PARSE_ERROR( "invalid pin length", aReader.GetSource(), aReader.Line(),
3539  aReader.LineNumber(), pos );
3540 
3541  pos += tmp.size() + 1;
3542  int length = Mils2Iu( (int) num );
3543 
3544 
3545  tmp = tokens.GetNextToken();
3546 
3547  if( tmp.size() > 1 )
3548  THROW_PARSE_ERROR( "invalid pin orientation", aReader.GetSource(), aReader.Line(),
3549  aReader.LineNumber(), pos );
3550 
3551  pos += tmp.size() + 1;
3552  int orientation = tmp[0];
3553 
3554  tmp = tokens.GetNextToken();
3555 
3556  if( !tmp.ToLong( &num ) )
3557  THROW_PARSE_ERROR( "invalid pin number text size", aReader.GetSource(), aReader.Line(),
3558  aReader.LineNumber(), pos );
3559 
3560  pos += tmp.size() + 1;
3561  int numberTextSize = Mils2Iu( (int) num );
3562 
3563  tmp = tokens.GetNextToken();
3564 
3565  if( !tmp.ToLong( &num ) )
3566  THROW_PARSE_ERROR( "invalid pin name text size", aReader.GetSource(), aReader.Line(),
3567  aReader.LineNumber(), pos );
3568 
3569  pos += tmp.size() + 1;
3570  int nameTextSize = Mils2Iu( (int) num );
3571 
3572  tmp = tokens.GetNextToken();
3573 
3574  if( !tmp.ToLong( &num ) )
3575  THROW_PARSE_ERROR( "invalid pin unit", aReader.GetSource(), aReader.Line(),
3576  aReader.LineNumber(), pos );
3577 
3578  pos += tmp.size() + 1;
3579  int unit = (int) num;
3580 
3581  tmp = tokens.GetNextToken();
3582 
3583  if( !tmp.ToLong( &num ) )
3584  THROW_PARSE_ERROR( "invalid pin alternate body type", aReader.GetSource(), aReader.Line(),
3585  aReader.LineNumber(), pos );
3586 
3587  pos += tmp.size() + 1;
3588  int convert = (int) num;
3589 
3590  tmp = tokens.GetNextToken();
3591 
3592  if( tmp.size() != 1 )
3593  THROW_PARSE_ERROR( "invalid pin type", aReader.GetSource(), aReader.Line(),
3594  aReader.LineNumber(), pos );
3595 
3596  pos += tmp.size() + 1;
3597  char type = tmp[0];
3598  ELECTRICAL_PINTYPE pinType;
3599 
3600  switch( type )
3601  {
3602  case 'I': pinType = ELECTRICAL_PINTYPE::PT_INPUT; break;
3603  case 'O': pinType = ELECTRICAL_PINTYPE::PT_OUTPUT; break;
3604  case 'B': pinType = ELECTRICAL_PINTYPE::PT_BIDI; break;
3605  case 'T': pinType = ELECTRICAL_PINTYPE::PT_TRISTATE; break;
3606  case 'P': pinType = ELECTRICAL_PINTYPE::PT_PASSIVE; break;
3607  case 'U': pinType = ELECTRICAL_PINTYPE::PT_UNSPECIFIED; break;
3608  case 'W': pinType = ELECTRICAL_PINTYPE::PT_POWER_IN; break;
3609  case 'w': pinType = ELECTRICAL_PINTYPE::PT_POWER_OUT; break;
3610  case 'C': pinType = ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR; break;
3611  case 'E': pinType = ELECTRICAL_PINTYPE::PT_OPENEMITTER; break;
3612  case 'N': pinType = ELECTRICAL_PINTYPE::PT_NC; break;
3613  default:
3614  THROW_PARSE_ERROR( "unknown pin type", aReader.GetSource(), aReader.Line(),
3615  aReader.LineNumber(), pos );
3616  }
3617 
3618 
3619  LIB_PIN* pin = new LIB_PIN( aSymbol.get(),
3621  ConvertToNewOverbarNotation( number ),
3622  orientation,
3623  pinType,
3624  length,
3625  nameTextSize,
3626  numberTextSize,
3627  convert,
3628  position,
3629  unit );
3630 
3631  // Optional
3632  if( tokens.HasMoreTokens() ) /* Special Symbol defined */
3633  {
3634  tmp = tokens.GetNextToken();
3635 
3636  enum
3637  {
3638  INVERTED = 1 << 0,
3639  CLOCK = 1 << 1,
3640  LOWLEVEL_IN = 1 << 2,
3641  LOWLEVEL_OUT = 1 << 3,
3642  FALLING_EDGE = 1 << 4,
3643  NONLOGIC = 1 << 5
3644  };
3645 
3646  int flags = 0;
3647 
3648  for( int j = tmp.size(); j > 0; )
3649  {
3650  switch( tmp[--j].GetValue() )
3651  {
3652  case '~': break;
3653  case 'N': pin->SetVisible( false ); break;
3654  case 'I': flags |= INVERTED; break;
3655  case 'C': flags |= CLOCK; break;
3656  case 'L': flags |= LOWLEVEL_IN; break;
3657  case 'V': flags |= LOWLEVEL_OUT; break;
3658  case 'F': flags |= FALLING_EDGE; break;
3659  case 'X': flags |= NONLOGIC; break;
3660  default: THROW_PARSE_ERROR( "invalid pin attribut", aReader.GetSource(),
3661  aReader.Line(), aReader.LineNumber(), pos );
3662  }
3663 
3664  pos += 1;
3665  }
3666 
3667  switch( flags )
3668  {
3669  case 0: pin->SetShape( GRAPHIC_PINSHAPE::LINE ); break;
3670  case INVERTED: pin->SetShape( GRAPHIC_PINSHAPE::INVERTED ); break;
3671  case CLOCK: pin->SetShape( GRAPHIC_PINSHAPE::CLOCK ); break;
3672  case INVERTED | CLOCK: pin->SetShape( GRAPHIC_PINSHAPE::INVERTED_CLOCK ); break;
3673  case LOWLEVEL_IN: pin->SetShape( GRAPHIC_PINSHAPE::INPUT_LOW ); break;
3674  case LOWLEVEL_IN | CLOCK: pin->SetShape( GRAPHIC_PINSHAPE::CLOCK_LOW ); break;
3675  case LOWLEVEL_OUT: pin->SetShape( GRAPHIC_PINSHAPE::OUTPUT_LOW ); break;
3676  case FALLING_EDGE: pin->SetShape( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK ); break;
3677  case NONLOGIC: pin->SetShape( GRAPHIC_PINSHAPE::NONLOGIC ); break;
3678  default:
3679  SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3680  }
3681  }
3682 
3683  return pin;
3684 }
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
power input (GND, VCC for ICs). Must be connected to a power output.
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
Definition: richio.h:109
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
pin for passive symbols: must be connected, and can be connected to any pin
unknown electrical properties: creates always a warning when connected
std::chrono::steady_clock CLOCK
#define Mils2Iu(x)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition: richio.h:135
#define SCH_PARSE_ERROR(text, reader, pos)
const char * name
Definition: DXF_plotter.cpp:56
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:35
usual pin input: must be connected
input or output (like port for a microprocessor)
not connected (must be left open)
output of a regulator: intended to be connected to power input pins

References CLOCK, CLOCK_LOW, convert, ConvertToNewOverbarNotation(), FALLING_EDGE_CLOCK, LINE_READER::GetSource(), INPUT_LOW, INVERTED, INVERTED_CLOCK, LINE, LINE_READER::Line(), LINE_READER::LineNumber(), Mils2Iu, name, NONLOGIC, OUTPUT_LOW, pin, PT_BIDI, PT_INPUT, PT_NC, PT_OPENCOLLECTOR, PT_OPENEMITTER, PT_OUTPUT, PT_PASSIVE, PT_POWER_IN, PT_POWER_OUT, PT_TRISTATE, PT_UNSPECIFIED, SCH_PARSE_ERROR, strCompare(), and THROW_PARSE_ERROR.

Referenced by loadDrawEntries().

◆ loadPolyLine()

LIB_SHAPE * SCH_LEGACY_PLUGIN_CACHE::loadPolyLine ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader 
)
staticprivate

Definition at line 3687 of file sch_legacy_plugin.cpp.

3689 {
3690  const char* line = aReader.Line();
3691 
3692  wxCHECK_MSG( strCompare( "P", line, &line ), nullptr, "Invalid poly definition" );
3693 
3694  LIB_SHAPE* polyLine = new LIB_SHAPE( aSymbol.get(), SHAPE_T::POLY );
3695 
3696  int points = parseInt( aReader, line, &line );
3697  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3698  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3699  polyLine->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3700 
3701  wxPoint pt;
3702 
3703  for( int i = 0; i < points; i++ )
3704  {
3705  pt.x = Mils2Iu( parseInt( aReader, line, &line ) );
3706  pt.y = Mils2Iu( parseInt( aReader, line, &line ) );
3707  polyLine->AddPoint( pt );
3708  }
3709 
3710  if( *line != 0 )
3711  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3712 
3713  return polyLine;
3714 }
void AddPoint(const wxPoint &aPosition)
Definition: lib_shape.cpp:395
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define Mils2Iu(x)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetWidth(int aWidth)
Definition: eda_shape.h:88
void SetConvert(int aConvert)
Definition: lib_item.h:260
void SetUnit(int aUnit)
Definition: lib_item.h:257
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:78

References LIB_SHAPE::AddPoint(), LINE_READER::Line(), Mils2Iu, parseFillMode(), parseInt(), POLY, LIB_ITEM::SetConvert(), EDA_SHAPE::SetFillMode(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

◆ loadRect()

LIB_SHAPE * SCH_LEGACY_PLUGIN_CACHE::loadRect ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader 
)
staticprivate

Definition at line 3456 of file sch_legacy_plugin.cpp.

3458 {
3459  const char* line = aReader.Line();
3460 
3461  wxCHECK_MSG( strCompare( "S", line, &line ), nullptr, "Invalid rectangle definition" );
3462 
3463  LIB_SHAPE* rectangle = new LIB_SHAPE( aSymbol.get(), SHAPE_T::RECT );
3464 
3465  wxPoint pos;
3466 
3467  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
3468  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
3469  rectangle->SetPosition( pos );
3470 
3471  wxPoint end;
3472 
3473  end.x = Mils2Iu( parseInt( aReader, line, &line ) );
3474  end.y = Mils2Iu( parseInt( aReader, line, &line ) );
3475  rectangle->SetEnd( end );
3476 
3477  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3478  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3479  rectangle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3480 
3481  if( *line != 0 )
3482  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3483 
3484  return rectangle;
3485 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetEnd(const wxPoint &aEnd)
Definition: eda_shape.h:126
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define Mils2Iu(x)
void SetPosition(const wxPoint &aPosition) override
Definition: lib_shape.h:87
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetWidth(int aWidth)
Definition: eda_shape.h:88
void SetConvert(int aConvert)
Definition: lib_item.h:260
void SetUnit(int aUnit)
Definition: lib_item.h:257
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:78

References LINE_READER::Line(), Mils2Iu, parseFillMode(), parseInt(), RECT, LIB_ITEM::SetConvert(), EDA_SHAPE::SetEnd(), EDA_SHAPE::SetFillMode(), LIB_SHAPE::SetPosition(), LIB_ITEM::SetUnit(), EDA_SHAPE::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

◆ loadText()

LIB_TEXT * SCH_LEGACY_PLUGIN_CACHE::loadText ( std::unique_ptr< LIB_SYMBOL > &  aSymbol,
LINE_READER aReader,
int  aMajorVersion,
int  aMinorVersion 
)
staticprivate

Definition at line 3359 of file sch_legacy_plugin.cpp.

3363 {
3364  const char* line = aReader.Line();
3365 
3366  wxCHECK_MSG( strCompare( "T", line, &line ), nullptr, "Invalid LIB_TEXT definition" );
3367 
3368  LIB_TEXT* text = new LIB_TEXT( aSymbol.get() );
3369 
3370  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3371 
3372  wxPoint center;
3373 
3374  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3375  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3376  text->SetPosition( center );
3377 
3378  wxSize size;
3379 
3380  size.x = size.y = Mils2Iu( parseInt( aReader, line, &line ) );
3381  text->SetTextSize( size );
3382  text->SetVisible( !parseInt( aReader, line, &line ) );
3383  text->SetUnit( parseInt( aReader, line, &line ) );
3384  text->SetConvert( parseInt( aReader, line, &line ) );
3385 
3386  wxString str;
3387 
3388  // If quoted string loading fails, load as not quoted string.
3389  if( *line == '"' )
3390  {
3391  parseQuotedString( str, aReader, line, &line );
3392 
3393  str = ConvertToNewOverbarNotation( str );
3394  }
3395  else
3396  {
3397  parseUnquotedString( str, aReader, line, &line );
3398 
3399  // In old libs, "spaces" are replaced by '~' in unquoted strings:
3400  str.Replace( "~", " " );
3401  }
3402 
3403  if( !str.IsEmpty() )
3404  {
3405  // convert two apostrophes back to double quote
3406  str.Replace( "''", "\"" );
3407  }
3408 
3409  text->SetText( str );
3410 
3411  // Here things are murky and not well defined. At some point it appears the format
3412  // was changed to add text properties. However rather than add the token to the end of
3413  // the text definition, it was added after the string and no mention if the file
3414  // verion was bumped or not so this code make break on very old symbol libraries.
3415  //
3416  // Update: apparently even in the latest version this can be different so added a test
3417  // for end of line before checking for the text properties.
3418  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
3419  && LIB_VERSION( aMajorVersion, aMinorVersion ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3420  {
3421  if( strCompare( "Italic", line, &line ) )
3422  text->SetItalic( true );
3423  else if( !strCompare( "Normal", line, &line ) )
3424  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );
3425 
3426  if( parseInt( aReader, line, &line ) > 0 )
3427  text->SetBold( true );
3428 
3429  // Some old libaries version > 2.0 do not have these options for text justification:
3430  if( !is_eol( *line ) )
3431  {
3432  switch( parseChar( aReader, line, &line ) )
3433  {
3434  case 'L': text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
3435  case 'C': text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
3436  case 'R': text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
3437  default: SCH_PARSE_ERROR( "invalid horizontal text justication; expected L, C, or R",
3438  aReader, line );
3439  }
3440 
3441  switch( parseChar( aReader, line, &line ) )
3442  {
3443  case 'T': text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3444  case 'C': text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3445  case 'B': text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3446  default: SCH_PARSE_ERROR( "invalid vertical text justication; expected T, C, or B",
3447  aReader, line );
3448  }
3449  }
3450  }
3451 
3452  return text;
3453 }
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
Define a symbol library graphical text item.
Definition: lib_text.h:39
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
#define Mils2Iu(x)
static bool is_eol(char c)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define SCH_PARSE_ERROR(text, reader, pos)
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
#define LIB_VERSION(major, minor)

References ConvertToNewOverbarNotation(), 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(), Mils2Iu, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, strCompare(), and text.

Referenced by loadDrawEntries().

◆ parseFillMode()

FILL_T SCH_LEGACY_PLUGIN_CACHE::parseFillMode ( LINE_READER aReader,
const char *  aLine,
const char **  aOutput 
)
staticprivate

Definition at line 3236 of file sch_legacy_plugin.cpp.

3238 {
3239  switch ( parseChar( aReader, aLine, aOutput ) )
3240  {
3241  case 'F': return FILL_T::FILLED_SHAPE;
3242  case 'f': return FILL_T::FILLED_WITH_BG_BODYCOLOR;
3243  case 'N': return FILL_T::NO_FILL;
3244  default: SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
3245  }
3246 
3247  // This will never be reached but quiets the compiler warnings
3248  return FILL_T::NO_FILL;
3249 }
#define SCH_PARSE_ERROR(text, reader, pos)
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.

References FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR, NO_FILL, parseChar(), and SCH_PARSE_ERROR.

Referenced by loadArc(), loadBezier(), loadCircle(), loadPolyLine(), and loadRect().

◆ removeSymbol()

LIB_SYMBOL * SCH_LEGACY_PLUGIN_CACHE::removeSymbol ( LIB_SYMBOL aAlias)
private

Definition at line 2505 of file sch_legacy_plugin.cpp.

2506 {
2507  wxCHECK_MSG( aSymbol != nullptr, nullptr, "NULL pointer cannot be removed from library." );
2508 
2509  LIB_SYMBOL* firstChild = nullptr;
2510  LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbol->GetName() );
2511 
2512  if( it == m_symbols.end() )
2513  return nullptr;
2514 
2515  // If the entry pointer doesn't match the name it is mapped to in the library, we
2516  // have done something terribly wrong.
2517  wxCHECK_MSG( *it->second == aSymbol, nullptr,
2518  "Pointer mismatch while attempting to remove alias entry <" + aSymbol->GetName() +
2519  "> from library cache <" + m_libFileName.GetName() + ">." );
2520 
2521  // If the symbol is a root symbol used by other symbols find the first alias that uses
2522  // the root symbol and make it the new root.
2523  if( aSymbol->IsRoot() )
2524  {
2525  for( auto entry : m_symbols )
2526  {
2527  if( entry.second->IsAlias()
2528  && entry.second->GetParent().lock() == aSymbol->SharedPtr() )
2529  {
2530  firstChild = entry.second;
2531  break;
2532  }
2533  }
2534 
2535  if( firstChild )
2536  {
2537  for( LIB_ITEM& drawItem : aSymbol->GetDrawItems() )
2538  {
2539  if( drawItem.Type() == LIB_FIELD_T )
2540  {
2541  LIB_FIELD& field = static_cast<LIB_FIELD&>( drawItem );
2542 
2543  if( firstChild->FindField( field.GetCanonicalName() ) )
2544  continue;
2545  }
2546 
2547  LIB_ITEM* newItem = (LIB_ITEM*) drawItem.Clone();
2548  drawItem.SetParent( firstChild );
2549  firstChild->AddDrawItem( newItem );
2550  }
2551 
2552  // Reparent the remaining aliases.
2553  for( auto entry : m_symbols )
2554  {
2555  if( entry.second->IsAlias()
2556  && entry.second->GetParent().lock() == aSymbol->SharedPtr() )
2557  entry.second->SetParent( firstChild );
2558  }
2559  }
2560  }
2561 
2562  m_symbols.erase( it );
2563  delete aSymbol;
2564  m_isModified = true;
2566  return firstChild;
2567 }
LIB_FIELD * FindField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName and returns it or NULL if not found.
Definition: lib_symbol.cpp:977
Field object used in symbol libraries.
Definition: lib_field.h:59
Define a library symbol object.
Definition: lib_symbol.h:96
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:83
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: lib_field.cpp:371
void AddDrawItem(LIB_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Definition: lib_symbol.cpp:665

References LIB_SYMBOL::AddDrawItem(), EDA_ITEM::Clone(), LIB_SYMBOL::FindField(), LIB_FIELD::GetCanonicalName(), LIB_SYMBOL::GetDrawItems(), LIB_SYMBOL::GetName(), IncrementModifyHash(), LIB_SYMBOL::IsRoot(), LIB_FIELD_T, m_isModified, m_libFileName, m_symbols, EDA_ITEM::SetParent(), and LIB_SYMBOL::SharedPtr().

Referenced by AddSymbol().

◆ Save()

void SCH_LEGACY_PLUGIN_CACHE::Save ( bool  aSaveDocFile = true)

Save the entire library to file m_libFileName;.

Definition at line 3785 of file sch_legacy_plugin.cpp.

3786 {
3787  if( !m_isModified )
3788  return;
3789 
3790  // Write through symlinks, don't replace them
3791  wxFileName fn = GetRealFile();
3792 
3793  auto formatter = std::make_unique<FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
3794  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3795  formatter->Print( 0, "#encoding utf-8\n");
3796 
3797  for( LIB_SYMBOL_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); it++ )
3798  {
3799  if( !it->second->IsRoot() )
3800  continue;
3801 
3802  SaveSymbol( it->second, *formatter.get(), &m_symbols );
3803  }
3804 
3805  formatter->Print( 0, "#\n#End Library\n" );
3806  formatter.reset();
3807 
3808  m_fileModTime = fn.GetModificationTime();
3809  m_isModified = false;
3810 
3811  if( aSaveDocFile )
3812  saveDocFile();
3813 }
#define LIB_VERSION_MINOR
#define LIB_VERSION_MAJOR
#define LIBFILE_IDENT
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_SYMBOL_MAP *aMap=nullptr)
wxFileName GetRealFile() const

References GetRealFile(), LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIBFILE_IDENT, m_fileModTime, m_isModified, m_symbols, saveDocFile(), and SaveSymbol().

Referenced by SCH_LEGACY_PLUGIN::CreateSymbolLib(), SCH_LEGACY_PLUGIN::DeleteSymbol(), SCH_LEGACY_PLUGIN::SaveLibrary(), and SCH_LEGACY_PLUGIN::SaveSymbol().

◆ saveDocFile()

void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 3823 of file sch_legacy_plugin.cpp.

3824 {
3825  wxFAIL_MSG( "Writing of legacy format no longer supported." );
3826 }

Referenced by Save().

◆ SaveSymbol()

void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol ( LIB_SYMBOL aSymbol,
OUTPUTFORMATTER aFormatter,
LIB_SYMBOL_MAP aMap = nullptr 
)
static

Definition at line 3816 of file sch_legacy_plugin.cpp.

3818 {
3819  wxFAIL_MSG( "Writing of legacy format no longer supported." );
3820 }

Referenced by SCH_LEGACY_PLUGIN::FormatPart(), and Save().

◆ SetFileName()

void SCH_LEGACY_PLUGIN_CACHE::SetFileName ( const wxString &  aFileName)
inline

Definition at line 550 of file sch_legacy_plugin.cpp.

550 { m_libFileName = aFileName; }

References m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

◆ SetModified()

void SCH_LEGACY_PLUGIN_CACHE::SetModified ( bool  aModified = true)
inline

Member Data Documentation

◆ m_fileModTime

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

Definition at line 473 of file sch_legacy_plugin.cpp.

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

◆ m_fileName

wxString SCH_LEGACY_PLUGIN_CACHE::m_fileName
private

Definition at line 471 of file sch_legacy_plugin.cpp.

Referenced by IsFile().

◆ m_isModified

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 476 of file sch_legacy_plugin.cpp.

Referenced by AddSymbol(), DeleteSymbol(), removeSymbol(), Save(), and SetModified().

◆ m_isWritable

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

Definition at line 475 of file sch_legacy_plugin.cpp.

Referenced by GetLibModificationTime().

◆ m_libFileName

wxFileName SCH_LEGACY_PLUGIN_CACHE::m_libFileName
private

◆ m_libType

SCH_LIB_TYPE SCH_LEGACY_PLUGIN_CACHE::m_libType
private

Definition at line 479 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ m_symbols

◆ m_versionMajor

int SCH_LEGACY_PLUGIN_CACHE::m_versionMajor
private

Definition at line 477 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ m_versionMinor

int SCH_LEGACY_PLUGIN_CACHE::m_versionMinor
private

Definition at line 478 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ s_modHash

int SCH_LEGACY_PLUGIN_CACHE::s_modHash = 1
staticprivate

Definition at line 470 of file sch_legacy_plugin.cpp.

Referenced by GetModifyHash(), and IncrementModifyHash().

◆ s_modHashMutex

std::mutex SCH_LEGACY_PLUGIN_CACHE::s_modHashMutex
staticprivate

Definition at line 506 of file sch_legacy_plugin.cpp.

Referenced by GetModifyHash(), and IncrementModifyHash().

◆ SCH_LEGACY_PLUGIN

friend SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN
private

Definition at line 504 of file sch_legacy_plugin.cpp.


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