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)
 
static void saveArc (LIB_SHAPE *aArc, OUTPUTFORMATTER &aFormatter)
 
static void saveBezier (LIB_SHAPE *aBezier, OUTPUTFORMATTER &aFormatter)
 
static void saveCircle (LIB_SHAPE *aCircle, OUTPUTFORMATTER &aFormatter)
 
static void saveField (const LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter)
 
static void savePin (const LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter)
 
static void savePolyLine (LIB_SHAPE *aPolyLine, OUTPUTFORMATTER &aFormatter)
 
static void saveRectangle (LIB_SHAPE *aRectangle, OUTPUTFORMATTER &aFormatter)
 
static void saveText (const LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter)
 

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

2457  :
2458  m_fileName( aFullPathAndFileName ),
2459  m_libFileName( aFullPathAndFileName ),
2460  m_isWritable( true ),
2461  m_isModified( false )
2462 {
2463  m_versionMajor = -1;
2464  m_versionMinor = -1;
2466 }

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

2470 {
2471  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2472  for( auto& symbol : m_symbols )
2473  delete symbol.second;
2474 
2475  m_symbols.clear();
2476 }

References m_symbols.

Member Function Documentation

◆ AddSymbol()

void SCH_LEGACY_PLUGIN_CACHE::AddSymbol ( const LIB_SYMBOL aSymbol)

Definition at line 2582 of file sch_legacy_plugin.cpp.

2583 {
2584  // aSymbol is cloned in SYMBOL_LIB::AddSymbol(). The cache takes ownership of aSymbol.
2585  wxString name = aSymbol->GetName();
2586  LIB_SYMBOL_MAP::iterator it = m_symbols.find( name );
2587 
2588  if( it != m_symbols.end() )
2589  {
2590  removeSymbol( it->second );
2591  }
2592 
2593  m_symbols[ name ] = const_cast< LIB_SYMBOL* >( aSymbol );
2594  m_isModified = true;
2596 }
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 4282 of file sch_legacy_plugin.cpp.

4283 {
4284  LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbolName );
4285 
4286  if( it == m_symbols.end() )
4287  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
4288  m_libFileName.GetFullName(), aSymbolName ) );
4289 
4290  LIB_SYMBOL* symbol = it->second;
4291 
4292  if( symbol->IsRoot() )
4293  {
4294  LIB_SYMBOL* rootSymbol = symbol;
4295 
4296  // Remove the root symbol and all its children.
4297  m_symbols.erase( it );
4298 
4299  LIB_SYMBOL_MAP::iterator it1 = m_symbols.begin();
4300 
4301  while( it1 != m_symbols.end() )
4302  {
4303  if( it1->second->IsAlias()
4304  && it1->second->GetParent().lock() == rootSymbol->SharedPtr() )
4305  {
4306  delete it1->second;
4307  it1 = m_symbols.erase( it1 );
4308  }
4309  else
4310  {
4311  it1++;
4312  }
4313  }
4314 
4315  delete rootSymbol;
4316  }
4317  else
4318  {
4319  // Just remove the alias.
4320  m_symbols.erase( it );
4321  delete symbol;
4322  }
4323 
4325  m_isModified = true;
4326 }
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 560 of file sch_legacy_plugin.cpp.

560 { return m_libFileName.GetFullPath(); }

References m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

◆ GetLibModificationTime()

wxDateTime SCH_LEGACY_PLUGIN_CACHE::GetLibModificationTime ( )

Definition at line 2488 of file sch_legacy_plugin.cpp.

2489 {
2490  wxFileName fn = GetRealFile();
2491 
2492  // update the writable flag while we have a wxFileName, in a network this
2493  // is possibly quite dynamic anyway.
2494  m_isWritable = fn.IsFileWritable();
2495 
2496  return fn.GetModificationTime();
2497 }
wxFileName GetRealFile() const

References GetRealFile(), and m_isWritable.

Referenced by Load().

◆ GetLogicalName()

wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 556 of file sch_legacy_plugin.cpp.

556 { return m_libFileName.GetName(); }

References m_libFileName.

◆ GetModifyHash()

static int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( )
inlinestatic

Definition at line 526 of file sch_legacy_plugin.cpp.

527  {
528  std::lock_guard<std::mutex> mut( SCH_LEGACY_PLUGIN_CACHE::s_modHashMutex );
530  }
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 2480 of file sch_legacy_plugin.cpp.

2481 {
2482  wxFileName fn( m_libFileName );
2484  return fn;
2485 }
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 520 of file sch_legacy_plugin.cpp.

521  {
522  std::lock_guard<std::mutex> mut( SCH_LEGACY_PLUGIN_CACHE::s_modHashMutex );
524  }
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 2500 of file sch_legacy_plugin.cpp.

2501 {
2502  return m_fileName == aFullPathAndFileName;
2503 }

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

2507 {
2508  wxFileName fn = GetRealFile();
2509 
2510  if( m_fileModTime.IsValid() && fn.IsOk() && fn.FileExists() )
2511  return fn.GetModificationTime() != m_fileModTime;
2512 
2513  return false;
2514 }
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 2599 of file sch_legacy_plugin.cpp.

2600 {
2601  if( !m_libFileName.FileExists() )
2602  {
2603  THROW_IO_ERROR( wxString::Format( _( "Library file '%s' not found." ),
2604  m_libFileName.GetFullPath() ) );
2605  }
2606 
2607  wxCHECK_RET( m_libFileName.IsAbsolute(),
2608  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2609  "open library '%s'.", m_libFileName.GetFullPath() ) );
2610 
2611  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file '%s'",
2612  m_libFileName.GetFullPath() );
2613 
2614  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2615 
2616  if( !reader.ReadLine() )
2617  THROW_IO_ERROR( _( "Unexpected end of file." ) );
2618 
2619  const char* line = reader.Line();
2620 
2621  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2622  {
2623  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2624  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2625  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2626  SCH_PARSE_ERROR( "file is not a valid symbol or symbol library file", reader, line );
2627  }
2628 
2629  m_versionMajor = parseInt( reader, line, &line );
2630 
2631  if( *line != '.' )
2632  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2633 
2634  line++;
2635 
2636  m_versionMinor = parseInt( reader, line, &line );
2637 
2638  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2639  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2640 
2641  // Check if this is a symbol library which is the same as a symbol library but without
2642  // any alias, documentation, footprint filters, etc.
2643  if( strCompare( "SYMBOL", line, &line ) )
2644  {
2645  // Symbol files add date and time stamp info to the header.
2647 
2649  }
2650  else
2651  {
2653  }
2654 
2655  while( reader.ReadLine() )
2656  {
2657  line = reader.Line();
2658 
2659  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2660  continue;
2661 
2662  // Headers where only supported in older library file formats.
2663  if( m_libType == SCH_LIB_TYPE::LT_EESCHEMA && strCompare( "$HEADER", line ) )
2664  loadHeader( reader );
2665 
2666  if( strCompare( "DEF", line ) )
2667  {
2668  // Read one DEF/ENDDEF symbol entry from library:
2669  LIB_SYMBOL* symbol = LoadPart( reader, m_versionMajor, m_versionMinor, &m_symbols );
2670 
2671  m_symbols[ symbol->GetName() ] = symbol;
2672  }
2673  }
2674 
2676 
2677  // Remember the file modification time of library file when the
2678  // cache snapshot was made, so that in a networked environment we will
2679  // reload the cache as needed.
2681 
2683  loadDocs();
2684 }
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 2991 of file sch_legacy_plugin.cpp.

2994 {
2995  wxString newAliasName;
2996  const char* line = aReader.Line();
2997 
2998  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2999 
3000  wxString utf8Line = wxString::FromUTF8( line );
3001  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
3002 
3003  // Parse the ALIAS list.
3004  while( tokens.HasMoreTokens() )
3005  {
3006  newAliasName = tokens.GetNextToken();
3007 
3008  if( aMap )
3009  {
3010  LIB_SYMBOL* newSymbol = new LIB_SYMBOL( newAliasName );
3011 
3012  // Inherit the parent mandatory field attributes.
3013  for( int id = 0; id < MANDATORY_FIELDS; ++id )
3014  {
3015  LIB_FIELD* field = newSymbol->GetFieldById( id );
3016 
3017  // the MANDATORY_FIELDS are exactly that in RAM.
3018  wxASSERT( field );
3019 
3020  LIB_FIELD* parentField = aSymbol->GetFieldById( id );
3021 
3022  wxASSERT( parentField );
3023 
3024  *field = *parentField;
3025 
3026  if( id == VALUE_FIELD )
3027  field->SetText( newAliasName );
3028 
3029  field->SetParent( newSymbol );
3030  }
3031 
3032  newSymbol->SetParent( aSymbol.get() );
3033 
3034  // This will prevent duplicate aliases.
3035  (*aMap)[ newSymbol->GetName() ] = newSymbol;
3036  }
3037  }
3038 }
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:115
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:371
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.

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

3277 {
3278  const char* line = aReader.Line();
3279 
3280  wxCHECK_MSG( strCompare( "A", line, &line ), nullptr, "Invalid arc definition" );
3281 
3282  LIB_SHAPE* arc = new LIB_SHAPE( aSymbol.get(), SHAPE_T::ARC );
3283 
3284  wxPoint center;
3285 
3286  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3287  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3288 
3289  arc->SetPosition( center );
3290 
3291  int radius = Mils2Iu( parseInt( aReader, line, &line ) );
3292  int angle1 = parseInt( aReader, line, &line );
3293  int angle2 = parseInt( aReader, line, &line );
3294 
3295  NORMALIZE_ANGLE_POS( angle1 );
3296  NORMALIZE_ANGLE_POS( angle2 );
3297 
3298  arc->SetUnit( parseInt( aReader, line, &line ) );
3299  arc->SetConvert( parseInt( aReader, line, &line ) );
3300  arc->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3301 
3302  // Old libraries (version <= 2.2) do not have always this FILL MODE param
3303  // when fill mode is no fill (default mode).
3304  if( *line != 0 )
3305  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
3306 
3307  // Actual Coordinates of arc ends are read from file
3308  if( *line != 0 )
3309  {
3310  wxPoint arcStart, arcEnd;
3311 
3312  arcStart.x = Mils2Iu( parseInt( aReader, line, &line ) );
3313  arcStart.y = Mils2Iu( parseInt( aReader, line, &line ) );
3314  arcEnd.x = Mils2Iu( parseInt( aReader, line, &line ) );
3315  arcEnd.y = Mils2Iu( parseInt( aReader, line, &line ) );
3316 
3317  arc->SetStart( arcStart );
3318  arc->SetEnd( arcEnd );
3319  }
3320  else
3321  {
3322  // Actual Coordinates of arc ends are not read from file
3323  // (old library), calculate them
3324  wxPoint arcStart( radius, 0 );
3325  wxPoint arcEnd( radius, 0 );
3326 
3327  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
3328  arcStart += arc->GetCenter();
3329  arc->SetStart( arcStart );
3330  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
3331  arcEnd += arc->GetCenter();
3332  arc->SetEnd( arcEnd );
3333  }
3334 
3342  if( !TRANSFORM().MapAngles( &angle1, &angle2 ) )
3343  {
3344  wxPoint temp = arc->GetStart();
3345  arc->SetStart( arc->GetEnd() );
3346  arc->SetEnd( temp );
3347  }
3348 
3349  return arc;
3350 }
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:135
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:106
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:110
void SetPosition(const wxPoint &aPosition) override
Definition: lib_shape.h:88
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:131
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:97
wxPoint GetCenter() const
Definition: lib_shape.h:90
void SetConvert(int aConvert)
Definition: lib_item.h:268
void SetUnit(int aUnit)
Definition: lib_item.h:265
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:87

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

3742 {
3743  const char* line = aReader.Line();
3744 
3745  wxCHECK_MSG( strCompare( "B", line, &line ), nullptr, "Invalid Bezier definition" );
3746 
3747  int points = parseInt( aReader, line, &line );
3748 
3749  wxCHECK_MSG( points == 4, NULL, "Invalid Bezier curve definition" );
3750 
3751  LIB_SHAPE* bezier = new LIB_SHAPE( aSymbol.get(), SHAPE_T::BEZIER );
3752 
3753  bezier->SetUnit( parseInt( aReader, line, &line ) );
3754  bezier->SetConvert( parseInt( aReader, line, &line ) );
3755  bezier->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3756 
3757  bezier->SetStart( wxPoint( Mils2Iu( parseInt( aReader, line, &line ) ),
3758  Mils2Iu( parseInt( aReader, line, &line ) ) ) );
3759 
3760  bezier->SetBezierC1( wxPoint( Mils2Iu( parseInt( aReader, line, &line ) ),
3761  Mils2Iu( parseInt( aReader, line, &line ) ) ) );
3762 
3763  bezier->SetBezierC2( wxPoint( Mils2Iu( parseInt( aReader, line, &line ) ),
3764  Mils2Iu( parseInt( aReader, line, &line ) ) ) );
3765 
3766  bezier->SetEnd( wxPoint( Mils2Iu( parseInt( aReader, line, &line ) ),
3767  Mils2Iu( parseInt( aReader, line, &line ) ) ) );
3768 
3769  bezier->RebuildBezierToSegmentsPointsList( bezier->GetWidth() );
3770 
3771  if( *line != 0 )
3772  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3773 
3774  return bezier;
3775 }
int GetWidth() const
Definition: eda_shape.h:98
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:135
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:153
void SetStart(const wxPoint &aStart)
Definition: eda_shape.h:110
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:97
void SetConvert(int aConvert)
Definition: lib_item.h:268
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
Definition: eda_shape.cpp:366
void SetUnit(int aUnit)
Definition: lib_item.h:265
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetBezierC2(const wxPoint &aPt)
Definition: eda_shape.h:156
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:87

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

3355 {
3356  const char* line = aReader.Line();
3357 
3358  wxCHECK_MSG( strCompare( "C", line, &line ), nullptr, "Invalid circle definition" );
3359 
3360  LIB_SHAPE* circle = new LIB_SHAPE( aSymbol.get(), SHAPE_T::CIRCLE );
3361 
3362  wxPoint center;
3363 
3364  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3365  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3366 
3367  int radius = Mils2Iu( parseInt( aReader, line, &line ) );
3368 
3369  circle->SetStart( center );
3370  circle->SetEnd( wxPoint( center.x + radius, center.y ) );
3371  circle->SetUnit( parseInt( aReader, line, &line ) );
3372  circle->SetConvert( parseInt( aReader, line, &line ) );
3373  circle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3374 
3375  if( *line != 0 )
3376  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3377 
3378  return circle;
3379 }
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:135
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:110
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:97
void SetConvert(int aConvert)
Definition: lib_item.h:268
void SetUnit(int aUnit)
Definition: lib_item.h:265
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:87

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

2688 {
2689  const char* line;
2690  wxString text;
2691  wxString aliasName;
2692  wxFileName fn = m_libFileName;
2693  LIB_SYMBOL* symbol = nullptr;;
2694 
2695  fn.SetExt( DOC_EXT );
2696 
2697  // Not all libraries will have a document file.
2698  if( !fn.FileExists() )
2699  return;
2700 
2701  if( !fn.IsFileReadable() )
2702  {
2703  THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to read library '%s'." ),
2704  fn.GetFullPath() ) );
2705  }
2706 
2707  FILE_LINE_READER reader( fn.GetFullPath() );
2708 
2709  line = reader.ReadLine();
2710 
2711  if( !line )
2712  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2713 
2714  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2715  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2716  reader, line );
2717 
2718  while( reader.ReadLine() )
2719  {
2720  line = reader.Line();
2721 
2722  if( *line == '#' ) // Comment line.
2723  continue;
2724 
2725  if( !strCompare( "$CMP", line, &line ) != 0 )
2726  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2727 
2728  aliasName = wxString::FromUTF8( line );
2729  aliasName.Trim();
2730 
2731  LIB_SYMBOL_MAP::iterator it = m_symbols.find( aliasName );
2732 
2733  if( it == m_symbols.end() )
2734  wxLogWarning( "Symbol '%s' not found in library:\n\n"
2735  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2736  reader.LineNumber(), (int) (line - reader.Line() ) );
2737  else
2738  symbol = it->second;
2739 
2740  // Read the current alias associated doc.
2741  // if the alias does not exist, just skip the description
2742  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2743  while( reader.ReadLine() )
2744  {
2745  line = reader.Line();
2746 
2747  if( !line )
2748  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2749 
2750  if( strCompare( "$ENDCMP", line, &line ) )
2751  break;
2752 
2753  text = FROM_UTF8( line + 2 );
2754  // Remove spaces at eol, and eol chars:
2755  text = text.Trim();
2756 
2757  switch( line[0] )
2758  {
2759  case 'D':
2760  if( symbol )
2761  symbol->SetDescription( text );
2762  break;
2763 
2764  case 'K':
2765  if( symbol )
2766  symbol->SetKeyWords( text );
2767  break;
2768 
2769  case 'F':
2770  if( symbol )
2771  symbol->GetFieldById( DATASHEET_FIELD )->SetText( text );
2772  break;
2773 
2774  case 0:
2775  case '\n':
2776  case '\r':
2777  case '#':
2778  // Empty line or commment
2779  break;
2780 
2781  default:
2782  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2783  }
2784  }
2785  }
2786 }
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.
#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 3192 of file sch_legacy_plugin.cpp.

3196 {
3197  const char* line = aReader.Line();
3198 
3199  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
3200 
3201  line = aReader.ReadLine();
3202 
3203  while( line )
3204  {
3205  if( strCompare( "ENDDRAW", line, &line ) )
3206  {
3207  aSymbol->GetDrawItems().sort();
3208  return;
3209  }
3210 
3211  switch( line[0] )
3212  {
3213  case 'A': // Arc
3214  aSymbol->AddDrawItem( loadArc( aSymbol, aReader ), false );
3215  break;
3216 
3217  case 'C': // Circle
3218  aSymbol->AddDrawItem( loadCircle( aSymbol, aReader ), false );
3219  break;
3220 
3221  case 'T': // Text
3222  aSymbol->AddDrawItem( loadText( aSymbol, aReader, aMajorVersion,
3223  aMinorVersion ), false );
3224  break;
3225 
3226  case 'S': // Square
3227  aSymbol->AddDrawItem( loadRect( aSymbol, aReader ), false );
3228  break;
3229 
3230  case 'X': // Pin Description
3231  aSymbol->AddDrawItem( loadPin( aSymbol, aReader ), false );
3232  break;
3233 
3234  case 'P': // Polyline
3235  aSymbol->AddDrawItem( loadPolyLine( aSymbol, aReader ), false );
3236  break;
3237 
3238  case 'B': // Bezier Curves
3239  aSymbol->AddDrawItem( loadBezier( aSymbol, aReader ), false );
3240  break;
3241 
3242  case '#': // Comment
3243  case '\n': // Empty line
3244  case '\r':
3245  case 0:
3246  break;
3247 
3248  default:
3249  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
3250  }
3251 
3252  line = aReader.ReadLine();
3253  }
3254 
3255  SCH_PARSE_ERROR( "File ended prematurely loading symbol draw element.", aReader, line );
3256 }
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 3041 of file sch_legacy_plugin.cpp.

3043 {
3044  const char* line = aReader.Line();
3045 
3046  wxCHECK_RET( *line == 'F', "Invalid field line" );
3047 
3048  wxString text;
3049  int id;
3050 
3051  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
3052  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
3053 
3054  LIB_FIELD* field;
3055 
3056  if( id >= 0 && id < MANDATORY_FIELDS )
3057  {
3058  field = aSymbol->GetFieldById( id );
3059 
3060  // this will fire only if somebody broke a constructor or editor.
3061  // MANDATORY_FIELDS are always present in ram resident symbols, no
3062  // exceptions, and they always have their names set, even fixed fields.
3063  wxASSERT( field );
3064  }
3065  else
3066  {
3067  field = new LIB_FIELD( aSymbol.get(), id );
3068  aSymbol->AddDrawItem( field, false );
3069  }
3070 
3071  // Skip to the first double quote.
3072  while( *line != '"' && *line != 0 )
3073  line++;
3074 
3075  if( *line == 0 )
3076  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
3077 
3078  parseQuotedString( text, aReader, line, &line, true );
3079 
3080  // The value field needs to be "special" escaped. The other fields are
3081  // escaped normally and don't need special handling
3082  if( id == VALUE_FIELD )
3084 
3085  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
3086  // not save like this.
3087  if( text.size() == 1 && text[0] == '~' )
3088  field->SetText( wxEmptyString );
3089  else
3091 
3092  wxPoint pos;
3093 
3094  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
3095  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
3096  field->SetPosition( pos );
3097 
3098  wxSize textSize;
3099 
3100  textSize.x = textSize.y = Mils2Iu( parseInt( aReader, line, &line ) );
3101  field->SetTextSize( textSize );
3102 
3103  char textOrient = parseChar( aReader, line, &line );
3104 
3105  if( textOrient == 'H' )
3106  field->SetTextAngle( TEXT_ANGLE_HORIZ );
3107  else if( textOrient == 'V' )
3108  field->SetTextAngle( TEXT_ANGLE_VERT );
3109  else
3110  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
3111 
3112  char textVisible = parseChar( aReader, line, &line );
3113 
3114  if( textVisible == 'V' )
3115  field->SetVisible( true );
3116  else if ( textVisible == 'I' )
3117  field->SetVisible( false );
3118  else
3119  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
3120 
3121  // It may be technically correct to use the library version to determine if the field text
3122  // attributes are present. If anyone knows if that is valid and what version that would be,
3123  // please change this to test the library version rather than an EOL or the quoted string
3124  // of the field name.
3125  if( *line != 0 && *line != '"' )
3126  {
3127  char textHJustify = parseChar( aReader, line, &line );
3128 
3129  if( textHJustify == 'C' )
3131  else if( textHJustify == 'L' )
3133  else if( textHJustify == 'R' )
3135  else
3136  SCH_PARSE_ERROR( "invalid field text horizontal justification", aReader, line );
3137 
3138  wxString attributes;
3139 
3140  parseUnquotedString( attributes, aReader, line, &line );
3141 
3142  size_t attrSize = attributes.size();
3143 
3144  if( !(attrSize == 3 || attrSize == 1 ) )
3145  SCH_PARSE_ERROR( "invalid field text attributes size", aReader, line );
3146 
3147  switch( (wxChar) attributes[0] )
3148  {
3149  case 'C': field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3150  case 'B': field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3151  case 'T': field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3152  default: SCH_PARSE_ERROR( "invalid field text vertical justification", aReader, line );
3153  }
3154 
3155  if( attrSize == 3 )
3156  {
3157  wxChar attr_1 = attributes[1];
3158  wxChar attr_2 = attributes[2];
3159 
3160  if( attr_1 == 'I' ) // Italic
3161  field->SetItalic( true );
3162  else if( attr_1 != 'N' ) // No italics is default, check for error.
3163  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
3164 
3165  if ( attr_2 == 'B' ) // Bold
3166  field->SetBold( true );
3167  else if( attr_2 != 'N' ) // No bold is default, check for error.
3168  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
3169  }
3170  }
3171 
3172  // Fields in RAM must always have names.
3173  if( id >= 0 && id < MANDATORY_FIELDS )
3174  {
3175  // Fields in RAM must always have names, because we are trying to get
3176  // less dependent on field ids and more dependent on names.
3177  // Plus assumptions are made in the field editors.
3179 
3180  // Ensure the VALUE field = the symbol name (can be not the case
3181  // with malformed libraries: edited by hand, or converted from other tools)
3182  if( id == VALUE_FIELD )
3183  field->SetText( aSymbol->GetName() );
3184  }
3185  else
3186  {
3187  parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
3188  }
3189 }
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:230
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 EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
wxString m_name
Name (not the field text value itself, that is #EDA_TEXT::m_Text)
Definition: lib_field.h:209
void SetBold(bool aBold)
Definition: eda_text.h:203

References _, ConvertToNewOverbarNotation(), CTX_QUOTED_STR, EscapeString(), 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 3778 of file sch_legacy_plugin.cpp.

3780 {
3781  const char* line = aReader.Line();
3782 
3783  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3784 
3785  line = aReader.ReadLine();
3786 
3787  wxArrayString footprintFilters;
3788 
3789  while( line )
3790  {
3791  if( strCompare( "$ENDFPLIST", line, &line ) )
3792  {
3793  aSymbol->SetFPFilters( footprintFilters );
3794  return;
3795  }
3796 
3797  wxString footprint;
3798 
3799  parseUnquotedString( footprint, aReader, line, &line );
3800  footprintFilters.Add( footprint );
3801  line = aReader.ReadLine();
3802  }
3803 
3804  SCH_PARSE_ERROR( "File ended prematurely while loading footprint filters.", aReader, line );
3805 }
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 2789 of file sch_legacy_plugin.cpp.

2790 {
2791  const char* line = aReader.Line();
2792 
2793  wxASSERT( strCompare( "$HEADER", line, &line ) );
2794 
2795  while( aReader.ReadLine() )
2796  {
2797  line = (char*) aReader;
2798 
2799  // The time stamp saved in old library files is not used or saved in the latest
2800  // library file version.
2801  if( strCompare( "TimeStamp", line, &line ) )
2802  continue;
2803  else if( strCompare( "$ENDHEADER", line, &line ) )
2804  return;
2805  }
2806 
2807  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2808 }
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 2811 of file sch_legacy_plugin.cpp.

2813 {
2814  const char* line = aReader.Line();
2815 
2816  while( *line == '#' )
2817  aReader.ReadLine();
2818 
2819  if( !strCompare( "DEF", line, &line ) )
2820  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2821 
2822  long num;
2823  size_t pos = 4; // "DEF" plus the first space.
2824  wxString utf8Line = wxString::FromUTF8( line );
2825  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2826 
2827  if( tokens.CountTokens() < 8 )
2828  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2829 
2830  // Read DEF line:
2831  std::unique_ptr<LIB_SYMBOL> symbol = std::make_unique<LIB_SYMBOL>( wxEmptyString );
2832 
2833  wxString name, prefix, tmp;
2834 
2835  name = tokens.GetNextToken();
2836 
2837  // Don't escape symbol library name if it's already been escaped. Given that the original
2838  // change to escape the symbol library name has resulted in rescue libraries with escaped
2839  // names, we will have to live with the consequences.
2840  if( name == UnescapeString( name ) )
2842 
2843  pos += name.size() + 1;
2844 
2845  prefix = tokens.GetNextToken();
2846  pos += prefix.size() + 1;
2847 
2848  tmp = tokens.GetNextToken();
2849  pos += tmp.size() + 1; // NumOfPins, unused.
2850 
2851  tmp = tokens.GetNextToken(); // Pin name offset.
2852 
2853  if( !tmp.ToLong( &num ) )
2854  THROW_PARSE_ERROR( "invalid pin offset", aReader.GetSource(), aReader.Line(),
2855  aReader.LineNumber(), pos );
2856 
2857  pos += tmp.size() + 1;
2858  symbol->SetPinNameOffset( Mils2Iu( (int)num ) );
2859 
2860  tmp = tokens.GetNextToken(); // Show pin numbers.
2861 
2862  if( !( tmp == "Y" || tmp == "N") )
2863  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2864  aReader.LineNumber(), pos );
2865 
2866  pos += tmp.size() + 1;
2867  symbol->SetShowPinNumbers( ( tmp == "N" ) ? false : true );
2868 
2869  tmp = tokens.GetNextToken(); // Show pin names.
2870 
2871  if( !( tmp == "Y" || tmp == "N") )
2872  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2873  aReader.LineNumber(), pos );
2874 
2875  pos += tmp.size() + 1;
2876  symbol->SetShowPinNames( ( tmp == "N" ) ? false : true );
2877 
2878  tmp = tokens.GetNextToken(); // Number of units.
2879 
2880  if( !tmp.ToLong( &num ) )
2881  THROW_PARSE_ERROR( "invalid unit count", aReader.GetSource(), aReader.Line(),
2882  aReader.LineNumber(), pos );
2883 
2884  pos += tmp.size() + 1;
2885  symbol->SetUnitCount( (int)num );
2886 
2887  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2888  if( symbol->GetUnitCount() < 1 )
2889  symbol->SetUnitCount( 1 );
2890 
2891  // Copy symbol name and prefix.
2892 
2893  // The root alias is added to the alias list by SetName() which is called by SetText().
2894  if( name.IsEmpty() )
2895  {
2896  symbol->SetName( "~" );
2897  }
2898  else if( name[0] != '~' )
2899  {
2900  symbol->SetName( name );
2901  }
2902  else
2903  {
2904  symbol->SetName( name.Right( name.Length() - 1 ) );
2905  symbol->GetValueField().SetVisible( false );
2906  }
2907 
2908  // Don't set the library alias, this is determined by the symbol library table.
2909  symbol->SetLibId( LIB_ID( wxEmptyString, symbol->GetName() ) );
2910 
2911  LIB_FIELD& reference = symbol->GetReferenceField();
2912 
2913  if( prefix == "~" )
2914  {
2915  reference.Empty();
2916  reference.SetVisible( false );
2917  }
2918  else
2919  {
2920  reference.SetText( prefix );
2921  }
2922 
2923  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2924  // The was no concept of interchangeable multiple unit symbols.
2925  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
2926  && LIB_VERSION( aMajorVersion, aMinorVersion ) <= LIB_VERSION( 2, 2 ) )
2927  {
2928  // Nothing needs to be set since the default setting for symbols with multiple
2929  // units were never interchangeable. Just parse the 0 an move on.
2930  tmp = tokens.GetNextToken();
2931  pos += tmp.size() + 1;
2932  }
2933  else
2934  {
2935  tmp = tokens.GetNextToken();
2936 
2937  if( tmp == "L" )
2938  symbol->LockUnits( true );
2939  else if( tmp == "F" || tmp == "0" )
2940  symbol->LockUnits( false );
2941  else
2942  THROW_PARSE_ERROR( "expected L, F, or 0", aReader.GetSource(), aReader.Line(),
2943  aReader.LineNumber(), pos );
2944 
2945  pos += tmp.size() + 1;
2946  }
2947 
2948  // There is the optional power symbol flag.
2949  if( tokens.HasMoreTokens() )
2950  {
2951  tmp = tokens.GetNextToken();
2952 
2953  if( tmp == "P" )
2954  symbol->SetPower();
2955  else if( tmp == "N" )
2956  symbol->SetNormal();
2957  else
2958  THROW_PARSE_ERROR( "expected P or N", aReader.GetSource(), aReader.Line(),
2959  aReader.LineNumber(), pos );
2960  }
2961 
2962  line = aReader.ReadLine();
2963 
2964  // Read lines until "ENDDEF" is found.
2965  while( line )
2966  {
2967  if( *line == '#' ) // Comment
2968  ;
2969  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2970  continue;
2971  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2972  loadAliases( symbol, aReader, aMap );
2973  else if( *line == 'F' ) // Fields
2974  loadField( symbol, aReader );
2975  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2976  loadDrawEntries( symbol, aReader, aMajorVersion, aMinorVersion );
2977  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2978  loadFootprintFilters( symbol, aReader );
2979  else if( strCompare( "ENDDEF", line, &line ) ) // End of symbol description
2980  {
2981  return symbol.release();
2982  }
2983 
2984  line = aReader.ReadLine();
2985  }
2986 
2987  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2988 }
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
wxString UnescapeString(const wxString &aSource)
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
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
static void loadFootprintFilters(std::unique_ptr< LIB_SYMBOL > &aSymbol, LINE_READER &aReader)
#define LIB_VERSION(major, minor)

References CTX_LIBID, EDA_TEXT::Empty(), EscapeString(), 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(), THROW_PARSE_ERROR, and UnescapeString().

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

3513 {
3514  const char* line = aReader.Line();
3515 
3516  wxCHECK_MSG( strCompare( "X", line, &line ), nullptr, "Invalid LIB_PIN definition" );
3517 
3518  wxString name;
3519  wxString number;
3520 
3521  size_t pos = 2; // "X" plus ' ' space character.
3522  wxString tmp;
3523  wxString utf8Line = wxString::FromUTF8( line );
3524  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
3525 
3526  if( tokens.CountTokens() < 11 )
3527  SCH_PARSE_ERROR( "invalid pin definition", aReader, line );
3528 
3529  tmp = tokens.GetNextToken();
3530  name = tmp;
3531  pos += tmp.size() + 1;
3532 
3533  tmp = tokens.GetNextToken();
3534  number = tmp ;
3535  pos += tmp.size() + 1;
3536 
3537  long num;
3538  wxPoint position;
3539 
3540  tmp = tokens.GetNextToken();
3541 
3542  if( !tmp.ToLong( &num ) )
3543  THROW_PARSE_ERROR( "invalid pin X coordinate", aReader.GetSource(), aReader.Line(),
3544  aReader.LineNumber(), pos );
3545 
3546  pos += tmp.size() + 1;
3547  position.x = Mils2Iu( (int) num );
3548 
3549  tmp = tokens.GetNextToken();
3550 
3551  if( !tmp.ToLong( &num ) )
3552  THROW_PARSE_ERROR( "invalid pin Y coordinate", aReader.GetSource(), aReader.Line(),
3553  aReader.LineNumber(), pos );
3554 
3555  pos += tmp.size() + 1;
3556  position.y = Mils2Iu( (int) num );
3557 
3558  tmp = tokens.GetNextToken();
3559 
3560  if( !tmp.ToLong( &num ) )
3561  THROW_PARSE_ERROR( "invalid pin length", aReader.GetSource(), aReader.Line(),
3562  aReader.LineNumber(), pos );
3563 
3564  pos += tmp.size() + 1;
3565  int length = Mils2Iu( (int) num );
3566 
3567 
3568  tmp = tokens.GetNextToken();
3569 
3570  if( tmp.size() > 1 )
3571  THROW_PARSE_ERROR( "invalid pin orientation", aReader.GetSource(), aReader.Line(),
3572  aReader.LineNumber(), pos );
3573 
3574  pos += tmp.size() + 1;
3575  int orientation = tmp[0];
3576 
3577  tmp = tokens.GetNextToken();
3578 
3579  if( !tmp.ToLong( &num ) )
3580  THROW_PARSE_ERROR( "invalid pin number text size", aReader.GetSource(), aReader.Line(),
3581  aReader.LineNumber(), pos );
3582 
3583  pos += tmp.size() + 1;
3584  int numberTextSize = Mils2Iu( (int) num );
3585 
3586  tmp = tokens.GetNextToken();
3587 
3588  if( !tmp.ToLong( &num ) )
3589  THROW_PARSE_ERROR( "invalid pin name text size", aReader.GetSource(), aReader.Line(),
3590  aReader.LineNumber(), pos );
3591 
3592  pos += tmp.size() + 1;
3593  int nameTextSize = Mils2Iu( (int) num );
3594 
3595  tmp = tokens.GetNextToken();
3596 
3597  if( !tmp.ToLong( &num ) )
3598  THROW_PARSE_ERROR( "invalid pin unit", aReader.GetSource(), aReader.Line(),
3599  aReader.LineNumber(), pos );
3600 
3601  pos += tmp.size() + 1;
3602  int unit = (int) num;
3603 
3604  tmp = tokens.GetNextToken();
3605 
3606  if( !tmp.ToLong( &num ) )
3607  THROW_PARSE_ERROR( "invalid pin alternate body type", aReader.GetSource(), aReader.Line(),
3608  aReader.LineNumber(), pos );
3609 
3610  pos += tmp.size() + 1;
3611  int convert = (int) num;
3612 
3613  tmp = tokens.GetNextToken();
3614 
3615  if( tmp.size() != 1 )
3616  THROW_PARSE_ERROR( "invalid pin type", aReader.GetSource(), aReader.Line(),
3617  aReader.LineNumber(), pos );
3618 
3619  pos += tmp.size() + 1;
3620  char type = tmp[0];
3621  ELECTRICAL_PINTYPE pinType;
3622 
3623  switch( type )
3624  {
3625  case 'I': pinType = ELECTRICAL_PINTYPE::PT_INPUT; break;
3626  case 'O': pinType = ELECTRICAL_PINTYPE::PT_OUTPUT; break;
3627  case 'B': pinType = ELECTRICAL_PINTYPE::PT_BIDI; break;
3628  case 'T': pinType = ELECTRICAL_PINTYPE::PT_TRISTATE; break;
3629  case 'P': pinType = ELECTRICAL_PINTYPE::PT_PASSIVE; break;
3630  case 'U': pinType = ELECTRICAL_PINTYPE::PT_UNSPECIFIED; break;
3631  case 'W': pinType = ELECTRICAL_PINTYPE::PT_POWER_IN; break;
3632  case 'w': pinType = ELECTRICAL_PINTYPE::PT_POWER_OUT; break;
3633  case 'C': pinType = ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR; break;
3634  case 'E': pinType = ELECTRICAL_PINTYPE::PT_OPENEMITTER; break;
3635  case 'N': pinType = ELECTRICAL_PINTYPE::PT_NC; break;
3636  default:
3637  THROW_PARSE_ERROR( "unknown pin type", aReader.GetSource(), aReader.Line(),
3638  aReader.LineNumber(), pos );
3639  }
3640 
3641 
3642  LIB_PIN* pin = new LIB_PIN( aSymbol.get(),
3644  ConvertToNewOverbarNotation( number ),
3645  orientation,
3646  pinType,
3647  length,
3648  nameTextSize,
3649  numberTextSize,
3650  convert,
3651  position,
3652  unit );
3653 
3654  // Optional
3655  if( tokens.HasMoreTokens() ) /* Special Symbol defined */
3656  {
3657  tmp = tokens.GetNextToken();
3658 
3659  enum
3660  {
3661  INVERTED = 1 << 0,
3662  CLOCK = 1 << 1,
3663  LOWLEVEL_IN = 1 << 2,
3664  LOWLEVEL_OUT = 1 << 3,
3665  FALLING_EDGE = 1 << 4,
3666  NONLOGIC = 1 << 5
3667  };
3668 
3669  int flags = 0;
3670 
3671  for( int j = tmp.size(); j > 0; )
3672  {
3673  switch( tmp[--j].GetValue() )
3674  {
3675  case '~': break;
3676  case 'N': pin->SetVisible( false ); break;
3677  case 'I': flags |= INVERTED; break;
3678  case 'C': flags |= CLOCK; break;
3679  case 'L': flags |= LOWLEVEL_IN; break;
3680  case 'V': flags |= LOWLEVEL_OUT; break;
3681  case 'F': flags |= FALLING_EDGE; break;
3682  case 'X': flags |= NONLOGIC; break;
3683  default: THROW_PARSE_ERROR( "invalid pin attribut", aReader.GetSource(),
3684  aReader.Line(), aReader.LineNumber(), pos );
3685  }
3686 
3687  pos += 1;
3688  }
3689 
3690  switch( flags )
3691  {
3692  case 0: pin->SetShape( GRAPHIC_PINSHAPE::LINE ); break;
3693  case INVERTED: pin->SetShape( GRAPHIC_PINSHAPE::INVERTED ); break;
3694  case CLOCK: pin->SetShape( GRAPHIC_PINSHAPE::CLOCK ); break;
3695  case INVERTED | CLOCK: pin->SetShape( GRAPHIC_PINSHAPE::INVERTED_CLOCK ); break;
3696  case LOWLEVEL_IN: pin->SetShape( GRAPHIC_PINSHAPE::INPUT_LOW ); break;
3697  case LOWLEVEL_IN | CLOCK: pin->SetShape( GRAPHIC_PINSHAPE::CLOCK_LOW ); break;
3698  case LOWLEVEL_OUT: pin->SetShape( GRAPHIC_PINSHAPE::OUTPUT_LOW ); break;
3699  case FALLING_EDGE: pin->SetShape( GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK ); break;
3700  case NONLOGIC: pin->SetShape( GRAPHIC_PINSHAPE::NONLOGIC ); break;
3701  default:
3702  SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3703  }
3704  }
3705 
3706  return pin;
3707 }
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 3710 of file sch_legacy_plugin.cpp.

3712 {
3713  const char* line = aReader.Line();
3714 
3715  wxCHECK_MSG( strCompare( "P", line, &line ), nullptr, "Invalid poly definition" );
3716 
3717  LIB_SHAPE* polyLine = new LIB_SHAPE( aSymbol.get(), SHAPE_T::POLY );
3718 
3719  int points = parseInt( aReader, line, &line );
3720  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3721  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3722  polyLine->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3723 
3724  wxPoint pt;
3725 
3726  for( int i = 0; i < points; i++ )
3727  {
3728  pt.x = Mils2Iu( parseInt( aReader, line, &line ) );
3729  pt.y = Mils2Iu( parseInt( aReader, line, &line ) );
3730  polyLine->AddPoint( pt );
3731  }
3732 
3733  if( *line != 0 )
3734  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3735 
3736  return polyLine;
3737 }
void AddPoint(const wxPoint &aPosition)
Definition: lib_shape.cpp:414
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:97
void SetConvert(int aConvert)
Definition: lib_item.h:268
void SetUnit(int aUnit)
Definition: lib_item.h:265
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:87

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

3481 {
3482  const char* line = aReader.Line();
3483 
3484  wxCHECK_MSG( strCompare( "S", line, &line ), nullptr, "Invalid rectangle definition" );
3485 
3486  LIB_SHAPE* rectangle = new LIB_SHAPE( aSymbol.get(), SHAPE_T::RECT );
3487 
3488  wxPoint pos;
3489 
3490  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
3491  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
3492  rectangle->SetPosition( pos );
3493 
3494  wxPoint end;
3495 
3496  end.x = Mils2Iu( parseInt( aReader, line, &line ) );
3497  end.y = Mils2Iu( parseInt( aReader, line, &line ) );
3498  rectangle->SetEnd( end );
3499 
3500  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3501  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3502  rectangle->SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
3503 
3504  if( *line != 0 )
3505  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3506 
3507  return rectangle;
3508 }
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:135
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:88
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:97
void SetConvert(int aConvert)
Definition: lib_item.h:268
void SetUnit(int aUnit)
Definition: lib_item.h:265
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:87

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

3386 {
3387  const char* line = aReader.Line();
3388 
3389  wxCHECK_MSG( strCompare( "T", line, &line ), nullptr, "Invalid LIB_TEXT definition" );
3390 
3391  LIB_TEXT* text = new LIB_TEXT( aSymbol.get() );
3392 
3393  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3394 
3395  wxPoint center;
3396 
3397  center.x = Mils2Iu( parseInt( aReader, line, &line ) );
3398  center.y = Mils2Iu( parseInt( aReader, line, &line ) );
3399  text->SetPosition( center );
3400 
3401  wxSize size;
3402 
3403  size.x = size.y = Mils2Iu( parseInt( aReader, line, &line ) );
3404  text->SetTextSize( size );
3405  text->SetVisible( !parseInt( aReader, line, &line ) );
3406  text->SetUnit( parseInt( aReader, line, &line ) );
3407  text->SetConvert( parseInt( aReader, line, &line ) );
3408 
3409  wxString str;
3410 
3411  // If quoted string loading fails, load as not quoted string.
3412  if( *line == '"' )
3413  {
3414  parseQuotedString( str, aReader, line, &line );
3415 
3416  str = ConvertToNewOverbarNotation( str );
3417  }
3418  else
3419  {
3420  parseUnquotedString( str, aReader, line, &line );
3421 
3422  // In old libs, "spaces" are replaced by '~' in unquoted strings:
3423  str.Replace( "~", " " );
3424  }
3425 
3426  if( !str.IsEmpty() )
3427  {
3428  // convert two apostrophes back to double quote
3429  str.Replace( "''", "\"" );
3430  }
3431 
3432  text->SetText( str );
3433 
3434  // Here things are murky and not well defined. At some point it appears the format
3435  // was changed to add text properties. However rather than add the token to the end of
3436  // the text definition, it was added after the string and no mention if the file
3437  // verion was bumped or not so this code make break on very old symbol libraries.
3438  //
3439  // Update: apparently even in the latest version this can be different so added a test
3440  // for end of line before checking for the text properties.
3441  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
3442  && LIB_VERSION( aMajorVersion, aMinorVersion ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3443  {
3444  if( strCompare( "Italic", line, &line ) )
3445  text->SetItalic( true );
3446  else if( !strCompare( "Normal", line, &line ) )
3447  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );
3448 
3449  if( parseInt( aReader, line, &line ) > 0 )
3450  text->SetBold( true );
3451 
3452  // Some old libaries version > 2.0 do not have these options for text justification:
3453  if( !is_eol( *line ) )
3454  {
3455  switch( parseChar( aReader, line, &line ) )
3456  {
3457  case 'L': text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
3458  case 'C': text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
3459  case 'R': text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
3460  default: SCH_PARSE_ERROR( "invalid horizontal text justication; expected L, C, or R",
3461  aReader, line );
3462  }
3463 
3464  switch( parseChar( aReader, line, &line ) )
3465  {
3466  case 'T': text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3467  case 'C': text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3468  case 'B': text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3469  default: SCH_PARSE_ERROR( "invalid vertical text justication; expected T, C, or B",
3470  aReader, line );
3471  }
3472  }
3473  }
3474 
3475  return text;
3476 }
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 3259 of file sch_legacy_plugin.cpp.

3261 {
3262  switch ( parseChar( aReader, aLine, aOutput ) )
3263  {
3264  case 'F': return FILL_T::FILLED_SHAPE;
3265  case 'f': return FILL_T::FILLED_WITH_BG_BODYCOLOR;
3266  case 'N': return FILL_T::NO_FILL;
3267  default: SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
3268  }
3269 
3270  // This will never be reached but quiets the compiler warnings
3271  return FILL_T::NO_FILL;
3272 }
#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 2517 of file sch_legacy_plugin.cpp.

2518 {
2519  wxCHECK_MSG( aSymbol != nullptr, nullptr, "NULL pointer cannot be removed from library." );
2520 
2521  LIB_SYMBOL* firstChild = nullptr;
2522  LIB_SYMBOL_MAP::iterator it = m_symbols.find( aSymbol->GetName() );
2523 
2524  if( it == m_symbols.end() )
2525  return nullptr;
2526 
2527  // If the entry pointer doesn't match the name it is mapped to in the library, we
2528  // have done something terribly wrong.
2529  wxCHECK_MSG( *it->second == aSymbol, nullptr,
2530  "Pointer mismatch while attempting to remove alias entry <" + aSymbol->GetName() +
2531  "> from library cache <" + m_libFileName.GetName() + ">." );
2532 
2533  // If the symbol is a root symbol used by other symbols find the first alias that uses
2534  // the root symbol and make it the new root.
2535  if( aSymbol->IsRoot() )
2536  {
2537  for( auto entry : m_symbols )
2538  {
2539  if( entry.second->IsAlias()
2540  && entry.second->GetParent().lock() == aSymbol->SharedPtr() )
2541  {
2542  firstChild = entry.second;
2543  break;
2544  }
2545  }
2546 
2547  if( firstChild )
2548  {
2549  for( LIB_ITEM& drawItem : aSymbol->GetDrawItems() )
2550  {
2551  if( drawItem.Type() == LIB_FIELD_T )
2552  {
2553  LIB_FIELD& field = static_cast<LIB_FIELD&>( drawItem );
2554 
2555  if( firstChild->FindField( field.GetCanonicalName() ) )
2556  continue;
2557  }
2558 
2559  LIB_ITEM* newItem = (LIB_ITEM*) drawItem.Clone();
2560  drawItem.SetParent( firstChild );
2561  firstChild->AddDrawItem( newItem );
2562  }
2563 
2564  // Reparent the remaining aliases.
2565  for( auto entry : m_symbols )
2566  {
2567  if( entry.second->IsAlias()
2568  && entry.second->GetParent().lock() == aSymbol->SharedPtr() )
2569  entry.second->SetParent( firstChild );
2570  }
2571  }
2572  }
2573 
2574  m_symbols.erase( it );
2575  delete aSymbol;
2576  m_isModified = true;
2578  return firstChild;
2579 }
LIB_FIELD * FindField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName and returns it or NULL if not found.
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:115
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:402
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:716

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

3809 {
3810  if( !m_isModified )
3811  return;
3812 
3813  // Write through symlinks, don't replace them
3814  wxFileName fn = GetRealFile();
3815 
3816  auto formatter = std::make_unique<FILE_OUTPUTFORMATTER>( fn.GetFullPath() );
3817  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3818  formatter->Print( 0, "#encoding utf-8\n");
3819 
3820  for( LIB_SYMBOL_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); it++ )
3821  {
3822  if( !it->second->IsRoot() )
3823  continue;
3824 
3825  SaveSymbol( it->second, *formatter.get(), &m_symbols );
3826  }
3827 
3828  formatter->Print( 0, "#\n#End Library\n" );
3829  formatter.reset();
3830 
3831  m_fileModTime = fn.GetModificationTime();
3832  m_isModified = false;
3833 
3834  if( aSaveDocFile )
3835  saveDocFile();
3836 }
#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().

◆ saveArc()

void SCH_LEGACY_PLUGIN_CACHE::saveArc ( LIB_SHAPE aArc,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 3992 of file sch_legacy_plugin.cpp.

3993 {
3994  wxCHECK_RET( aArc && aArc->GetShape() == SHAPE_T::ARC, "Invalid ARC object." );
3995 
3996  int x1;
3997  int x2;
3998 
3999  aArc->CalcArcAngles( x1, x2 );
4000 
4001  if( x1 > 1800 )
4002  x1 -= 3600;
4003 
4004  if( x2 > 1800 )
4005  x2 -= 3600;
4006 
4007  aFormatter.Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
4008  Iu2Mils( aArc->GetPosition().x ),
4009  Iu2Mils( aArc->GetPosition().y ),
4010  Iu2Mils( aArc->GetRadius() ),
4011  x1,
4012  x2,
4013  aArc->GetUnit(),
4014  aArc->GetConvert(),
4015  Iu2Mils( aArc->GetWidth() ),
4016  fill_tab[ static_cast<int>( aArc->GetFillType() ) - 1 ],
4017  Iu2Mils( aArc->GetStart().x ),
4018  Iu2Mils( aArc->GetStart().y ),
4019  Iu2Mils( aArc->GetEnd().x ),
4020  Iu2Mils( aArc->GetEnd().y ) );
4021 }
void CalcArcAngles(int &aStartAngle, int &aEndAngle) const
Definition: lib_shape.cpp:430
int GetWidth() const
Definition: eda_shape.h:98
const wxPoint & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:106
int GetUnit() const
Definition: lib_item.h:266
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:131
const int fill_tab[3]
Definition: lib_item.cpp:32
int GetConvert() const
Definition: lib_item.h:269
SHAPE_T GetShape() const
Definition: eda_shape.h:101
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
int GetRadius() const
Definition: eda_shape.cpp:472
wxPoint GetPosition() const override
Definition: lib_shape.h:87
FILL_T GetFillType() const
Definition: eda_shape.h:88

References ARC, LIB_SHAPE::CalcArcAngles(), fill_tab, LIB_ITEM::GetConvert(), EDA_SHAPE::GetEnd(), EDA_SHAPE::GetFillType(), LIB_SHAPE::GetPosition(), EDA_SHAPE::GetRadius(), EDA_SHAPE::GetShape(), EDA_SHAPE::GetStart(), LIB_ITEM::GetUnit(), EDA_SHAPE::GetWidth(), and OUTPUTFORMATTER::Print().

Referenced by SaveSymbol().

◆ saveBezier()

void SCH_LEGACY_PLUGIN_CACHE::saveBezier ( LIB_SHAPE aBezier,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4024 of file sch_legacy_plugin.cpp.

4025 {
4026  wxCHECK_RET( aBezier && aBezier->GetShape() == SHAPE_T::BEZIER, "Invalid BEZIER object." );
4027 
4028  aFormatter.Print( 0, "B %u %d %d %d",
4029  (unsigned)aBezier->GetBezierPoints().size(),
4030  aBezier->GetUnit(),
4031  aBezier->GetConvert(),
4032  Iu2Mils( aBezier->GetWidth() ) );
4033 
4034  for( const wxPoint& pt : aBezier->GetBezierPoints() )
4035  aFormatter.Print( 0, " %d %d", Iu2Mils( pt.x ), Iu2Mils( pt.y ) );
4036 
4037  aFormatter.Print( 0, " %c\n", fill_tab[ static_cast<int>( aBezier->GetFillType() ) - 1 ] );
4038 }
const std::vector< wxPoint > & GetBezierPoints() const
Definition: eda_shape.h:210
int GetWidth() const
Definition: eda_shape.h:98
int GetUnit() const
Definition: lib_item.h:266
const int fill_tab[3]
Definition: lib_item.cpp:32
int GetConvert() const
Definition: lib_item.h:269
SHAPE_T GetShape() const
Definition: eda_shape.h:101
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
FILL_T GetFillType() const
Definition: eda_shape.h:88

References BEZIER, fill_tab, EDA_SHAPE::GetBezierPoints(), LIB_ITEM::GetConvert(), EDA_SHAPE::GetFillType(), EDA_SHAPE::GetShape(), LIB_ITEM::GetUnit(), EDA_SHAPE::GetWidth(), and OUTPUTFORMATTER::Print().

Referenced by SaveSymbol().

◆ saveCircle()

void SCH_LEGACY_PLUGIN_CACHE::saveCircle ( LIB_SHAPE aCircle,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4041 of file sch_legacy_plugin.cpp.

4042 {
4043  wxCHECK_RET( aCircle && aCircle->GetShape() == SHAPE_T::CIRCLE, "Invalid CIRCLE object." );
4044 
4045  aFormatter.Print( 0, "C %d %d %d %d %d %d %c\n",
4046  Iu2Mils( aCircle->GetPosition().x ),
4047  Iu2Mils( aCircle->GetPosition().y ),
4048  Iu2Mils( aCircle->GetRadius() ),
4049  aCircle->GetUnit(),
4050  aCircle->GetConvert(),
4051  Iu2Mils( aCircle->GetWidth() ),
4052  fill_tab[ static_cast<int>( aCircle->GetFillType() ) - 1 ] );
4053 }
int GetWidth() const
Definition: eda_shape.h:98
int GetUnit() const
Definition: lib_item.h:266
const int fill_tab[3]
Definition: lib_item.cpp:32
int GetConvert() const
Definition: lib_item.h:269
SHAPE_T GetShape() const
Definition: eda_shape.h:101
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
int GetRadius() const
Definition: eda_shape.cpp:472
wxPoint GetPosition() const override
Definition: lib_shape.h:87
FILL_T GetFillType() const
Definition: eda_shape.h:88

References CIRCLE, fill_tab, LIB_ITEM::GetConvert(), EDA_SHAPE::GetFillType(), LIB_SHAPE::GetPosition(), EDA_SHAPE::GetRadius(), EDA_SHAPE::GetShape(), LIB_ITEM::GetUnit(), EDA_SHAPE::GetWidth(), and OUTPUTFORMATTER::Print().

Referenced by SaveSymbol().

◆ saveDocFile()

void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 4240 of file sch_legacy_plugin.cpp.

4241 {
4242  /*
4243  * NB:
4244  * Some of the rescue code still uses the legacy format as an intermediary, so we have
4245  * to keep this code.
4246  */
4247 
4248  wxFileName fileName = m_libFileName;
4249 
4250  fileName.SetExt( DOC_EXT );
4251  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
4252 
4253  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
4254 
4255  for( LIB_SYMBOL_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); ++it )
4256  {
4257  wxString description = it->second->GetDescription();
4258  wxString keyWords = it->second->GetKeyWords();
4259  wxString docFileName = it->second->GetDatasheetField().GetText();
4260 
4261  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
4262  continue;
4263 
4264  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
4265 
4266  if( !description.IsEmpty() )
4267  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
4268 
4269  if( !keyWords.IsEmpty() )
4270  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
4271 
4272  if( !docFileName.IsEmpty() )
4273  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
4274 
4275  formatter.Print( 0, "$ENDCMP\n" );
4276  }
4277 
4278  formatter.Print( 0, "#\n#End Doc Library\n" );
4279 }
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
#define DOC_EXT
#define DOCFILE_IDENT
Used for text file output.
Definition: richio.h:456
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426

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

Referenced by Save().

◆ saveField()

void SCH_LEGACY_PLUGIN_CACHE::saveField ( const LIB_FIELD aField,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4056 of file sch_legacy_plugin.cpp.

4057 {
4058  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
4059 
4060  int hjustify, vjustify;
4061  int id = aField->GetId();
4062  wxString text = aField->GetText();
4063 
4064  hjustify = 'C';
4065 
4066  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
4067  hjustify = 'L';
4068  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
4069  hjustify = 'R';
4070 
4071  vjustify = 'C';
4072 
4073  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
4074  vjustify = 'B';
4075  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
4076  vjustify = 'T';
4077 
4078  aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
4079  id,
4080  EscapedUTF8( text ).c_str(), // wraps in quotes
4081  Iu2Mils( aField->GetTextPos().x ),
4082  Iu2Mils( aField->GetTextPos().y ),
4083  Iu2Mils( aField->GetTextWidth() ),
4084  aField->GetTextAngle() == 0 ? 'H' : 'V',
4085  aField->IsVisible() ? 'V' : 'I',
4086  hjustify, vjustify,
4087  aField->IsItalic() ? 'I' : 'N',
4088  aField->IsBold() ? 'B' : 'N' );
4089 
4090  /* Save field name, if necessary
4091  * Field name is saved only if it is not the default name.
4092  * Just because default name depends on the language and can change from
4093  * a country to another
4094  */
4095  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
4096 
4097  if( id >= MANDATORY_FIELDS && !aField->m_name.IsEmpty() && aField->m_name != defName )
4098  aFormatter.Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
4099 
4100  aFormatter.Print( 0, "\n" );
4101 }
bool IsBold() const
Definition: eda_text.h:204
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:220
double GetTextAngle() const
Definition: eda_text.h:195
int GetId() const
Definition: lib_field.h:115
bool IsItalic() const
Definition: eda_text.h:201
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:219
virtual bool IsVisible() const
Definition: eda_text.h:207
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.
int GetTextWidth() const
Definition: eda_text.h:262
const wxPoint & GetTextPos() const
Definition: eda_text.h:268
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
wxString m_name
Name (not the field text value itself, that is #EDA_TEXT::m_Text)
Definition: lib_field.h:209
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:154
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References EscapedUTF8(), TEMPLATE_FIELDNAME::GetDefaultFieldName(), EDA_TEXT::GetHorizJustify(), LIB_FIELD::GetId(), EDA_TEXT::GetText(), 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(), EDA_TEXT::IsVisible(), LIB_FIELD_T, LIB_FIELD::m_name, MANDATORY_FIELDS, OUTPUTFORMATTER::Print(), text, and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ savePin()

void SCH_LEGACY_PLUGIN_CACHE::savePin ( const LIB_PIN aPin,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4104 of file sch_legacy_plugin.cpp.

4105 {
4106  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
4107 
4108  int Etype;
4109 
4110  switch( aPin->GetType() )
4111  {
4112  default:
4113  case ELECTRICAL_PINTYPE::PT_INPUT: Etype = 'I'; break;
4114  case ELECTRICAL_PINTYPE::PT_OUTPUT: Etype = 'O'; break;
4115  case ELECTRICAL_PINTYPE::PT_BIDI: Etype = 'B'; break;
4116  case ELECTRICAL_PINTYPE::PT_TRISTATE: Etype = 'T'; break;
4117  case ELECTRICAL_PINTYPE::PT_PASSIVE: Etype = 'P'; break;
4118  case ELECTRICAL_PINTYPE::PT_UNSPECIFIED: Etype = 'U'; break;
4119  case ELECTRICAL_PINTYPE::PT_POWER_IN: Etype = 'W'; break;
4120  case ELECTRICAL_PINTYPE::PT_POWER_OUT: Etype = 'w'; break;
4121  case ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR: Etype = 'C'; break;
4122  case ELECTRICAL_PINTYPE::PT_OPENEMITTER: Etype = 'E'; break;
4123  case ELECTRICAL_PINTYPE::PT_NC: Etype = 'N'; break;
4124  }
4125 
4126  if( !aPin->GetName().IsEmpty() )
4127  aFormatter.Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
4128  else
4129  aFormatter.Print( 0, "X ~" );
4130 
4131  aFormatter.Print( 0, " %s %d %d %d %c %d %d %d %d %c",
4132  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
4133  Iu2Mils( aPin->GetPosition().x ),
4134  Iu2Mils( aPin->GetPosition().y ),
4135  Iu2Mils( (int) aPin->GetLength() ),
4136  (int) aPin->GetOrientation(),
4137  Iu2Mils( aPin->GetNumberTextSize() ),
4138  Iu2Mils( aPin->GetNameTextSize() ),
4139  aPin->GetUnit(),
4140  aPin->GetConvert(),
4141  Etype );
4142 
4143  if( aPin->GetShape() != GRAPHIC_PINSHAPE::LINE || !aPin->IsVisible() )
4144  aFormatter.Print( 0, " " );
4145 
4146  if( !aPin->IsVisible() )
4147  aFormatter.Print( 0, "N" );
4148 
4149  switch( aPin->GetShape() )
4150  {
4151  case GRAPHIC_PINSHAPE::LINE: break;
4152  case GRAPHIC_PINSHAPE::INVERTED: aFormatter.Print( 0, "I" ); break;
4153  case GRAPHIC_PINSHAPE::CLOCK: aFormatter.Print( 0, "C" ); break;
4154  case GRAPHIC_PINSHAPE::INVERTED_CLOCK: aFormatter.Print( 0, "IC" ); break;
4155  case GRAPHIC_PINSHAPE::INPUT_LOW: aFormatter.Print( 0, "L" ); break;
4156  case GRAPHIC_PINSHAPE::CLOCK_LOW: aFormatter.Print( 0, "CL" ); break;
4157  case GRAPHIC_PINSHAPE::OUTPUT_LOW: aFormatter.Print( 0, "V" ); break;
4158  case GRAPHIC_PINSHAPE::FALLING_EDGE_CLOCK: aFormatter.Print( 0, "F" ); break;
4159  case GRAPHIC_PINSHAPE::NONLOGIC: aFormatter.Print( 0, "X" ); break;
4160  default: wxFAIL_MSG( "Invalid pin shape" );
4161  }
4162 
4163  aFormatter.Print( 0, "\n" );
4164 
4165  const_cast<LIB_PIN*>( aPin )->ClearFlags( IS_CHANGED );
4166 }
power input (GND, VCC for ICs). Must be connected to a power output.
#define IS_CHANGED
Item was edited, and modified.
int GetOrientation() const
Definition: lib_pin.h:75
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:78
pin for passive symbols: must be connected, and can be connected to any pin
unknown electrical properties: creates always a warning when connected
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
int GetUnit() const
Definition: lib_item.h:266
const wxString & GetName() const
Definition: lib_pin.h:106
bool IsVisible() const
Definition: lib_pin.h:97
int GetNameTextSize() const
Definition: lib_pin.h:126
int GetConvert() const
Definition: lib_item.h:269
wxPoint GetPosition() const override
Definition: lib_pin.h:212
const wxString & GetNumber() const
Definition: lib_pin.h:116
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:84
int GetNumberTextSize() const
Definition: lib_pin.h:129
int GetLength() const
Definition: lib_pin.h:81
usual pin input: must be connected
input or output (like port for a microprocessor)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
not connected (must be left open)
output of a regulator: intended to be connected to power input pins
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References CLOCK, CLOCK_LOW, FALLING_EDGE_CLOCK, 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(), INPUT_LOW, INVERTED, INVERTED_CLOCK, IS_CHANGED, LIB_PIN::IsVisible(), LIB_PIN_T, LINE, NONLOGIC, OUTPUT_LOW, OUTPUTFORMATTER::Print(), PT_BIDI, PT_INPUT, PT_NC, PT_OPENCOLLECTOR, PT_OPENEMITTER, PT_OUTPUT, PT_PASSIVE, PT_POWER_IN, PT_POWER_OUT, PT_TRISTATE, PT_UNSPECIFIED, TO_UTF8, and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ savePolyLine()

void SCH_LEGACY_PLUGIN_CACHE::savePolyLine ( LIB_SHAPE aPolyLine,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4169 of file sch_legacy_plugin.cpp.

4170 {
4171  wxCHECK_RET( aPolyLine && aPolyLine->GetShape() == SHAPE_T::POLY, "Invalid POLY object." );
4172 
4173  aFormatter.Print( 0, "P %d %d %d %d",
4174  (int) aPolyLine->GetPolyShape().Outline( 0 ).GetPointCount(),
4175  aPolyLine->GetUnit(),
4176  aPolyLine->GetConvert(),
4177  Iu2Mils( aPolyLine->GetWidth() ) );
4178 
4179  for( const VECTOR2I& pt : aPolyLine->GetPolyShape().Outline( 0 ).CPoints() )
4180  aFormatter.Print( 0, " %d %d", Iu2Mils( pt.x ), Iu2Mils( pt.y ) );
4181 
4182  aFormatter.Print( 0, " %c\n", fill_tab[ static_cast<int>( aPolyLine->GetFillType() ) - 1 ] );
4183 }
int GetWidth() const
Definition: eda_shape.h:98
virtual size_t GetPointCount() const override
int GetUnit() const
Definition: lib_item.h:266
const std::vector< VECTOR2I > & CPoints() const
SHAPE_LINE_CHAIN & Outline(int aIndex)
const int fill_tab[3]
Definition: lib_item.cpp:32
int GetConvert() const
Definition: lib_item.h:269
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:227
SHAPE_T GetShape() const
Definition: eda_shape.h:101
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
FILL_T GetFillType() const
Definition: eda_shape.h:88

References SHAPE_LINE_CHAIN::CPoints(), fill_tab, LIB_ITEM::GetConvert(), EDA_SHAPE::GetFillType(), SHAPE_LINE_CHAIN::GetPointCount(), EDA_SHAPE::GetPolyShape(), EDA_SHAPE::GetShape(), LIB_ITEM::GetUnit(), EDA_SHAPE::GetWidth(), SHAPE_POLY_SET::Outline(), POLY, and OUTPUTFORMATTER::Print().

Referenced by SaveSymbol().

◆ saveRectangle()

void SCH_LEGACY_PLUGIN_CACHE::saveRectangle ( LIB_SHAPE aRectangle,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4186 of file sch_legacy_plugin.cpp.

4187 {
4188  wxCHECK_RET( aRectangle && aRectangle->GetShape() == SHAPE_T::RECT, "Invalid RECT object." );
4189 
4190  aFormatter.Print( 0, "S %d %d %d %d %d %d %d %c\n",
4191  Iu2Mils( aRectangle->GetPosition().x ),
4192  Iu2Mils( aRectangle->GetPosition().y ),
4193  Iu2Mils( aRectangle->GetEnd().x ),
4194  Iu2Mils( aRectangle->GetEnd().y ),
4195  aRectangle->GetUnit(),
4196  aRectangle->GetConvert(),
4197  Iu2Mils( aRectangle->GetWidth() ),
4198  fill_tab[ static_cast<int>( aRectangle->GetFillType() ) - 1 ] );
4199 }
int GetWidth() const
Definition: eda_shape.h:98
int GetUnit() const
Definition: lib_item.h:266
const wxPoint & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:131
const int fill_tab[3]
Definition: lib_item.cpp:32
int GetConvert() const
Definition: lib_item.h:269
SHAPE_T GetShape() const
Definition: eda_shape.h:101
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
wxPoint GetPosition() const override
Definition: lib_shape.h:87
FILL_T GetFillType() const
Definition: eda_shape.h:88

References fill_tab, LIB_ITEM::GetConvert(), EDA_SHAPE::GetEnd(), EDA_SHAPE::GetFillType(), LIB_SHAPE::GetPosition(), EDA_SHAPE::GetShape(), LIB_ITEM::GetUnit(), EDA_SHAPE::GetWidth(), OUTPUTFORMATTER::Print(), and RECT.

Referenced by SaveSymbol().

◆ SaveSymbol()

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

Definition at line 3839 of file sch_legacy_plugin.cpp.

3841 {
3842  /*
3843  * NB:
3844  * Some of the rescue code still uses the legacy format as an intermediary, so we have
3845  * to keep this code.
3846  */
3847 
3848  wxCHECK_RET( aSymbol && aSymbol->IsRoot(), "Invalid LIB_SYMBOL pointer." );
3849 
3850  // LIB_ALIAS objects are deprecated but we still need to gather up the derived symbols
3851  // and save their names for the old file format.
3852  wxArrayString aliasNames;
3853 
3854  if( aMap )
3855  {
3856  for( auto entry : *aMap )
3857  {
3858  LIB_SYMBOL* symbol = entry.second;
3859 
3860  if( symbol->IsAlias() && symbol->GetParent().lock() == aSymbol->SharedPtr() )
3861  aliasNames.Add( symbol->GetName() );
3862  }
3863  }
3864 
3865  LIB_FIELD& value = aSymbol->GetValueField();
3866 
3867  // First line: it s a comment (symbol name for readers)
3868  aFormatter.Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3869 
3870  // Save data
3871  aFormatter.Print( 0, "DEF" );
3872  aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) );
3873 
3874  LIB_FIELD& reference = aSymbol->GetReferenceField();
3875 
3876  if( !reference.GetText().IsEmpty() )
3877  aFormatter.Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3878  else
3879  aFormatter.Print( 0, " ~" );
3880 
3881  aFormatter.Print( 0, " %d %d %c %c %d %c %c\n",
3882  0, Iu2Mils( aSymbol->GetPinNameOffset() ),
3883  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3884  aSymbol->ShowPinNames() ? 'Y' : 'N',
3885  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3886  aSymbol->IsPower() ? 'P' : 'N' );
3887 
3888  timestamp_t dateModified = aSymbol->GetLastModDate();
3889 
3890  if( dateModified != 0 )
3891  {
3892  int sec = dateModified & 63;
3893  int min = ( dateModified >> 6 ) & 63;
3894  int hour = ( dateModified >> 12 ) & 31;
3895  int day = ( dateModified >> 17 ) & 31;
3896  int mon = ( dateModified >> 22 ) & 15;
3897  int year = ( dateModified >> 26 ) + 1990;
3898 
3899  aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3900  }
3901 
3902  std::vector<LIB_FIELD*> fields;
3903  aSymbol->GetFields( fields );
3904 
3905  // Mandatory fields:
3906  // may have their own save policy so there is a separate loop for them.
3907  // Empty fields are saved, because the user may have set visibility,
3908  // size and orientation
3909  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3910  saveField( fields[i], aFormatter );
3911 
3912  // User defined fields:
3913  // may have their own save policy so there is a separate loop for them.
3914  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3915 
3916  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3917  {
3918  // There is no need to save empty fields, i.e. no reason to preserve field
3919  // names now that fields names come in dynamically through the template
3920  // fieldnames.
3921  if( !fields[i]->GetText().IsEmpty() )
3922  {
3923  fields[i]->SetId( fieldId++ );
3924  saveField( fields[i], aFormatter );
3925  }
3926  }
3927 
3928  // Save the alias list: a line starting by "ALIAS".
3929  if( !aliasNames.IsEmpty() )
3930  {
3931  aFormatter.Print( 0, "ALIAS" );
3932 
3933  for( unsigned i = 0; i < aliasNames.GetCount(); i++ )
3934  aFormatter.Print( 0, " %s", TO_UTF8( aliasNames[i] ) );
3935 
3936  aFormatter.Print( 0, "\n" );
3937  }
3938 
3939  wxArrayString footprints = aSymbol->GetFPFilters();
3940 
3941  // Write the footprint filter list
3942  if( footprints.GetCount() != 0 )
3943  {
3944  aFormatter.Print( 0, "$FPLIST\n" );
3945 
3946  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3947  aFormatter.Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3948 
3949  aFormatter.Print( 0, "$ENDFPLIST\n" );
3950  }
3951 
3952  // Save graphics items (including pins)
3953  if( !aSymbol->GetDrawItems().empty() )
3954  {
3955  // Sort the draw items in order to editing a file editing by hand.
3956  aSymbol->GetDrawItems().sort();
3957 
3958  aFormatter.Print( 0, "DRAW\n" );
3959 
3960  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3961  {
3962  switch( item.Type() )
3963  {
3964  default:
3965  case LIB_FIELD_T: /* Fields have already been saved above. */ break;
3966  case LIB_PIN_T: savePin( (LIB_PIN* ) &item, aFormatter ); break;
3967  case LIB_TEXT_T: saveText( ( LIB_TEXT* ) &item, aFormatter ); break;
3968  case LIB_SHAPE_T:
3969  {
3970  LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( item );
3971 
3972  switch( shape.GetShape() )
3973  {
3974  case SHAPE_T::ARC: saveArc( &shape, aFormatter ); break;
3975  case SHAPE_T::BEZIER: saveBezier( &shape, aFormatter ); break;
3976  case SHAPE_T::CIRCLE: saveCircle( &shape, aFormatter ); break;
3977  case SHAPE_T::POLY: savePolyLine( &shape, aFormatter ); break;
3978  case SHAPE_T::RECT: saveRectangle( &shape, aFormatter ); break;
3979  default: break;
3980  }
3981  }
3982  }
3983  }
3984 
3985  aFormatter.Print( 0, "ENDDRAW\n" );
3986  }
3987 
3988  aFormatter.Print( 0, "ENDDEF\n" );
3989 }
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:124
int GetPinNameOffset() const
Definition: lib_symbol.h:572
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:107
timestamp_t GetLastModDate() const
Definition: lib_symbol.h:179
static void saveCircle(LIB_SHAPE *aCircle, OUTPUTFORMATTER &aFormatter)
static void saveBezier(LIB_SHAPE *aBezier, OUTPUTFORMATTER &aFormatter)
static void saveRectangle(LIB_SHAPE *aRectangle, OUTPUTFORMATTER &aFormatter)
wxString GetName() const override
Definition: lib_symbol.h:133
Define a symbol library graphical text item.
Definition: lib_text.h:39
static void saveArc(LIB_SHAPE *aArc, OUTPUTFORMATTER &aFormatter)
static void savePolyLine(LIB_SHAPE *aPolyLine, OUTPUTFORMATTER &aFormatter)
Field object used in symbol libraries.
Definition: lib_field.h:59
bool IsAlias() const
Definition: lib_symbol.h:172
bool ShowPinNumbers() const
Definition: lib_symbol.h:588
void sort()
Definition: multivector.h:247
bool IsPower() const
Definition: lib_symbol.cpp:459
LIB_FIELD & GetValueField()
Return reference to the value field.
bool empty(int aType=UNDEFINED_TYPE) const
Definition: multivector.h:242
Define a library symbol object.
Definition: lib_symbol.h:96
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
void GetFields(std::vector< LIB_FIELD * > &aList)
Return a list of fields within this symbol.
Definition: lib_symbol.cpp:982
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
int GetUnitCount() const override
For items with units, return the number of units.
bool ShowPinNames() const
Definition: lib_symbol.h:580
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:484
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:241
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
static void saveText(const LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter)
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: kiid.h:32
static void savePin(const LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter)
static void saveField(const LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter)
wxArrayString GetFPFilters() const
Definition: lib_symbol.h:183
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:171
SHAPE_T GetShape() const
Definition: eda_shape.h:101
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:154

References ARC, BEZIER, CIRCLE, MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::empty(), LIB_SYMBOL::GetDrawItems(), LIB_SYMBOL::GetFields(), LIB_SYMBOL::GetFPFilters(), LIB_SYMBOL::GetLastModDate(), LIB_SYMBOL::GetName(), LIB_SYMBOL::GetParent(), LIB_SYMBOL::GetPinNameOffset(), LIB_SYMBOL::GetReferenceField(), EDA_SHAPE::GetShape(), EDA_TEXT::GetText(), LIB_SYMBOL::GetUnitCount(), LIB_SYMBOL::GetValueField(), LIB_SYMBOL::IsAlias(), LIB_SYMBOL::IsPower(), LIB_SYMBOL::IsRoot(), LIB_FIELD_T, LIB_PIN_T, LIB_SHAPE_T, LIB_TEXT_T, MANDATORY_FIELDS, POLY, OUTPUTFORMATTER::Print(), RECT, saveArc(), saveBezier(), saveCircle(), saveField(), savePin(), savePolyLine(), saveRectangle(), saveText(), LIB_SYMBOL::SharedPtr(), LIB_SYMBOL::ShowPinNames(), LIB_SYMBOL::ShowPinNumbers(), MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::sort(), TO_UTF8, and LIB_SYMBOL::UnitsLocked().

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

◆ saveText()

void SCH_LEGACY_PLUGIN_CACHE::saveText ( const LIB_TEXT aText,
OUTPUTFORMATTER aFormatter 
)
staticprivate

Definition at line 4202 of file sch_legacy_plugin.cpp.

4203 {
4204  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
4205 
4206  wxString text = aText->GetText();
4207 
4208  if( text.Contains( wxT( " " ) ) || text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
4209  {
4210  // convert double quote to similar-looking two apostrophes
4211  text.Replace( wxT( "\"" ), wxT( "''" ) );
4212  text = wxT( "\"" ) + text + wxT( "\"" );
4213  }
4214 
4215  aFormatter.Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
4216  Iu2Mils( aText->GetTextPos().x ), Iu2Mils( aText->GetTextPos().y ),
4217  Iu2Mils( aText->GetTextWidth() ), !aText->IsVisible(),
4218  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
4219 
4220  aFormatter.Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
4221 
4222  char hjustify = 'C';
4223 
4224  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
4225  hjustify = 'L';
4226  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
4227  hjustify = 'R';
4228 
4229  char vjustify = 'C';
4230 
4231  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
4232  vjustify = 'B';
4233  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
4234  vjustify = 'T';
4235 
4236  aFormatter.Print( 0, " %c %c\n", hjustify, vjustify );
4237 }
bool IsBold() const
Definition: eda_text.h:204
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:220
double GetTextAngle() const
Definition: eda_text.h:195
bool IsItalic() const
Definition: eda_text.h:201
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
int GetUnit() const
Definition: lib_item.h:266
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:219
virtual bool IsVisible() const
Definition: eda_text.h:207
int GetConvert() const
Definition: lib_item.h:269
int GetTextWidth() const
Definition: eda_text.h:262
const wxPoint & GetTextPos() const
Definition: eda_text.h:268
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:154
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

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, OUTPUTFORMATTER::Print(), text, TO_UTF8, and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ SetFileName()

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

Definition at line 558 of file sch_legacy_plugin.cpp.

558 { 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 514 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 512 of file sch_legacy_plugin.cpp.


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