KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN_CACHE Class Reference

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

Public Member Functions

 SCH_LEGACY_PLUGIN_CACHE (const wxString &aLibraryPath)
 
 ~SCH_LEGACY_PLUGIN_CACHE ()
 
int GetModifyHash () const
 
void Save (bool aSaveDocFile=true)
 Save the entire library to file m_libFileName;. More...
 
void Load ()
 
void AddSymbol (const LIB_PART *aPart)
 
void DeleteAlias (const wxString &aAliasName)
 
void DeleteSymbol (const wxString &aAliasName)
 
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 LIB_PARTLoadPart (LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
 
static void SaveSymbol (LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter)
 

Private Member Functions

void loadHeader (FILE_LINE_READER &aReader)
 
void loadDocs ()
 
LIB_ALIASremoveAlias (LIB_ALIAS *aAlias)
 
void saveDocFile ()
 

Static Private Member Functions

static void loadAliases (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static void loadField (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static void loadDrawEntries (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
 
static void loadFootprintFilters (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_ARCloadArc (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_CIRCLEloadCircle (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_TEXTloadText (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
 
static LIB_RECTANGLEloadRectangle (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_PINloadPin (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_POLYLINEloadPolyLine (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static LIB_BEZIERloadBezier (std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
 
static FILL_T parseFillMode (LINE_READER &aReader, const char *aLine, const char **aOutput)
 
static void saveArc (LIB_ARC *aArc, OUTPUTFORMATTER &aFormatter)
 
static void saveBezier (LIB_BEZIER *aBezier, OUTPUTFORMATTER &aFormatter)
 
static void saveCircle (LIB_CIRCLE *aCircle, OUTPUTFORMATTER &aFormatter)
 
static void saveField (LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter)
 
static void savePin (LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter)
 
static void savePolyLine (LIB_POLYLINE *aPolyLine, OUTPUTFORMATTER &aFormatter)
 
static void saveRectangle (LIB_RECTANGLE *aRectangle, OUTPUTFORMATTER &aFormatter)
 
static void saveText (LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter)
 

Private Attributes

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

Static Private Attributes

static int m_modHash = 1
 

Detailed Description

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

not placed into a header.

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

2317  :
2318  m_fileName( aFullPathAndFileName ),
2319  m_libFileName( aFullPathAndFileName ),
2320  m_isWritable( true ),
2321  m_isModified( false )
2322 {
2323  m_versionMajor = -1;
2324  m_versionMinor = -1;
2326 }

References LIBRARY_TYPE_EESCHEMA, m_libType, m_versionMajor, and m_versionMinor.

◆ ~SCH_LEGACY_PLUGIN_CACHE()

SCH_LEGACY_PLUGIN_CACHE::~SCH_LEGACY_PLUGIN_CACHE ( )

Definition at line 2329 of file sch_legacy_plugin.cpp.

2330 {
2331  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2332  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); ++it )
2333  {
2334  wxLogTrace( traceSchLegacyPlugin, wxT( "Removing alias %s from library %s." ),
2335  GetChars( it->second->GetName() ), GetChars( GetLogicalName() ) );
2336  LIB_PART* part = it->second->GetPart();
2337  LIB_ALIAS* alias = it->second;
2338  delete alias;
2339 
2340  // When the last alias of a part is destroyed, the part is no longer required and it
2341  // too is destroyed.
2342  if( part && part->GetAliasCount() == 0 )
2343  delete part;
2344  }
2345 
2346  m_aliases.clear();
2347 }
Part library alias object definition.
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
wxString GetLogicalName() const
Define a library symbol object.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:101
size_t GetAliasCount() const

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

Member Function Documentation

◆ AddSymbol()

void SCH_LEGACY_PLUGIN_CACHE::AddSymbol ( const LIB_PART aPart)

Definition at line 2446 of file sch_legacy_plugin.cpp.

2447 {
2448  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2449  wxArrayString aliasNames = aPart->GetAliasNames();
2450 
2451  for( size_t i = 0; i < aliasNames.size(); i++ )
2452  {
2453  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasNames[i] );
2454 
2455  if( it != m_aliases.end() )
2456  removeAlias( it->second );
2457 
2458  LIB_ALIAS* alias = const_cast< LIB_PART* >( aPart )->GetAlias( aliasNames[i] );
2459 
2460  wxASSERT_MSG( alias != NULL, "No alias <" + aliasNames[i] + "> found in symbol <" +
2461  aPart->GetName() +">." );
2462 
2463  m_aliases[ aliasNames[i] ] = alias;
2464  }
2465 
2466  m_isModified = true;
2467  ++m_modHash;
2468 }
Part library alias object definition.
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
LIB_ALIAS * removeAlias(LIB_ALIAS *aAlias)
const wxString & GetName() const
size_t i
Definition: json11.cpp:597

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

Referenced by SCH_LEGACY_PLUGIN::SaveSymbol().

◆ DeleteAlias()

void SCH_LEGACY_PLUGIN_CACHE::DeleteAlias ( const wxString &  aAliasName)

Definition at line 4178 of file sch_legacy_plugin.cpp.

4179 {
4180  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
4181 
4182  if( it == m_aliases.end() )
4183  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
4184  m_libFileName.GetFullName(), aAliasName ) );
4185 
4186  LIB_ALIAS* alias = it->second;
4187  LIB_PART* part = alias->GetPart();
4188 
4189  alias = part->RemoveAlias( alias );
4190 
4191  if( !alias )
4192  {
4193  delete part;
4194 
4195  if( m_aliases.size() > 1 )
4196  {
4197  LIB_ALIAS_MAP::iterator next = it;
4198  next++;
4199 
4200  if( next == m_aliases.end() )
4201  next = m_aliases.begin();
4202 
4203  alias = next->second;
4204  }
4205  }
4206 
4207  m_aliases.erase( it );
4208  ++m_modHash;
4209  m_isModified = true;
4210 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Define a library symbol object.
#define THROW_IO_ERROR(msg)
LIB_PART * GetPart() const
Get the shared LIB_PART.
#define _(s)
void RemoveAlias(const wxString &aName)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References _, Format(), LIB_ALIAS::GetPart(), m_aliases, m_isModified, m_libFileName, m_modHash, next(), LIB_PART::RemoveAlias(), and THROW_IO_ERROR.

Referenced by SCH_LEGACY_PLUGIN::DeleteAlias(), and DeleteSymbol().

◆ DeleteSymbol()

void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol ( const wxString &  aAliasName)

Definition at line 4213 of file sch_legacy_plugin.cpp.

4214 {
4215  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
4216 
4217  if( it == m_aliases.end() )
4218  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
4219  m_libFileName.GetFullName(), aAliasName ) );
4220 
4221  LIB_ALIAS* alias = it->second;
4222  LIB_PART* part = alias->GetPart();
4223 
4224  wxArrayString aliasNames = part->GetAliasNames();
4225 
4226  // Deleting all of the aliases deletes the symbol from the library.
4227  for( size_t i = 0; i < aliasNames.Count(); i++ )
4228  DeleteAlias( aliasNames[i] );
4229 }
Part library alias object definition.
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
void DeleteAlias(const wxString &aAliasName)
Define a library symbol object.
#define THROW_IO_ERROR(msg)
LIB_PART * GetPart() const
Get the shared LIB_PART.
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
size_t i
Definition: json11.cpp:597

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

Referenced by SCH_LEGACY_PLUGIN::DeleteSymbol().

◆ GetFileName()

wxString SCH_LEGACY_PLUGIN_CACHE::GetFileName ( ) const
inline

Definition at line 553 of file sch_legacy_plugin.cpp.

553 { return m_libFileName.GetFullPath(); }

References m_libFileName.

Referenced by SCH_LEGACY_PLUGIN::SaveLibrary().

◆ GetLibModificationTime()

wxDateTime SCH_LEGACY_PLUGIN_CACHE::GetLibModificationTime ( )

Definition at line 2374 of file sch_legacy_plugin.cpp.

2375 {
2376  wxFileName fn = GetRealFile();
2377 
2378  // update the writable flag while we have a wxFileName, in a network this
2379  // is possibly quite dynamic anyway.
2380  m_isWritable = fn.IsFileWritable();
2381 
2382  return fn.GetModificationTime();
2383 }
wxFileName GetRealFile() const

References GetRealFile(), and m_isWritable.

Referenced by Load().

◆ GetLogicalName()

wxString SCH_LEGACY_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 549 of file sch_legacy_plugin.cpp.

549 { return m_libFileName.GetName(); }

References m_libFileName.

Referenced by ~SCH_LEGACY_PLUGIN_CACHE().

◆ GetModifyHash()

int SCH_LEGACY_PLUGIN_CACHE::GetModifyHash ( ) const
inline

Definition at line 521 of file sch_legacy_plugin.cpp.

521 { return m_modHash; }

References m_modHash.

Referenced by SCH_LEGACY_PLUGIN::GetModifyHash().

◆ GetRealFile()

wxFileName SCH_LEGACY_PLUGIN_CACHE::GetRealFile ( ) const

Definition at line 2351 of file sch_legacy_plugin.cpp.

2352 {
2353  wxFileName fn( m_libFileName );
2354 
2355 #ifndef __WINDOWS__
2356  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2357  {
2358  char buffer[ PATH_MAX + 1 ];
2359  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2360 
2361  if( pathLen > 0 )
2362  {
2363  buffer[ pathLen ] = '\0';
2364  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2365  fn.Normalize();
2366  }
2367  }
2368 #endif
2369 
2370  return fn;
2371 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48

References m_libFileName, and TO_UTF8.

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

◆ IsFile()

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

Definition at line 2386 of file sch_legacy_plugin.cpp.

2387 {
2388  return m_fileName == aFullPathAndFileName;
2389 }

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

2393 {
2394  wxFileName fn = GetRealFile();
2395 
2396  if( m_fileModTime.IsValid() && fn.IsOk() && fn.FileExists() )
2397  return fn.GetModificationTime() != m_fileModTime;
2398 
2399  return false;
2400 }
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 2471 of file sch_legacy_plugin.cpp.

2472 {
2473  if( !m_libFileName.FileExists() )
2474  {
2475  THROW_IO_ERROR( wxString::Format( _( "Library file \"%s\" not found." ),
2476  m_libFileName.GetFullPath() ) );
2477  }
2478 
2479  wxCHECK_RET( m_libFileName.IsAbsolute(),
2480  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2481  "open library \"%s\".", m_libFileName.GetFullPath() ) );
2482 
2483  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file \"%s\"",
2484  m_libFileName.GetFullPath() );
2485 
2486  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2487 
2488  if( !reader.ReadLine() )
2489  THROW_IO_ERROR( _( "unexpected end of file" ) );
2490 
2491  const char* line = reader.Line();
2492 
2493  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2494  {
2495  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2496  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2497  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2498  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2499  }
2500 
2501  m_versionMajor = parseInt( reader, line, &line );
2502 
2503  if( *line != '.' )
2504  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2505 
2506  line++;
2507 
2508  m_versionMinor = parseInt( reader, line, &line );
2509 
2510  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2511  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2512 
2513  // Check if this is a symbol library which is the same as a component library but without
2514  // any alias, documentation, footprint filters, etc.
2515  if( strCompare( "SYMBOL", line, &line ) )
2516  {
2517  // Symbol files add date and time stamp info to the header.
2519 
2521  }
2522  else
2523  {
2525  }
2526 
2527  while( reader.ReadLine() )
2528  {
2529  line = reader.Line();
2530 
2531  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2532  continue;
2533 
2534  // Headers where only supported in older library file formats.
2535  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2536  loadHeader( reader );
2537 
2538  if( strCompare( "DEF", line ) )
2539  {
2540  // Read one DEF/ENDDEF part entry from library:
2541  LIB_PART * part = LoadPart( reader, m_versionMajor, m_versionMinor );
2542 
2543  // Add aliases to cache
2544  for( size_t ii = 0; ii < part->GetAliasCount(); ++ii )
2545  {
2546  LIB_ALIAS* alias = part->GetAlias( ii );
2547  const wxString& aliasName = alias->GetName();
2548 
2549  // This section seems to do a similar job as checkForDuplicates, so
2550  // I'm not sure checkForDuplicates needs to be preserved.
2551  auto it = m_aliases.find( aliasName );
2552 
2553  if( it != m_aliases.end() )
2554  {
2555  // Find a new name for the alias
2556  wxString newName;
2557  int idx = 0;
2558  LIB_ALIAS_MAP::const_iterator jt;
2559 
2560  do
2561  {
2562  newName = wxString::Format( "%s_%d", aliasName, idx );
2563  jt = m_aliases.find( newName );
2564  ++idx;
2565  }
2566  while( jt != m_aliases.end() );
2567 
2568  wxLogWarning( "Symbol name conflict in library:\n%s\n"
2569  "'%s' has been renamed to '%s'",
2570  m_fileName, aliasName, newName );
2571 
2572  if( alias->IsRoot() )
2573  part->SetName( newName );
2574  else
2575  alias->SetName( newName );
2576 
2577  m_aliases[newName] = alias;
2578  }
2579  else
2580  {
2581  m_aliases[aliasName] = alias;
2582  }
2583  }
2584  }
2585  }
2586 
2587  ++m_modHash;
2588 
2589  // Remember the file modification time of library file when the
2590  // cache snapshot was made, so that in a networked environment we will
2591  // reload the cache as needed.
2593 
2595  loadDocs();
2596 }
Part library alias object definition.
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
LIB_ALIAS * GetAlias(size_t aIndex) const
void loadHeader(FILE_LINE_READER &aReader)
bool IsRoot() const override
For symbols having aliases, IsRoot() indicates the principal item.
void SetName(const wxString &aName)
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
Define a library symbol object.
#define THROW_IO_ERROR(msg)
#define USE_OLD_DOC_FILE_FORMAT(major, minor)
Definition: class_library.h:75
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define _(s)
#define SCH_PARSE_ERROR(text, reader, pos)
const wxString & GetName() const override
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
virtual void SetName(const wxString &aName)
size_t GetAliasCount() const
static LIB_PART * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion)

References _, Format(), LIB_PART::GetAlias(), LIB_PART::GetAliasCount(), GetLibModificationTime(), LIB_ALIAS::GetName(), LIB_ALIAS::IsRoot(), LIBRARY_TYPE_EESCHEMA, LIBRARY_TYPE_SYMBOL, loadDocs(), loadHeader(), LoadPart(), m_aliases, m_fileModTime, m_fileName, m_libFileName, m_libType, m_modHash, m_versionMajor, m_versionMinor, parseInt(), SCH_PARSE_ERROR, LIB_ALIAS::SetName(), LIB_PART::SetName(), 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_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 2928 of file sch_legacy_plugin.cpp.

2930 {
2931  wxString newAlias;
2932  const char* line = aReader.Line();
2933 
2934  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2935 
2936  wxString utf8Line = wxString::FromUTF8( line );
2937  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2938 
2939  // Parse the ALIAS list.
2940  while( tokens.HasMoreTokens() )
2941  {
2942  newAlias = tokens.GetNextToken();
2943  aPart->AddAlias( newAlias );
2944  }
2945 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

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

Referenced by LoadPart().

◆ loadArc()

LIB_ARC * SCH_LEGACY_PLUGIN_CACHE::loadArc ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3172 of file sch_legacy_plugin.cpp.

3174 {
3175  const char* line = aReader.Line();
3176 
3177  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
3178 
3179  LIB_ARC* arc = new LIB_ARC( aPart.get() );
3180 
3181  wxPoint center;
3182 
3183  center.x = parseInt( aReader, line, &line );
3184  center.y = parseInt( aReader, line, &line );
3185 
3186  arc->SetPosition( center );
3187  arc->SetRadius( parseInt( aReader, line, &line ) );
3188 
3189  int angle1 = parseInt( aReader, line, &line );
3190  int angle2 = parseInt( aReader, line, &line );
3191 
3192  NORMALIZE_ANGLE_POS( angle1 );
3193  NORMALIZE_ANGLE_POS( angle2 );
3194  arc->SetFirstRadiusAngle( angle1 );
3195  arc->SetSecondRadiusAngle( angle2 );
3196 
3197  arc->SetUnit( parseInt( aReader, line, &line ) );
3198  arc->SetConvert( parseInt( aReader, line, &line ) );
3199  arc->SetWidth( parseInt( aReader, line, &line ) );
3200 
3201  // Old libraries (version <= 2.2) do not have always this FILL MODE param
3202  // when fill mode is no fill (default mode).
3203  if( *line != 0 )
3204  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
3205 
3206  // Actual Coordinates of arc ends are read from file
3207  if( *line != 0 )
3208  {
3209  wxPoint arcStart, arcEnd;
3210 
3211  arcStart.x = parseInt( aReader, line, &line );
3212  arcStart.y = parseInt( aReader, line, &line );
3213  arcEnd.x = parseInt( aReader, line, &line );
3214  arcEnd.y = parseInt( aReader, line, &line );
3215 
3216  arc->SetStart( arcStart );
3217  arc->SetEnd( arcEnd );
3218  }
3219  else
3220  {
3221  // Actual Coordinates of arc ends are not read from file
3222  // (old library), calculate them
3223  wxPoint arcStart( arc->GetRadius(), 0 );
3224  wxPoint arcEnd( arc->GetRadius(), 0 );
3225 
3226  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
3227  arcStart += arc->GetPosition();
3228  arc->SetStart( arcStart );
3229  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
3230  arcEnd += arc->GetPosition();
3231  arc->SetEnd( arcEnd );
3232  }
3233 
3234  return arc;
3235 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:252
void SetFirstRadiusAngle(int aAngle)
Definition: lib_arc.h:107
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:206
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:252
void SetWidth(int aWidth) override
Definition: lib_arc.h:102
void SetEnd(const wxPoint &aPoint)
Definition: lib_arc.h:117
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:306
void SetSecondRadiusAngle(int aAngle)
Definition: lib_arc.h:110
int GetRadius() const
Definition: lib_arc.h:105
void SetConvert(int aConvert)
Definition: lib_item.h:303
void SetUnit(int aUnit)
Definition: lib_item.h:300
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
void SetRadius(int aRadius)
Definition: lib_arc.h:104
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetStart(const wxPoint &aPoint)
Definition: lib_arc.h:114
wxPoint GetPosition() const override
Definition: lib_arc.h:92

References LIB_ARC::GetPosition(), LIB_ARC::GetRadius(), LINE_READER::Line(), NORMALIZE_ANGLE_POS(), parseFillMode(), parseInt(), RotatePoint(), LIB_ITEM::SetConvert(), LIB_ARC::SetEnd(), LIB_ITEM::SetFillMode(), LIB_ARC::SetFirstRadiusAngle(), LIB_ITEM::SetPosition(), LIB_ARC::SetRadius(), LIB_ARC::SetSecondRadiusAngle(), LIB_ARC::SetStart(), LIB_ITEM::SetUnit(), LIB_ARC::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

◆ loadBezier()

LIB_BEZIER * SCH_LEGACY_PLUGIN_CACHE::loadBezier ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3603 of file sch_legacy_plugin.cpp.

3605 {
3606  const char* line = aReader.Line();
3607 
3608  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3609 
3610  LIB_BEZIER* bezier = new LIB_BEZIER( aPart.get() );
3611 
3612  int points = parseInt( aReader, line, &line );
3613  bezier->SetUnit( parseInt( aReader, line, &line ) );
3614  bezier->SetConvert( parseInt( aReader, line, &line ) );
3615  bezier->SetWidth( parseInt( aReader, line, &line ) );
3616 
3617  wxPoint pt;
3618  bezier->Reserve( points );
3619 
3620  for( int i = 0; i < points; i++ )
3621  {
3622  pt.x = parseInt( aReader, line, &line );
3623  pt.y = parseInt( aReader, line, &line );
3624  bezier->AddPoint( pt );
3625  }
3626 
3627  if( *line != 0 )
3628  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3629 
3630  return bezier;
3631 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static dpoint_t bezier(double t, dpoint_t p0, dpoint_t p1, dpoint_t p2, dpoint_t p3)
Definition: trace.cpp:260
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
size_t i
Definition: json11.cpp:597
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
Class LIB_BEZIER defines bezier curve graphic body item.
Definition: lib_bezier.h:35

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

Referenced by loadDrawEntries().

◆ loadCircle()

LIB_CIRCLE * SCH_LEGACY_PLUGIN_CACHE::loadCircle ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3238 of file sch_legacy_plugin.cpp.

3240 {
3241  const char* line = aReader.Line();
3242 
3243  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
3244 
3245  LIB_CIRCLE* circle = new LIB_CIRCLE( aPart.get() );
3246 
3247  wxPoint center;
3248 
3249  center.x = parseInt( aReader, line, &line );
3250  center.y = parseInt( aReader, line, &line );
3251 
3252  circle->SetPosition( center );
3253  circle->SetRadius( parseInt( aReader, line, &line ) );
3254  circle->SetUnit( parseInt( aReader, line, &line ) );
3255  circle->SetConvert( parseInt( aReader, line, &line ) );
3256  circle->SetWidth( parseInt( aReader, line, &line ) );
3257 
3258  if( *line != 0 )
3259  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3260 
3261  return circle;
3262 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:252
void SetRadius(int aRadius)
Definition: lib_circle.h:90
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:306
void SetConvert(int aConvert)
Definition: lib_item.h:303
void SetUnit(int aUnit)
Definition: lib_item.h:300
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetWidth(int aWidth) override
Definition: lib_circle.h:88

References LINE_READER::Line(), parseFillMode(), parseInt(), LIB_ITEM::SetConvert(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetPosition(), LIB_CIRCLE::SetRadius(), LIB_ITEM::SetUnit(), LIB_CIRCLE::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

◆ loadDocs()

void SCH_LEGACY_PLUGIN_CACHE::loadDocs ( )
private

Definition at line 2599 of file sch_legacy_plugin.cpp.

2600 {
2601  const char* line;
2602  wxString text;
2603  wxString aliasName;
2604  wxFileName fn = m_libFileName;
2605  LIB_ALIAS* alias = NULL;;
2606 
2607  fn.SetExt( DOC_EXT );
2608 
2609  // Not all libraries will have a document file.
2610  if( !fn.FileExists() )
2611  return;
2612 
2613  if( !fn.IsFileReadable() )
2614  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2615  "document file \"%s\"" ), fn.GetFullPath() ) );
2616 
2617  FILE_LINE_READER reader( fn.GetFullPath() );
2618 
2619  line = reader.ReadLine();
2620 
2621  if( !line )
2622  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2623 
2624  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2625  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2626  reader, line );
2627 
2628  while( reader.ReadLine() )
2629  {
2630  line = reader.Line();
2631 
2632  if( *line == '#' ) // Comment line.
2633  continue;
2634 
2635  if( !strCompare( "$CMP", line, &line ) != 0 )
2636  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2637 
2638  aliasName = wxString::FromUTF8( line );
2639  aliasName.Trim();
2640  aliasName = LIB_ID::FixIllegalChars( aliasName, LIB_ID::ID_SCH );
2641 
2642  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
2643 
2644  if( it == m_aliases.end() )
2645  wxLogWarning( "Alias '%s' not found in library:\n\n"
2646  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2647  reader.LineNumber(), (int) (line - reader.Line() ) );
2648  else
2649  alias = it->second;
2650 
2651  // Read the curent alias associated doc.
2652  // if the alias does not exist, just skip the description
2653  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2654  while( reader.ReadLine() )
2655  {
2656  line = reader.Line();
2657 
2658  if( !line )
2659  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2660 
2661  if( strCompare( "$ENDCMP", line, &line ) )
2662  break;
2663 
2664  text = FROM_UTF8( line + 2 );
2665  // Remove spaces at eol, and eol chars:
2666  text = text.Trim();
2667 
2668  switch( line[0] )
2669  {
2670  case 'D':
2671  if( alias )
2672  alias->SetDescription( text );
2673  break;
2674 
2675  case 'K':
2676  if( alias )
2677  alias->SetKeyWords( text );
2678  break;
2679 
2680  case 'F':
2681  if( alias )
2682  alias->SetDocFileName( text );
2683  break;
2684 
2685  case 0:
2686  case '\n':
2687  case '\r':
2688  case '#':
2689  // Empty line or commment
2690  break;
2691 
2692  default:
2693  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2694  }
2695  }
2696  }
2697 }
Part library alias object definition.
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:62
void SetDocFileName(const wxString &aDocFileName)
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define DOCFILE_IDENT
#define DOC_EXT
Definition: class_library.h:50
#define THROW_IO_ERROR(msg)
#define _(s)
void SetDescription(const wxString &aDescription)
#define SCH_PARSE_ERROR(text, reader, pos)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void SetKeyWords(const wxString &aKeyWords)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, LIB_ID_TYPE aType, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:352

References _, DOC_EXT, DOCFILE_IDENT, LIB_ID::FixIllegalChars(), Format(), FROM_UTF8(), LIB_ID::ID_SCH, m_aliases, m_libFileName, FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, LIB_ALIAS::SetDescription(), LIB_ALIAS::SetDocFileName(), LIB_ALIAS::SetKeyWords(), strCompare(), and THROW_IO_ERROR.

Referenced by Load().

◆ loadDrawEntries()

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

Definition at line 3096 of file sch_legacy_plugin.cpp.

3100 {
3101  const char* line = aReader.Line();
3102 
3103  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
3104 
3105  line = aReader.ReadLine();
3106 
3107  while( line )
3108  {
3109  if( strCompare( "ENDDRAW", line, &line ) )
3110  return;
3111 
3112  switch( line[0] )
3113  {
3114  case 'A': // Arc
3115  aPart->AddDrawItem( loadArc( aPart, aReader ) );
3116  break;
3117 
3118  case 'C': // Circle
3119  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
3120  break;
3121 
3122  case 'T': // Text
3123  aPart->AddDrawItem( loadText( aPart, aReader, aMajorVersion, aMinorVersion ) );
3124  break;
3125 
3126  case 'S': // Square
3127  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
3128  break;
3129 
3130  case 'X': // Pin Description
3131  aPart->AddDrawItem( loadPin( aPart, aReader ) );
3132  break;
3133 
3134  case 'P': // Polyline
3135  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
3136  break;
3137 
3138  case 'B': // Bezier Curves
3139  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
3140  break;
3141 
3142  case '#': // Comment
3143  case '\n': // Empty line
3144  case '\r':
3145  case 0:
3146  break;
3147 
3148  default:
3149  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
3150  }
3151 
3152  line = aReader.ReadLine();
3153  }
3154 
3155  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
3156 }
static LIB_POLYLINE * loadPolyLine(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_TEXT * loadText(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static LIB_CIRCLE * loadCircle(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_RECTANGLE * loadRectangle(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_BEZIER * loadBezier(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static LIB_PIN * loadPin(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static LIB_ARC * loadArc(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)

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

Referenced by LoadPart().

◆ loadField()

void SCH_LEGACY_PLUGIN_CACHE::loadField ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 2948 of file sch_legacy_plugin.cpp.

2950 {
2951  const char* line = aReader.Line();
2952 
2953  wxCHECK_RET( *line == 'F', "Invalid field line" );
2954 
2955  wxString text;
2956  int id;
2957 
2958  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2959  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
2960 
2961  LIB_FIELD* field;
2962 
2963  if( (unsigned) id < MANDATORY_FIELDS )
2964  {
2965  field = aPart->GetField( id );
2966 
2967  // this will fire only if somebody broke a constructor or editor.
2968  // MANDATORY_FIELDS are always present in ram resident components, no
2969  // exceptions, and they always have their names set, even fixed fields.
2970  wxASSERT( field );
2971  }
2972  else
2973  {
2974  field = new LIB_FIELD( aPart.get(), id );
2975  aPart->AddDrawItem( field );
2976  }
2977 
2978  // Skip to the first double quote.
2979  while( *line != '"' && *line != 0 )
2980  line++;
2981 
2982  if( *line == 0 )
2983  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
2984 
2985  parseQuotedString( text, aReader, line, &line, true );
2986 
2987  field->SetText( text );
2988 
2989  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
2990  // not save like this.
2991  if( text.size() == 1 && text[0] == '~' )
2992  field->SetText( wxEmptyString );
2993  else
2994  field->SetText( text );
2995 
2996  wxPoint pos;
2997 
2998  pos.x = parseInt( aReader, line, &line );
2999  pos.y = parseInt( aReader, line, &line );
3000  field->SetPosition( pos );
3001 
3002  wxSize textSize;
3003 
3004  textSize.x = textSize.y = parseInt( aReader, line, &line );
3005  field->SetTextSize( textSize );
3006 
3007  char textOrient = parseChar( aReader, line, &line );
3008 
3009  if( textOrient == 'H' )
3010  field->SetTextAngle( TEXT_ANGLE_HORIZ );
3011  else if( textOrient == 'V' )
3012  field->SetTextAngle( TEXT_ANGLE_VERT );
3013  else
3014  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
3015 
3016  char textVisible = parseChar( aReader, line, &line );
3017 
3018  if( textVisible == 'V' )
3019  field->SetVisible( true );
3020  else if ( textVisible == 'I' )
3021  field->SetVisible( false );
3022  else
3023  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
3024 
3025  // It may be technically correct to use the library version to determine if the field text
3026  // attributes are present. If anyone knows if that is valid and what version that would be,
3027  // please change this to test the library version rather than an EOL or the quoted string
3028  // of the field name.
3029  if( *line != 0 && *line != '"' )
3030  {
3031  char textHJustify = parseChar( aReader, line, &line );
3032 
3033  if( textHJustify == 'C' )
3035  else if( textHJustify == 'L' )
3037  else if( textHJustify == 'R' )
3039  else
3040  SCH_PARSE_ERROR( "invalid field text horizontal justification", aReader, line );
3041 
3042  wxString attributes;
3043 
3044  parseUnquotedString( attributes, aReader, line, &line );
3045 
3046  size_t attrSize = attributes.size();
3047 
3048  if( !(attrSize == 3 || attrSize == 1 ) )
3049  SCH_PARSE_ERROR( "invalid field text attributes size", aReader, line );
3050 
3051  switch( (wxChar) attributes[0] )
3052  {
3053  case 'C': field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3054  case 'B': field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3055  case 'T': field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3056  default: SCH_PARSE_ERROR( "invalid field text vertical justification", aReader, line );
3057  }
3058 
3059  if( attrSize == 3 )
3060  {
3061  wxChar attr_1 = attributes[1];
3062  wxChar attr_2 = attributes[2];
3063 
3064  if( attr_1 == 'I' ) // Italic
3065  field->SetItalic( true );
3066  else if( attr_1 != 'N' ) // No italics is default, check for error.
3067  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
3068 
3069  if ( attr_2 == 'B' ) // Bold
3070  field->SetBold( true );
3071  else if( attr_2 != 'N' ) // No bold is default, check for error.
3072  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
3073  }
3074  }
3075 
3076  // Fields in RAM must always have names.
3077  if( (unsigned) id < MANDATORY_FIELDS )
3078  {
3079  // Fields in RAM must always have names, because we are trying to get
3080  // less dependent on field ids and more dependent on names.
3081  // Plus assumptions are made in the field editors.
3083 
3084  // Ensure the VALUE field = the part name (can be not the case
3085  // with malformed libraries: edited by hand, or converted from other tools)
3086  if( id == VALUE )
3087  field->SetText( aPart->GetName() );
3088  }
3089  else
3090  {
3091  parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
3092  }
3093 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:150
#define TEXT_ANGLE_HORIZ
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:252
#define TEXT_ANGLE_VERT
void SetItalic(bool isItalic)
Definition: eda_text.h:163
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:169
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
#define VALUE
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:126
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:188
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define _(s)
#define SCH_PARSE_ERROR(text, reader, pos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:187
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
void SetBold(bool aBold)
Definition: eda_text.h:166

References _, 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, 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_ANGLE_HORIZ, TEXT_ANGLE_VERT, and VALUE.

Referenced by LoadPart().

◆ loadFootprintFilters()

void SCH_LEGACY_PLUGIN_CACHE::loadFootprintFilters ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3634 of file sch_legacy_plugin.cpp.

3636 {
3637  const char* line = aReader.Line();
3638 
3639  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3640 
3641  line = aReader.ReadLine();
3642 
3643  while( line )
3644  {
3645  if( strCompare( "$ENDFPLIST", line, &line ) )
3646  return;
3647 
3648  wxString footprint;
3649 
3650  parseUnquotedString( footprint, aReader, line, &line );
3651  aPart->GetFootprints().Add( footprint );
3652  line = aReader.ReadLine();
3653  }
3654 
3655  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3656 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

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

2701 {
2702  const char* line = aReader.Line();
2703 
2704  wxASSERT( strCompare( "$HEADER", line, &line ) );
2705 
2706  while( aReader.ReadLine() )
2707  {
2708  line = (char*) aReader;
2709 
2710  // The time stamp saved in old library files is not used or saved in the latest
2711  // library file version.
2712  if( strCompare( "TimeStamp", line, &line ) )
2713  continue;
2714  else if( strCompare( "$ENDHEADER", line, &line ) )
2715  return;
2716  }
2717 
2718  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2719 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

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

Referenced by Load().

◆ LoadPart()

LIB_PART * SCH_LEGACY_PLUGIN_CACHE::LoadPart ( LINE_READER aReader,
int  aMajorVersion,
int  aMinorVersion 
)
static

Definition at line 2722 of file sch_legacy_plugin.cpp.

2724 {
2725  const char* line = aReader.Line();
2726 
2727  while( *line == '#' )
2728  aReader.ReadLine();
2729 
2730  if( !strCompare( "DEF", line, &line ) )
2731  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2732 
2733  long num;
2734  size_t pos = 4; // "DEF" plus the first space.
2735  wxString utf8Line = wxString::FromUTF8( line );
2736  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2737 
2738  if( tokens.CountTokens() < 8 )
2739  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2740 
2741  // Read DEF line:
2742  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2743 
2744  wxString name, prefix, tmp;
2745 
2746  name = tokens.GetNextToken();
2747  pos += name.size() + 1;
2748 
2749  prefix = tokens.GetNextToken();
2750  pos += prefix.size() + 1;
2751 
2752  tmp = tokens.GetNextToken();
2753  pos += tmp.size() + 1; // NumOfPins, unused.
2754 
2755  tmp = tokens.GetNextToken(); // Pin name offset.
2756 
2757  if( !tmp.ToLong( &num ) )
2758  THROW_PARSE_ERROR( "invalid pin offset", aReader.GetSource(), aReader.Line(),
2759  aReader.LineNumber(), pos );
2760 
2761  pos += tmp.size() + 1;
2762  part->SetPinNameOffset( (int)num );
2763 
2764  tmp = tokens.GetNextToken(); // Show pin numbers.
2765 
2766  if( !( tmp == "Y" || tmp == "N") )
2767  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2768  aReader.LineNumber(), pos );
2769 
2770  pos += tmp.size() + 1;
2771  part->SetShowPinNumbers( ( tmp == "N" ) ? false : true );
2772 
2773  tmp = tokens.GetNextToken(); // Show pin names.
2774 
2775  if( !( tmp == "Y" || tmp == "N") )
2776  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2777  aReader.LineNumber(), pos );
2778 
2779  pos += tmp.size() + 1;
2780  part->SetShowPinNames( ( tmp == "N" ) ? false : true );
2781 
2782  tmp = tokens.GetNextToken(); // Number of units.
2783 
2784  if( !tmp.ToLong( &num ) )
2785  THROW_PARSE_ERROR( "invalid unit count", aReader.GetSource(), aReader.Line(),
2786  aReader.LineNumber(), pos );
2787 
2788  pos += tmp.size() + 1;
2789  part->SetUnitCount( (int)num );
2790 
2791  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2792  if( part->GetUnitCount() < 1 )
2793  part->SetUnitCount( 1 );
2794 
2795  // Copy part name and prefix.
2796 
2797  // The root alias is added to the alias list by SetName() which is called by SetText().
2798  if( name.IsEmpty() )
2799  {
2800  part->SetName( "~" );
2801  }
2802  else if( name[0] != '~' )
2803  {
2804  part->SetName( name );
2805  }
2806  else
2807  {
2808  part->SetName( name.Right( name.Length() - 1 ) );
2809  part->GetValueField().SetVisible( false );
2810  }
2811 
2812  // Don't set the library alias, this is determined by the symbol library table.
2813  part->SetLibId( LIB_ID( wxEmptyString, part->GetName() ) );
2814 
2815  // There are some code paths in SetText() that do not set the root alias to the
2816  // alias list so add it here if it didn't get added by SetText().
2817  if( !part->HasAlias( part->GetName() ) )
2818  part->AddAlias( part->GetName() );
2819 
2820  LIB_FIELD& reference = part->GetReferenceField();
2821 
2822  if( prefix == "~" )
2823  {
2824  reference.Empty();
2825  reference.SetVisible( false );
2826  }
2827  else
2828  {
2829  reference.SetText( prefix );
2830  }
2831 
2832  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2833  // The was no concept of interchangeable multiple unit symbols.
2834  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
2835  && LIB_VERSION( aMajorVersion, aMinorVersion ) <= LIB_VERSION( 2, 2 ) )
2836  {
2837  // Nothing needs to be set since the default setting for symbols with multiple
2838  // units were never interchangeable. Just parse the 0 an move on.
2839  tmp = tokens.GetNextToken();
2840  pos += tmp.size() + 1;
2841  }
2842  else
2843  {
2844  tmp = tokens.GetNextToken();
2845 
2846  if( tmp == "L" )
2847  part->LockUnits( true );
2848  else if( tmp == "F" || tmp == "0" )
2849  part->LockUnits( false );
2850  else
2851  THROW_PARSE_ERROR( "expected L, F, or 0", aReader.GetSource(), aReader.Line(),
2852  aReader.LineNumber(), pos );
2853 
2854  pos += tmp.size() + 1;
2855  }
2856 
2857  // There is the optional power component flag.
2858  if( tokens.HasMoreTokens() )
2859  {
2860  tmp = tokens.GetNextToken();
2861 
2862  if( tmp == "P" )
2863  part->SetPower();
2864  else if( tmp == "N" )
2865  part->SetNormal();
2866  else
2867  THROW_PARSE_ERROR( "expected P or N", aReader.GetSource(), aReader.Line(),
2868  aReader.LineNumber(), pos );
2869  }
2870 
2871  line = aReader.ReadLine();
2872 
2873  // Read lines until "ENDDEF" is found.
2874  while( line )
2875  {
2876  if( *line == '#' ) // Comment
2877  ;
2878  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2879  continue;
2880  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2881  loadAliases( part, aReader );
2882  else if( *line == 'F' ) // Fields
2883  loadField( part, aReader );
2884  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2885  loadDrawEntries( part, aReader, aMajorVersion, aMinorVersion );
2886  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2887  loadFootprintFilters( part, aReader );
2888  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2889  {
2890  return part.release();
2891  }
2892 
2893  line = aReader.ReadLine();
2894  }
2895 
2896  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2897 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
static void loadDrawEntries(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader, int aMajorVersion, int aMinorVersion)
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetVisible(bool aVisible)
Definition: eda_text.h:169
#define LIB_VERSION(major, minor)
Definition: class_library.h:61
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:126
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
static void loadField(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
void Empty()
Definition: eda_text.h:239
Define a library symbol object.
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static void loadFootprintFilters(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
const char * name
Definition: DXF_plotter.cpp:61
static void loadAliases(std::unique_ptr< LIB_PART > &aPart, LINE_READER &aReader)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

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

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

◆ loadPin()

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

Definition at line 3390 of file sch_legacy_plugin.cpp.

3392 {
3393  const char* line = aReader.Line();
3394 
3395  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3396 
3397  LIB_PIN* pin = new LIB_PIN( aPart.get() );
3398 
3399  size_t pos = 2; // "X" plus ' ' space character.
3400  wxString tmp;
3401  wxString utf8Line = wxString::FromUTF8( line );
3402  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
3403 
3404  if( tokens.CountTokens() < 11 )
3405  SCH_PARSE_ERROR( "invalid pin definition", aReader, line );
3406 
3407  pin->m_name = tokens.GetNextToken();
3408  pos += pin->m_name.size() + 1;
3409  pin->m_number = tokens.GetNextToken();
3410  pos += pin->m_number.size() + 1;
3411 
3412  long num;
3413  wxPoint position;
3414 
3415  tmp = tokens.GetNextToken();
3416 
3417  if( !tmp.ToLong( &num ) )
3418  THROW_PARSE_ERROR( "invalid pin X coordinate", aReader.GetSource(), aReader.Line(),
3419  aReader.LineNumber(), pos );
3420 
3421  pos += tmp.size() + 1;
3422  position.x = (int) num;
3423 
3424  tmp = tokens.GetNextToken();
3425 
3426  if( !tmp.ToLong( &num ) )
3427  THROW_PARSE_ERROR( "invalid pin Y coordinate", aReader.GetSource(), aReader.Line(),
3428  aReader.LineNumber(), pos );
3429 
3430  pos += tmp.size() + 1;
3431  position.y = (int) num;
3432  pin->m_position = position;
3433 
3434  tmp = tokens.GetNextToken();
3435 
3436  if( !tmp.ToLong( &num ) )
3437  THROW_PARSE_ERROR( "invalid pin length", aReader.GetSource(), aReader.Line(),
3438  aReader.LineNumber(), pos );
3439 
3440  pos += tmp.size() + 1;
3441  pin->m_length = (int) num;
3442 
3443 
3444  tmp = tokens.GetNextToken();
3445 
3446  if( tmp.size() > 1 )
3447  THROW_PARSE_ERROR( "invalid pin orientation", aReader.GetSource(), aReader.Line(),
3448  aReader.LineNumber(), pos );
3449 
3450  pos += tmp.size() + 1;
3451  pin->m_orientation = tmp[0];
3452 
3453  tmp = tokens.GetNextToken();
3454 
3455  if( !tmp.ToLong( &num ) )
3456  THROW_PARSE_ERROR( "invalid pin number text size", aReader.GetSource(), aReader.Line(),
3457  aReader.LineNumber(), pos );
3458 
3459  pos += tmp.size() + 1;
3460  pin->m_numTextSize = (int) num;
3461 
3462  tmp = tokens.GetNextToken();
3463 
3464  if( !tmp.ToLong( &num ) )
3465  THROW_PARSE_ERROR( "invalid pin name text size", aReader.GetSource(), aReader.Line(),
3466  aReader.LineNumber(), pos );
3467 
3468  pos += tmp.size() + 1;
3469  pin->m_nameTextSize = (int) num;
3470 
3471  tmp = tokens.GetNextToken();
3472 
3473  if( !tmp.ToLong( &num ) )
3474  THROW_PARSE_ERROR( "invalid pin unit", aReader.GetSource(), aReader.Line(),
3475  aReader.LineNumber(), pos );
3476 
3477  pos += tmp.size() + 1;
3478  pin->m_Unit = (int) num;
3479 
3480  tmp = tokens.GetNextToken();
3481 
3482  if( !tmp.ToLong( &num ) )
3483  THROW_PARSE_ERROR( "invalid pin alternate body type", aReader.GetSource(), aReader.Line(),
3484  aReader.LineNumber(), pos );
3485 
3486  pos += tmp.size() + 1;
3487  pin->m_Convert = (int) num;
3488 
3489  tmp = tokens.GetNextToken();
3490 
3491  if( tmp.size() != 1 )
3492  THROW_PARSE_ERROR( "invalid pin type", aReader.GetSource(), aReader.Line(),
3493  aReader.LineNumber(), pos );
3494 
3495  pos += tmp.size() + 1;
3496  char type = tmp[0];
3497 
3498  wxString attributes;
3499 
3500  switch( type )
3501  {
3502  case 'I': pin->m_type = PIN_INPUT; break;
3503  case 'O': pin->m_type = PIN_OUTPUT; break;
3504  case 'B': pin->m_type = PIN_BIDI; break;
3505  case 'T': pin->m_type = PIN_TRISTATE; break;
3506  case 'P': pin->m_type = PIN_PASSIVE; break;
3507  case 'U': pin->m_type = PIN_UNSPECIFIED; break;
3508  case 'W': pin->m_type = PIN_POWER_IN; break;
3509  case 'w': pin->m_type = PIN_POWER_OUT; break;
3510  case 'C': pin->m_type = PIN_OPENCOLLECTOR; break;
3511  case 'E': pin->m_type = PIN_OPENEMITTER; break;
3512  case 'N': pin->m_type = PIN_NC; break;
3513  default: THROW_PARSE_ERROR( "unknown pin type", aReader.GetSource(),
3514  aReader.Line(), aReader.LineNumber(), pos );
3515  }
3516 
3517  // Optional
3518  if( tokens.HasMoreTokens() ) /* Special Symbol defined */
3519  {
3520  tmp = tokens.GetNextToken();
3521 
3522  enum
3523  {
3524  INVERTED = 1 << 0,
3525  CLOCK = 1 << 1,
3526  LOWLEVEL_IN = 1 << 2,
3527  LOWLEVEL_OUT = 1 << 3,
3528  FALLING_EDGE = 1 << 4,
3529  NONLOGIC = 1 << 5
3530  };
3531 
3532  int flags = 0;
3533 
3534  for( int j = tmp.size(); j > 0; )
3535  {
3536  switch( tmp[--j].GetValue() )
3537  {
3538  case '~': break;
3539  case 'N': pin->m_attributes |= PIN_INVISIBLE; break;
3540  case 'I': flags |= INVERTED; break;
3541  case 'C': flags |= CLOCK; break;
3542  case 'L': flags |= LOWLEVEL_IN; break;
3543  case 'V': flags |= LOWLEVEL_OUT; break;
3544  case 'F': flags |= FALLING_EDGE; break;
3545  case 'X': flags |= NONLOGIC; break;
3546  default: THROW_PARSE_ERROR( "invalid pin attribut", aReader.GetSource(),
3547  aReader.Line(), aReader.LineNumber(), pos );
3548  }
3549 
3550  pos += 1;
3551  }
3552 
3553  switch( flags )
3554  {
3555  case 0: pin->m_shape = PINSHAPE_LINE; break;
3556  case INVERTED: pin->m_shape = PINSHAPE_INVERTED; break;
3557  case CLOCK: pin->m_shape = PINSHAPE_CLOCK; break;
3558  case INVERTED | CLOCK: pin->m_shape = PINSHAPE_INVERTED_CLOCK; break;
3559  case LOWLEVEL_IN: pin->m_shape = PINSHAPE_INPUT_LOW; break;
3560  case LOWLEVEL_IN | CLOCK: pin->m_shape = PINSHAPE_CLOCK_LOW; break;
3561  case LOWLEVEL_OUT: pin->m_shape = PINSHAPE_OUTPUT_LOW; break;
3562  case FALLING_EDGE: pin->m_shape = PINSHAPE_FALLING_EDGE_CLOCK; break;
3563  case NONLOGIC: pin->m_shape = PINSHAPE_NONLOGIC; break;
3564  default: SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3565  }
3566  }
3567 
3568  return pin;
3569 }
int m_nameTextSize
Pin num and Pin name sizes.
Definition: lib_pin.h:77
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
GRAPHIC_PINSHAPE m_shape
Shape drawn around pin.
Definition: lib_pin.h:70
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
int m_numTextSize
Definition: lib_pin.h:76
int m_Unit
Unit identification for multiple parts per package.
Definition: lib_item.h:82
wxString m_name
Definition: lib_pin.h:74
int m_length
Length of the pin.
Definition: lib_pin.h:68
int m_orientation
Pin orientation (Up, Down, Left, Right)
Definition: lib_pin.h:69
wxString m_number
Definition: lib_pin.h:75
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
#define PIN_INVISIBLE
Definition: lib_pin.h:46
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
int m_attributes
Set bit 0 to indicate pin is invisible.
Definition: lib_pin.h:73
wxPoint m_position
Position of the pin.
Definition: lib_pin.h:67
#define SCH_PARSE_ERROR(text, reader, pos)
ELECTRICAL_PINTYPE m_type
Electrical type of the pin. See enum ELECTRICAL_PINTYPE.
Definition: lib_pin.h:72
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
int m_Convert
Shape identification for alternate body styles.
Definition: lib_item.h:88

References LINE_READER::GetSource(), LINE_READER::Line(), LINE_READER::LineNumber(), LIB_PIN::m_attributes, LIB_ITEM::m_Convert, LIB_PIN::m_length, LIB_PIN::m_name, LIB_PIN::m_nameTextSize, LIB_PIN::m_number, LIB_PIN::m_numTextSize, LIB_PIN::m_orientation, LIB_PIN::m_position, LIB_PIN::m_shape, LIB_PIN::m_type, LIB_ITEM::m_Unit, PIN_BIDI, PIN_INPUT, PIN_INVISIBLE, PIN_NC, PIN_OPENCOLLECTOR, PIN_OPENEMITTER, PIN_OUTPUT, PIN_PASSIVE, PIN_POWER_IN, PIN_POWER_OUT, PIN_TRISTATE, PIN_UNSPECIFIED, PINSHAPE_CLOCK, PINSHAPE_CLOCK_LOW, PINSHAPE_FALLING_EDGE_CLOCK, PINSHAPE_INPUT_LOW, PINSHAPE_INVERTED, PINSHAPE_INVERTED_CLOCK, PINSHAPE_LINE, PINSHAPE_NONLOGIC, PINSHAPE_OUTPUT_LOW, SCH_PARSE_ERROR, strCompare(), and THROW_PARSE_ERROR.

Referenced by loadDrawEntries().

◆ loadPolyLine()

LIB_POLYLINE * SCH_LEGACY_PLUGIN_CACHE::loadPolyLine ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3572 of file sch_legacy_plugin.cpp.

3574 {
3575  const char* line = aReader.Line();
3576 
3577  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3578 
3579  LIB_POLYLINE* polyLine = new LIB_POLYLINE( aPart.get() );
3580 
3581  int points = parseInt( aReader, line, &line );
3582  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3583  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3584  polyLine->SetWidth( parseInt( aReader, line, &line ) );
3585  polyLine->Reserve( points );
3586 
3587  wxPoint pt;
3588 
3589  for( int i = 0; i < points; i++ )
3590  {
3591  pt.x = parseInt( aReader, line, &line );
3592  pt.y = parseInt( aReader, line, &line );
3593  polyLine->AddPoint( pt );
3594  }
3595 
3596  if( *line != 0 )
3597  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3598 
3599  return polyLine;
3600 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetWidth(int aWidth) override
Definition: lib_polyline.h:105
void Reserve(size_t aPointCount)
Definition: lib_polyline.h:57
void AddPoint(const wxPoint &aPoint)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:306
void SetConvert(int aConvert)
Definition: lib_item.h:303
void SetUnit(int aUnit)
Definition: lib_item.h:300
size_t i
Definition: json11.cpp:597
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LIB_POLYLINE::AddPoint(), i, LINE_READER::Line(), parseFillMode(), parseInt(), LIB_POLYLINE::Reserve(), LIB_ITEM::SetConvert(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetUnit(), LIB_POLYLINE::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

◆ loadRectangle()

LIB_RECTANGLE * SCH_LEGACY_PLUGIN_CACHE::loadRectangle ( std::unique_ptr< LIB_PART > &  aPart,
LINE_READER aReader 
)
staticprivate

Definition at line 3358 of file sch_legacy_plugin.cpp.

3360 {
3361  const char* line = aReader.Line();
3362 
3363  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
3364 
3365  LIB_RECTANGLE* rectangle = new LIB_RECTANGLE( aPart.get() );
3366 
3367  wxPoint pos;
3368 
3369  pos.x = parseInt( aReader, line, &line );
3370  pos.y = parseInt( aReader, line, &line );
3371  rectangle->SetPosition( pos );
3372 
3373  wxPoint end;
3374 
3375  end.x = parseInt( aReader, line, &line );
3376  end.y = parseInt( aReader, line, &line );
3377  rectangle->SetEnd( end );
3378 
3379  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3380  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3381  rectangle->SetWidth( parseInt( aReader, line, &line ) );
3382 
3383  if( *line != 0 )
3384  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3385 
3386  return rectangle;
3387 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:252
void SetWidth(int aWidth) override
Definition: lib_rectangle.h:86
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetFillMode(FILL_T aFillMode)
Definition: lib_item.h:306
void SetConvert(int aConvert)
Definition: lib_item.h:303
void SetUnit(int aUnit)
Definition: lib_item.h:300
void SetEnd(const wxPoint &aEnd)
Definition: lib_rectangle.h:88
static FILL_T parseFillMode(LINE_READER &aReader, const char *aLine, const char **aOutput)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), parseFillMode(), parseInt(), LIB_ITEM::SetConvert(), LIB_RECTANGLE::SetEnd(), LIB_ITEM::SetFillMode(), LIB_ITEM::SetPosition(), LIB_ITEM::SetUnit(), LIB_RECTANGLE::SetWidth(), and strCompare().

Referenced by loadDrawEntries().

◆ loadText()

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

Definition at line 3265 of file sch_legacy_plugin.cpp.

3269 {
3270  const char* line = aReader.Line();
3271 
3272  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
3273 
3274  LIB_TEXT* text = new LIB_TEXT( aPart.get() );
3275 
3276  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3277 
3278  wxPoint center;
3279 
3280  center.x = parseInt( aReader, line, &line );
3281  center.y = parseInt( aReader, line, &line );
3282  text->SetPosition( center );
3283 
3284  wxSize size;
3285 
3286  size.x = size.y = parseInt( aReader, line, &line );
3287  text->SetTextSize( size );
3288  text->SetVisible( !parseInt( aReader, line, &line ) );
3289  text->SetUnit( parseInt( aReader, line, &line ) );
3290  text->SetConvert( parseInt( aReader, line, &line ) );
3291 
3292  wxString str;
3293 
3294  // If quoted string loading fails, load as not quoted string.
3295  if( *line == '"' )
3296  parseQuotedString( str, aReader, line, &line );
3297  else
3298  {
3299  parseUnquotedString( str, aReader, line, &line );
3300 
3301  // In old libs, "spaces" are replaced by '~' in unquoted strings:
3302  str.Replace( "~", " " );
3303  }
3304 
3305  if( !str.IsEmpty() )
3306  {
3307  // convert two apostrophes back to double quote
3308  str.Replace( "''", "\"" );
3309  }
3310 
3311  text->SetText( str );
3312 
3313  // Here things are murky and not well defined. At some point it appears the format
3314  // was changed to add text properties. However rather than add the token to the end of
3315  // the text definition, it was added after the string and no mention if the file
3316  // verion was bumped or not so this code make break on very old component libraries.
3317  //
3318  // Update: apparently even in the latest version this can be different so added a test
3319  // for end of line before checking for the text properties.
3320  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
3321  && LIB_VERSION( aMajorVersion, aMinorVersion ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3322  {
3323  if( strCompare( "Italic", line, &line ) )
3324  text->SetItalic( true );
3325  else if( !strCompare( "Normal", line, &line ) )
3326  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );
3327 
3328  if( parseInt( aReader, line, &line ) > 0 )
3329  text->SetBold( true );
3330 
3331  // Some old libaries version > 2.0 do not have these options for text justification:
3332  if( !is_eol( *line ) )
3333  {
3334  switch( parseChar( aReader, line, &line ) )
3335  {
3336  case 'L': text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
3337  case 'C': text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
3338  case 'R': text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
3339  default: SCH_PARSE_ERROR( "invalid horizontal text justication; expected L, C, or R",
3340  aReader, line );
3341  }
3342 
3343  switch( parseChar( aReader, line, &line ) )
3344  {
3345  case 'T': text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3346  case 'C': text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3347  case 'B': text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3348  default: SCH_PARSE_ERROR( "invalid vertical text justication; expected T, C, or B",
3349  aReader, line );
3350  }
3351  }
3352  }
3353 
3354  return text;
3355 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:150
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetPosition(const wxPoint &aPosition)
Definition: lib_item.h:252
Define a symbol library graphical text item.
Definition: lib_text.h:40
void SetItalic(bool isItalic)
Definition: eda_text.h:163
void SetVisible(bool aVisible)
Definition: eda_text.h:169
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
#define LIB_VERSION(major, minor)
Definition: class_library.h:61
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
const string & str
Definition: json11.cpp:596
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:126
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:188
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
static bool is_eol(char c)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetConvert(int aConvert)
Definition: lib_item.h:303
void SetUnit(int aUnit)
Definition: lib_item.h:300
#define SCH_PARSE_ERROR(text, reader, pos)
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:187
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetBold(bool aBold)
Definition: eda_text.h:166

References GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, is_eol(), LIB_VERSION, LINE_READER::Line(), parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), SCH_PARSE_ERROR, EDA_TEXT::SetBold(), LIB_ITEM::SetConvert(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), LIB_ITEM::SetPosition(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextSize(), LIB_ITEM::SetUnit(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), str, and strCompare().

Referenced by loadDrawEntries().

◆ parseFillMode()

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

Definition at line 3159 of file sch_legacy_plugin.cpp.

3161 {
3162  switch( parseChar( aReader, aLine, aOutput ) )
3163  {
3164  case 'F': return FILLED_SHAPE;
3165  case 'f': return FILLED_WITH_BG_BODYCOLOR;
3166  case 'N': return NO_FILL;
3167  default: SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
3168  }
3169 }
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
#define SCH_PARSE_ERROR(text, reader, pos)

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

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

◆ removeAlias()

LIB_ALIAS * SCH_LEGACY_PLUGIN_CACHE::removeAlias ( LIB_ALIAS aAlias)
private

Definition at line 2403 of file sch_legacy_plugin.cpp.

2404 {
2405  wxCHECK_MSG( aAlias != NULL, NULL, "NULL pointer cannot be removed from library." );
2406 
2407  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAlias->GetName() );
2408 
2409  if( it == m_aliases.end() )
2410  return NULL;
2411 
2412  // If the entry pointer doesn't match the name it is mapped to in the library, we
2413  // have done something terribly wrong.
2414  wxCHECK_MSG( *it->second == aAlias, NULL,
2415  "Pointer mismatch while attempting to remove alias entry <" + aAlias->GetName() +
2416  "> from library cache <" + m_libFileName.GetName() + ">." );
2417 
2418  LIB_ALIAS* alias = aAlias;
2419  LIB_PART* part = alias->GetPart();
2420 
2421  alias = part->RemoveAlias( alias );
2422 
2423  if( !alias )
2424  {
2425  delete part;
2426 
2427  if( m_aliases.size() > 1 )
2428  {
2429  LIB_ALIAS_MAP::iterator next = it;
2430  next++;
2431 
2432  if( next == m_aliases.end() )
2433  next = m_aliases.begin();
2434 
2435  alias = next->second;
2436  }
2437  }
2438 
2439  m_aliases.erase( it );
2440  m_isModified = true;
2441  ++m_modHash;
2442  return alias;
2443 }
CITER next(CITER it)
Definition: ptree.cpp:130
Part library alias object definition.
Define a library symbol object.
const wxString & GetName() const override
void RemoveAlias(const wxString &aName)

References LIB_ALIAS::GetName(), m_aliases, m_isModified, m_libFileName, m_modHash, next(), and LIB_PART::RemoveAlias().

Referenced by AddSymbol().

◆ Save()

void SCH_LEGACY_PLUGIN_CACHE::Save ( bool  aSaveDocFile = true)

Save the entire library to file m_libFileName;.

Definition at line 3659 of file sch_legacy_plugin.cpp.

3660 {
3661  if( !m_isModified )
3662  return;
3663 
3664  // Write through symlinks, don't replace them
3665  wxFileName fn = GetRealFile();
3666 
3667  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( fn.GetFullPath() ) );
3668  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3669  formatter->Print( 0, "#encoding utf-8\n");
3670 
3671  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3672  {
3673  if( !it->second->IsRoot() )
3674  continue;
3675 
3676  SaveSymbol( it->second->GetPart(), *formatter.get() );
3677  }
3678 
3679  formatter->Print( 0, "#\n#End Library\n" );
3680  formatter.reset();
3681 
3682  m_fileModTime = fn.GetModificationTime();
3683  m_isModified = false;
3684 
3685  if( aSaveDocFile )
3686  saveDocFile();
3687 }
#define LIBFILE_IDENT
Definition: class_library.h:59
#define LIB_VERSION_MINOR
Definition: class_library.h:56
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter)
#define LIB_VERSION_MAJOR
Definition: class_library.h:55
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
wxFileName GetRealFile() const

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

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

◆ saveArc()

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

Definition at line 3852 of file sch_legacy_plugin.cpp.

3854 {
3855  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
3856 
3857  int x1 = aArc->GetFirstRadiusAngle();
3858 
3859  if( x1 > 1800 )
3860  x1 -= 3600;
3861 
3862  int x2 = aArc->GetSecondRadiusAngle();
3863 
3864  if( x2 > 1800 )
3865  x2 -= 3600;
3866 
3867  aFormatter.Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
3868  aArc->GetPosition().x, aArc->GetPosition().y,
3869  aArc->GetRadius(), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
3870  aArc->GetWidth(), fill_tab[aArc->GetFillMode()],
3871  aArc->GetStart().x, aArc->GetStart().y,
3872  aArc->GetEnd().x, aArc->GetEnd().y );
3873 }
FILL_T GetFillMode() const
Definition: lib_item.h:307
int GetSecondRadiusAngle() const
Definition: lib_arc.h:111
int GetUnit() const
Definition: lib_item.h:301
wxPoint GetStart() const
Definition: lib_arc.h:113
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetConvert() const
Definition: lib_item.h:304
int GetRadius() const
Definition: lib_arc.h:105
int GetWidth() const override
Definition: lib_arc.h:101
wxPoint GetEnd() const
Definition: lib_arc.h:116
int GetFirstRadiusAngle() const
Definition: lib_arc.h:108
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
wxPoint GetPosition() const override
Definition: lib_arc.h:92

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

Referenced by SaveSymbol().

◆ saveBezier()

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

Definition at line 3876 of file sch_legacy_plugin.cpp.

3878 {
3879  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
3880 
3881  aFormatter.Print( 0, "B %u %d %d %d", (unsigned)aBezier->GetPoints().size(),
3882  aBezier->GetUnit(), aBezier->GetConvert(), aBezier->GetWidth() );
3883 
3884  for( const auto& pt : aBezier->GetPoints() )
3885  aFormatter.Print( 0, " %d %d", pt.x, pt.y );
3886 
3887  aFormatter.Print( 0, " %c\n", fill_tab[aBezier->GetFillMode()] );
3888 }
FILL_T GetFillMode() const
Definition: lib_item.h:307
int GetWidth() const override
Definition: lib_bezier.h:92
int GetUnit() const
Definition: lib_item.h:301
const int fill_tab[3]
Definition: lib_item.cpp:34
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:72
int GetConvert() const
Definition: lib_item.h:304
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

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

Referenced by SaveSymbol().

◆ saveCircle()

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

Definition at line 3891 of file sch_legacy_plugin.cpp.

3893 {
3894  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
3895 
3896  aFormatter.Print( 0, "C %d %d %d %d %d %d %c\n",
3897  aCircle->GetPosition().x, aCircle->GetPosition().y,
3898  aCircle->GetRadius(), aCircle->GetUnit(), aCircle->GetConvert(),
3899  aCircle->GetWidth(), fill_tab[aCircle->GetFillMode()] );
3900 }
FILL_T GetFillMode() const
Definition: lib_item.h:307
wxPoint GetPosition() const override
Definition: lib_circle.h:75
int GetWidth() const override
Definition: lib_circle.h:87
int GetUnit() const
Definition: lib_item.h:301
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetRadius() const
Definition: lib_circle.h:91
int GetConvert() const
Definition: lib_item.h:304
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References fill_tab, LIB_ITEM::GetConvert(), LIB_ITEM::GetFillMode(), LIB_CIRCLE::GetPosition(), LIB_CIRCLE::GetRadius(), LIB_ITEM::GetUnit(), LIB_CIRCLE::GetWidth(), LIB_CIRCLE_T, OUTPUTFORMATTER::Print(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ saveDocFile()

void SCH_LEGACY_PLUGIN_CACHE::saveDocFile ( )
private

Definition at line 4142 of file sch_legacy_plugin.cpp.

4143 {
4144  wxFileName fileName = m_libFileName;
4145 
4146  fileName.SetExt( DOC_EXT );
4147  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
4148 
4149  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
4150 
4151  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
4152  {
4153  wxString description = it->second->GetDescription();
4154  wxString keyWords = it->second->GetKeyWords();
4155  wxString docFileName = it->second->GetDocFileName();
4156 
4157  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
4158  continue;
4159 
4160  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
4161 
4162  if( !description.IsEmpty() )
4163  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
4164 
4165  if( !keyWords.IsEmpty() )
4166  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
4167 
4168  if( !docFileName.IsEmpty() )
4169  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
4170 
4171  formatter.Print( 0, "$ENDCMP\n" );
4172  }
4173 
4174  formatter.Print( 0, "#\n#End Doc Library\n" );
4175 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
#define DOCFILE_IDENT
#define DOC_EXT
Definition: class_library.h:50
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

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

Referenced by Save().

◆ saveField()

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

Definition at line 3903 of file sch_legacy_plugin.cpp.

3905 {
3906  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
3907 
3908  int hjustify, vjustify;
3909  int id = aField->GetId();
3910  wxString text = aField->GetText();
3911 
3912  hjustify = 'C';
3913 
3914  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3915  hjustify = 'L';
3916  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3917  hjustify = 'R';
3918 
3919  vjustify = 'C';
3920 
3921  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3922  vjustify = 'B';
3923  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3924  vjustify = 'T';
3925 
3926  aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
3927  id,
3928  EscapedUTF8( text ).c_str(), // wraps in quotes
3929  aField->GetTextPos().x, aField->GetTextPos().y, aField->GetTextWidth(),
3930  aField->GetTextAngle() == 0 ? 'H' : 'V',
3931  aField->IsVisible() ? 'V' : 'I',
3932  hjustify, vjustify,
3933  aField->IsItalic() ? 'I' : 'N',
3934  aField->IsBold() ? 'B' : 'N' );
3935 
3936  /* Save field name, if necessary
3937  * Field name is saved only if it is not the default name.
3938  * Just because default name depends on the language and can change from
3939  * a country to another
3940  */
3941  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
3942 
3943  if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
3944  aFormatter.Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
3945 
3946  aFormatter.Print( 0, "\n" );
3947 }
bool IsBold() const
Definition: eda_text.h:167
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:185
bool IsVisible() const
Definition: eda_text.h:170
double GetTextAngle() const
Definition: eda_text.h:158
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
int GetId() const
Definition: lib_field.h:135
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:249
bool IsItalic() const
Definition: eda_text.h:164
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:184
int GetTextWidth() const
Definition: eda_text.h:226
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxString m_name
Name (not the field text value itself, that is .m_Text)
Definition: lib_field.h:62
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References EscapedUTF8(), FIELD1, 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, OUTPUTFORMATTER::Print(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ savePin()

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

Definition at line 3950 of file sch_legacy_plugin.cpp.

3952 {
3953  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
3954 
3955  int Etype;
3956 
3957  switch( aPin->GetType() )
3958  {
3959  default:
3960  case PIN_INPUT:
3961  Etype = 'I';
3962  break;
3963 
3964  case PIN_OUTPUT:
3965  Etype = 'O';
3966  break;
3967 
3968  case PIN_BIDI:
3969  Etype = 'B';
3970  break;
3971 
3972  case PIN_TRISTATE:
3973  Etype = 'T';
3974  break;
3975 
3976  case PIN_PASSIVE:
3977  Etype = 'P';
3978  break;
3979 
3980  case PIN_UNSPECIFIED:
3981  Etype = 'U';
3982  break;
3983 
3984  case PIN_POWER_IN:
3985  Etype = 'W';
3986  break;
3987 
3988  case PIN_POWER_OUT:
3989  Etype = 'w';
3990  break;
3991 
3992  case PIN_OPENCOLLECTOR:
3993  Etype = 'C';
3994  break;
3995 
3996  case PIN_OPENEMITTER:
3997  Etype = 'E';
3998  break;
3999 
4000  case PIN_NC:
4001  Etype = 'N';
4002  break;
4003  }
4004 
4005  if( !aPin->GetName().IsEmpty() )
4006  aFormatter.Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
4007  else
4008  aFormatter.Print( 0, "X ~" );
4009 
4010  aFormatter.Print( 0, " %s %d %d %d %c %d %d %d %d %c",
4011  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
4012  aPin->GetPosition().x, aPin->GetPosition().y,
4013  (int) aPin->GetLength(), (int) aPin->GetOrientation(),
4014  aPin->GetNumberTextSize(), aPin->GetNameTextSize(),
4015  aPin->GetUnit(), aPin->GetConvert(), Etype );
4016 
4017  if( aPin->GetShape() || !aPin->IsVisible() )
4018  aFormatter.Print( 0, " " );
4019 
4020  if( !aPin->IsVisible() )
4021  aFormatter.Print( 0, "N" );
4022 
4023  switch( aPin->GetShape() )
4024  {
4025  case PINSHAPE_LINE:
4026  break;
4027 
4028  case PINSHAPE_INVERTED:
4029  aFormatter.Print( 0, "I" );
4030  break;
4031 
4032  case PINSHAPE_CLOCK:
4033  aFormatter.Print( 0, "C" );
4034  break;
4035 
4037  aFormatter.Print( 0, "IC" );
4038  break;
4039 
4040  case PINSHAPE_INPUT_LOW:
4041  aFormatter.Print( 0, "L" );
4042  break;
4043 
4044  case PINSHAPE_CLOCK_LOW:
4045  aFormatter.Print( 0, "CL" );
4046  break;
4047 
4048  case PINSHAPE_OUTPUT_LOW:
4049  aFormatter.Print( 0, "V" );
4050  break;
4051 
4053  aFormatter.Print( 0, "F" );
4054  break;
4055 
4056  case PINSHAPE_NONLOGIC:
4057  aFormatter.Print( 0, "X" );
4058  break;
4059 
4060  default:
4061  assert( !"Invalid pin shape" );
4062  }
4063 
4064  aFormatter.Print( 0, "\n" );
4065 
4066  aPin->ClearFlags( IS_CHANGED );
4067 }
int GetOrientation() const
Definition: lib_pin.h:204
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:216
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
int GetUnit() const
Definition: lib_item.h:301
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:116
const wxString & GetName() const
Definition: lib_pin.h:149
bool IsVisible() const
Return the visibility status of the draw object.
Definition: lib_pin.h:343
int GetNameTextSize() const
Definition: lib_pin.h:175
int GetConvert() const
Definition: lib_item.h:304
wxPoint GetPosition() const override
Definition: lib_pin.h:427
const wxString & GetNumber() const
Definition: lib_pin.h:177
ELECTRICAL_PINTYPE GetType() const
Get the electrical type of the pin.
Definition: lib_pin.h:232
int GetNumberTextSize() const
Definition: lib_pin.h:202
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:266
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
int GetLength()
Definition: lib_pin.h:282
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References EDA_ITEM::ClearFlags(), LIB_ITEM::GetConvert(), LIB_PIN::GetLength(), LIB_PIN::GetName(), LIB_PIN::GetNameTextSize(), LIB_PIN::GetNumber(), LIB_PIN::GetNumberTextSize(), LIB_PIN::GetOrientation(), LIB_PIN::GetPosition(), LIB_PIN::GetShape(), LIB_PIN::GetType(), LIB_ITEM::GetUnit(), IS_CHANGED, LIB_PIN::IsVisible(), LIB_PIN_T, PIN_BIDI, PIN_INPUT, PIN_NC, PIN_OPENCOLLECTOR, PIN_OPENEMITTER, PIN_OUTPUT, PIN_PASSIVE, PIN_POWER_IN, PIN_POWER_OUT, PIN_TRISTATE, PIN_UNSPECIFIED, PINSHAPE_CLOCK, PINSHAPE_CLOCK_LOW, PINSHAPE_FALLING_EDGE_CLOCK, PINSHAPE_INPUT_LOW, PINSHAPE_INVERTED, PINSHAPE_INVERTED_CLOCK, PINSHAPE_LINE, PINSHAPE_NONLOGIC, PINSHAPE_OUTPUT_LOW, OUTPUTFORMATTER::Print(), TO_UTF8, and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ savePolyLine()

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

Definition at line 4070 of file sch_legacy_plugin.cpp.

4072 {
4073  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
4074 
4075  int ccount = aPolyLine->GetCornerCount();
4076 
4077  aFormatter.Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
4078  aPolyLine->GetWidth() );
4079 
4080  for( const auto& pt : aPolyLine->GetPolyPoints() )
4081  {
4082  aFormatter.Print( 0, " %d %d", pt.x, pt.y );
4083  }
4084 
4085  aFormatter.Print( 0, " %c\n", fill_tab[aPolyLine->GetFillMode()] );
4086 }
FILL_T GetFillMode() const
Definition: lib_item.h:307
int GetWidth() const override
Definition: lib_polyline.h:104
unsigned GetCornerCount() const
Definition: lib_polyline.h:73
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:60
int GetUnit() const
Definition: lib_item.h:301
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetConvert() const
Definition: lib_item.h:304
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

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

Referenced by SaveSymbol().

◆ saveRectangle()

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

Definition at line 4089 of file sch_legacy_plugin.cpp.

4091 {
4092  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
4093  "Invalid LIB_RECTANGLE object." );
4094 
4095  aFormatter.Print( 0, "S %d %d %d %d %d %d %d %c\n",
4096  aRectangle->GetPosition().x, aRectangle->GetPosition().y,
4097  aRectangle->GetEnd().x, aRectangle->GetEnd().y,
4098  aRectangle->GetUnit(), aRectangle->GetConvert(),
4099  aRectangle->GetWidth(), fill_tab[aRectangle->GetFillMode()] );
4100 }
wxPoint GetEnd() const
Definition: lib_rectangle.h:89
FILL_T GetFillMode() const
Definition: lib_item.h:307
int GetUnit() const
Definition: lib_item.h:301
int GetWidth() const override
Definition: lib_rectangle.h:85
const int fill_tab[3]
Definition: lib_item.cpp:34
int GetConvert() const
Definition: lib_item.h:304
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxPoint GetPosition() const override
Definition: lib_rectangle.h:76
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References fill_tab, LIB_ITEM::GetConvert(), LIB_RECTANGLE::GetEnd(), LIB_ITEM::GetFillMode(), LIB_RECTANGLE::GetPosition(), LIB_ITEM::GetUnit(), LIB_RECTANGLE::GetWidth(), LIB_RECTANGLE_T, OUTPUTFORMATTER::Print(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ SaveSymbol()

void SCH_LEGACY_PLUGIN_CACHE::SaveSymbol ( LIB_PART aSymbol,
OUTPUTFORMATTER aFormatter 
)
static

Definition at line 3690 of file sch_legacy_plugin.cpp.

3692 {
3693  wxCHECK_RET( aSymbol, "Invalid LIB_PART pointer." );
3694 
3695  LIB_FIELD& value = aSymbol->GetValueField();
3696 
3697  // First line: it s a comment (component name for readers)
3698  aFormatter.Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3699 
3700  // Save data
3701  aFormatter.Print( 0, "DEF" );
3702  aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) );
3703 
3704  LIB_FIELD& reference = aSymbol->GetReferenceField();
3705 
3706  if( !reference.GetText().IsEmpty() )
3707  {
3708  aFormatter.Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3709  }
3710  else
3711  {
3712  aFormatter.Print( 0, " ~" );
3713  }
3714 
3715  aFormatter.Print( 0, " %d %d %c %c %d %c %c\n",
3716  0, aSymbol->GetPinNameOffset(),
3717  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3718  aSymbol->ShowPinNames() ? 'Y' : 'N',
3719  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3720  aSymbol->IsPower() ? 'P' : 'N' );
3721 
3722  timestamp_t dateModified = aSymbol->GetDateLastEdition();
3723 
3724  if( dateModified != 0 )
3725  {
3726  int sec = dateModified & 63;
3727  int min = ( dateModified >> 6 ) & 63;
3728  int hour = ( dateModified >> 12 ) & 31;
3729  int day = ( dateModified >> 17 ) & 31;
3730  int mon = ( dateModified >> 22 ) & 15;
3731  int year = ( dateModified >> 26 ) + 1990;
3732 
3733  aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3734  }
3735 
3736  LIB_FIELDS fields;
3737  aSymbol->GetFields( fields );
3738 
3739  // Mandatory fields:
3740  // may have their own save policy so there is a separate loop for them.
3741  // Empty fields are saved, because the user may have set visibility,
3742  // size and orientation
3743  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3744  {
3745  saveField( &fields[i], aFormatter );
3746  }
3747 
3748  // User defined fields:
3749  // may have their own save policy so there is a separate loop for them.
3750 
3751  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3752 
3753  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3754  {
3755  // There is no need to save empty fields, i.e. no reason to preserve field
3756  // names now that fields names come in dynamically through the template
3757  // fieldnames.
3758  if( !fields[i].GetText().IsEmpty() )
3759  {
3760  fields[i].SetId( fieldId++ );
3761  saveField( &fields[i], aFormatter );
3762  }
3763  }
3764 
3765  // Save the alias list: a line starting by "ALIAS". The first alias is the root
3766  // and has the same name as the component. In the old library file format this
3767  // alias does not get added to the alias list.
3768  if( aSymbol->GetAliasCount() > 1 )
3769  {
3770  wxArrayString aliases = aSymbol->GetAliasNames();
3771 
3772  aFormatter.Print( 0, "ALIAS" );
3773 
3774  for( unsigned i = 1; i < aliases.size(); i++ )
3775  {
3776  aFormatter.Print( 0, " %s", TO_UTF8( aliases[i] ) );
3777  }
3778 
3779  aFormatter.Print( 0, "\n" );
3780  }
3781 
3782  wxArrayString footprints = aSymbol->GetFootprints();
3783 
3784  // Write the footprint filter list
3785  if( footprints.GetCount() != 0 )
3786  {
3787  aFormatter.Print( 0, "$FPLIST\n" );
3788 
3789  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3790  {
3791  aFormatter.Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3792  }
3793 
3794  aFormatter.Print( 0, "$ENDFPLIST\n" );
3795  }
3796 
3797  // Save graphics items (including pins)
3798  if( !aSymbol->GetDrawItems().empty() )
3799  {
3800  // Sort the draw items in order to editing a file editing by hand.
3801  aSymbol->GetDrawItems().sort();
3802 
3803  aFormatter.Print( 0, "DRAW\n" );
3804 
3805  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3806  {
3807  switch( item.Type() )
3808  {
3809  case LIB_FIELD_T: // Fields have already been saved above.
3810  continue;
3811 
3812  case LIB_ARC_T:
3813  saveArc( (LIB_ARC*) &item, aFormatter );
3814  break;
3815 
3816  case LIB_BEZIER_T:
3817  saveBezier( (LIB_BEZIER*) &item, aFormatter );
3818  break;
3819 
3820  case LIB_CIRCLE_T:
3821  saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
3822  break;
3823 
3824  case LIB_PIN_T:
3825  savePin( (LIB_PIN* ) &item, aFormatter );
3826  break;
3827 
3828  case LIB_POLYLINE_T:
3829  savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
3830  break;
3831 
3832  case LIB_RECTANGLE_T:
3833  saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
3834  break;
3835 
3836  case LIB_TEXT_T:
3837  saveText( ( LIB_TEXT* ) &item, aFormatter );
3838  break;
3839 
3840  default:
3841  ;
3842  }
3843  }
3844 
3845  aFormatter.Print( 0, "ENDDRAW\n" );
3846  }
3847 
3848  aFormatter.Print( 0, "ENDDEF\n" );
3849 }
int GetUnitCount() const
static void saveCircle(LIB_CIRCLE *aCircle, OUTPUTFORMATTER &aFormatter)
int GetPinNameOffset()
Define a symbol library graphical text item.
Definition: lib_text.h:40
timestamp_t GetDateLastEdition() const
bool empty(int aType=UNDEFINED_TYPE)
Definition: multivector.h:224
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
Field object used in symbol libraries.
Definition: lib_field.h:59
void sort()
Definition: multivector.h:229
LIB_FIELD & GetValueField()
Return reference to the value field.
static void savePin(LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter)
static void saveBezier(LIB_BEZIER *aBezier, OUTPUTFORMATTER &aFormatter)
static void saveField(LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter)
The base class for drawable items used by schematic library components.
Definition: lib_item.h:61
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
bool ShowPinNames()
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
bool ShowPinNumbers()
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
static void saveText(LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter)
static void saveRectangle(LIB_RECTANGLE *aRectangle, OUTPUTFORMATTER &aFormatter)
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
static void savePolyLine(LIB_POLYLINE *aPolyLine, OUTPUTFORMATTER &aFormatter)
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
wxArrayString & GetFootprints()
bool IsPower() const
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:214
size_t i
Definition: json11.cpp:597
static void saveArc(LIB_ARC *aArc, OUTPUTFORMATTER &aFormatter)
size_t GetAliasCount() const
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
bool UnitsLocked() const
Check whether part units are interchangeable.
void GetFields(LIB_FIELDS &aList)
Return a list of fields within this part.
#define min(a, b)
Definition: auxiliary.h:85
Class LIB_BEZIER defines bezier curve graphic body item.
Definition: lib_bezier.h:35

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

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

◆ saveText()

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

Definition at line 4103 of file sch_legacy_plugin.cpp.

4105 {
4106  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
4107 
4108  wxString text = aText->GetText();
4109 
4110  if( text.Contains( wxT( " " ) ) || text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
4111  {
4112  // convert double quote to similar-looking two apostrophes
4113  text.Replace( wxT( "\"" ), wxT( "''" ) );
4114  text = wxT( "\"" ) + text + wxT( "\"" );
4115  }
4116 
4117  aFormatter.Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
4118  aText->GetTextPos().x, aText->GetTextPos().y,
4119  aText->GetTextWidth(), !aText->IsVisible(),
4120  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
4121 
4122  aFormatter.Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
4123 
4124  char hjustify = 'C';
4125 
4126  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
4127  hjustify = 'L';
4128  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
4129  hjustify = 'R';
4130 
4131  char vjustify = 'C';
4132 
4133  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
4134  vjustify = 'B';
4135  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
4136  vjustify = 'T';
4137 
4138  aFormatter.Print( 0, " %c %c\n", hjustify, vjustify );
4139 }
bool IsBold() const
Definition: eda_text.h:167
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:185
bool IsVisible() const
Definition: eda_text.h:170
double GetTextAngle() const
Definition: eda_text.h:158
bool IsItalic() const
Definition: eda_text.h:164
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
int GetUnit() const
Definition: lib_item.h:301
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:184
int GetConvert() const
Definition: lib_item.h:304
int GetTextWidth() const
Definition: eda_text.h:226
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

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

Referenced by SaveSymbol().

◆ SetFileName()

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

Definition at line 551 of file sch_legacy_plugin.cpp.

551 { 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_aliases

◆ m_fileModTime

wxDateTime SCH_LEGACY_PLUGIN_CACHE::m_fileModTime
private

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

Referenced by IsFile(), and Load().

◆ m_isModified

bool SCH_LEGACY_PLUGIN_CACHE::m_isModified
private

Definition at line 478 of file sch_legacy_plugin.cpp.

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

◆ m_isWritable

bool SCH_LEGACY_PLUGIN_CACHE::m_isWritable
private

Definition at line 477 of file sch_legacy_plugin.cpp.

Referenced by GetLibModificationTime().

◆ m_libFileName

wxFileName SCH_LEGACY_PLUGIN_CACHE::m_libFileName
private

◆ m_libType

int SCH_LEGACY_PLUGIN_CACHE::m_libType
private

Definition at line 481 of file sch_legacy_plugin.cpp.

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ m_modHash

int SCH_LEGACY_PLUGIN_CACHE::m_modHash = 1
staticprivate

Definition at line 471 of file sch_legacy_plugin.cpp.

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

◆ m_versionMajor

int SCH_LEGACY_PLUGIN_CACHE::m_versionMajor
private

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

Referenced by Load(), and SCH_LEGACY_PLUGIN_CACHE().

◆ SCH_LEGACY_PLUGIN

friend SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN
private

Definition at line 515 of file sch_legacy_plugin.cpp.


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