KiCad PCB EDA Suite
SCH_SEXPR_PLUGIN_CACHE Class Reference

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

Public Member Functions

 SCH_SEXPR_PLUGIN_CACHE (const wxString &aLibraryPath)
 
 ~SCH_SEXPR_PLUGIN_CACHE ()
 
int GetModifyHash () const
 
void Save ()
 Save the entire library to file m_libFileName;. More...
 
void Load ()
 
void AddSymbol (const LIB_PART *aPart)
 
void DeleteSymbol (const wxString &aName)
 
wxFileName GetRealFile () const
 
wxDateTime GetLibModificationTime ()
 
bool IsFile (const wxString &aFullPathAndFileName) const
 
bool IsFileChanged () const
 
void SetModified (bool aModified=true)
 
wxString GetLogicalName () const
 
void SetFileName (const wxString &aFileName)
 
wxString GetFileName () const
 

Static Public Member Functions

static void SaveSymbol (LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
 

Private Member Functions

LIB_PARTremoveSymbol (LIB_PART *aAlias)
 

Static Private Member Functions

static FILL_T parseFillMode (LINE_READER &aReader, const char *aLine, const char **aOutput)
 
static void saveSymbolDrawItem (LIB_ITEM *aItem, OUTPUTFORMATTER &aFormatter, int aNestLevel)
 
static void saveArc (LIB_ARC *aArc, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
 
static void saveBezier (LIB_BEZIER *aBezier, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
 
static void saveCircle (LIB_CIRCLE *aCircle, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
 
static void saveField (LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
 
static void savePin (LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
 
static void savePolyLine (LIB_POLYLINE *aPolyLine, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
 
static void saveRectangle (LIB_RECTANGLE *aRectangle, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
 
static void saveText (LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
 
static void saveDcmInfoAsFields (LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, int aFirstId=MANDATORY_FIELDS)
 

Private Attributes

wxString m_fileName
 
wxFileName m_libFileName
 
wxDateTime m_fileModTime
 
LIB_PART_MAP m_symbols
 
bool m_isWritable
 
bool m_isModified
 
int m_versionMajor
 
int m_versionMinor
 
int m_libType
 
friend SCH_SEXPR_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_SEXPR_PLUGIN, so therefore is private to this implementation file, i.e.

not placed into a header.

Definition at line 286 of file sch_sexpr_plugin.cpp.

Constructor & Destructor Documentation

◆ SCH_SEXPR_PLUGIN_CACHE()

SCH_SEXPR_PLUGIN_CACHE::SCH_SEXPR_PLUGIN_CACHE ( const wxString &  aLibraryPath)

Definition at line 1229 of file sch_sexpr_plugin.cpp.

1229  :
1230  m_fileName( aFullPathAndFileName ),
1231  m_libFileName( aFullPathAndFileName ),
1232  m_isWritable( true ),
1233  m_isModified( false )
1234 {
1235  m_versionMajor = -1;
1236  m_versionMinor = -1;
1238 }

References LIBRARY_TYPE_EESCHEMA, m_libType, m_versionMajor, and m_versionMinor.

◆ ~SCH_SEXPR_PLUGIN_CACHE()

SCH_SEXPR_PLUGIN_CACHE::~SCH_SEXPR_PLUGIN_CACHE ( )

Definition at line 1241 of file sch_sexpr_plugin.cpp.

1242 {
1243  // When the cache is destroyed, all of the alias objects on the heap should be deleted.
1244  for( LIB_PART_MAP::iterator it = m_symbols.begin(); it != m_symbols.end(); ++it )
1245  delete it->second;
1246 
1247  m_symbols.clear();
1248 }

References m_symbols.

Member Function Documentation

◆ AddSymbol()

void SCH_SEXPR_PLUGIN_CACHE::AddSymbol ( const LIB_PART aPart)

Definition at line 1369 of file sch_sexpr_plugin.cpp.

1370 {
1371  // aPart is cloned in PART_LIB::AddPart(). The cache takes ownership of aPart.
1372  wxString name = aPart->GetName();
1373  LIB_PART_MAP::iterator it = m_symbols.find( name );
1374 
1375  if( it != m_symbols.end() )
1376  {
1377  removeSymbol( it->second );
1378  }
1379 
1380  m_symbols[ name ] = const_cast< LIB_PART* >( aPart );
1381  m_isModified = true;
1382  ++m_modHash;
1383 }
wxString GetName() const override
const char * name
Definition: DXF_plotter.cpp:60
LIB_PART * removeSymbol(LIB_PART *aAlias)

References LIB_PART::GetName(), m_isModified, m_modHash, m_symbols, name, and removeSymbol().

Referenced by SCH_SEXPR_PLUGIN::SaveSymbol().

◆ DeleteSymbol()

void SCH_SEXPR_PLUGIN_CACHE::DeleteSymbol ( const wxString &  aName)

Definition at line 1924 of file sch_sexpr_plugin.cpp.

1925 {
1926  LIB_PART_MAP::iterator it = m_symbols.find( aSymbolName );
1927 
1928  if( it == m_symbols.end() )
1929  THROW_IO_ERROR( wxString::Format( _( "library %s does not contain a symbol named %s" ),
1930  m_libFileName.GetFullName(), aSymbolName ) );
1931 
1932  LIB_PART* part = it->second;
1933 
1934  if( part->IsRoot() )
1935  {
1936  LIB_PART* rootPart = part;
1937 
1938  // Remove the root symbol and all it's children.
1939  m_symbols.erase( it );
1940 
1941  LIB_PART_MAP::iterator it1 = m_symbols.begin();
1942 
1943  while( it1 != m_symbols.end() )
1944  {
1945  if( it1->second->IsAlias() && it1->second->GetParent().lock() == rootPart->SharedPtr() )
1946  {
1947  delete it1->second;
1948  it1 = m_symbols.erase( it1 );
1949  }
1950  else
1951  {
1952  it1++;
1953  }
1954  }
1955 
1956  delete rootPart;
1957  }
1958  else
1959  {
1960  // Just remove the alias.
1961  m_symbols.erase( it );
1962  delete part;
1963  }
1964 
1965  ++m_modHash;
1966  m_isModified = true;
1967 }
PART_SPTR SharedPtr()
Define a library symbol object.
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:201
#define _(s)
Definition: 3d_actions.cpp:33
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), LIB_PART::IsRoot(), m_isModified, m_libFileName, m_modHash, m_symbols, LIB_PART::SharedPtr(), and THROW_IO_ERROR.

Referenced by SCH_SEXPR_PLUGIN::DeleteSymbol().

◆ GetFileName()

wxString SCH_SEXPR_PLUGIN_CACHE::GetFileName ( void  ) const
inline

Definition at line 358 of file sch_sexpr_plugin.cpp.

358 { return m_libFileName.GetFullPath(); }

Referenced by SCH_SEXPR_PLUGIN::SaveLibrary().

◆ GetLibModificationTime()

wxDateTime SCH_SEXPR_PLUGIN_CACHE::GetLibModificationTime ( )

Definition at line 1275 of file sch_sexpr_plugin.cpp.

1276 {
1277  wxFileName fn = GetRealFile();
1278 
1279  // update the writable flag while we have a wxFileName, in a network this
1280  // is possibly quite dynamic anyway.
1281  m_isWritable = fn.IsFileWritable();
1282 
1283  return fn.GetModificationTime();
1284 }
wxFileName GetRealFile() const

References GetRealFile(), and m_isWritable.

Referenced by Load().

◆ GetLogicalName()

wxString SCH_SEXPR_PLUGIN_CACHE::GetLogicalName ( ) const
inline

Definition at line 354 of file sch_sexpr_plugin.cpp.

354 { return m_libFileName.GetName(); }

◆ GetModifyHash()

int SCH_SEXPR_PLUGIN_CACHE::GetModifyHash ( ) const
inline

Definition at line 328 of file sch_sexpr_plugin.cpp.

328 { return m_modHash; }

Referenced by SCH_SEXPR_PLUGIN::GetModifyHash().

◆ GetRealFile()

wxFileName SCH_SEXPR_PLUGIN_CACHE::GetRealFile ( ) const

Definition at line 1252 of file sch_sexpr_plugin.cpp.

1253 {
1254  wxFileName fn( m_libFileName );
1255 
1256 #ifndef __WINDOWS__
1257  if( fn.Exists( wxFILE_EXISTS_SYMLINK ) )
1258  {
1259  char buffer[ PATH_MAX + 1 ];
1260  ssize_t pathLen = readlink( TO_UTF8( fn.GetFullPath() ), buffer, PATH_MAX );
1261 
1262  if( pathLen > 0 )
1263  {
1264  buffer[ pathLen ] = '\0';
1265  fn.Assign( fn.GetPath() + wxT( "/" ) + wxString::FromUTF8( buffer ) );
1266  fn.Normalize();
1267  }
1268  }
1269 #endif
1270 
1271  return fn;
1272 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:100

References m_libFileName, and TO_UTF8.

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

◆ IsFile()

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

Definition at line 1287 of file sch_sexpr_plugin.cpp.

1288 {
1289  return m_fileName == aFullPathAndFileName;
1290 }

References m_fileName.

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

◆ IsFileChanged()

bool SCH_SEXPR_PLUGIN_CACHE::IsFileChanged ( ) const

Definition at line 1293 of file sch_sexpr_plugin.cpp.

1294 {
1295  wxFileName fn = GetRealFile();
1296 
1297  if( m_fileModTime.IsValid() && fn.IsOk() && fn.FileExists() )
1298  return fn.GetModificationTime() != m_fileModTime;
1299 
1300  return false;
1301 }
wxFileName GetRealFile() const

References GetRealFile(), and m_fileModTime.

Referenced by SCH_SEXPR_PLUGIN::cacheLib().

◆ Load()

void SCH_SEXPR_PLUGIN_CACHE::Load ( )

Definition at line 1386 of file sch_sexpr_plugin.cpp.

1387 {
1388  if( !m_libFileName.FileExists() )
1389  {
1390  THROW_IO_ERROR( wxString::Format( _( "Library file \"%s\" not found." ),
1391  m_libFileName.GetFullPath() ) );
1392  }
1393 
1394  wxCHECK_RET( m_libFileName.IsAbsolute(),
1395  wxString::Format( "Cannot use relative file paths in sexpr plugin to "
1396  "open library \"%s\".", m_libFileName.GetFullPath() ) );
1397 
1398  wxLogTrace( traceSchLegacyPlugin, "Loading sexpr symbol library file \"%s\"",
1399  m_libFileName.GetFullPath() );
1400 
1401  FILE_LINE_READER reader( m_libFileName.GetFullPath() );
1402 
1403  SCH_SEXPR_PARSER parser( &reader );
1404 
1405  parser.ParseLib( m_symbols );
1406  ++m_modHash;
1407 
1408  // Remember the file modification time of library file when the
1409  // cache snapshot was made, so that in a networked environment we will
1410  // reload the cache as needed.
1412 }
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
Object to parser s-expression symbol library and schematic file formats.
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:201
#define _(s)
Definition: 3d_actions.cpp:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), GetLibModificationTime(), m_fileModTime, m_libFileName, m_modHash, m_symbols, THROW_IO_ERROR, and traceSchLegacyPlugin.

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

◆ parseFillMode()

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

◆ removeSymbol()

LIB_PART * SCH_SEXPR_PLUGIN_CACHE::removeSymbol ( LIB_PART aAlias)
private

Definition at line 1304 of file sch_sexpr_plugin.cpp.

1305 {
1306  wxCHECK_MSG( aPart != NULL, NULL, "NULL pointer cannot be removed from library." );
1307 
1308  LIB_PART* firstChild = NULL;
1309  LIB_PART_MAP::iterator it = m_symbols.find( aPart->GetName() );
1310 
1311  if( it == m_symbols.end() )
1312  return NULL;
1313 
1314  // If the entry pointer doesn't match the name it is mapped to in the library, we
1315  // have done something terribly wrong.
1316  wxCHECK_MSG( *it->second == aPart, NULL,
1317  "Pointer mismatch while attempting to remove alias entry <" + aPart->GetName() +
1318  "> from library cache <" + m_libFileName.GetName() + ">." );
1319 
1320  // If the symbol is a root symbol used by other symbols find the first alias that uses
1321  // the root part and make it the new root.
1322  if( aPart->IsRoot() )
1323  {
1324  for( auto entry : m_symbols )
1325  {
1326  if( entry.second->IsAlias()
1327  && entry.second->GetParent().lock() == aPart->SharedPtr() )
1328  {
1329  firstChild = entry.second;
1330  break;
1331  }
1332  }
1333 
1334  if( firstChild )
1335  {
1336  for( LIB_ITEM& drawItem : aPart->GetDrawItems() )
1337  {
1338  if( drawItem.Type() == LIB_FIELD_T )
1339  {
1340  LIB_FIELD& field = static_cast<LIB_FIELD&>( drawItem );
1341 
1342  if( firstChild->FindField( field.GetCanonicalName() ) )
1343  continue;
1344  }
1345 
1346  LIB_ITEM* newItem = (LIB_ITEM*) drawItem.Clone();
1347  drawItem.SetParent( firstChild );
1348  firstChild->AddDrawItem( newItem );
1349  }
1350 
1351  // Reparent the remaining aliases.
1352  for( auto entry : m_symbols )
1353  {
1354  if( entry.second->IsAlias()
1355  && entry.second->GetParent().lock() == aPart->SharedPtr() )
1356  entry.second->SetParent( firstChild );
1357  }
1358  }
1359  }
1360 
1361  m_symbols.erase( it );
1362  delete aPart;
1363  m_isModified = true;
1364  ++m_modHash;
1365  return firstChild;
1366 }
Field object used in symbol libraries.
Definition: lib_field.h:59
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:196
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
The base class for drawable items used by schematic library components.
Definition: lib_item.h:61
void AddDrawItem(LIB_ITEM *aItem)
Add a new draw aItem to the draw object list.
LIB_FIELD * FindField(const wxString &aFieldName)
Find a field within this part matching aFieldName and returns it or NULL if not found.
#define NULL
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: lib_field.cpp:375
Define a library symbol object.

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

Referenced by AddSymbol().

◆ Save()

void SCH_SEXPR_PLUGIN_CACHE::Save ( )

Save the entire library to file m_libFileName;.

Definition at line 1415 of file sch_sexpr_plugin.cpp.

1416 {
1417  if( !m_isModified )
1418  return;
1419 
1420  LOCALE_IO toggle; // toggles on, then off, the C locale.
1421 
1422  // Write through symlinks, don't replace them.
1423  wxFileName fn = GetRealFile();
1424 
1425  std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( fn.GetFullPath() ) );
1426 
1427  formatter->Print( 0, "(kicad_symbol_lib (version %d) (generator kicad_symbol_editor)\n",
1429 
1430  for( auto parent : m_symbols )
1431  {
1432  // Save the root symbol first so alias can inherit from them.
1433  if( parent.second->IsRoot() )
1434  {
1435  SaveSymbol( parent.second, *formatter.get(), 1 );
1436 
1437  // Save all of the aliases associated with the current root symbol.
1438  for( auto alias : m_symbols )
1439  {
1440  if( !alias.second->IsAlias() )
1441  continue;
1442 
1443  std::shared_ptr<LIB_PART> aliasParent = alias.second->GetParent().lock();
1444 
1445  if( aliasParent.get() != parent.second )
1446  continue;
1447 
1448  SaveSymbol( alias.second, *formatter.get(), 1 );
1449  }
1450  }
1451  }
1452 
1453  formatter->Print( 0, ")\n" );
1454 
1455  formatter.reset();
1456 
1457  m_fileModTime = fn.GetModificationTime();
1458  m_isModified = false;
1459 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
#define SEXPR_SYMBOL_LIB_FILE_VERSION
This file contains the file format version information for the s-expression schematic and symbol libr...
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
wxFileName GetRealFile() const
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492

References GetRealFile(), m_fileModTime, m_isModified, m_symbols, SaveSymbol(), and SEXPR_SYMBOL_LIB_FILE_VERSION.

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

◆ saveArc()

void SCH_SEXPR_PLUGIN_CACHE::saveArc ( LIB_ARC aArc,
OUTPUTFORMATTER aFormatter,
int  aNestLevel = 0 
)
staticprivate

Definition at line 1667 of file sch_sexpr_plugin.cpp.

1670 {
1671  wxCHECK_RET( aArc && aArc->Type() == LIB_ARC_T, "Invalid LIB_ARC object." );
1672 
1673  int x1 = aArc->GetFirstRadiusAngle();
1674 
1675  if( x1 > 1800 )
1676  x1 -= 3600;
1677 
1678  int x2 = aArc->GetSecondRadiusAngle();
1679 
1680  if( x2 > 1800 )
1681  x2 -= 3600;
1682 
1683  aFormatter.Print( aNestLevel,
1684  "(arc (start %s %s) (end %s %s) (radius (at %s %s) (length %s) "
1685  "(angles %g %g))",
1686  FormatInternalUnits( aArc->GetStart().x ).c_str(),
1687  FormatInternalUnits( aArc->GetStart().y ).c_str(),
1688  FormatInternalUnits( aArc->GetEnd().x ).c_str(),
1689  FormatInternalUnits( aArc->GetEnd().y ).c_str(),
1690  FormatInternalUnits( aArc->GetPosition().x ).c_str(),
1691  FormatInternalUnits( aArc->GetPosition().y ).c_str(),
1692  FormatInternalUnits( aArc->GetRadius() ).c_str(),
1693  static_cast<double>( x1 ) / 10.0,
1694  static_cast<double>( x2 ) / 10.0 );
1695 
1696  aFormatter.Print( 0, "\n" );
1697  aFormatter.Print( aNestLevel + 1, "(stroke (width %s)) ",
1698  FormatInternalUnits( aArc->GetWidth() ).c_str() );
1699 
1700  formatFill( static_cast< LIB_ITEM* >( aArc ), aFormatter, 0 );
1701  aFormatter.Print( 0, "\n" );
1702  aFormatter.Print( aNestLevel, ")\n" );
1703 }
int GetSecondRadiusAngle() const
Definition: lib_arc.h:109
wxPoint GetStart() const
Definition: lib_arc.h:111
static void formatFill(const LIB_ITEM *aItem, OUTPUTFORMATTER &aFormatter, int aNestLevel)
Fill token formatting helper.
int GetRadius() const
Definition: lib_arc.h:103
int GetWidth() const override
Definition: lib_arc.h:99
wxPoint GetEnd() const
Definition: lib_arc.h:114
int GetFirstRadiusAngle() const
Definition: lib_arc.h:106
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
wxPoint GetPosition() const override
Definition: lib_arc.h:90

References formatFill(), FormatInternalUnits(), LIB_ARC::GetEnd(), LIB_ARC::GetFirstRadiusAngle(), LIB_ARC::GetPosition(), LIB_ARC::GetRadius(), LIB_ARC::GetSecondRadiusAngle(), LIB_ARC::GetStart(), LIB_ARC::GetWidth(), LIB_ARC_T, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by saveSymbolDrawItem().

◆ saveBezier()

void SCH_SEXPR_PLUGIN_CACHE::saveBezier ( LIB_BEZIER aBezier,
OUTPUTFORMATTER aFormatter,
int  aNestLevel = 0 
)
staticprivate

Definition at line 1706 of file sch_sexpr_plugin.cpp.

1709 {
1710  wxCHECK_RET( aBezier && aBezier->Type() == LIB_BEZIER_T, "Invalid LIB_BEZIER object." );
1711 
1712  int newLine = 0;
1713  int lineCount = 1;
1714  aFormatter.Print( aNestLevel, "(bezier\n" );
1715  aFormatter.Print( aNestLevel + 1, "(pts " );
1716 
1717  for( const auto& pt : aBezier->GetPoints() )
1718  {
1719  if( newLine == 4 )
1720  {
1721  aFormatter.Print( 0, "\n" );
1722  aFormatter.Print( aNestLevel + 3, " (xy %s %s)",
1723  FormatInternalUnits( pt.x ).c_str(),
1724  FormatInternalUnits( pt.y ).c_str() );
1725  newLine = 0;
1726  lineCount += 1;
1727  }
1728  else
1729  {
1730  aFormatter.Print( 0, " (xy %s %s)",
1731  FormatInternalUnits( pt.x ).c_str(),
1732  FormatInternalUnits( pt.y ).c_str() );
1733  }
1734 
1735  newLine += 1;
1736  }
1737 
1738  if( lineCount == 1 )
1739  {
1740  aFormatter.Print( 0, ")\n" ); // Closes pts token on same line.
1741  }
1742  else
1743  {
1744  aFormatter.Print( 0, "\n" );
1745  aFormatter.Print( aNestLevel + 1, ")\n" ); // Closes pts token with multiple lines.
1746  }
1747 
1748  aFormatter.Print( aNestLevel + 1, "(stroke (width %s)) ",
1749  FormatInternalUnits( aBezier->GetWidth() ).c_str() );
1750 
1751  formatFill( static_cast< LIB_ITEM* >( aBezier ), aFormatter, 0 );
1752  aFormatter.Print( 0, "\n" );
1753  aFormatter.Print( aNestLevel, ")\n" );
1754 }
int GetWidth() const override
Definition: lib_bezier.h:86
static void formatFill(const LIB_ITEM *aItem, OUTPUTFORMATTER &aFormatter, int aNestLevel)
Fill token formatting helper.
const std::vector< wxPoint > & GetPoints() const
Definition: lib_bezier.h:68
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References formatFill(), FormatInternalUnits(), LIB_BEZIER::GetPoints(), LIB_BEZIER::GetWidth(), LIB_BEZIER_T, OUTPUTFORMATTER::Print(), and EDA_ITEM::Type().

Referenced by saveSymbolDrawItem().

◆ saveCircle()

void SCH_SEXPR_PLUGIN_CACHE::saveCircle ( LIB_CIRCLE aCircle,
OUTPUTFORMATTER aFormatter,
int  aNestLevel = 0 
)
staticprivate

Definition at line 1757 of file sch_sexpr_plugin.cpp.

1760 {
1761  wxCHECK_RET( aCircle && aCircle->Type() == LIB_CIRCLE_T, "Invalid LIB_CIRCLE object." );
1762 
1763  aFormatter.Print( aNestLevel, "(circle (center %s %s) (radius %s) (stroke (width %s)) ",
1764  FormatInternalUnits( aCircle->GetPosition().x ).c_str(),
1765  FormatInternalUnits( aCircle->GetPosition().y ).c_str(),
1766  FormatInternalUnits( aCircle->GetRadius() ).c_str(),
1767  FormatInternalUnits( aCircle->GetWidth() ).c_str() );
1768 
1769  formatFill( static_cast< LIB_ITEM* >( aCircle ), aFormatter, 0 );
1770  aFormatter.Print( 0, ")\n" );
1771 }
wxPoint GetPosition() const override
Definition: lib_circle.h:72
int GetWidth() const override
Definition: lib_circle.h:84
static void formatFill(const LIB_ITEM *aItem, OUTPUTFORMATTER &aFormatter, int aNestLevel)
Fill token formatting helper.
int GetRadius() const
Definition: lib_circle.h:88
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References formatFill(), FormatInternalUnits(), LIB_CIRCLE::GetPosition(), LIB_CIRCLE::GetRadius(), LIB_CIRCLE::GetWidth(), LIB_CIRCLE_T, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by saveSymbolDrawItem().

◆ saveDcmInfoAsFields()

void SCH_SEXPR_PLUGIN_CACHE::saveDcmInfoAsFields ( LIB_PART aSymbol,
OUTPUTFORMATTER aFormatter,
int  aNestLevel = 0,
int  aFirstId = MANDATORY_FIELDS 
)
staticprivate

Definition at line 1578 of file sch_sexpr_plugin.cpp.

1580 {
1581  wxCHECK_RET( aSymbol, "Invalid LIB_PART pointer." );
1582 
1583  int id = aFirstId;
1584 
1585  if( !aSymbol->GetKeyWords().IsEmpty() )
1586  {
1587  LIB_FIELD keywords( id, wxString( "ki_keywords" ) );
1588  keywords.SetVisible( false );
1589  keywords.SetText( aSymbol->GetKeyWords() );
1590  saveField( &keywords, aFormatter, aNestLevel + 1 );
1591  id += 1;
1592  }
1593 
1594  if( !aSymbol->GetDescription().IsEmpty() )
1595  {
1596  LIB_FIELD description( id, wxString( "ki_description" ) );
1597  description.SetVisible( false );
1598  description.SetText( aSymbol->GetDescription() );
1599  saveField( &description, aFormatter, aNestLevel + 1 );
1600  id += 1;
1601  }
1602 
1603  wxArrayString fpFilters = aSymbol->GetFootprints();
1604 
1605  if( !fpFilters.IsEmpty() )
1606  {
1607  wxString tmp;
1608 
1609  for( auto filter : fpFilters )
1610  {
1611  if( tmp.IsEmpty() )
1612  tmp = filter;
1613  else
1614  tmp += "\n" + filter;
1615  }
1616 
1617  LIB_FIELD description( id, wxString( "ki_fp_filters" ) );
1618  description.SetVisible( false );
1619  description.SetText( tmp );
1620  saveField( &description, aFormatter, aNestLevel + 1 );
1621  id += 1;
1622  }
1623 }
static void saveField(LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
Field object used in symbol libraries.
Definition: lib_field.h:59
wxString GetKeyWords() const
wxString GetDescription() override
wxArrayString GetFootprints() const

References LIB_PART::GetDescription(), LIB_PART::GetFootprints(), LIB_PART::GetKeyWords(), saveField(), EDA_TEXT::SetText(), and EDA_TEXT::SetVisible().

Referenced by SaveSymbol().

◆ saveField()

void SCH_SEXPR_PLUGIN_CACHE::saveField ( LIB_FIELD aField,
OUTPUTFORMATTER aFormatter,
int  aNestLevel = 0 
)
staticprivate

Definition at line 1774 of file sch_sexpr_plugin.cpp.

1777 {
1778  wxCHECK_RET( aField && aField->Type() == LIB_FIELD_T, "Invalid LIB_FIELD object." );
1779 
1780  aFormatter.Print( aNestLevel, "(property %s %s (id %d) (at %s %s %g)\n",
1781  aFormatter.Quotew( aField->GetName() ).c_str(),
1782  aFormatter.Quotew( aField->GetText() ).c_str(),
1783  aField->GetId(),
1784  FormatInternalUnits( aField->GetPosition().x ).c_str(),
1785  FormatInternalUnits( aField->GetPosition().y ).c_str(),
1786  static_cast<double>( aField->GetTextAngle() ) / 10.0 );
1787 
1788  aField->Format( &aFormatter, aNestLevel, 0 );
1789  aFormatter.Print( aNestLevel, ")\n" );
1790 }
wxPoint GetPosition() const override
Definition: lib_field.h:180
double GetTextAngle() const
Definition: eda_text.h:174
int GetId() const
Definition: lib_field.h:138
wxString GetName(bool aUseDefaultName=true) const
Returns the field name.
Definition: lib_field.cpp:366
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:519
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
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
Return the string associated with the text object.
Definition: eda_text.h:127
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References EDA_TEXT::Format(), FormatInternalUnits(), LIB_FIELD::GetId(), LIB_FIELD::GetName(), LIB_FIELD::GetPosition(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), LIB_FIELD_T, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by saveDcmInfoAsFields(), and SaveSymbol().

◆ savePin()

void SCH_SEXPR_PLUGIN_CACHE::savePin ( LIB_PIN aPin,
OUTPUTFORMATTER aFormatter,
int  aNestLevel = 0 
)
staticprivate

Definition at line 1793 of file sch_sexpr_plugin.cpp.

1796 {
1797  wxCHECK_RET( aPin && aPin->Type() == LIB_PIN_T, "Invalid LIB_PIN object." );
1798 
1799  aPin->ClearFlags( IS_CHANGED );
1800 
1801  aFormatter.Print( aNestLevel, "(pin %s %s (at %s %s %s) (length %s)",
1803  getPinShapeToken( aPin->GetShape() ),
1804  FormatInternalUnits( aPin->GetPosition().x ).c_str(),
1805  FormatInternalUnits( aPin->GetPosition().y ).c_str(),
1806  FormatAngle( getPinAngle( aPin->GetOrientation() ) * 10.0 ).c_str(),
1807  FormatInternalUnits( aPin->GetLength() ).c_str() );
1808 
1809  if( !aPin->IsVisible() )
1810  aFormatter.Print( 0, " hide\n" );
1811  else
1812  aFormatter.Print( 0, "\n" );
1813 
1814  // This follows the EDA_TEXT effects formatting for future expansion.
1815  aFormatter.Print( aNestLevel + 1, "(name %s (effects (font (size %s %s))))\n",
1816  aFormatter.Quotew( aPin->GetName() ).c_str(),
1817  FormatInternalUnits( aPin->GetNameTextSize() ).c_str(),
1818  FormatInternalUnits( aPin->GetNameTextSize() ).c_str() );
1819 
1820  aFormatter.Print( aNestLevel + 1, "(number %s (effects (font (size %s %s))))\n",
1821  aFormatter.Quotew( aPin->GetNumber() ).c_str(),
1822  FormatInternalUnits( aPin->GetNumberTextSize() ).c_str(),
1823  FormatInternalUnits( aPin->GetNumberTextSize() ).c_str() );
1824 
1825 
1826  for( const std::pair<const wxString, LIB_PIN::ALT>& alt : aPin->GetAlternates() )
1827  {
1828  aFormatter.Print( aNestLevel + 1, "(alternate %s %s %s)\n",
1829  aFormatter.Quotew( alt.second.m_Name ).c_str(),
1830  getPinElectricalTypeToken( alt.second.m_Type ),
1831  getPinShapeToken( alt.second.m_Shape ) );
1832  }
1833 
1834  aFormatter.Print( aNestLevel, ")\n" );
1835 }
int GetOrientation() const
Definition: lib_pin.h:125
GRAPHIC_PINSHAPE GetShape() const
Definition: lib_pin.h:128
static float getPinAngle(int aOrientation)
static const char * getPinShapeToken(GRAPHIC_PINSHAPE aShape)
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:589
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: base_struct.h:113
const wxString & GetName() const
Definition: lib_pin.h:156
static const char * getPinElectricalTypeToken(ELECTRICAL_PINTYPE aType)
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
bool IsVisible() const
Definition: lib_pin.h:147
int GetNameTextSize() const
Definition: lib_pin.h:174
wxPoint GetPosition() const override
Definition: lib_pin.h:254
const wxString & GetNumber() const
Definition: lib_pin.h:165
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:134
std::map< wxString, ALT > & GetAlternates()
Definition: lib_pin.h:180
int GetNumberTextSize() const
Definition: lib_pin.h:177
int GetLength() const
Definition: lib_pin.h:131
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:233
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References EDA_ITEM::ClearFlags(), FormatAngle(), FormatInternalUnits(), LIB_PIN::GetAlternates(), LIB_PIN::GetLength(), LIB_PIN::GetName(), LIB_PIN::GetNameTextSize(), LIB_PIN::GetNumber(), LIB_PIN::GetNumberTextSize(), LIB_PIN::GetOrientation(), getPinAngle(), getPinElectricalTypeToken(), getPinShapeToken(), LIB_PIN::GetPosition(), LIB_PIN::GetShape(), LIB_PIN::GetType(), IS_CHANGED, LIB_PIN::IsVisible(), LIB_PIN_T, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by saveSymbolDrawItem().

◆ savePolyLine()

void SCH_SEXPR_PLUGIN_CACHE::savePolyLine ( LIB_POLYLINE aPolyLine,
OUTPUTFORMATTER aFormatter,
int  aNestLevel = 0 
)
staticprivate

Definition at line 1838 of file sch_sexpr_plugin.cpp.

1841 {
1842  wxCHECK_RET( aPolyLine && aPolyLine->Type() == LIB_POLYLINE_T, "Invalid LIB_POLYLINE object." );
1843 
1844  int newLine = 0;
1845  int lineCount = 1;
1846  aFormatter.Print( aNestLevel, "(polyline\n" );
1847  aFormatter.Print( aNestLevel + 1, "(pts" );
1848 
1849  for( const auto& pt : aPolyLine->GetPolyPoints() )
1850  {
1851  if( newLine == 4 || !ADVANCED_CFG::GetCfg().m_CompactSave )
1852  {
1853  aFormatter.Print( 0, "\n" );
1854  aFormatter.Print( aNestLevel + 2, "(xy %s %s)",
1855  FormatInternalUnits( pt.x ).c_str(),
1856  FormatInternalUnits( pt.y ).c_str() );
1857  newLine = 0;
1858  lineCount += 1;
1859  }
1860  else
1861  {
1862  aFormatter.Print( 0, " (xy %s %s)",
1863  FormatInternalUnits( pt.x ).c_str(),
1864  FormatInternalUnits( pt.y ).c_str() );
1865  }
1866 
1867  newLine += 1;
1868  }
1869 
1870  if( lineCount == 1 )
1871  {
1872  aFormatter.Print( 0, ")\n" ); // Closes pts token on same line.
1873  }
1874  else
1875  {
1876  aFormatter.Print( 0, "\n" );
1877  aFormatter.Print( aNestLevel + 1, ")\n" ); // Closes pts token with multiple lines.
1878  }
1879 
1880  aFormatter.Print( aNestLevel + 1, "(stroke (width %s)) ",
1881  FormatInternalUnits( aPolyLine->GetWidth() ).c_str() );
1882  formatFill( static_cast< LIB_ITEM* >( aPolyLine ), aFormatter, 0 );
1883  aFormatter.Print( 0, "\n" );
1884  aFormatter.Print( aNestLevel, ")\n" );
1885 }
bool m_CompactSave
Save files in compact display mode When is is not specified, points are written one per line.
int GetWidth() const override
Definition: lib_polyline.h:102
const std::vector< wxPoint > & GetPolyPoints() const
Definition: lib_polyline.h:60
static void formatFill(const LIB_ITEM *aItem, OUTPUTFORMATTER &aFormatter, int aNestLevel)
Fill token formatting helper.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References formatFill(), FormatInternalUnits(), ADVANCED_CFG::GetCfg(), LIB_POLYLINE::GetPolyPoints(), LIB_POLYLINE::GetWidth(), LIB_POLYLINE_T, ADVANCED_CFG::m_CompactSave, OUTPUTFORMATTER::Print(), and EDA_ITEM::Type().

Referenced by saveSymbolDrawItem().

◆ saveRectangle()

void SCH_SEXPR_PLUGIN_CACHE::saveRectangle ( LIB_RECTANGLE aRectangle,
OUTPUTFORMATTER aFormatter,
int  aNestLevel = 0 
)
staticprivate

Definition at line 1888 of file sch_sexpr_plugin.cpp.

1891 {
1892  wxCHECK_RET( aRectangle && aRectangle->Type() == LIB_RECTANGLE_T,
1893  "Invalid LIB_RECTANGLE object." );
1894 
1895  aFormatter.Print( aNestLevel, "(rectangle (start %s %s) (end %s %s)\n",
1896  FormatInternalUnits( aRectangle->GetPosition().x ).c_str(),
1897  FormatInternalUnits( aRectangle->GetPosition().y ).c_str(),
1898  FormatInternalUnits( aRectangle->GetEnd().x ).c_str(),
1899  FormatInternalUnits( aRectangle->GetEnd().y ).c_str() );
1900  aFormatter.Print( aNestLevel + 1, "(stroke (width %s)) ",
1901  FormatInternalUnits( aRectangle->GetWidth() ).c_str() );
1902  formatFill( static_cast< LIB_ITEM* >( aRectangle ), aFormatter, 0 );
1903  aFormatter.Print( 0, "\n" );
1904  aFormatter.Print( aNestLevel, ")\n" );
1905 }
wxPoint GetEnd() const
Definition: lib_rectangle.h:87
int GetWidth() const override
Definition: lib_rectangle.h:83
static void formatFill(const LIB_ITEM *aItem, OUTPUTFORMATTER &aFormatter, int aNestLevel)
Fill token formatting helper.
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:74
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References formatFill(), FormatInternalUnits(), LIB_RECTANGLE::GetEnd(), LIB_RECTANGLE::GetPosition(), LIB_RECTANGLE::GetWidth(), LIB_RECTANGLE_T, OUTPUTFORMATTER::Print(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by saveSymbolDrawItem().

◆ SaveSymbol()

void SCH_SEXPR_PLUGIN_CACHE::SaveSymbol ( LIB_PART aSymbol,
OUTPUTFORMATTER aFormatter,
int  aNestLevel = 0,
const wxString &  aLibName = wxEmptyString 
)
static

Definition at line 1462 of file sch_sexpr_plugin.cpp.

1464 {
1465  wxCHECK_RET( aSymbol, "Invalid LIB_PART pointer." );
1466 
1467  int lastFieldId;
1468  LIB_FIELDS fields;
1469  std::string name = aFormatter.Quotew( aSymbol->GetLibId().Format().wx_str() );
1470  std::string unitName = aSymbol->GetLibId().GetLibItemName();
1471 
1472  if( !aLibName.IsEmpty() )
1473  {
1474  name = aFormatter.Quotew( aLibName );
1475 
1476  LIB_ID unitId;
1477 
1478  wxCHECK2( unitId.Parse( aLibName, LIB_ID::ID_SCH ) < 0, /* do nothing */ );
1479 
1480  unitName = unitId.GetLibItemName();
1481  }
1482 
1483  if( aSymbol->IsRoot() )
1484  {
1485  aFormatter.Print( aNestLevel, "(symbol %s", name.c_str() );
1486 
1487  if( aSymbol->IsPower() )
1488  aFormatter.Print( 0, " (power)" );
1489 
1490  // TODO: add uuid token here.
1491 
1492  // TODO: add anchor position token here.
1493 
1494  if( !aSymbol->ShowPinNumbers() )
1495  aFormatter.Print( 0, " (pin_numbers hide)" );
1496 
1497  if( aSymbol->GetPinNameOffset() != Mils2iu( DEFAULT_PIN_NAME_OFFSET )
1498  || !aSymbol->ShowPinNames() )
1499  {
1500  aFormatter.Print( 0, " (pin_names" );
1501 
1502  if( aSymbol->GetPinNameOffset() != Mils2iu( DEFAULT_PIN_NAME_OFFSET ) )
1503  aFormatter.Print( 0, " (offset %s)",
1504  FormatInternalUnits( aSymbol->GetPinNameOffset() ).c_str() );
1505 
1506  if( !aSymbol->ShowPinNames() )
1507  aFormatter.Print( 0, " hide" );
1508 
1509  aFormatter.Print( 0, ")" );
1510  }
1511 
1512  aFormatter.Print( 0, " (in_bom %s)", ( aSymbol->GetIncludeInBom() ) ? "yes" : "no" );
1513  aFormatter.Print( 0, " (on_board %s)", ( aSymbol->GetIncludeOnBoard() ) ? "yes" : "no" );
1514 
1515  // TODO: add atomic token here.
1516 
1517  // TODO: add required token here."
1518 
1519  aFormatter.Print( 0, "\n" );
1520 
1521  aSymbol->GetFields( fields );
1522 
1523  for( auto field : fields )
1524  saveField( &field, aFormatter, aNestLevel + 1 );
1525 
1526  lastFieldId = fields.back().GetId() + 1;
1527 
1528  // @todo At some point in the future the lock status (all units interchangeable) should
1529  // be set deterministically. For now a custom lock propertery is used to preserve the
1530  // locked flag state.
1531  if( aSymbol->UnitsLocked() )
1532  {
1533  LIB_FIELD locked( lastFieldId, "ki_locked" );
1534  saveField( &locked, aFormatter, aNestLevel + 1 );
1535  lastFieldId += 1;
1536  }
1537 
1538  saveDcmInfoAsFields( aSymbol, aFormatter, aNestLevel, lastFieldId );
1539 
1540  // Save the draw items grouped by units.
1541  std::vector<PART_UNITS> units = aSymbol->GetUnitDrawItems();
1542 
1543  for( auto unit : units )
1544  {
1545  aFormatter.Print( aNestLevel + 1, "(symbol \"%s_%d_%d\"\n",
1546  unitName.c_str(), unit.m_unit, unit.m_convert );
1547 
1548  for( auto item : unit.m_items )
1549  saveSymbolDrawItem( item, aFormatter, aNestLevel + 2 );
1550 
1551  aFormatter.Print( aNestLevel + 1, ")\n" );
1552  }
1553  }
1554  else
1555  {
1556  std::shared_ptr<LIB_PART> parent = aSymbol->GetParent().lock();
1557 
1558  wxASSERT( parent );
1559 
1560  aFormatter.Print( aNestLevel, "(symbol %s (extends %s)\n",
1561  name.c_str(),
1562  aFormatter.Quotew( parent->GetName() ).c_str() );
1563 
1564  aSymbol->GetFields( fields );
1565 
1566  for( auto field : fields )
1567  saveField( &field, aFormatter, aNestLevel + 1 );
1568 
1569  lastFieldId = fields.back().GetId() + 1;
1570 
1571  saveDcmInfoAsFields( aSymbol, aFormatter, aNestLevel, lastFieldId );
1572  }
1573 
1574  aFormatter.Print( aNestLevel, ")\n" );
1575 }
static void saveField(LIB_FIELD *aField, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
LIB_ID GetLibId() const override
int GetPinNameOffset()
Field object used in symbol libraries.
Definition: lib_field.h:59
std::vector< struct PART_UNITS > GetUnitDrawItems()
Return a list of LIB_ITEM objects separated by unit and convert number.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
bool ShowPinNames()
static void saveDcmInfoAsFields(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, int aFirstId=MANDATORY_FIELDS)
bool ShowPinNumbers()
PART_REF & GetParent()
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
#define DEFAULT_PIN_NAME_OFFSET
UTF8 Format() const
Definition: lib_id.cpp:237
bool IsPower() const
const char * name
Definition: DXF_plotter.cpp:60
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:218
wxString wx_str() const
Definition: utf8.cpp:51
bool GetIncludeOnBoard() const
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
static void saveSymbolDrawItem(LIB_ITEM *aItem, OUTPUTFORMATTER &aFormatter, int aNestLevel)
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
bool GetIncludeInBom() const
bool UnitsLocked() const
Check whether part units are interchangeable.
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
void GetFields(LIB_FIELDS &aList)
Return a list of fields within this part.

References DEFAULT_PIN_NAME_OFFSET, LIB_ID::Format(), FormatInternalUnits(), LIB_PART::GetFields(), LIB_PART::GetIncludeInBom(), LIB_PART::GetIncludeOnBoard(), LIB_PART::GetLibId(), LIB_ID::GetLibItemName(), LIB_PART::GetParent(), LIB_PART::GetPinNameOffset(), LIB_PART::GetUnitDrawItems(), LIB_ID::ID_SCH, LIB_PART::IsPower(), LIB_PART::IsRoot(), name, LIB_ID::Parse(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), saveDcmInfoAsFields(), saveField(), saveSymbolDrawItem(), LIB_PART::ShowPinNames(), LIB_PART::ShowPinNumbers(), LIB_PART::UnitsLocked(), and UTF8::wx_str().

Referenced by SCH_SEXPR_PLUGIN::Format(), SCH_SEXPR_PLUGIN::FormatPart(), and Save().

◆ saveSymbolDrawItem()

void SCH_SEXPR_PLUGIN_CACHE::saveSymbolDrawItem ( LIB_ITEM aItem,
OUTPUTFORMATTER aFormatter,
int  aNestLevel 
)
staticprivate

Definition at line 1626 of file sch_sexpr_plugin.cpp.

1628 {
1629  wxCHECK_RET( aItem, "Invalid LIB_ITEM pointer." );
1630 
1631  switch( aItem->Type() )
1632  {
1633  case LIB_ARC_T:
1634  saveArc( (LIB_ARC*) aItem, aFormatter, aNestLevel );
1635  break;
1636 
1637  case LIB_BEZIER_T:
1638  saveBezier( (LIB_BEZIER*) aItem, aFormatter, aNestLevel );
1639  break;
1640 
1641  case LIB_CIRCLE_T:
1642  saveCircle( ( LIB_CIRCLE* ) aItem, aFormatter, aNestLevel );
1643  break;
1644 
1645  case LIB_PIN_T:
1646  savePin( (LIB_PIN* ) aItem, aFormatter, aNestLevel );
1647  break;
1648 
1649  case LIB_POLYLINE_T:
1650  savePolyLine( ( LIB_POLYLINE* ) aItem, aFormatter, aNestLevel );
1651  break;
1652 
1653  case LIB_RECTANGLE_T:
1654  saveRectangle( ( LIB_RECTANGLE* ) aItem, aFormatter, aNestLevel );
1655  break;
1656 
1657  case LIB_TEXT_T:
1658  saveText( ( LIB_TEXT* ) aItem, aFormatter, aNestLevel );
1659  break;
1660 
1661  default:
1662  ;
1663  }
1664 }
static void saveBezier(LIB_BEZIER *aBezier, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
static void saveText(LIB_TEXT *aText, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
Define a symbol library graphical text item.
Definition: lib_text.h:40
static void saveCircle(LIB_CIRCLE *aCircle, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
static void savePolyLine(LIB_POLYLINE *aPolyLine, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
static void savePin(LIB_PIN *aPin, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
static void saveRectangle(LIB_RECTANGLE *aRectangle, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
static void saveArc(LIB_ARC *aArc, OUTPUTFORMATTER &aFormatter, int aNestLevel=0)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
Define a bezier curve graphic body item.
Definition: lib_bezier.h:34

References LIB_ARC_T, LIB_BEZIER_T, LIB_CIRCLE_T, LIB_PIN_T, LIB_POLYLINE_T, LIB_RECTANGLE_T, LIB_TEXT_T, saveArc(), saveBezier(), saveCircle(), savePin(), savePolyLine(), saveRectangle(), saveText(), and EDA_ITEM::Type().

Referenced by SaveSymbol().

◆ saveText()

void SCH_SEXPR_PLUGIN_CACHE::saveText ( LIB_TEXT aText,
OUTPUTFORMATTER aFormatter,
int  aNestLevel = 0 
)
staticprivate

Definition at line 1908 of file sch_sexpr_plugin.cpp.

1911 {
1912  wxCHECK_RET( aText && aText->Type() == LIB_TEXT_T, "Invalid LIB_TEXT object." );
1913 
1914  aFormatter.Print( aNestLevel, "(text %s (at %s %s %g)\n",
1915  aFormatter.Quotew( aText->GetText() ).c_str(),
1916  FormatInternalUnits( aText->GetPosition().x ).c_str(),
1917  FormatInternalUnits( aText->GetPosition().y ).c_str(),
1918  aText->GetTextAngle() );
1919  aText->Format( &aFormatter, aNestLevel, 0 );
1920  aFormatter.Print( aNestLevel, ")\n" );
1921 }
wxPoint GetPosition() const override
Definition: lib_text.h:84
double GetTextAngle() const
Definition: eda_text.h:174
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:519
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
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
Return the string associated with the text object.
Definition: eda_text.h:127
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References EDA_TEXT::Format(), FormatInternalUnits(), LIB_TEXT::GetPosition(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), LIB_TEXT_T, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

Referenced by saveSymbolDrawItem().

◆ SetFileName()

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

Definition at line 356 of file sch_sexpr_plugin.cpp.

356 { m_libFileName = aFileName; }

Referenced by SCH_SEXPR_PLUGIN::SaveLibrary().

◆ SetModified()

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

Member Data Documentation

◆ m_fileModTime

wxDateTime SCH_SEXPR_PLUGIN_CACHE::m_fileModTime
private

Definition at line 292 of file sch_sexpr_plugin.cpp.

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

◆ m_fileName

wxString SCH_SEXPR_PLUGIN_CACHE::m_fileName
private

Definition at line 290 of file sch_sexpr_plugin.cpp.

Referenced by IsFile().

◆ m_isModified

bool SCH_SEXPR_PLUGIN_CACHE::m_isModified
private

Definition at line 295 of file sch_sexpr_plugin.cpp.

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

◆ m_isWritable

bool SCH_SEXPR_PLUGIN_CACHE::m_isWritable
private

Definition at line 294 of file sch_sexpr_plugin.cpp.

Referenced by GetLibModificationTime().

◆ m_libFileName

wxFileName SCH_SEXPR_PLUGIN_CACHE::m_libFileName
private

Definition at line 291 of file sch_sexpr_plugin.cpp.

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

◆ m_libType

int SCH_SEXPR_PLUGIN_CACHE::m_libType
private

Definition at line 298 of file sch_sexpr_plugin.cpp.

Referenced by SCH_SEXPR_PLUGIN_CACHE().

◆ m_modHash

int SCH_SEXPR_PLUGIN_CACHE::m_modHash = 1
staticprivate

Definition at line 288 of file sch_sexpr_plugin.cpp.

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

◆ m_symbols

◆ m_versionMajor

int SCH_SEXPR_PLUGIN_CACHE::m_versionMajor
private

Definition at line 296 of file sch_sexpr_plugin.cpp.

Referenced by SCH_SEXPR_PLUGIN_CACHE().

◆ m_versionMinor

int SCH_SEXPR_PLUGIN_CACHE::m_versionMinor
private

Definition at line 297 of file sch_sexpr_plugin.cpp.

Referenced by SCH_SEXPR_PLUGIN_CACHE().

◆ SCH_SEXPR_PLUGIN

friend SCH_SEXPR_PLUGIN_CACHE::SCH_SEXPR_PLUGIN
private

Definition at line 322 of file sch_sexpr_plugin.cpp.


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