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

2291  :
2292  m_fileName( aFullPathAndFileName ),
2293  m_libFileName( aFullPathAndFileName ),
2294  m_isWritable( true ),
2295  m_isModified( false )
2296 {
2297  m_versionMajor = -1;
2298  m_versionMinor = -1;
2300 }

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

2304 {
2305  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
2306  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); ++it )
2307  {
2308  wxLogTrace( traceSchLegacyPlugin, wxT( "Removing alias %s from library %s." ),
2309  GetChars( it->second->GetName() ), GetChars( GetLogicalName() ) );
2310  LIB_PART* part = it->second->GetPart();
2311  LIB_ALIAS* alias = it->second;
2312  delete alias;
2313 
2314  // When the last alias of a part is destroyed, the part is no longer required and it
2315  // too is destroyed.
2316  if( part && part->GetAliasCount() == 0 )
2317  delete part;
2318  }
2319 
2320  m_aliases.clear();
2321 }
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 2420 of file sch_legacy_plugin.cpp.

2421 {
2422  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
2423  wxArrayString aliasNames = aPart->GetAliasNames();
2424 
2425  for( size_t i = 0; i < aliasNames.size(); i++ )
2426  {
2427  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasNames[i] );
2428 
2429  if( it != m_aliases.end() )
2430  removeAlias( it->second );
2431 
2432  LIB_ALIAS* alias = const_cast< LIB_PART* >( aPart )->GetAlias( aliasNames[i] );
2433 
2434  wxASSERT_MSG( alias != NULL, "No alias <" + aliasNames[i] + "> found in symbol <" +
2435  aPart->GetName() +">." );
2436 
2437  m_aliases[ aliasNames[i] ] = alias;
2438  }
2439 
2440  m_isModified = true;
2441  ++m_modHash;
2442 }
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 4152 of file sch_legacy_plugin.cpp.

4153 {
4154  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
4155 
4156  if( it == m_aliases.end() )
4157  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
4158  m_libFileName.GetFullName(), aAliasName ) );
4159 
4160  LIB_ALIAS* alias = it->second;
4161  LIB_PART* part = alias->GetPart();
4162 
4163  alias = part->RemoveAlias( alias );
4164 
4165  if( !alias )
4166  {
4167  delete part;
4168 
4169  if( m_aliases.size() > 1 )
4170  {
4171  LIB_ALIAS_MAP::iterator next = it;
4172  next++;
4173 
4174  if( next == m_aliases.end() )
4175  next = m_aliases.begin();
4176 
4177  alias = next->second;
4178  }
4179  }
4180 
4181  m_aliases.erase( it );
4182  ++m_modHash;
4183  m_isModified = true;
4184 }
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 4187 of file sch_legacy_plugin.cpp.

4188 {
4189  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
4190 
4191  if( it == m_aliases.end() )
4192  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
4193  m_libFileName.GetFullName(), aAliasName ) );
4194 
4195  LIB_ALIAS* alias = it->second;
4196  LIB_PART* part = alias->GetPart();
4197 
4198  wxArrayString aliasNames = part->GetAliasNames();
4199 
4200  // Deleting all of the aliases deletes the symbol from the library.
4201  for( size_t i = 0; i < aliasNames.Count(); i++ )
4202  DeleteAlias( aliasNames[i] );
4203 }
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 2348 of file sch_legacy_plugin.cpp.

2349 {
2350  wxFileName fn = GetRealFile();
2351 
2352  // update the writable flag while we have a wxFileName, in a network this
2353  // is possibly quite dynamic anyway.
2354  m_isWritable = fn.IsFileWritable();
2355 
2356  return fn.GetModificationTime();
2357 }
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 2325 of file sch_legacy_plugin.cpp.

2326 {
2327  wxFileName fn( m_libFileName );
2328 
2329 #ifndef __WINDOWS__
2330  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
2331  {
2332  char buffer[ PATH_MAX + 1 ];
2333  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
2334 
2335  if( pathLen > 0 )
2336  {
2337  buffer[ pathLen ] = '\0';
2338  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
2339  fn.Normalize();
2340  }
2341  }
2342 #endif
2343 
2344  return fn;
2345 }
#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 2360 of file sch_legacy_plugin.cpp.

2361 {
2362  return m_fileName == aFullPathAndFileName;
2363 }

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

2367 {
2368  wxFileName fn = GetRealFile();
2369 
2370  if( m_fileModTime.IsValid() && fn.IsOk() && fn.FileExists() )
2371  return fn.GetModificationTime() != m_fileModTime;
2372 
2373  return false;
2374 }
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 2445 of file sch_legacy_plugin.cpp.

2446 {
2447  if( !m_libFileName.FileExists() )
2448  {
2449  THROW_IO_ERROR( wxString::Format( _( "Library file \"%s\" not found." ),
2450  m_libFileName.GetFullPath() ) );
2451  }
2452 
2453  wxCHECK_RET( m_libFileName.IsAbsolute(),
2454  wxString::Format( "Cannot use relative file paths in legacy plugin to "
2455  "open library \"%s\".", m_libFileName.GetFullPath() ) );
2456 
2457  wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file \"%s\"",
2458  m_libFileName.GetFullPath() );
2459 
2460  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
2461 
2462  if( !reader.ReadLine() )
2463  THROW_IO_ERROR( _( "unexpected end of file" ) );
2464 
2465  const char* line = reader.Line();
2466 
2467  if( !strCompare( "EESchema-LIBRARY Version", line, &line ) )
2468  {
2469  // Old .sym files (which are libraries with only one symbol, used to store and reuse shapes)
2470  // EESchema-LIB Version x.x SYMBOL. They are valid files.
2471  if( !strCompare( "EESchema-LIB Version", line, &line ) )
2472  SCH_PARSE_ERROR( "file is not a valid component or symbol library file", reader, line );
2473  }
2474 
2475  m_versionMajor = parseInt( reader, line, &line );
2476 
2477  if( *line != '.' )
2478  SCH_PARSE_ERROR( "invalid file version formatting in header", reader, line );
2479 
2480  line++;
2481 
2482  m_versionMinor = parseInt( reader, line, &line );
2483 
2484  if( m_versionMajor < 1 || m_versionMinor < 0 || m_versionMinor > 99 )
2485  SCH_PARSE_ERROR( "invalid file version in header", reader, line );
2486 
2487  // Check if this is a symbol library which is the same as a component library but without
2488  // any alias, documentation, footprint filters, etc.
2489  if( strCompare( "SYMBOL", line, &line ) )
2490  {
2491  // Symbol files add date and time stamp info to the header.
2493 
2495  }
2496  else
2497  {
2499  }
2500 
2501  while( reader.ReadLine() )
2502  {
2503  line = reader.Line();
2504 
2505  if( *line == '#' || isspace( *line ) ) // Skip comments and blank lines.
2506  continue;
2507 
2508  // Headers where only supported in older library file formats.
2509  if( m_libType == LIBRARY_TYPE_EESCHEMA && strCompare( "$HEADER", line ) )
2510  loadHeader( reader );
2511 
2512  if( strCompare( "DEF", line ) )
2513  {
2514  // Read one DEF/ENDDEF part entry from library:
2515  LIB_PART * part = LoadPart( reader, m_versionMajor, m_versionMinor );
2516 
2517  // Add aliases to cache
2518  for( size_t ii = 0; ii < part->GetAliasCount(); ++ii )
2519  {
2520  LIB_ALIAS* alias = part->GetAlias( ii );
2521  const wxString& aliasName = alias->GetName();
2522 
2523  // This section seems to do a similar job as checkForDuplicates, so
2524  // I'm not sure checkForDuplicates needs to be preserved.
2525  auto it = m_aliases.find( aliasName );
2526 
2527  if( it != m_aliases.end() )
2528  {
2529  // Find a new name for the alias
2530  wxString newName;
2531  int idx = 0;
2532  LIB_ALIAS_MAP::const_iterator jt;
2533 
2534  do
2535  {
2536  newName = wxString::Format( "%s_%d", aliasName, idx );
2537  jt = m_aliases.find( newName );
2538  ++idx;
2539  }
2540  while( jt != m_aliases.end() );
2541 
2542  wxLogWarning( "Symbol name conflict in library:\n%s\n"
2543  "'%s' has been renamed to '%s'",
2544  m_fileName, aliasName, newName );
2545 
2546  if( alias->IsRoot() )
2547  part->SetName( newName );
2548  else
2549  alias->SetName( newName );
2550 
2551  m_aliases[newName] = alias;
2552  }
2553  else
2554  {
2555  m_aliases[aliasName] = alias;
2556  }
2557  }
2558  }
2559  }
2560 
2561  ++m_modHash;
2562 
2563  // Remember the file modification time of library file when the
2564  // cache snapshot was made, so that in a networked environment we will
2565  // reload the cache as needed.
2567 
2569  loadDocs();
2570 }
Part library alias object definition.
LIB_ALIAS * GetAlias(size_t aIndex)
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
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 2902 of file sch_legacy_plugin.cpp.

2904 {
2905  wxString newAlias;
2906  const char* line = aReader.Line();
2907 
2908  wxCHECK_RET( strCompare( "ALIAS", line, &line ), "Invalid ALIAS section" );
2909 
2910  wxString utf8Line = wxString::FromUTF8( line );
2911  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2912 
2913  // Parse the ALIAS list.
2914  while( tokens.HasMoreTokens() )
2915  {
2916  newAlias = tokens.GetNextToken();
2917  aPart->AddAlias( newAlias );
2918  }
2919 }
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 3146 of file sch_legacy_plugin.cpp.

3148 {
3149  const char* line = aReader.Line();
3150 
3151  wxCHECK_MSG( strCompare( "A", line, &line ), NULL, "Invalid LIB_ARC definition" );
3152 
3153  LIB_ARC* arc = new LIB_ARC( aPart.get() );
3154 
3155  wxPoint center;
3156 
3157  center.x = parseInt( aReader, line, &line );
3158  center.y = parseInt( aReader, line, &line );
3159 
3160  arc->SetPosition( center );
3161  arc->SetRadius( parseInt( aReader, line, &line ) );
3162 
3163  int angle1 = parseInt( aReader, line, &line );
3164  int angle2 = parseInt( aReader, line, &line );
3165 
3166  NORMALIZE_ANGLE_POS( angle1 );
3167  NORMALIZE_ANGLE_POS( angle2 );
3168  arc->SetFirstRadiusAngle( angle1 );
3169  arc->SetSecondRadiusAngle( angle2 );
3170 
3171  arc->SetUnit( parseInt( aReader, line, &line ) );
3172  arc->SetConvert( parseInt( aReader, line, &line ) );
3173  arc->SetWidth( parseInt( aReader, line, &line ) );
3174 
3175  // Old libraries (version <= 2.2) do not have always this FILL MODE param
3176  // when fill mode is no fill (default mode).
3177  if( *line != 0 )
3178  arc->SetFillMode( parseFillMode( aReader, line, &line ) );
3179 
3180  // Actual Coordinates of arc ends are read from file
3181  if( *line != 0 )
3182  {
3183  wxPoint arcStart, arcEnd;
3184 
3185  arcStart.x = parseInt( aReader, line, &line );
3186  arcStart.y = parseInt( aReader, line, &line );
3187  arcEnd.x = parseInt( aReader, line, &line );
3188  arcEnd.y = parseInt( aReader, line, &line );
3189 
3190  arc->SetStart( arcStart );
3191  arc->SetEnd( arcEnd );
3192  }
3193  else
3194  {
3195  // Actual Coordinates of arc ends are not read from file
3196  // (old library), calculate them
3197  wxPoint arcStart( arc->GetRadius(), 0 );
3198  wxPoint arcEnd( arc->GetRadius(), 0 );
3199 
3200  RotatePoint( &arcStart.x, &arcStart.y, -angle1 );
3201  arcStart += arc->GetPosition();
3202  arc->SetStart( arcStart );
3203  RotatePoint( &arcEnd.x, &arcEnd.y, -angle2 );
3204  arcEnd += arc->GetPosition();
3205  arc->SetEnd( arcEnd );
3206  }
3207 
3208  return arc;
3209 }
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:229
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 3577 of file sch_legacy_plugin.cpp.

3579 {
3580  const char* line = aReader.Line();
3581 
3582  wxCHECK_MSG( strCompare( "B", line, &line ), NULL, "Invalid LIB_BEZIER definition" );
3583 
3584  LIB_BEZIER* bezier = new LIB_BEZIER( aPart.get() );
3585 
3586  int points = parseInt( aReader, line, &line );
3587  bezier->SetUnit( parseInt( aReader, line, &line ) );
3588  bezier->SetConvert( parseInt( aReader, line, &line ) );
3589  bezier->SetWidth( parseInt( aReader, line, &line ) );
3590 
3591  wxPoint pt;
3592  bezier->Reserve( points );
3593 
3594  for( int i = 0; i < points; i++ )
3595  {
3596  pt.x = parseInt( aReader, line, &line );
3597  pt.y = parseInt( aReader, line, &line );
3598  bezier->AddPoint( pt );
3599  }
3600 
3601  if( *line != 0 )
3602  bezier->SetFillMode( parseFillMode( aReader, line, &line ) );
3603 
3604  return bezier;
3605 }
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 3212 of file sch_legacy_plugin.cpp.

3214 {
3215  const char* line = aReader.Line();
3216 
3217  wxCHECK_MSG( strCompare( "C", line, &line ), NULL, "Invalid LIB_CIRCLE definition" );
3218 
3219  LIB_CIRCLE* circle = new LIB_CIRCLE( aPart.get() );
3220 
3221  wxPoint center;
3222 
3223  center.x = parseInt( aReader, line, &line );
3224  center.y = parseInt( aReader, line, &line );
3225 
3226  circle->SetPosition( center );
3227  circle->SetRadius( parseInt( aReader, line, &line ) );
3228  circle->SetUnit( parseInt( aReader, line, &line ) );
3229  circle->SetConvert( parseInt( aReader, line, &line ) );
3230  circle->SetWidth( parseInt( aReader, line, &line ) );
3231 
3232  if( *line != 0 )
3233  circle->SetFillMode( parseFillMode( aReader, line, &line ) );
3234 
3235  return circle;
3236 }
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 2573 of file sch_legacy_plugin.cpp.

2574 {
2575  const char* line;
2576  wxString text;
2577  wxString aliasName;
2578  wxFileName fn = m_libFileName;
2579  LIB_ALIAS* alias = NULL;;
2580 
2581  fn.SetExt( DOC_EXT );
2582 
2583  // Not all libraries will have a document file.
2584  if( !fn.FileExists() )
2585  return;
2586 
2587  if( !fn.IsFileReadable() )
2588  THROW_IO_ERROR( wxString::Format( _( "user does not have permission to read library "
2589  "document file \"%s\"" ), fn.GetFullPath() ) );
2590 
2591  FILE_LINE_READER reader( fn.GetFullPath() );
2592 
2593  line = reader.ReadLine();
2594 
2595  if( !line )
2596  THROW_IO_ERROR( _( "symbol document library file is empty" ) );
2597 
2598  if( !strCompare( DOCFILE_IDENT, line, &line ) )
2599  SCH_PARSE_ERROR( "invalid document library file version formatting in header",
2600  reader, line );
2601 
2602  while( reader.ReadLine() )
2603  {
2604  line = reader.Line();
2605 
2606  if( *line == '#' ) // Comment line.
2607  continue;
2608 
2609  if( !strCompare( "$CMP", line, &line ) != 0 )
2610  SCH_PARSE_ERROR( "$CMP command expected", reader, line );
2611 
2612  aliasName = wxString::FromUTF8( line );
2613  aliasName.Trim();
2614  aliasName = LIB_ID::FixIllegalChars( aliasName, LIB_ID::ID_SCH );
2615 
2616  LIB_ALIAS_MAP::iterator it = m_aliases.find( aliasName );
2617 
2618  if( it == m_aliases.end() )
2619  wxLogWarning( "Alias '%s' not found in library:\n\n"
2620  "'%s'\n\nat line %d offset %d", aliasName, fn.GetFullPath(),
2621  reader.LineNumber(), (int) (line - reader.Line() ) );
2622  else
2623  alias = it->second;
2624 
2625  // Read the curent alias associated doc.
2626  // if the alias does not exist, just skip the description
2627  // (Can happen if a .dcm is not synchronized with the corresponding .lib file)
2628  while( reader.ReadLine() )
2629  {
2630  line = reader.Line();
2631 
2632  if( !line )
2633  SCH_PARSE_ERROR( "unexpected end of file", reader, line );
2634 
2635  if( strCompare( "$ENDCMP", line, &line ) )
2636  break;
2637 
2638  text = FROM_UTF8( line + 2 );
2639  // Remove spaces at eol, and eol chars:
2640  text = text.Trim();
2641 
2642  switch( line[0] )
2643  {
2644  case 'D':
2645  if( alias )
2646  alias->SetDescription( text );
2647  break;
2648 
2649  case 'K':
2650  if( alias )
2651  alias->SetKeyWords( text );
2652  break;
2653 
2654  case 'F':
2655  if( alias )
2656  alias->SetDocFileName( text );
2657  break;
2658 
2659  case 0:
2660  case '\n':
2661  case '\r':
2662  case '#':
2663  // Empty line or commment
2664  break;
2665 
2666  default:
2667  SCH_PARSE_ERROR( "expected token in symbol definition", reader, line );
2668  }
2669  }
2670  }
2671 }
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 3070 of file sch_legacy_plugin.cpp.

3074 {
3075  const char* line = aReader.Line();
3076 
3077  wxCHECK_RET( strCompare( "DRAW", line, &line ), "Invalid DRAW section" );
3078 
3079  line = aReader.ReadLine();
3080 
3081  while( line )
3082  {
3083  if( strCompare( "ENDDRAW", line, &line ) )
3084  return;
3085 
3086  switch( line[0] )
3087  {
3088  case 'A': // Arc
3089  aPart->AddDrawItem( loadArc( aPart, aReader ) );
3090  break;
3091 
3092  case 'C': // Circle
3093  aPart->AddDrawItem( loadCircle( aPart, aReader ) );
3094  break;
3095 
3096  case 'T': // Text
3097  aPart->AddDrawItem( loadText( aPart, aReader, aMajorVersion, aMinorVersion ) );
3098  break;
3099 
3100  case 'S': // Square
3101  aPart->AddDrawItem( loadRectangle( aPart, aReader ) );
3102  break;
3103 
3104  case 'X': // Pin Description
3105  aPart->AddDrawItem( loadPin( aPart, aReader ) );
3106  break;
3107 
3108  case 'P': // Polyline
3109  aPart->AddDrawItem( loadPolyLine( aPart, aReader ) );
3110  break;
3111 
3112  case 'B': // Bezier Curves
3113  aPart->AddDrawItem( loadBezier( aPart, aReader ) );
3114  break;
3115 
3116  case '#': // Comment
3117  case '\n': // Empty line
3118  case '\r':
3119  case 0:
3120  break;
3121 
3122  default:
3123  SCH_PARSE_ERROR( "undefined DRAW entry", aReader, line );
3124  }
3125 
3126  line = aReader.ReadLine();
3127  }
3128 
3129  SCH_PARSE_ERROR( "file ended prematurely loading component draw element", aReader, line );
3130 }
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 2922 of file sch_legacy_plugin.cpp.

2924 {
2925  const char* line = aReader.Line();
2926 
2927  wxCHECK_RET( *line == 'F', "Invalid field line" );
2928 
2929  wxString text;
2930  int id;
2931 
2932  if( sscanf( line + 1, "%d", &id ) != 1 || id < 0 )
2933  SCH_PARSE_ERROR( "invalid field ID", aReader, line + 1 );
2934 
2935  LIB_FIELD* field;
2936 
2937  if( (unsigned) id < MANDATORY_FIELDS )
2938  {
2939  field = aPart->GetField( id );
2940 
2941  // this will fire only if somebody broke a constructor or editor.
2942  // MANDATORY_FIELDS are always present in ram resident components, no
2943  // exceptions, and they always have their names set, even fixed fields.
2944  wxASSERT( field );
2945  }
2946  else
2947  {
2948  field = new LIB_FIELD( aPart.get(), id );
2949  aPart->AddDrawItem( field );
2950  }
2951 
2952  // Skip to the first double quote.
2953  while( *line != '"' && *line != 0 )
2954  line++;
2955 
2956  if( *line == 0 )
2957  SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, line );
2958 
2959  parseQuotedString( text, aReader, line, &line, true );
2960 
2961  field->SetText( text );
2962 
2963  // Doctor the *.lib file field which has a "~" in blank fields. New saves will
2964  // not save like this.
2965  if( text.size() == 1 && text[0] == '~' )
2966  field->SetText( wxEmptyString );
2967  else
2968  field->SetText( text );
2969 
2970  wxPoint pos;
2971 
2972  pos.x = parseInt( aReader, line, &line );
2973  pos.y = parseInt( aReader, line, &line );
2974  field->SetPosition( pos );
2975 
2976  wxSize textSize;
2977 
2978  textSize.x = textSize.y = parseInt( aReader, line, &line );
2979  field->SetTextSize( textSize );
2980 
2981  char textOrient = parseChar( aReader, line, &line );
2982 
2983  if( textOrient == 'H' )
2984  field->SetTextAngle( TEXT_ANGLE_HORIZ );
2985  else if( textOrient == 'V' )
2986  field->SetTextAngle( TEXT_ANGLE_VERT );
2987  else
2988  SCH_PARSE_ERROR( "invalid field text orientation parameter", aReader, line );
2989 
2990  char textVisible = parseChar( aReader, line, &line );
2991 
2992  if( textVisible == 'V' )
2993  field->SetVisible( true );
2994  else if ( textVisible == 'I' )
2995  field->SetVisible( false );
2996  else
2997  SCH_PARSE_ERROR( "invalid field text visibility parameter", aReader, line );
2998 
2999  // It may be technically correct to use the library version to determine if the field text
3000  // attributes are present. If anyone knows if that is valid and what version that would be,
3001  // please change this to test the library version rather than an EOL or the quoted string
3002  // of the field name.
3003  if( *line != 0 && *line != '"' )
3004  {
3005  char textHJustify = parseChar( aReader, line, &line );
3006 
3007  if( textHJustify == 'C' )
3009  else if( textHJustify == 'L' )
3011  else if( textHJustify == 'R' )
3013  else
3014  SCH_PARSE_ERROR( "invalid field text horizontal justification", aReader, line );
3015 
3016  wxString attributes;
3017 
3018  parseUnquotedString( attributes, aReader, line, &line );
3019 
3020  size_t attrSize = attributes.size();
3021 
3022  if( !(attrSize == 3 || attrSize == 1 ) )
3023  SCH_PARSE_ERROR( "invalid field text attributes size", aReader, line );
3024 
3025  switch( (wxChar) attributes[0] )
3026  {
3027  case 'C': field->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3028  case 'B': field->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3029  case 'T': field->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3030  default: SCH_PARSE_ERROR( "invalid field text vertical justification", aReader, line );
3031  }
3032 
3033  if( attrSize == 3 )
3034  {
3035  wxChar attr_1 = attributes[1];
3036  wxChar attr_2 = attributes[2];
3037 
3038  if( attr_1 == 'I' ) // Italic
3039  field->SetItalic( true );
3040  else if( attr_1 != 'N' ) // No italics is default, check for error.
3041  SCH_PARSE_ERROR( "invalid field text italic parameter", aReader, line );
3042 
3043  if ( attr_2 == 'B' ) // Bold
3044  field->SetBold( true );
3045  else if( attr_2 != 'N' ) // No bold is default, check for error.
3046  SCH_PARSE_ERROR( "invalid field text bold parameter", aReader, line );
3047  }
3048  }
3049 
3050  // Fields in RAM must always have names.
3051  if( (unsigned) id < MANDATORY_FIELDS )
3052  {
3053  // Fields in RAM must always have names, because we are trying to get
3054  // less dependent on field ids and more dependent on names.
3055  // Plus assumptions are made in the field editors.
3057 
3058  // Ensure the VALUE field = the part name (can be not the case
3059  // with malformed libraries: edited by hand, or converted from other tools)
3060  if( id == VALUE )
3061  field->SetText( aPart->GetName() );
3062  }
3063  else
3064  {
3065  parseQuotedString( field->m_name, aReader, line, &line, true ); // Optional.
3066  }
3067 }
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:220
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:112
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 3608 of file sch_legacy_plugin.cpp.

3610 {
3611  const char* line = aReader.Line();
3612 
3613  wxCHECK_RET( strCompare( "$FPLIST", line, &line ), "Invalid footprint filter list" );
3614 
3615  line = aReader.ReadLine();
3616 
3617  while( line )
3618  {
3619  if( strCompare( "$ENDFPLIST", line, &line ) )
3620  return;
3621 
3622  wxString footprint;
3623 
3624  parseUnquotedString( footprint, aReader, line, &line );
3625  aPart->GetFootprints().Add( footprint );
3626  line = aReader.ReadLine();
3627  }
3628 
3629  SCH_PARSE_ERROR( "file ended prematurely while loading footprint filters", aReader, line );
3630 }
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 2674 of file sch_legacy_plugin.cpp.

2675 {
2676  const char* line = aReader.Line();
2677 
2678  wxASSERT( strCompare( "$HEADER", line, &line ) );
2679 
2680  while( aReader.ReadLine() )
2681  {
2682  line = (char*) aReader;
2683 
2684  // The time stamp saved in old library files is not used or saved in the latest
2685  // library file version.
2686  if( strCompare( "TimeStamp", line, &line ) )
2687  continue;
2688  else if( strCompare( "$ENDHEADER", line, &line ) )
2689  return;
2690  }
2691 
2692  SCH_PARSE_ERROR( "$ENDHEADER not found", aReader, line );
2693 }
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 2696 of file sch_legacy_plugin.cpp.

2698 {
2699  const char* line = aReader.Line();
2700 
2701  while( *line == '#' )
2702  aReader.ReadLine();
2703 
2704  if( !strCompare( "DEF", line, &line ) )
2705  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2706 
2707  long num;
2708  size_t pos = 4; // "DEF" plus the first space.
2709  wxString utf8Line = wxString::FromUTF8( line );
2710  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
2711 
2712  if( tokens.CountTokens() < 8 )
2713  SCH_PARSE_ERROR( "invalid symbol definition", aReader, line );
2714 
2715  // Read DEF line:
2716  std::unique_ptr< LIB_PART > part( new LIB_PART( wxEmptyString ) );
2717 
2718  wxString name, prefix, tmp;
2719 
2720  name = tokens.GetNextToken();
2721  pos += name.size() + 1;
2722 
2723  prefix = tokens.GetNextToken();
2724  pos += prefix.size() + 1;
2725 
2726  tmp = tokens.GetNextToken();
2727  pos += tmp.size() + 1; // NumOfPins, unused.
2728 
2729  tmp = tokens.GetNextToken(); // Pin name offset.
2730 
2731  if( !tmp.ToLong( &num ) )
2732  THROW_PARSE_ERROR( "invalid pin offset", aReader.GetSource(), aReader.Line(),
2733  aReader.LineNumber(), pos );
2734 
2735  pos += tmp.size() + 1;
2736  part->SetPinNameOffset( (int)num );
2737 
2738  tmp = tokens.GetNextToken(); // Show pin numbers.
2739 
2740  if( !( tmp == "Y" || tmp == "N") )
2741  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2742  aReader.LineNumber(), pos );
2743 
2744  pos += tmp.size() + 1;
2745  part->SetShowPinNumbers( ( tmp == "N" ) ? false : true );
2746 
2747  tmp = tokens.GetNextToken(); // Show pin names.
2748 
2749  if( !( tmp == "Y" || tmp == "N") )
2750  THROW_PARSE_ERROR( "expected Y or N", aReader.GetSource(), aReader.Line(),
2751  aReader.LineNumber(), pos );
2752 
2753  pos += tmp.size() + 1;
2754  part->SetShowPinNames( ( tmp == "N" ) ? false : true );
2755 
2756  tmp = tokens.GetNextToken(); // Number of units.
2757 
2758  if( !tmp.ToLong( &num ) )
2759  THROW_PARSE_ERROR( "invalid unit count", aReader.GetSource(), aReader.Line(),
2760  aReader.LineNumber(), pos );
2761 
2762  pos += tmp.size() + 1;
2763  part->SetUnitCount( (int)num );
2764 
2765  // Ensure m_unitCount is >= 1. Could be read as 0 in old libraries.
2766  if( part->GetUnitCount() < 1 )
2767  part->SetUnitCount( 1 );
2768 
2769  // Copy part name and prefix.
2770 
2771  // The root alias is added to the alias list by SetName() which is called by SetText().
2772  if( name.IsEmpty() )
2773  {
2774  part->SetName( "~" );
2775  }
2776  else if( name[0] != '~' )
2777  {
2778  part->SetName( name );
2779  }
2780  else
2781  {
2782  part->SetName( name.Right( name.Length() - 1 ) );
2783  part->GetValueField().SetVisible( false );
2784  }
2785 
2786  // Don't set the library alias, this is determined by the symbol library table.
2787  part->SetLibId( LIB_ID( wxEmptyString, part->GetName() ) );
2788 
2789  // There are some code paths in SetText() that do not set the root alias to the
2790  // alias list so add it here if it didn't get added by SetText().
2791  if( !part->HasAlias( part->GetName() ) )
2792  part->AddAlias( part->GetName() );
2793 
2794  LIB_FIELD& reference = part->GetReferenceField();
2795 
2796  if( prefix == "~" )
2797  {
2798  reference.Empty();
2799  reference.SetVisible( false );
2800  }
2801  else
2802  {
2803  reference.SetText( prefix );
2804  }
2805 
2806  // In version 2.2 and earlier, this parameter was a '0' which was just a place holder.
2807  // The was no concept of interchangeable multiple unit symbols.
2808  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
2809  && LIB_VERSION( aMajorVersion, aMinorVersion ) <= LIB_VERSION( 2, 2 ) )
2810  {
2811  // Nothing needs to be set since the default setting for symbols with multiple
2812  // units were never interchangeable. Just parse the 0 an move on.
2813  tmp = tokens.GetNextToken();
2814  pos += tmp.size() + 1;
2815  }
2816  else
2817  {
2818  tmp = tokens.GetNextToken();
2819 
2820  if( tmp == "L" )
2821  part->LockUnits( true );
2822  else if( tmp == "F" || tmp == "0" )
2823  part->LockUnits( false );
2824  else
2825  THROW_PARSE_ERROR( "expected L, F, or 0", aReader.GetSource(), aReader.Line(),
2826  aReader.LineNumber(), pos );
2827 
2828  pos += tmp.size() + 1;
2829  }
2830 
2831  // There is the optional power component flag.
2832  if( tokens.HasMoreTokens() )
2833  {
2834  tmp = tokens.GetNextToken();
2835 
2836  if( tmp == "P" )
2837  part->SetPower();
2838  else if( tmp == "N" )
2839  part->SetNormal();
2840  else
2841  THROW_PARSE_ERROR( "expected P or N", aReader.GetSource(), aReader.Line(),
2842  aReader.LineNumber(), pos );
2843  }
2844 
2845  line = aReader.ReadLine();
2846 
2847  // Read lines until "ENDDEF" is found.
2848  while( line )
2849  {
2850  if( *line == '#' ) // Comment
2851  ;
2852  else if( strCompare( "Ti", line, &line ) ) // Modification date is ignored.
2853  continue;
2854  else if( strCompare( "ALIAS", line, &line ) ) // Aliases
2855  loadAliases( part, aReader );
2856  else if( *line == 'F' ) // Fields
2857  loadField( part, aReader );
2858  else if( strCompare( "DRAW", line, &line ) ) // Drawing objects.
2859  loadDrawEntries( part, aReader, aMajorVersion, aMinorVersion );
2860  else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list
2861  loadFootprintFilters( part, aReader );
2862  else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
2863  {
2864  return part.release();
2865  }
2866 
2867  line = aReader.ReadLine();
2868  }
2869 
2870  SCH_PARSE_ERROR( "missing ENDDEF", aReader, line );
2871 }
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:112
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:237
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 3364 of file sch_legacy_plugin.cpp.

3366 {
3367  const char* line = aReader.Line();
3368 
3369  wxCHECK_MSG( strCompare( "X", line, &line ), NULL, "Invalid LIB_PIN definition" );
3370 
3371  LIB_PIN* pin = new LIB_PIN( aPart.get() );
3372 
3373  size_t pos = 2; // "X" plus ' ' space character.
3374  wxString tmp;
3375  wxString utf8Line = wxString::FromUTF8( line );
3376  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
3377 
3378  if( tokens.CountTokens() < 11 )
3379  SCH_PARSE_ERROR( "invalid pin definition", aReader, line );
3380 
3381  pin->m_name = tokens.GetNextToken();
3382  pos += pin->m_name.size() + 1;
3383  pin->m_number = tokens.GetNextToken();
3384  pos += pin->m_number.size() + 1;
3385 
3386  long num;
3387  wxPoint position;
3388 
3389  tmp = tokens.GetNextToken();
3390 
3391  if( !tmp.ToLong( &num ) )
3392  THROW_PARSE_ERROR( "invalid pin X coordinate", aReader.GetSource(), aReader.Line(),
3393  aReader.LineNumber(), pos );
3394 
3395  pos += tmp.size() + 1;
3396  position.x = (int) num;
3397 
3398  tmp = tokens.GetNextToken();
3399 
3400  if( !tmp.ToLong( &num ) )
3401  THROW_PARSE_ERROR( "invalid pin Y coordinate", aReader.GetSource(), aReader.Line(),
3402  aReader.LineNumber(), pos );
3403 
3404  pos += tmp.size() + 1;
3405  position.y = (int) num;
3406  pin->m_position = position;
3407 
3408  tmp = tokens.GetNextToken();
3409 
3410  if( !tmp.ToLong( &num ) )
3411  THROW_PARSE_ERROR( "invalid pin length", aReader.GetSource(), aReader.Line(),
3412  aReader.LineNumber(), pos );
3413 
3414  pos += tmp.size() + 1;
3415  pin->m_length = (int) num;
3416 
3417 
3418  tmp = tokens.GetNextToken();
3419 
3420  if( tmp.size() > 1 )
3421  THROW_PARSE_ERROR( "invalid pin orientation", aReader.GetSource(), aReader.Line(),
3422  aReader.LineNumber(), pos );
3423 
3424  pos += tmp.size() + 1;
3425  pin->m_orientation = tmp[0];
3426 
3427  tmp = tokens.GetNextToken();
3428 
3429  if( !tmp.ToLong( &num ) )
3430  THROW_PARSE_ERROR( "invalid pin number text size", aReader.GetSource(), aReader.Line(),
3431  aReader.LineNumber(), pos );
3432 
3433  pos += tmp.size() + 1;
3434  pin->m_numTextSize = (int) num;
3435 
3436  tmp = tokens.GetNextToken();
3437 
3438  if( !tmp.ToLong( &num ) )
3439  THROW_PARSE_ERROR( "invalid pin name text size", aReader.GetSource(), aReader.Line(),
3440  aReader.LineNumber(), pos );
3441 
3442  pos += tmp.size() + 1;
3443  pin->m_nameTextSize = (int) num;
3444 
3445  tmp = tokens.GetNextToken();
3446 
3447  if( !tmp.ToLong( &num ) )
3448  THROW_PARSE_ERROR( "invalid pin unit", aReader.GetSource(), aReader.Line(),
3449  aReader.LineNumber(), pos );
3450 
3451  pos += tmp.size() + 1;
3452  pin->m_Unit = (int) num;
3453 
3454  tmp = tokens.GetNextToken();
3455 
3456  if( !tmp.ToLong( &num ) )
3457  THROW_PARSE_ERROR( "invalid pin alternate body type", aReader.GetSource(), aReader.Line(),
3458  aReader.LineNumber(), pos );
3459 
3460  pos += tmp.size() + 1;
3461  pin->m_Convert = (int) num;
3462 
3463  tmp = tokens.GetNextToken();
3464 
3465  if( tmp.size() != 1 )
3466  THROW_PARSE_ERROR( "invalid pin type", aReader.GetSource(), aReader.Line(),
3467  aReader.LineNumber(), pos );
3468 
3469  pos += tmp.size() + 1;
3470  char type = tmp[0];
3471 
3472  wxString attributes;
3473 
3474  switch( type )
3475  {
3476  case 'I': pin->m_type = PIN_INPUT; break;
3477  case 'O': pin->m_type = PIN_OUTPUT; break;
3478  case 'B': pin->m_type = PIN_BIDI; break;
3479  case 'T': pin->m_type = PIN_TRISTATE; break;
3480  case 'P': pin->m_type = PIN_PASSIVE; break;
3481  case 'U': pin->m_type = PIN_UNSPECIFIED; break;
3482  case 'W': pin->m_type = PIN_POWER_IN; break;
3483  case 'w': pin->m_type = PIN_POWER_OUT; break;
3484  case 'C': pin->m_type = PIN_OPENCOLLECTOR; break;
3485  case 'E': pin->m_type = PIN_OPENEMITTER; break;
3486  case 'N': pin->m_type = PIN_NC; break;
3487  default: THROW_PARSE_ERROR( "unknown pin type", aReader.GetSource(),
3488  aReader.Line(), aReader.LineNumber(), pos );
3489  }
3490 
3491  // Optional
3492  if( tokens.HasMoreTokens() ) /* Special Symbol defined */
3493  {
3494  tmp = tokens.GetNextToken();
3495 
3496  enum
3497  {
3498  INVERTED = 1 << 0,
3499  CLOCK = 1 << 1,
3500  LOWLEVEL_IN = 1 << 2,
3501  LOWLEVEL_OUT = 1 << 3,
3502  FALLING_EDGE = 1 << 4,
3503  NONLOGIC = 1 << 5
3504  };
3505 
3506  int flags = 0;
3507 
3508  for( int j = tmp.size(); j > 0; )
3509  {
3510  switch( tmp[--j].GetValue() )
3511  {
3512  case '~': break;
3513  case 'N': pin->m_attributes |= PIN_INVISIBLE; break;
3514  case 'I': flags |= INVERTED; break;
3515  case 'C': flags |= CLOCK; break;
3516  case 'L': flags |= LOWLEVEL_IN; break;
3517  case 'V': flags |= LOWLEVEL_OUT; break;
3518  case 'F': flags |= FALLING_EDGE; break;
3519  case 'X': flags |= NONLOGIC; break;
3520  default: THROW_PARSE_ERROR( "invalid pin attribut", aReader.GetSource(),
3521  aReader.Line(), aReader.LineNumber(), pos );
3522  }
3523 
3524  pos += 1;
3525  }
3526 
3527  switch( flags )
3528  {
3529  case 0: pin->m_shape = PINSHAPE_LINE; break;
3530  case INVERTED: pin->m_shape = PINSHAPE_INVERTED; break;
3531  case CLOCK: pin->m_shape = PINSHAPE_CLOCK; break;
3532  case INVERTED | CLOCK: pin->m_shape = PINSHAPE_INVERTED_CLOCK; break;
3533  case LOWLEVEL_IN: pin->m_shape = PINSHAPE_INPUT_LOW; break;
3534  case LOWLEVEL_IN | CLOCK: pin->m_shape = PINSHAPE_CLOCK_LOW; break;
3535  case LOWLEVEL_OUT: pin->m_shape = PINSHAPE_OUTPUT_LOW; break;
3536  case FALLING_EDGE: pin->m_shape = PINSHAPE_FALLING_EDGE_CLOCK; break;
3537  case NONLOGIC: pin->m_shape = PINSHAPE_NONLOGIC; break;
3538  default: SCH_PARSE_ERROR( "pin attributes do not define a valid pin shape", aReader, line );
3539  }
3540  }
3541 
3542  return pin;
3543 }
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 3546 of file sch_legacy_plugin.cpp.

3548 {
3549  const char* line = aReader.Line();
3550 
3551  wxCHECK_MSG( strCompare( "P", line, &line ), NULL, "Invalid LIB_POLYLINE definition" );
3552 
3553  LIB_POLYLINE* polyLine = new LIB_POLYLINE( aPart.get() );
3554 
3555  int points = parseInt( aReader, line, &line );
3556  polyLine->SetUnit( parseInt( aReader, line, &line ) );
3557  polyLine->SetConvert( parseInt( aReader, line, &line ) );
3558  polyLine->SetWidth( parseInt( aReader, line, &line ) );
3559  polyLine->Reserve( points );
3560 
3561  wxPoint pt;
3562 
3563  for( int i = 0; i < points; i++ )
3564  {
3565  pt.x = parseInt( aReader, line, &line );
3566  pt.y = parseInt( aReader, line, &line );
3567  polyLine->AddPoint( pt );
3568  }
3569 
3570  if( *line != 0 )
3571  polyLine->SetFillMode( parseFillMode( aReader, line, &line ) );
3572 
3573  return polyLine;
3574 }
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 3332 of file sch_legacy_plugin.cpp.

3334 {
3335  const char* line = aReader.Line();
3336 
3337  wxCHECK_MSG( strCompare( "S", line, &line ), NULL, "Invalid LIB_RECTANGLE definition" );
3338 
3339  LIB_RECTANGLE* rectangle = new LIB_RECTANGLE( aPart.get() );
3340 
3341  wxPoint pos;
3342 
3343  pos.x = parseInt( aReader, line, &line );
3344  pos.y = parseInt( aReader, line, &line );
3345  rectangle->SetPosition( pos );
3346 
3347  wxPoint end;
3348 
3349  end.x = parseInt( aReader, line, &line );
3350  end.y = parseInt( aReader, line, &line );
3351  rectangle->SetEnd( end );
3352 
3353  rectangle->SetUnit( parseInt( aReader, line, &line ) );
3354  rectangle->SetConvert( parseInt( aReader, line, &line ) );
3355  rectangle->SetWidth( parseInt( aReader, line, &line ) );
3356 
3357  if( *line != 0 )
3358  rectangle->SetFillMode( parseFillMode( aReader, line, &line ) );
3359 
3360  return rectangle;
3361 }
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 3239 of file sch_legacy_plugin.cpp.

3243 {
3244  const char* line = aReader.Line();
3245 
3246  wxCHECK_MSG( strCompare( "T", line, &line ), NULL, "Invalid LIB_TEXT definition" );
3247 
3248  LIB_TEXT* text = new LIB_TEXT( aPart.get() );
3249 
3250  text->SetTextAngle( (double) parseInt( aReader, line, &line ) );
3251 
3252  wxPoint center;
3253 
3254  center.x = parseInt( aReader, line, &line );
3255  center.y = parseInt( aReader, line, &line );
3256  text->SetPosition( center );
3257 
3258  wxSize size;
3259 
3260  size.x = size.y = parseInt( aReader, line, &line );
3261  text->SetTextSize( size );
3262  text->SetVisible( !parseInt( aReader, line, &line ) );
3263  text->SetUnit( parseInt( aReader, line, &line ) );
3264  text->SetConvert( parseInt( aReader, line, &line ) );
3265 
3266  wxString str;
3267 
3268  // If quoted string loading fails, load as not quoted string.
3269  if( *line == '"' )
3270  parseQuotedString( str, aReader, line, &line );
3271  else
3272  {
3273  parseUnquotedString( str, aReader, line, &line );
3274 
3275  // In old libs, "spaces" are replaced by '~' in unquoted strings:
3276  str.Replace( "~", " " );
3277  }
3278 
3279  if( !str.IsEmpty() )
3280  {
3281  // convert two apostrophes back to double quote
3282  str.Replace( "''", "\"" );
3283  }
3284 
3285  text->SetText( str );
3286 
3287  // Here things are murky and not well defined. At some point it appears the format
3288  // was changed to add text properties. However rather than add the token to the end of
3289  // the text definition, it was added after the string and no mention if the file
3290  // verion was bumped or not so this code make break on very old component libraries.
3291  //
3292  // Update: apparently even in the latest version this can be different so added a test
3293  // for end of line before checking for the text properties.
3294  if( LIB_VERSION( aMajorVersion, aMinorVersion ) > 0
3295  && LIB_VERSION( aMajorVersion, aMinorVersion ) > LIB_VERSION( 2, 0 ) && !is_eol( *line ) )
3296  {
3297  if( strCompare( "Italic", line, &line ) )
3298  text->SetItalic( true );
3299  else if( !strCompare( "Normal", line, &line ) )
3300  SCH_PARSE_ERROR( "invalid text stype, expected 'Normal' or 'Italic'", aReader, line );
3301 
3302  if( parseInt( aReader, line, &line ) > 0 )
3303  text->SetBold( true );
3304 
3305  // Some old libaries version > 2.0 do not have these options for text justification:
3306  if( !is_eol( *line ) )
3307  {
3308  switch( parseChar( aReader, line, &line ) )
3309  {
3310  case 'L': text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break;
3311  case 'C': text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break;
3312  case 'R': text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break;
3313  default: SCH_PARSE_ERROR( "invalid horizontal text justication; expected L, C, or R",
3314  aReader, line );
3315  }
3316 
3317  switch( parseChar( aReader, line, &line ) )
3318  {
3319  case 'T': text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break;
3320  case 'C': text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break;
3321  case 'B': text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break;
3322  default: SCH_PARSE_ERROR( "invalid vertical text justication; expected T, C, or B",
3323  aReader, line );
3324  }
3325  }
3326  }
3327 
3328  return text;
3329 }
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:220
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:112
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 3133 of file sch_legacy_plugin.cpp.

3135 {
3136  switch( parseChar( aReader, aLine, aOutput ) )
3137  {
3138  case 'F': return FILLED_SHAPE;
3139  case 'f': return FILLED_WITH_BG_BODYCOLOR;
3140  case 'N': return NO_FILL;
3141  default: SCH_PARSE_ERROR( "invalid fill type, expected f, F, or N", aReader, aLine );
3142  }
3143 }
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 2377 of file sch_legacy_plugin.cpp.

2378 {
2379  wxCHECK_MSG( aAlias != NULL, NULL, "NULL pointer cannot be removed from library." );
2380 
2381  LIB_ALIAS_MAP::iterator it = m_aliases.find( aAlias->GetName() );
2382 
2383  if( it == m_aliases.end() )
2384  return NULL;
2385 
2386  // If the entry pointer doesn't match the name it is mapped to in the library, we
2387  // have done something terribly wrong.
2388  wxCHECK_MSG( *it->second == aAlias, NULL,
2389  "Pointer mismatch while attempting to remove alias entry <" + aAlias->GetName() +
2390  "> from library cache <" + m_libFileName.GetName() + ">." );
2391 
2392  LIB_ALIAS* alias = aAlias;
2393  LIB_PART* part = alias->GetPart();
2394 
2395  alias = part->RemoveAlias( alias );
2396 
2397  if( !alias )
2398  {
2399  delete part;
2400 
2401  if( m_aliases.size() > 1 )
2402  {
2403  LIB_ALIAS_MAP::iterator next = it;
2404  next++;
2405 
2406  if( next == m_aliases.end() )
2407  next = m_aliases.begin();
2408 
2409  alias = next->second;
2410  }
2411  }
2412 
2413  m_aliases.erase( it );
2414  m_isModified = true;
2415  ++m_modHash;
2416  return alias;
2417 }
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 3633 of file sch_legacy_plugin.cpp.

3634 {
3635  if( !m_isModified )
3636  return;
3637 
3638  // Write through symlinks, don't replace them
3639  wxFileName fn = GetRealFile();
3640 
3641  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( fn.GetFullPath() ) );
3642  formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
3643  formatter->Print( 0, "#encoding utf-8\n");
3644 
3645  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
3646  {
3647  if( !it->second->IsRoot() )
3648  continue;
3649 
3650  SaveSymbol( it->second->GetPart(), *formatter.get() );
3651  }
3652 
3653  formatter->Print( 0, "#\n#End Library\n" );
3654  formatter.reset();
3655 
3656  m_fileModTime = fn.GetModificationTime();
3657  m_isModified = false;
3658 
3659  if( aSaveDocFile )
3660  saveDocFile();
3661 }
#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 3826 of file sch_legacy_plugin.cpp.

3828 {
3829  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
3830 
3831  int x1 = aArc->GetFirstRadiusAngle();
3832 
3833  if( x1 > 1800 )
3834  x1 -= 3600;
3835 
3836  int x2 = aArc->GetSecondRadiusAngle();
3837 
3838  if( x2 > 1800 )
3839  x2 -= 3600;
3840 
3841  aFormatter.Print( 0, "A %d %d %d %d %d %d %d %d %c %d %d %d %d\n",
3842  aArc->GetPosition().x, aArc->GetPosition().y,
3843  aArc->GetRadius(), x1, x2, aArc->GetUnit(), aArc->GetConvert(),
3844  aArc->GetWidth(), fill_tab[aArc->GetFillMode()],
3845  aArc->GetStart().x, aArc->GetStart().y,
3846  aArc->GetEnd().x, aArc->GetEnd().y );
3847 }
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 3850 of file sch_legacy_plugin.cpp.

3852 {
3853  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
3854 
3855  aFormatter.Print( 0, "B %u %d %d %d", (unsigned)aBezier->GetPoints().size(),
3856  aBezier->GetUnit(), aBezier->GetConvert(), aBezier->GetWidth() );
3857 
3858  for( const auto& pt : aBezier->GetPoints() )
3859  aFormatter.Print( 0, " %d %d", pt.x, pt.y );
3860 
3861  aFormatter.Print( 0, " %c\n", fill_tab[aBezier->GetFillMode()] );
3862 }
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 3865 of file sch_legacy_plugin.cpp.

3867 {
3868  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
3869 
3870  aFormatter.Print( 0, "C %d %d %d %d %d %d %c\n",
3871  aCircle->GetPosition().x, aCircle->GetPosition().y,
3872  aCircle->GetRadius(), aCircle->GetUnit(), aCircle->GetConvert(),
3873  aCircle->GetWidth(), fill_tab[aCircle->GetFillMode()] );
3874 }
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 4116 of file sch_legacy_plugin.cpp.

4117 {
4118  wxFileName fileName = m_libFileName;
4119 
4120  fileName.SetExt( DOC_EXT );
4121  FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() );
4122 
4123  formatter.Print( 0, "%s\n", DOCFILE_IDENT );
4124 
4125  for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
4126  {
4127  wxString description = it->second->GetDescription();
4128  wxString keyWords = it->second->GetKeyWords();
4129  wxString docFileName = it->second->GetDocFileName();
4130 
4131  if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
4132  continue;
4133 
4134  formatter.Print( 0, "#\n$CMP %s\n", TO_UTF8( it->second->GetName() ) );
4135 
4136  if( !description.IsEmpty() )
4137  formatter.Print( 0, "D %s\n", TO_UTF8( description ) );
4138 
4139  if( !keyWords.IsEmpty() )
4140  formatter.Print( 0, "K %s\n", TO_UTF8( keyWords ) );
4141 
4142  if( !docFileName.IsEmpty() )
4143  formatter.Print( 0, "F %s\n", TO_UTF8( docFileName ) );
4144 
4145  formatter.Print( 0, "$ENDCMP\n" );
4146  }
4147 
4148  formatter.Print( 0, "#\n#End Doc Library\n" );
4149 }
#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 3877 of file sch_legacy_plugin.cpp.

3879 {
3880  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
3881 
3882  int hjustify, vjustify;
3883  int id = aField->GetId();
3884  wxString text = aField->GetText();
3885 
3886  hjustify = 'C';
3887 
3888  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
3889  hjustify = 'L';
3890  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
3891  hjustify = 'R';
3892 
3893  vjustify = 'C';
3894 
3895  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
3896  vjustify = 'B';
3897  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
3898  vjustify = 'T';
3899 
3900  aFormatter.Print( 0, "F%d %s %d %d %d %c %c %c %c%c%c",
3901  id,
3902  EscapedUTF8( text ).c_str(), // wraps in quotes
3903  aField->GetTextPos().x, aField->GetTextPos().y, aField->GetTextWidth(),
3904  aField->GetTextAngle() == 0 ? 'H' : 'V',
3905  aField->IsVisible() ? 'V' : 'I',
3906  hjustify, vjustify,
3907  aField->IsItalic() ? 'I' : 'N',
3908  aField->IsBold() ? 'B' : 'N' );
3909 
3910  /* Save field name, if necessary
3911  * Field name is saved only if it is not the default name.
3912  * Just because default name depends on the language and can change from
3913  * a country to another
3914  */
3915  wxString defName = TEMPLATE_FIELDNAME::GetDefaultFieldName( id );
3916 
3917  if( id >= FIELD1 && !aField->m_name.IsEmpty() && aField->m_name != defName )
3918  aFormatter.Print( 0, " %s", EscapedUTF8( aField->m_name ).c_str() );
3919 
3920  aFormatter.Print( 0, "\n" );
3921 }
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
bool IsItalic() const
Definition: eda_text.h:164
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:241
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:184
int GetTextWidth() const
Definition: eda_text.h:224
const wxPoint & GetTextPos() const
Definition: eda_text.h:230
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 3924 of file sch_legacy_plugin.cpp.

3926 {
3927  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
3928 
3929  int Etype;
3930 
3931  switch( aPin->GetType() )
3932  {
3933  default:
3934  case PIN_INPUT:
3935  Etype = 'I';
3936  break;
3937 
3938  case PIN_OUTPUT:
3939  Etype = 'O';
3940  break;
3941 
3942  case PIN_BIDI:
3943  Etype = 'B';
3944  break;
3945 
3946  case PIN_TRISTATE:
3947  Etype = 'T';
3948  break;
3949 
3950  case PIN_PASSIVE:
3951  Etype = 'P';
3952  break;
3953 
3954  case PIN_UNSPECIFIED:
3955  Etype = 'U';
3956  break;
3957 
3958  case PIN_POWER_IN:
3959  Etype = 'W';
3960  break;
3961 
3962  case PIN_POWER_OUT:
3963  Etype = 'w';
3964  break;
3965 
3966  case PIN_OPENCOLLECTOR:
3967  Etype = 'C';
3968  break;
3969 
3970  case PIN_OPENEMITTER:
3971  Etype = 'E';
3972  break;
3973 
3974  case PIN_NC:
3975  Etype = 'N';
3976  break;
3977  }
3978 
3979  if( !aPin->GetName().IsEmpty() )
3980  aFormatter.Print( 0, "X %s", TO_UTF8( aPin->GetName() ) );
3981  else
3982  aFormatter.Print( 0, "X ~" );
3983 
3984  aFormatter.Print( 0, " %s %d %d %d %c %d %d %d %d %c",
3985  aPin->GetNumber().IsEmpty() ? "~" : TO_UTF8( aPin->GetNumber() ),
3986  aPin->GetPosition().x, aPin->GetPosition().y,
3987  (int) aPin->GetLength(), (int) aPin->GetOrientation(),
3988  aPin->GetNumberTextSize(), aPin->GetNameTextSize(),
3989  aPin->GetUnit(), aPin->GetConvert(), Etype );
3990 
3991  if( aPin->GetShape() || !aPin->IsVisible() )
3992  aFormatter.Print( 0, " " );
3993 
3994  if( !aPin->IsVisible() )
3995  aFormatter.Print( 0, "N" );
3996 
3997  switch( aPin->GetShape() )
3998  {
3999  case PINSHAPE_LINE:
4000  break;
4001 
4002  case PINSHAPE_INVERTED:
4003  aFormatter.Print( 0, "I" );
4004  break;
4005 
4006  case PINSHAPE_CLOCK:
4007  aFormatter.Print( 0, "C" );
4008  break;
4009 
4011  aFormatter.Print( 0, "IC" );
4012  break;
4013 
4014  case PINSHAPE_INPUT_LOW:
4015  aFormatter.Print( 0, "L" );
4016  break;
4017 
4018  case PINSHAPE_CLOCK_LOW:
4019  aFormatter.Print( 0, "CL" );
4020  break;
4021 
4022  case PINSHAPE_OUTPUT_LOW:
4023  aFormatter.Print( 0, "V" );
4024  break;
4025 
4027  aFormatter.Print( 0, "F" );
4028  break;
4029 
4030  case PINSHAPE_NONLOGIC:
4031  aFormatter.Print( 0, "X" );
4032  break;
4033 
4034  default:
4035  assert( !"Invalid pin shape" );
4036  }
4037 
4038  aFormatter.Print( 0, "\n" );
4039 
4040  aPin->ClearFlags( IS_CHANGED );
4041 }
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 4044 of file sch_legacy_plugin.cpp.

4046 {
4047  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
4048 
4049  int ccount = aPolyLine->GetCornerCount();
4050 
4051  aFormatter.Print( 0, "P %d %d %d %d", ccount, aPolyLine->GetUnit(), aPolyLine->GetConvert(),
4052  aPolyLine->GetWidth() );
4053 
4054  for( const auto& pt : aPolyLine->GetPolyPoints() )
4055  {
4056  aFormatter.Print( 0, " %d %d", pt.x, pt.y );
4057  }
4058 
4059  aFormatter.Print( 0, " %c\n", fill_tab[aPolyLine->GetFillMode()] );
4060 }
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 4063 of file sch_legacy_plugin.cpp.

4065 {
4066  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
4067  "Invalid LIB_RECTANGLE object." );
4068 
4069  aFormatter.Print( 0, "S %d %d %d %d %d %d %d %c\n",
4070  aRectangle->GetPosition().x, aRectangle->GetPosition().y,
4071  aRectangle->GetEnd().x, aRectangle->GetEnd().y,
4072  aRectangle->GetUnit(), aRectangle->GetConvert(),
4073  aRectangle->GetWidth(), fill_tab[aRectangle->GetFillMode()] );
4074 }
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 3664 of file sch_legacy_plugin.cpp.

3666 {
3667  wxCHECK_RET( aSymbol, "Invalid LIB_PART pointer." );
3668 
3669  LIB_FIELD& value = aSymbol->GetValueField();
3670 
3671  // First line: it s a comment (component name for readers)
3672  aFormatter.Print( 0, "#\n# %s\n#\n", TO_UTF8( value.GetText() ) );
3673 
3674  // Save data
3675  aFormatter.Print( 0, "DEF" );
3676  aFormatter.Print( 0, " %s", TO_UTF8( value.GetText() ) );
3677 
3678  LIB_FIELD& reference = aSymbol->GetReferenceField();
3679 
3680  if( !reference.GetText().IsEmpty() )
3681  {
3682  aFormatter.Print( 0, " %s", TO_UTF8( reference.GetText() ) );
3683  }
3684  else
3685  {
3686  aFormatter.Print( 0, " ~" );
3687  }
3688 
3689  aFormatter.Print( 0, " %d %d %c %c %d %c %c\n",
3690  0, aSymbol->GetPinNameOffset(),
3691  aSymbol->ShowPinNumbers() ? 'Y' : 'N',
3692  aSymbol->ShowPinNames() ? 'Y' : 'N',
3693  aSymbol->GetUnitCount(), aSymbol->UnitsLocked() ? 'L' : 'F',
3694  aSymbol->IsPower() ? 'P' : 'N' );
3695 
3696  timestamp_t dateModified = aSymbol->GetDateLastEdition();
3697 
3698  if( dateModified != 0 )
3699  {
3700  int sec = dateModified & 63;
3701  int min = ( dateModified >> 6 ) & 63;
3702  int hour = ( dateModified >> 12 ) & 31;
3703  int day = ( dateModified >> 17 ) & 31;
3704  int mon = ( dateModified >> 22 ) & 15;
3705  int year = ( dateModified >> 26 ) + 1990;
3706 
3707  aFormatter.Print( 0, "Ti %d/%d/%d %d:%d:%d\n", year, mon, day, hour, min, sec );
3708  }
3709 
3710  LIB_FIELDS fields;
3711  aSymbol->GetFields( fields );
3712 
3713  // Mandatory fields:
3714  // may have their own save policy so there is a separate loop for them.
3715  // Empty fields are saved, because the user may have set visibility,
3716  // size and orientation
3717  for( int i = 0; i < MANDATORY_FIELDS; ++i )
3718  {
3719  saveField( &fields[i], aFormatter );
3720  }
3721 
3722  // User defined fields:
3723  // may have their own save policy so there is a separate loop for them.
3724 
3725  int fieldId = MANDATORY_FIELDS; // really wish this would go away.
3726 
3727  for( unsigned i = MANDATORY_FIELDS; i < fields.size(); ++i )
3728  {
3729  // There is no need to save empty fields, i.e. no reason to preserve field
3730  // names now that fields names come in dynamically through the template
3731  // fieldnames.
3732  if( !fields[i].GetText().IsEmpty() )
3733  {
3734  fields[i].SetId( fieldId++ );
3735  saveField( &fields[i], aFormatter );
3736  }
3737  }
3738 
3739  // Save the alias list: a line starting by "ALIAS". The first alias is the root
3740  // and has the same name as the component. In the old library file format this
3741  // alias does not get added to the alias list.
3742  if( aSymbol->GetAliasCount() > 1 )
3743  {
3744  wxArrayString aliases = aSymbol->GetAliasNames();
3745 
3746  aFormatter.Print( 0, "ALIAS" );
3747 
3748  for( unsigned i = 1; i < aliases.size(); i++ )
3749  {
3750  aFormatter.Print( 0, " %s", TO_UTF8( aliases[i] ) );
3751  }
3752 
3753  aFormatter.Print( 0, "\n" );
3754  }
3755 
3756  wxArrayString footprints = aSymbol->GetFootprints();
3757 
3758  // Write the footprint filter list
3759  if( footprints.GetCount() != 0 )
3760  {
3761  aFormatter.Print( 0, "$FPLIST\n" );
3762 
3763  for( unsigned i = 0; i < footprints.GetCount(); i++ )
3764  {
3765  aFormatter.Print( 0, " %s\n", TO_UTF8( footprints[i] ) );
3766  }
3767 
3768  aFormatter.Print( 0, "$ENDFPLIST\n" );
3769  }
3770 
3771  // Save graphics items (including pins)
3772  if( !aSymbol->GetDrawItems().empty() )
3773  {
3774  // Sort the draw items in order to editing a file editing by hand.
3775  aSymbol->GetDrawItems().sort();
3776 
3777  aFormatter.Print( 0, "DRAW\n" );
3778 
3779  for( LIB_ITEM& item : aSymbol->GetDrawItems() )
3780  {
3781  switch( item.Type() )
3782  {
3783  case LIB_FIELD_T: // Fields have already been saved above.
3784  continue;
3785 
3786  case LIB_ARC_T:
3787  saveArc( (LIB_ARC*) &item, aFormatter );
3788  break;
3789 
3790  case LIB_BEZIER_T:
3791  saveBezier( (LIB_BEZIER*) &item, aFormatter );
3792  break;
3793 
3794  case LIB_CIRCLE_T:
3795  saveCircle( ( LIB_CIRCLE* ) &item, aFormatter );
3796  break;
3797 
3798  case LIB_PIN_T:
3799  savePin( (LIB_PIN* ) &item, aFormatter );
3800  break;
3801 
3802  case LIB_POLYLINE_T:
3803  savePolyLine( ( LIB_POLYLINE* ) &item, aFormatter );
3804  break;
3805 
3806  case LIB_RECTANGLE_T:
3807  saveRectangle( ( LIB_RECTANGLE* ) &item, aFormatter );
3808  break;
3809 
3810  case LIB_TEXT_T:
3811  saveText( ( LIB_TEXT* ) &item, aFormatter );
3812  break;
3813 
3814  default:
3815  ;
3816  }
3817  }
3818 
3819  aFormatter.Print( 0, "ENDDRAW\n" );
3820  }
3821 
3822  aFormatter.Print( 0, "ENDDEF\n" );
3823 }
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:50
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 4077 of file sch_legacy_plugin.cpp.

4079 {
4080  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
4081 
4082  wxString text = aText->GetText();
4083 
4084  if( text.Contains( wxT( " " ) ) || text.Contains( wxT( "~" ) ) || text.Contains( wxT( "\"" ) ) )
4085  {
4086  // convert double quote to similar-looking two apostrophes
4087  text.Replace( wxT( "\"" ), wxT( "''" ) );
4088  text = wxT( "\"" ) + text + wxT( "\"" );
4089  }
4090 
4091  aFormatter.Print( 0, "T %g %d %d %d %d %d %d %s", aText->GetTextAngle(),
4092  aText->GetTextPos().x, aText->GetTextPos().y,
4093  aText->GetTextWidth(), !aText->IsVisible(),
4094  aText->GetUnit(), aText->GetConvert(), TO_UTF8( text ) );
4095 
4096  aFormatter.Print( 0, " %s %d", aText->IsItalic() ? "Italic" : "Normal", aText->IsBold() );
4097 
4098  char hjustify = 'C';
4099 
4100  if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
4101  hjustify = 'L';
4102  else if( aText->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
4103  hjustify = 'R';
4104 
4105  char vjustify = 'C';
4106 
4107  if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
4108  vjustify = 'B';
4109  else if( aText->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
4110  vjustify = 'T';
4111 
4112  aFormatter.Print( 0, " %c %c\n", hjustify, vjustify );
4113 }
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:224
const wxPoint & GetTextPos() const
Definition: eda_text.h:230
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: