KiCad PCB EDA Suite
SCH_SEXPR_PLUGIN Class Reference

A SCH_PLUGIN derivation for loading schematic files using the new s-expression file format. More...

#include <sch_sexpr_plugin.h>

Inheritance diagram for SCH_SEXPR_PLUGIN:
SCH_PLUGIN

Public Member Functions

 SCH_SEXPR_PLUGIN ()
 
virtual ~SCH_SEXPR_PLUGIN ()
 
const wxString GetName () const override
 Returns a brief hard coded name for this SCH_PLUGIN. More...
 
const wxString GetFileExtension () const override
 Returns the file extension for the SCH_PLUGIN. More...
 
const wxString GetLibraryFileExtension () const override
 Return the library file extension for the SCH_PLUGIN object. More...
 
int GetModifyHash () const override
 Return the modification hash from the library cache. More...
 
SCH_SHEETLoad (const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr) override
 Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one. More...
 
void LoadContent (LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
 
void Save (const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr) override
 Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file. More...
 
void Format (SCH_SHEET *aSheet)
 
void Format (EE_SELECTION *aSelection, OUTPUTFORMATTER *aFormatter)
 
void EnumerateSymbolLib (wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Populate a list of LIB_PART alias names contained within the library aLibraryPath. More...
 
void EnumerateSymbolLib (std::vector< LIB_PART * > &aSymbolList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Populate a list of LIB_PART aliases contained within the library aLibraryPath. More...
 
LIB_PARTLoadSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=nullptr) override
 Load a LIB_PART object having aPartName from the aLibraryPath containing a library format that this SCH_PLUGIN knows about. More...
 
void SaveSymbol (const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=nullptr) override
 Write aSymbol to an existing library located at aLibraryPath. More...
 
void DeleteSymbol (const wxString &aLibraryPath, const wxString &aSymbolName, const PROPERTIES *aProperties=nullptr) override
 Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath. More...
 
void CreateSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Create a new empty symbol library at aLibraryPath. More...
 
bool DeleteSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Delete an existing symbol library and returns true if successful, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 
void SaveLibrary (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 
bool CheckHeader (const wxString &aFileName) override
 Return true if the first line in aFileName begins with the expected header. More...
 
bool IsSymbolLibWritable (const wxString &aLibraryPath) override
 Return true if the library at aLibraryPath is writable. More...
 
const wxString & GetError () const override
 Return an error string to the caller. More...
 
virtual void SymbolLibOptions (PROPERTIES *aListToAppendTo) const
 Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Static Public Member Functions

static LIB_PARTParsePart (LINE_READER &aReader, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
 
static void FormatPart (LIB_PART *aPart, OUTPUTFORMATTER &aFormatter)
 

Static Public Attributes

static const char * PropBuffering = "buffering"
 The property used internally by the plugin to enable cache buffering which prevents the library file from being written every time the cache is changed. More...
 

Protected Member Functions

void init (SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
 initialize PLUGIN like a constructor would. More...
 

Protected Attributes

int m_version
 Version of file being loaded. More...
 
int m_fieldId
 Non-mandatory schematic field ID counter. More...
 
wxString m_error
 For throwing exceptions or errors on partial schematic loads. More...
 
wxString m_path
 Root project path for loading child sheets. More...
 
std::stack< wxString > m_currentPath
 Stack to maintain nested sheet paths. More...
 
const PROPERTIESm_props
 Passed via Save() or Load(), no ownership, may be nullptr. More...
 
SCH_SHEETm_rootSheet
 The root sheet of the schematic being loaded.. More...
 
SCHEMATICm_schematic
 Passed to Load(), the schematic object being loaded. More...
 
OUTPUTFORMATTERm_out
 The output formatter for saving SCH_SCREEN objects. More...
 
SCH_SEXPR_PLUGIN_CACHEm_cache
 

Private Member Functions

void loadHierarchy (SCH_SHEET *aSheet)
 
void loadFile (const wxString &aFileName, SCH_SHEET *aSheet)
 
void saveSymbol (SCH_COMPONENT *aComponent, int aNestLevel)
 
void saveField (SCH_FIELD *aField, int aNestLevel)
 
void saveBitmap (SCH_BITMAP *aBitmap, int aNestLevel)
 
void saveSheet (SCH_SHEET *aSheet, int aNestLevel)
 
void saveJunction (SCH_JUNCTION *aJunction, int aNestLevel)
 
void saveNoConnect (SCH_NO_CONNECT *aNoConnect, int aNestLevel)
 
void saveBusEntry (SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
 
void saveLine (SCH_LINE *aLine, int aNestLevel)
 
void saveText (SCH_TEXT *aText, int aNestLevel)
 
void saveBusAlias (std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
 
void cacheLib (const wxString &aLibraryFileName)
 
bool isBuffering (const PROPERTIES *aProperties)
 

Detailed Description

A SCH_PLUGIN derivation for loading schematic files using the new s-expression file format.

As with all SCH_PLUGINs there is no UI dependencies i.e. windowing calls allowed.

Definition at line 56 of file sch_sexpr_plugin.h.

Constructor & Destructor Documentation

◆ SCH_SEXPR_PLUGIN()

SCH_SEXPR_PLUGIN::SCH_SEXPR_PLUGIN ( )

Definition at line 400 of file sch_sexpr_plugin.cpp.

401 {
402  init( NULL );
403 }
#define NULL
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.

References NULL.

◆ ~SCH_SEXPR_PLUGIN()

SCH_SEXPR_PLUGIN::~SCH_SEXPR_PLUGIN ( )
virtual

Definition at line 406 of file sch_sexpr_plugin.cpp.

407 {
408  delete m_cache;
409 }
SCH_SEXPR_PLUGIN_CACHE * m_cache

Member Function Documentation

◆ cacheLib()

void SCH_SEXPR_PLUGIN::cacheLib ( const wxString &  aLibraryFileName)
private

Definition at line 1983 of file sch_sexpr_plugin.cpp.

1984 {
1985  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
1986  {
1987  // a spectacular episode in memory management:
1988  delete m_cache;
1989  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryFileName );
1990 
1991  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
1992  // to modify the hash value that indicate component to symbol links
1993  // must be updated.
1995 
1996  if( !isBuffering( m_props ) )
1997  m_cache->Load();
1998  }
1999 }
static int s_modify_generation
helper for GetModifyHash()
SCH_SEXPR_PLUGIN_CACHE * m_cache
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PLUG...
bool IsFile(const wxString &aFullPathAndFileName) const
bool isBuffering(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

References isBuffering(), SCH_SEXPR_PLUGIN_CACHE::IsFile(), SCH_SEXPR_PLUGIN_CACHE::IsFileChanged(), SCH_SEXPR_PLUGIN_CACHE::Load(), m_cache, m_props, and PART_LIBS::s_modify_generation.

Referenced by DeleteSymbol(), EnumerateSymbolLib(), LoadSymbol(), and SaveSymbol().

◆ CheckHeader()

bool SCH_SEXPR_PLUGIN::CheckHeader ( const wxString &  aFileName)
overridevirtual

Return true if the first line in aFileName begins with the expected header.

Parameters
aFileNameis the name of the file to use as input

Reimplemented from SCH_PLUGIN.

Definition at line 2175 of file sch_sexpr_plugin.cpp.

2176 {
2177  // Open file and check first line
2178  wxTextFile tempFile;
2179 
2180  tempFile.Open( aFileName );
2181  wxString firstline;
2182  // read the first line
2183  firstline = tempFile.GetFirstLine();
2184  tempFile.Close();
2185 
2186  return firstline.StartsWith( "EESchema" );
2187 }

◆ CreateSymbolLib()

void SCH_SEXPR_PLUGIN::CreateSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Create a new empty symbol library at aLibraryPath.

It is an error to attempt to create an existing library or to attempt to create on a "read only" location.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several footprints.
aPropertiesis an associative array that can be used to tell the library create function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem finding the library, or creating it.

Reimplemented from SCH_PLUGIN.

Definition at line 2108 of file sch_sexpr_plugin.cpp.

2110 {
2111  if( wxFileExists( aLibraryPath ) )
2112  {
2114  _( "symbol library \"%s\" already exists, cannot create a new library" ),
2115  aLibraryPath.GetData() ) );
2116  }
2117 
2118  LOCALE_IO toggle;
2119 
2120  m_props = aProperties;
2121 
2122  delete m_cache;
2123  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
2124  m_cache->SetModified();
2125  m_cache->Save();
2126  m_cache->Load(); // update m_writable and m_mod_time
2127 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
void Save()
Save the entire library to file m_libFileName;.
SCH_SEXPR_PLUGIN_CACHE * m_cache
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PLUG...
void SetModified(bool aModified=true)
#define THROW_IO_ERROR(msg)
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
#define _(s)
Definition: 3d_actions.cpp:33
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

References _, Format(), SCH_SEXPR_PLUGIN_CACHE::Load(), m_cache, m_props, SCH_SEXPR_PLUGIN_CACHE::Save(), SCH_SEXPR_PLUGIN_CACHE::SetModified(), and THROW_IO_ERROR.

◆ DeleteSymbol()

void SCH_SEXPR_PLUGIN::DeleteSymbol ( const wxString &  aLibraryPath,
const wxString &  aSymbolName,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aSymbolNameis the name of a LIB_PART associated with it's root LIB_PART object to delete from the specified library.
aPropertiesis an associative array that can be used to tell the library delete function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem finding the alias or the library or deleting it.

Reimplemented from SCH_PLUGIN.

Definition at line 2094 of file sch_sexpr_plugin.cpp.

2096 {
2097  m_props = aProperties;
2098 
2099  cacheLib( aLibraryPath );
2100 
2101  m_cache->DeleteSymbol( aSymbolName );
2102 
2103  if( !isBuffering( aProperties ) )
2104  m_cache->Save();
2105 }
void Save()
Save the entire library to file m_libFileName;.
SCH_SEXPR_PLUGIN_CACHE * m_cache
void DeleteSymbol(const wxString &aName)
void cacheLib(const wxString &aLibraryFileName)
bool isBuffering(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

References cacheLib(), SCH_SEXPR_PLUGIN_CACHE::DeleteSymbol(), isBuffering(), m_cache, m_props, and SCH_SEXPR_PLUGIN_CACHE::Save().

◆ DeleteSymbolLib()

bool SCH_SEXPR_PLUGIN::DeleteSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Delete an existing symbol library and returns true if successful, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.

Parameters
aLibraryPathis a locator for the "library", usually a directory or file which will contain symbols.
aPropertiesis an associative array that can be used to tell the library delete implementation function anything special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
true if library deleted or false if library did not exist.
Exceptions
IO_ERRORif there is a problem deleting an existing library.

Reimplemented from SCH_PLUGIN.

Definition at line 2130 of file sch_sexpr_plugin.cpp.

2132 {
2133  wxFileName fn = aLibraryPath;
2134 
2135  if( !fn.FileExists() )
2136  return false;
2137 
2138  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2139  // we don't want that. we want bare metal portability with no UI here.
2140  if( wxRemove( aLibraryPath ) )
2141  {
2142  THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
2143  aLibraryPath.GetData() ) );
2144  }
2145 
2146  if( m_cache && m_cache->IsFile( aLibraryPath ) )
2147  {
2148  delete m_cache;
2149  m_cache = 0;
2150  }
2151 
2152  return true;
2153 }
SCH_SEXPR_PLUGIN_CACHE * m_cache
bool IsFile(const wxString &aFullPathAndFileName) const
#define THROW_IO_ERROR(msg)
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
#define _(s)
Definition: 3d_actions.cpp:33

References _, Format(), SCH_SEXPR_PLUGIN_CACHE::IsFile(), m_cache, and THROW_IO_ERROR.

◆ EnumerateSymbolLib() [1/2]

void SCH_SEXPR_PLUGIN::EnumerateSymbolLib ( wxArrayString &  aSymbolNameList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Populate a list of LIB_PART alias names contained within the library aLibraryPath.

Parameters
aSymbolNameListis an array to populate with the LIB_PART names associated with the library.
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing one or more LIB_PART objects.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif the library cannot be found, the part library cannot be loaded.

Reimplemented from SCH_PLUGIN.

Definition at line 2018 of file sch_sexpr_plugin.cpp.

2021 {
2022  LOCALE_IO toggle; // toggles on, then off, the C locale.
2023 
2024  m_props = aProperties;
2025 
2026  bool powerSymbolsOnly = ( aProperties &&
2027  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2028  cacheLib( aLibraryPath );
2029 
2030  const LIB_PART_MAP& symbols = m_cache->m_symbols;
2031 
2032  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2033  {
2034  if( !powerSymbolsOnly || it->second->IsPower() )
2035  aSymbolNameList.Add( it->first );
2036  }
2037 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
SCH_SEXPR_PLUGIN_CACHE * m_cache
std::map< wxString, LIB_PART *, LibPartMapSort > LIB_PART_MAP
Part map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.
static const char * PropPowerSymsOnly

References cacheLib(), m_cache, m_props, SCH_SEXPR_PLUGIN_CACHE::m_symbols, and SYMBOL_LIB_TABLE::PropPowerSymsOnly.

◆ EnumerateSymbolLib() [2/2]

void SCH_SEXPR_PLUGIN::EnumerateSymbolLib ( std::vector< LIB_PART * > &  aSymbolList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Populate a list of LIB_PART aliases contained within the library aLibraryPath.

Note
It is the reponsibility of the caller to delete the returned object from the heap. Failure to do this will result in memory leaks.
Parameters
aSymbolListis an array to populate with the LIB_PART pointers associated with the library.
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing one or more LIB_PART objects.
aPropertiesis an associative array that can be used to tell the plugin anything needed about how to perform with respect to aLibraryPath. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif the library cannot be found, the part library cannot be loaded.

Reimplemented from SCH_PLUGIN.

Definition at line 2040 of file sch_sexpr_plugin.cpp.

2043 {
2044  LOCALE_IO toggle; // toggles on, then off, the C locale.
2045 
2046  m_props = aProperties;
2047 
2048  bool powerSymbolsOnly = ( aProperties &&
2049  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2050  cacheLib( aLibraryPath );
2051 
2052  const LIB_PART_MAP& symbols = m_cache->m_symbols;
2053 
2054  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2055  {
2056  if( !powerSymbolsOnly || it->second->IsPower() )
2057  aSymbolList.push_back( it->second );
2058  }
2059 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
SCH_SEXPR_PLUGIN_CACHE * m_cache
std::map< wxString, LIB_PART *, LibPartMapSort > LIB_PART_MAP
Part map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.
static const char * PropPowerSymsOnly

References cacheLib(), m_cache, m_props, SCH_SEXPR_PLUGIN_CACHE::m_symbols, and SYMBOL_LIB_TABLE::PropPowerSymsOnly.

◆ Format() [1/2]

void SCH_SEXPR_PLUGIN::Format ( SCH_SHEET aSheet)

Definition at line 608 of file sch_sexpr_plugin.cpp.

609 {
610  wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET* object." );
611  wxCHECK_RET( m_schematic != NULL, "NULL SCHEMATIC* object." );
612 
613  SCH_SCREEN* screen = aSheet->GetScreen();
614 
615  wxCHECK( screen, /* void */ );
616 
617  m_out->Print( 0, "(kicad_sch (version %d) (host eeschema %s)\n\n",
619  m_out->Quotew( GetBuildVersion() ).c_str() );
620 
621  // Root sheet must have a permanent UUID.
622  // if( aSheet->IsRootSheet() && aSheet->m_Uuid.IsLegacyTimestamp() )
623  // const_cast<KIID&>( aSheet->m_Uuid ).ConvertTimestampToUuid();
624 
625  // m_out->Print( 1, "(uuid %s)\n\n", m_out->Quotew( aSheet->m_Uuid.AsString() ).c_str() );
626 
627  m_out->Print( 1, "(page %d %d)\n\n",
628  screen->m_ScreenNumber,
629  screen->m_NumberOfScreens );
630 
631  screen->GetPageSettings().Format( m_out, 1, 0 );
632  m_out->Print( 0, "\n" );
633  screen->GetTitleBlock().Format( m_out, 1, 0 );
634 
635  // Save cache library.
636  m_out->Print( 1, "(lib_symbols\n" );
637 
638  for( auto libSymbol : screen->GetLibSymbols() )
639  SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( libSymbol.second, *m_out, 2, libSymbol.first );
640 
641  m_out->Print( 1, ")\n\n" );
642 
643  for( const auto& alias : screen->GetBusAliases() )
644  {
645  saveBusAlias( alias, 1 );
646  }
647 
648  // Enforce item ordering
649  auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b )
650  {
651  return *a < *b;
652  };
653 
654  std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
655 
656  for( SCH_ITEM* item : screen->Items() )
657  save_map.insert( item );
658 
659  KICAD_T itemType = TYPE_NOT_INIT;
661 
662  for( SCH_ITEM* item : save_map )
663  {
664  if( itemType != item->Type() )
665  {
666  itemType = item->Type();
667 
668  if( itemType != SCH_COMPONENT_T
669  && itemType != SCH_JUNCTION_T
670  && itemType != SCH_SHEET_T )
671  m_out->Print( 0, "\n" );
672  }
673 
674  switch( item->Type() )
675  {
676  case SCH_COMPONENT_T:
677  m_out->Print( 0, "\n" );
678  saveSymbol( static_cast<SCH_COMPONENT*>( item ), 1 );
679  break;
680 
681  case SCH_BITMAP_T:
682  saveBitmap( static_cast<SCH_BITMAP*>( item ), 1 );
683  break;
684 
685  case SCH_SHEET_T:
686  m_out->Print( 0, "\n" );
687  saveSheet( static_cast<SCH_SHEET*>( item ), 1 );
688  break;
689 
690  case SCH_JUNCTION_T:
691  saveJunction( static_cast<SCH_JUNCTION*>( item ), 1 );
692  break;
693 
694  case SCH_NO_CONNECT_T:
695  saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ), 1 );
696  break;
697 
699  case SCH_BUS_BUS_ENTRY_T:
700  saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ), 1 );
701  break;
702 
703  case SCH_LINE_T:
704  if( layer != item->GetLayer() )
705  {
706  if( layer == SCH_LAYER_ID_START )
707  {
708  layer = item->GetLayer();
709  }
710  else
711  {
712  layer = item->GetLayer();
713  m_out->Print( 0, "\n" );
714  }
715  }
716 
717  saveLine( static_cast<SCH_LINE*>( item ), 1 );
718  break;
719 
720  case SCH_TEXT_T:
721  case SCH_LABEL_T:
722  case SCH_GLOBAL_LABEL_T:
723  case SCH_HIER_LABEL_T:
724  saveText( static_cast<SCH_TEXT*>( item ), 1 );
725  break;
726 
727  default:
728  wxASSERT( "Unexpected schematic object type in SCH_SEXPR_PLUGIN::Format()" );
729  }
730  }
731 
732  // If this is the root sheet, save all of the sheet paths.
733  if( aSheet->IsRootSheet() )
734  {
735  m_out->Print( 0, "\n" );
736  m_out->Print( 1, "(symbol_instances\n" );
737 
738  SCH_SHEET_LIST sheetPaths( aSheet );
739 
740  for( const SCH_SHEET_PATH& sheetPath : sheetPaths )
741  {
742  SCH_REFERENCE_LIST instances;
743 
744  sheetPath.GetComponents( instances, true, true );
745  instances.SortByReferenceOnly();
746 
747  for( size_t i = 0; i < instances.GetCount(); i++ )
748  {
749  m_out->Print( 2, "(path %s\n",
750  m_out->Quotew( instances[i].GetPath() ).c_str() );
751  m_out->Print( 3, "(reference %s) (unit %d)\n",
752  m_out->Quotew( instances[i].GetRef() ).c_str(),
753  instances[i].GetUnit() );
754  m_out->Print( 2, ")\n" );
755  }
756  }
757 
758  m_out->Print( 1, ")\n" ); // Close instances token.
759  }
760  else if( screen->m_symbolInstances.size() )
761  {
762  m_out->Print( 0, "\n" );
763  m_out->Print( 1, "(symbol_instances\n" );
764 
765  for( const COMPONENT_INSTANCE_REFERENCE& instance : screen->m_symbolInstances )
766  {
767  m_out->Print( 2, "(path %s (reference %s) (unit %d))\n",
768  m_out->Quotew( instance.m_Path.AsString() ).c_str(),
769  m_out->Quotew( instance.m_Reference ).c_str(),
770  instance.m_Unit );
771  }
772 
773  m_out->Print( 1, ")\n" ); // Close instances token.
774  }
775 
776  m_out->Print( 0, ")\n" );
777 }
SCH_SHEET_LIST.
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
int m_ScreenNumber
Definition: base_screen.h:79
void saveLine(SCH_LINE *aLine, int aNestLevel)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect, int aNestLevel)
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
void saveText(SCH_TEXT *aText, int aNestLevel)
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:190
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function GetStandardSizes returns the standard page types, such as "A4", "A3", etc.
Definition: page_info.cpp:271
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:180
void saveSymbol(SCH_COMPONENT *aComponent, int aNestLevel)
std::map< wxString, LIB_PART * > & GetLibSymbols()
Fetch a list of unique LIB_PART object pointers required to properly render each SCH_COMPONENT in thi...
Definition: sch_screen.h:474
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierarchy,...
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
#define NULL
wxString GetBuildVersion()
Get the full KiCad version string.
A simple container for schematic symbol instance infromation.
bool IsRootSheet() const
Definition: sch_sheet.cpp:183
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: title_block.cpp:28
SCH_LAYER_ID
Eeschema drawing layers.
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
SCH_SHEET_PATH.
std::vector< COMPONENT_INSTANCE_REFERENCE > m_symbolInstances
The list of symbol instances loaded from the schematic file.
Definition: sch_screen.h:139
unsigned GetCount() const
Function GetCount.
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
void SortByReferenceOnly()
Function SortByReferenceOnly sorts the list of references by reference.
wxString AsString() const
Definition: common.h:137
EE_RTREE & Items()
Definition: sch_screen.h:158
void saveSheet(SCH_SHEET *aSheet, int aNestLevel)
int m_NumberOfScreens
Definition: base_screen.h:80
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
#define SEXPR_SCHEMATIC_FILE_VERSION
Symbol library file version.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
std::unordered_set< std::shared_ptr< BUS_ALIAS > > GetBusAliases()
Returns a list of bus aliases defined in this screen.
Definition: sch_screen.h:503
void saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)

References KIID_PATH::AsString(), TITLE_BLOCK::Format(), PAGE_INFO::Format(), GetBuildVersion(), SCH_SCREEN::GetBusAliases(), SCH_REFERENCE_LIST::GetCount(), SCH_SCREEN::GetLibSymbols(), SCH_SCREEN::GetPageSettings(), SCH_SHEET::GetScreen(), SCH_SCREEN::GetTitleBlock(), SCH_SHEET::IsRootSheet(), SCH_SCREEN::Items(), BASE_SCREEN::m_NumberOfScreens, COMPONENT_INSTANCE_REFERENCE::m_Path, COMPONENT_INSTANCE_REFERENCE::m_Reference, BASE_SCREEN::m_ScreenNumber, SCH_SCREEN::m_symbolInstances, COMPONENT_INSTANCE_REFERENCE::m_Unit, NULL, SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), SCH_BITMAP_T, SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T, SCH_COMPONENT_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_JUNCTION_T, SCH_LABEL_T, SCH_LAYER_ID_START, SCH_LINE_T, SCH_NO_CONNECT_T, SCH_SHEET_T, SCH_TEXT_T, SEXPR_SCHEMATIC_FILE_VERSION, SCH_REFERENCE_LIST::SortByReferenceOnly(), and TYPE_NOT_INIT.

Referenced by SCH_EDITOR_CONTROL::doCopy().

◆ Format() [2/2]

void SCH_SEXPR_PLUGIN::Format ( EE_SELECTION aSelection,
OUTPUTFORMATTER aFormatter 
)

Definition at line 780 of file sch_sexpr_plugin.cpp.

781 {
782  wxCHECK( aSelection && aFormatter, /* void */ );
783 
784  LOCALE_IO toggle;
785 
786  m_out = aFormatter;
787 
788  size_t i;
789  SCH_ITEM* item;
790  std::map<wxString, LIB_PART*> libSymbols;
791  SCH_SCREEN* screen = aSelection->GetScreen();
792 
793  for( i = 0; i < aSelection->GetSize(); ++i )
794  {
795  item = dynamic_cast<SCH_ITEM*>( aSelection->GetItem( i ) );
796 
797  wxCHECK2( item, continue );
798 
799  if( item->Type() != SCH_COMPONENT_T )
800  continue;
801 
802  SCH_COMPONENT* symbol = dynamic_cast<SCH_COMPONENT*>( item );
803 
804  wxCHECK2( symbol, continue );
805 
806  wxString libSymbolLookup = symbol->GetLibId().Format().wx_str();
807 
808  if( !symbol->UseLibIdLookup() )
809  libSymbolLookup = symbol->GetSchSymbolLibraryName();
810 
811  auto it = screen->GetLibSymbols().find( libSymbolLookup );
812 
813  if( it != screen->GetLibSymbols().end() )
814  libSymbols[ libSymbolLookup ] = it->second;
815  }
816 
817  if( !libSymbols.empty() )
818  {
819  m_out->Print( 0, "(lib_symbols\n" );
820 
821  for( auto libSymbol : libSymbols )
822  SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( libSymbol.second, *m_out, 1, libSymbol.first );
823 
824  m_out->Print( 0, ")\n\n" );
825  }
826 
827  for( i = 0; i < aSelection->GetSize(); ++i )
828  {
829  item = (SCH_ITEM*) aSelection->GetItem( i );
830 
831  switch( item->Type() )
832  {
833  case SCH_COMPONENT_T:
834  saveSymbol( static_cast< SCH_COMPONENT* >( item ), 0 );
835  break;
836 
837  case SCH_BITMAP_T:
838  saveBitmap( static_cast< SCH_BITMAP* >( item ), 0 );
839  break;
840 
841  case SCH_SHEET_T:
842  saveSheet( static_cast< SCH_SHEET* >( item ), 0 );
843  break;
844 
845  case SCH_JUNCTION_T:
846  saveJunction( static_cast< SCH_JUNCTION* >( item ), 0 );
847  break;
848 
849  case SCH_NO_CONNECT_T:
850  saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ), 0 );
851  break;
852 
854  case SCH_BUS_BUS_ENTRY_T:
855  saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ), 0 );
856  break;
857 
858  case SCH_LINE_T:
859  saveLine( static_cast< SCH_LINE* >( item ), 0 );
860  break;
861 
862  case SCH_TEXT_T:
863  case SCH_LABEL_T:
864  case SCH_GLOBAL_LABEL_T:
865  case SCH_HIER_LABEL_T:
866  saveText( static_cast< SCH_TEXT* >( item ), 0 );
867  break;
868 
869  default:
870  wxASSERT( "Unexpected schematic object type in SCH_SEXPR_PLUGIN::Format()" );
871  }
872  }
873 }
void saveLine(SCH_LINE *aLine, int aNestLevel)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect, int aNestLevel)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
SCH_SCREEN * GetScreen()
Definition: ee_selection.h:47
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
wxString GetSchSymbolLibraryName() const
void saveText(SCH_TEXT *aText, int aNestLevel)
void saveSymbol(SCH_COMPONENT *aComponent, int aNestLevel)
std::map< wxString, LIB_PART * > & GetLibSymbols()
Fetch a list of unique LIB_PART object pointers required to properly render each SCH_COMPONENT in thi...
Definition: sch_screen.h:474
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
bool UseLibIdLookup() const
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.h:105
UTF8 Format() const
Definition: lib_id.cpp:237
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:100
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxString wx_str() const
Definition: utf8.cpp:51
Schematic symbol object.
Definition: sch_component.h:88
void saveSheet(SCH_SHEET *aSheet, int aNestLevel)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
const LIB_ID & GetLibId() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
void saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References LIB_ID::Format(), SELECTION::GetItem(), SCH_COMPONENT::GetLibId(), SCH_SCREEN::GetLibSymbols(), SCH_COMPONENT::GetSchSymbolLibraryName(), EE_SELECTION::GetScreen(), SELECTION::GetSize(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), SCH_BITMAP_T, SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T, SCH_COMPONENT_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_JUNCTION_T, SCH_LABEL_T, SCH_LINE_T, SCH_NO_CONNECT_T, SCH_SHEET_T, SCH_TEXT_T, EDA_ITEM::Type(), SCH_COMPONENT::UseLibIdLookup(), and UTF8::wx_str().

◆ FormatPart()

void SCH_SEXPR_PLUGIN::FormatPart ( LIB_PART aPart,
OUTPUTFORMATTER aFormatter 
)
static

Definition at line 2210 of file sch_sexpr_plugin.cpp.

2211 {
2212 
2213  SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( part, formatter );
2214 }
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)

References SCH_SEXPR_PLUGIN_CACHE::SaveSymbol().

Referenced by LIB_EDIT_TOOL::Copy(), and LIB_EDIT_FRAME::CopyPartToClipboard().

◆ GetError()

const wxString& SCH_SEXPR_PLUGIN::GetError ( ) const
inlineoverridevirtual

Return an error string to the caller.

This is useful for schematic loaders that can load partial schematics where throwing an exception would be problematic such as the KiCad legacy plugin.

Returns
an unformatted string containing errors if any.

Reimplemented from SCH_PLUGIN.

Definition at line 123 of file sch_sexpr_plugin.h.

123 { return m_error; }
wxString m_error
For throwing exceptions or errors on partial schematic loads.

References m_error.

◆ GetFileExtension()

const wxString SCH_SEXPR_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Returns the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 68 of file sch_sexpr_plugin.h.

69  {
70  return wxT( "kicad_sch" );
71  }

◆ GetLibraryFileExtension()

const wxString SCH_SEXPR_PLUGIN::GetLibraryFileExtension ( ) const
inlineoverridevirtual

Return the library file extension for the SCH_PLUGIN object.

Implements SCH_PLUGIN.

Definition at line 73 of file sch_sexpr_plugin.h.

74  {
75  return wxT( "kicad_sym" );
76  }

◆ GetModifyHash()

int SCH_SEXPR_PLUGIN::GetModifyHash ( ) const
overridevirtual

Return the modification hash from the library cache.

Note
This is temporary until the new s-expr file format is implement. The new file format will embed symbols instead of referencing them from the library. This function can be removed when the new file format is implemented.
Returns
the modification hash of the library cache.

Implements SCH_PLUGIN.

Definition at line 2008 of file sch_sexpr_plugin.cpp.

2009 {
2010  if( m_cache )
2011  return m_cache->GetModifyHash();
2012 
2013  // If the cache hasn't been loaded, it hasn't been modified.
2014  return 0;
2015 }
SCH_SEXPR_PLUGIN_CACHE * m_cache

References SCH_SEXPR_PLUGIN_CACHE::GetModifyHash(), and m_cache.

◆ GetName()

const wxString SCH_SEXPR_PLUGIN::GetName ( ) const
inlineoverridevirtual

Returns a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 63 of file sch_sexpr_plugin.h.

64  {
65  return wxT( "Eeschema s-expression" );
66  }

◆ init()

void SCH_SEXPR_PLUGIN::init ( SCHEMATIC aSchematic,
const PROPERTIES aProperties = nullptr 
)
protected

initialize PLUGIN like a constructor would.

Definition at line 412 of file sch_sexpr_plugin.cpp.

413 {
414  m_version = 0;
415  m_rootSheet = nullptr;
416  m_props = aProperties;
417  m_schematic = aSchematic;
418  m_cache = nullptr;
419  m_out = nullptr;
420  m_fieldId = 100; // number arbitrarily > MANDATORY_FIELDS or SHEET_MANDATORY_FIELDS
421 }
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
int m_version
Version of file being loaded.
int m_fieldId
Non-mandatory schematic field ID counter.
SCH_SEXPR_PLUGIN_CACHE * m_cache
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

◆ isBuffering()

bool SCH_SEXPR_PLUGIN::isBuffering ( const PROPERTIES aProperties)
private

Definition at line 2002 of file sch_sexpr_plugin.cpp.

2003 {
2004  return ( aProperties && aProperties->Exists( SCH_SEXPR_PLUGIN::PropBuffering ) );
2005 }
bool Exists(const std::string &aProperty) const
Definition: properties.h:44
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...

References PROPERTIES::Exists(), and PropBuffering.

Referenced by cacheLib(), DeleteSymbol(), and SaveSymbol().

◆ IsSymbolLibWritable()

bool SCH_SEXPR_PLUGIN::IsSymbolLibWritable ( const wxString &  aLibraryPath)
overridevirtual

Return true if the library at aLibraryPath is writable.

(Often system libraries are read only because of where they are installed.)

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
Exceptions
IO_ERRORif no library at aLibraryPath exists.

Reimplemented from SCH_PLUGIN.

Definition at line 2190 of file sch_sexpr_plugin.cpp.

2191 {
2192  wxFileName fn( aLibraryPath );
2193 
2194  return ( fn.FileExists() && fn.IsFileWritable() ) || fn.IsDirWritable();
2195 }

◆ Load()

SCH_SHEET * SCH_SEXPR_PLUGIN::Load ( const wxString &  aFileName,
SCHEMATIC aSchematic,
SCH_SHEET aAppendToMe = nullptr,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one.

This may be used to load an entire new SCH_SHEET, or to augment an existing one if aAppendToMe is not NULL.

Parameters
aFileNameis the name of the file to use as input and may be foreign in nature or native in nature.
aKiwayis the KIWAY object used to access the component libraries loaded by the project.
aAppendToMeis an existing SCH_SHEET to append to, but if NULL then this means "do not append, rather load anew".
aPropertiesis an associative array that can be used to tell the loader how to load the file, because it can take any number of additional named arguments that the plugin is known to support. These are tuning parameters for the import or load. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
the successfully loaded schematic, or the same one as aAppendToMe if aAppendToMe was not NULL, and the caller owns it.
Exceptions
IO_ERRORif there is a problem loading, and its contents should say what went wrong, using line number and character offsets of the input file if possible.

Reimplemented from SCH_PLUGIN.

Definition at line 424 of file sch_sexpr_plugin.cpp.

426 {
427  wxASSERT( !aFileName || aSchematic != nullptr );
428 
429  LOCALE_IO toggle; // toggles on, then off, the C locale.
430  SCH_SHEET* sheet;
431 
432  wxFileName fn = aFileName;
433 
434  // Unfortunately child sheet file names the legacy schematic file format are not fully
435  // qualified and are always appended to the project path. The aFileName attribute must
436  // always be an absolute path so the project path can be used for load child sheet files.
437  wxASSERT( fn.IsAbsolute() );
438 
439  if( aAppendToMe )
440  {
441  wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
442  aFileName, aAppendToMe->GetFileName() );
443 
444  wxFileName normedFn = aAppendToMe->GetFileName();
445 
446  if( !normedFn.IsAbsolute() )
447  {
448  if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
449  m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
450  }
451 
452  if( m_path.IsEmpty() )
453  m_path = aSchematic->Prj().GetProjectPath();
454 
455  wxLogTrace( traceSchLegacyPlugin, "Normalized append path \"%s\".", m_path );
456  }
457  else
458  {
459  m_path = aSchematic->Prj().GetProjectPath();
460  }
461 
462  m_currentPath.push( m_path );
463  init( aSchematic, aProperties );
464 
465  if( aAppendToMe == NULL )
466  {
467  // Clean up any allocated memory if an exception occurs loading the schematic.
468  std::unique_ptr< SCH_SHEET > newSheet( new SCH_SHEET( aSchematic ) );
469  newSheet->SetFileName( aFileName );
470  m_rootSheet = newSheet.get();
471  loadHierarchy( newSheet.get() );
472 
473  // If we got here, the schematic loaded successfully.
474  sheet = newSheet.release();
475  m_rootSheet = nullptr; // Quiet Coverity warning.
476  }
477  else
478  {
479  wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
480  m_rootSheet = &aSchematic->Root();
481  sheet = aAppendToMe;
482  loadHierarchy( sheet );
483  }
484 
485  wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
486 
487  return sheet;
488 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:111
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:123
#define NULL
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:496
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
SCH_SHEET & Root() const
Definition: schematic.h:97
wxString m_path
Root project path for loading child sheets.
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:77
void loadHierarchy(SCH_SHEET *aSheet)
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.

References SCH_SHEET::GetFileName(), PROJECT::GetProjectPath(), SCHEMATIC::IsValid(), NULL, SCHEMATIC::Prj(), SCHEMATIC::Root(), and traceSchLegacyPlugin.

◆ LoadContent()

void SCH_SEXPR_PLUGIN::LoadContent ( LINE_READER aReader,
SCH_SHEET aSheet,
int  aVersion = SEXPR_SCHEMATIC_FILE_VERSION 
)

Definition at line 573 of file sch_sexpr_plugin.cpp.

574 {
575  wxCHECK( aSheet, /* void */ );
576 
577  LOCALE_IO toggle;
578  SCH_SEXPR_PARSER parser( &aReader );
579 
580  parser.ParseSchematic( aSheet, true, aFileVersion );
581 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
Object to parser s-expression symbol library and schematic file formats.

References SCH_SEXPR_PARSER::ParseSchematic().

Referenced by SCH_EDITOR_CONTROL::Paste().

◆ loadFile()

void SCH_SEXPR_PLUGIN::loadFile ( const wxString &  aFileName,
SCH_SHEET aSheet 
)
private

Definition at line 563 of file sch_sexpr_plugin.cpp.

564 {
565  FILE_LINE_READER reader( aFileName );
566 
567  SCH_SEXPR_PARSER parser( &reader );
568 
569  parser.ParseSchematic( aSheet );
570 }
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.

References SCH_SEXPR_PARSER::ParseSchematic().

◆ loadHierarchy()

void SCH_SEXPR_PLUGIN::loadHierarchy ( SCH_SHEET aSheet)
private

Definition at line 493 of file sch_sexpr_plugin.cpp.

494 {
495  SCH_SCREEN* screen = NULL;
496 
497  if( !aSheet->GetScreen() )
498  {
499  // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
500  // stores the file name and extension. Add the project path to the file name and
501  // extension to compare when calling SCH_SHEET::SearchHierarchy().
502  wxFileName fileName = aSheet->GetFileName();
503 
504  if( !fileName.IsAbsolute() )
505  fileName.MakeAbsolute( m_currentPath.top() );
506 
507  // Save the current path so that it gets restored when decending and ascending the
508  // sheet hierarchy which allows for sheet schematic files to be nested in folders
509  // relative to the last path a schematic was loaded from.
510  wxLogTrace( traceSchLegacyPlugin, "Saving path \"%s\"", m_currentPath.top() );
511  m_currentPath.push( fileName.GetPath() );
512  wxLogTrace( traceSchLegacyPlugin, "Current path \"%s\"", m_currentPath.top() );
513  wxLogTrace( traceSchLegacyPlugin, "Loading \"%s\"", fileName.GetFullPath() );
514 
515  m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
516 
517  if( screen )
518  {
519  aSheet->SetScreen( screen );
520  aSheet->GetScreen()->SetParent( m_schematic );
521  // Do not need to load the sub-sheets - this has already been done.
522  }
523  else
524  {
525  aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
526  aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
527 
528  try
529  {
530  loadFile( fileName.GetFullPath(), aSheet );
531  }
532  catch( const IO_ERROR& ioe )
533  {
534  // If there is a problem loading the root sheet, there is no recovery.
535  if( aSheet == m_rootSheet )
536  throw( ioe );
537 
538  // For all subsheets, queue up the error message for the caller.
539  if( !m_error.IsEmpty() )
540  m_error += "\n";
541 
542  m_error += ioe.What();
543  }
544 
545  // This was moved out of the try{} block so that any sheets definitionsthat
546  // the plugin fully parsed before the exception was raised will be loaded.
547  for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
548  {
549  wxCHECK2( aItem->Type() == SCH_SHEET_T, /* do nothing */ );
550  auto sheet = static_cast<SCH_SHEET*>( aItem );
551 
552  // Recursion starts here.
553  loadHierarchy( sheet );
554  }
555  }
556 
557  m_currentPath.pop();
558  wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
559  }
560 }
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:635
wxString m_error
For throwing exceptions or errors on partial schematic loads.
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:151
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:196
#define NULL
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:496
void loadFile(const wxString &aFileName, SCH_SHEET *aSheet)
EE_RTREE & Items()
Definition: sch_screen.h:158
void loadHierarchy(SCH_SHEET *aSheet)
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:183
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References SCH_SHEET::GetFileName(), SCH_SHEET::GetScreen(), SCH_SCREEN::Items(), NULL, EE_RTREE::OfType(), SCH_SHEET_T, SCH_SCREEN::SetFileName(), EDA_ITEM::SetParent(), SCH_SHEET::SetScreen(), traceSchLegacyPlugin, and IO_ERROR::What().

◆ LoadSymbol()

LIB_PART * SCH_SEXPR_PLUGIN::LoadSymbol ( const wxString &  aLibraryPath,
const wxString &  aPartName,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Load a LIB_PART object having aPartName from the aLibraryPath containing a library format that this SCH_PLUGIN knows about.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aPartNameis the name of the LIB_PART to load.
aPropertiesis an associative array that can be used to tell the loader implementation to do something special, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Returns
the part created on the heap if found caller shares it or NULL if not found.
Exceptions
IO_ERRORif the library cannot be found or read. No exception is thrown in the case where aAliasName cannot be found.

Reimplemented from SCH_PLUGIN.

Definition at line 2062 of file sch_sexpr_plugin.cpp.

2064 {
2065  LOCALE_IO toggle; // toggles on, then off, the C locale.
2066 
2067  m_props = aProperties;
2068 
2069  cacheLib( aLibraryPath );
2070 
2071  LIB_PART_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
2072 
2073  if( it == m_cache->m_symbols.end() )
2074  return nullptr;
2075 
2076  return it->second;
2077 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
SCH_SEXPR_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

References cacheLib(), m_cache, m_props, and SCH_SEXPR_PLUGIN_CACHE::m_symbols.

◆ ParsePart()

LIB_PART * SCH_SEXPR_PLUGIN::ParsePart ( LINE_READER aReader,
int  aVersion = SEXPR_SCHEMATIC_FILE_VERSION 
)
static

Definition at line 2198 of file sch_sexpr_plugin.cpp.

2199 {
2200  LIB_PART_MAP map;
2201  SCH_SEXPR_PARSER parser( &aReader );
2202 
2203  parser.NeedLEFT();
2204  parser.NextTok();
2205 
2206  return parser.ParseSymbol( map, aFileVersion );
2207 }
std::map< wxString, LIB_PART *, LibPartMapSort > LIB_PART_MAP
Part map used by part library object.
Object to parser s-expression symbol library and schematic file formats.

References SCH_SEXPR_PARSER::ParseSymbol().

Referenced by LIB_EDIT_FRAME::DuplicatePart(), and LIB_EDIT_TOOL::Paste().

◆ Save()

void SCH_SEXPR_PLUGIN::Save ( const wxString &  aFileName,
SCH_SHEET aSheet,
SCHEMATIC aSchematic,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file.

Parameters
aFileNameis the name of a file to save to on disk.
aSheetis the class SCH_SHEET in memory document tree from which to extract information when writing to aFileName. The caller continues to own the SCHEMATIC, and the plugin should refrain from modifying the SCHEMATIC if possible.
aSchematicis the SCHEMATIC object used to access any schematic-wide or project information needed to save the document.
aPropertiesis an associative array that can be used to tell the saver how to save the file, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL. Set the #PropSaveCurrentSheetOnly property to only save the current sheet. Otherwise, all hierarchial sheets are saved.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented from SCH_PLUGIN.

Definition at line 584 of file sch_sexpr_plugin.cpp.

586 {
587  wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET object." );
588  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
589 
590  LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
591 
592  init( aSchematic, aProperties );
593 
594  wxFileName fn = aFileName;
595 
596  // File names should be absolute. Don't assume everything relative to the project path
597  // works properly.
598  wxASSERT( fn.IsAbsolute() );
599 
600  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
601 
602  m_out = &formatter; // no ownership
603 
604  Format( aSheet );
605 }
void Format(SCH_SHEET *aSheet)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
#define NULL
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.

References Format(), and NULL.

◆ saveBitmap()

void SCH_SEXPR_PLUGIN::saveBitmap ( SCH_BITMAP aBitmap,
int  aNestLevel 
)
private

Definition at line 1011 of file sch_sexpr_plugin.cpp.

1012 {
1013  wxCHECK_RET( aBitmap != nullptr && m_out != nullptr, "" );
1014 
1015  const wxImage* image = aBitmap->GetImage()->GetImageData();
1016 
1017  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
1018 
1019  m_out->Print( aNestLevel, "(image (at %s %s)",
1020  FormatInternalUnits( aBitmap->GetPosition().x ).c_str(),
1021  FormatInternalUnits( aBitmap->GetPosition().y ).c_str() );
1022 
1023  if( aBitmap->GetImage()->GetScale() != 1.0 )
1024  m_out->Print( 0, " (scale %g)", aBitmap->GetImage()->GetScale() );
1025 
1026  m_out->Print( 0, "\n" );
1027  m_out->Print( aNestLevel + 1, "(data" );
1028 
1029  wxMemoryOutputStream stream;
1030 
1031  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1032 
1033  // Write binary data in hexadecimal form (ASCII)
1034  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1035  wxString out = wxBase64Encode( buffer->GetBufferStart(), buffer->GetBufferSize() );
1036 
1037  // Apparently the MIME standard character width for base64 encoding is 76 (unconfirmed)
1038  // so use it in a vein attempt to be standard like.
1039 #define MIME_BASE64_LENGTH 76
1040 
1041  size_t first = 0;
1042 
1043  while( first < out.Length() )
1044  {
1045  m_out->Print( 0, "\n" );
1046  m_out->Print( aNestLevel + 2, "%s", TO_UTF8( out( first, MIME_BASE64_LENGTH ) ) );
1047  first += MIME_BASE64_LENGTH;
1048  }
1049 
1050  m_out->Print( 0, "\n" );
1051  m_out->Print( aNestLevel + 1, ")\n" ); // Closes data token.
1052  m_out->Print( aNestLevel, ")\n" ); // Closes image token.
1053 }
double GetScale() const
Definition: bitmap_base.h:92
wxImage * GetImageData()
Definition: bitmap_base.h:83
wxPoint GetPosition() const override
Definition: sch_bitmap.h:140
#define NULL
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:59
#define MIME_BASE64_LENGTH
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
#define TO_UTF8(wxstring)
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

References FormatInternalUnits(), SCH_BITMAP::GetImage(), BITMAP_BASE::GetImageData(), SCH_BITMAP::GetPosition(), BITMAP_BASE::GetScale(), MIME_BASE64_LENGTH, NULL, TO_UTF8, wxPoint::x, and wxPoint::y.

◆ saveBusAlias()

void SCH_SEXPR_PLUGIN::saveBusAlias ( std::shared_ptr< BUS_ALIAS aAlias,
int  aNestLevel 
)
private

Definition at line 1230 of file sch_sexpr_plugin.cpp.

1231 {
1232  wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" );
1233 
1234  wxString members;
1235 
1236  for( auto member : aAlias->Members() )
1237  {
1238  if( members.IsEmpty() )
1239  members = m_out->Quotew( member );
1240  else
1241  members += " " + m_out->Quotew( member );
1242  }
1243 
1244  m_out->Print( aNestLevel, "(bus_alias %s (members %s))\n",
1245  m_out->Quotew( aAlias->GetName() ).c_str(),
1246  TO_UTF8( members ) );
1247 }
#define NULL
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
#define TO_UTF8(wxstring)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References NULL, and TO_UTF8.

◆ saveBusEntry()

void SCH_SEXPR_PLUGIN::saveBusEntry ( SCH_BUS_ENTRY_BASE aBusEntry,
int  aNestLevel 
)
private

Definition at line 1131 of file sch_sexpr_plugin.cpp.

1132 {
1133  wxCHECK_RET( aBusEntry != nullptr && m_out != nullptr, "" );
1134 
1135  // Bus to bus entries are converted to bus line segments.
1136  if( aBusEntry->GetClass() == "SCH_BUS_BUS_ENTRY" )
1137  {
1138  SCH_LINE busEntryLine( aBusEntry->GetPosition(), LAYER_BUS );
1139 
1140  busEntryLine.SetEndPoint( aBusEntry->m_End() );
1141  saveLine( &busEntryLine, aNestLevel );
1142  }
1143  else
1144  {
1145  m_out->Print( aNestLevel, "(bus_entry (at %s %s) (size %s %s)\n",
1146  FormatInternalUnits( aBusEntry->GetPosition().x ).c_str(),
1147  FormatInternalUnits( aBusEntry->GetPosition().y ).c_str(),
1148  FormatInternalUnits( aBusEntry->GetSize().GetWidth() ).c_str(),
1149  FormatInternalUnits( aBusEntry->GetSize().GetHeight() ).c_str() );
1150 
1151  formatStroke( m_out, aNestLevel + 1, aBusEntry->GetStroke() );
1152 
1153  m_out->Print( 0, "\n" );
1154  m_out->Print( aNestLevel, ")\n" );
1155  }
1156 }
void saveLine(SCH_LINE *aLine, int aNestLevel)
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_bus_entry.h:78
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:98
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
wxPoint m_End() const
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxSize GetSize() const
Definition: sch_bus_entry.h:71
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_item.h:214
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
wxPoint GetPosition() const override

References FormatInternalUnits(), formatStroke(), SCH_ITEM::GetClass(), SCH_BUS_ENTRY_BASE::GetPosition(), SCH_BUS_ENTRY_BASE::GetSize(), SCH_BUS_ENTRY_BASE::GetStroke(), LAYER_BUS, SCH_BUS_ENTRY_BASE::m_End(), SCH_LINE::SetEndPoint(), wxPoint::x, and wxPoint::y.

◆ saveField()

void SCH_SEXPR_PLUGIN::saveField ( SCH_FIELD aField,
int  aNestLevel 
)
private

Definition at line 964 of file sch_sexpr_plugin.cpp.

965 {
966  wxCHECK_RET( aField != nullptr && m_out != nullptr, "" );
967 
968  wxString fieldName = aField->GetName();
969 
970  // For some reason (bug in legacy parser?) the field ID for non-mandatory fields is -1 so
971  // check for this in order to correctly use the field name.
972  if( aField->GetParent()->Type() == SCH_COMPONENT_T )
973  {
974  if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
975  fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId() );
976  }
977  else if( aField->GetParent()->Type() == SCH_SHEET_T )
978  {
979  if( aField->GetId() >= 0 && aField->GetId() < SHEET_MANDATORY_FIELDS )
980  fieldName = SCH_SHEET::GetDefaultFieldName( aField->GetId() );
981  }
982 
983  if( aField->GetId() == -1 /* undefined ID */ )
984  {
985  aField->SetId( m_fieldId );
986  m_fieldId += 1;
987  }
988 
989  m_out->Print( aNestLevel, "(property %s %s (id %d) (at %s %s %s)",
990  m_out->Quotew( fieldName ).c_str(),
991  m_out->Quotew( aField->GetText() ).c_str(),
992  aField->GetId(),
993  FormatInternalUnits( aField->GetPosition().x ).c_str(),
994  FormatInternalUnits( aField->GetPosition().y ).c_str(),
995  FormatAngle( aField->GetTextAngleDegrees() * 10.0 ).c_str() );
996 
997  if( !aField->IsDefaultFormatting()
998  || ( aField->GetTextHeight() != Mils2iu( DEFAULT_SIZE_TEXT ) ) )
999  {
1000  m_out->Print( 0, "\n" );
1001  aField->Format( m_out, aNestLevel, 0 );
1002  m_out->Print( aNestLevel, ")\n" ); // Closes property token with font effects.
1003  }
1004  else
1005  {
1006  m_out->Print( 0, ")\n" ); // Closes property token without font effects.
1007  }
1008 }
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:74
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:70
int m_fieldId
Non-mandatory schematic field ID counter.
wxPoint GetPosition() const override
Definition: sch_field.cpp:597
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
int GetId() const
Definition: sch_field.h:114
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
int GetTextHeight() const
Definition: eda_text.h:245
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
EDA_ITEM * GetParent() const
Definition: base_struct.h:195
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:45
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
bool IsDefaultFormatting() const
Definition: eda_text.cpp:505
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
double GetTextAngleDegrees() const
Definition: eda_text.h:176
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:438
void SetId(int aId)
Definition: sch_field.cpp:76
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 DEFAULT_SIZE_TEXT, EDA_TEXT::Format(), FormatAngle(), FormatInternalUnits(), TEMPLATE_FIELDNAME::GetDefaultFieldName(), SCH_SHEET::GetDefaultFieldName(), SCH_FIELD::GetId(), SCH_FIELD::GetName(), EDA_ITEM::GetParent(), SCH_FIELD::GetPosition(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngleDegrees(), EDA_TEXT::GetTextHeight(), EDA_TEXT::IsDefaultFormatting(), MANDATORY_FIELDS, SCH_COMPONENT_T, SCH_SHEET_T, SCH_FIELD::SetId(), SHEET_MANDATORY_FIELDS, EDA_ITEM::Type(), wxPoint::x, and wxPoint::y.

◆ saveJunction()

void SCH_SEXPR_PLUGIN::saveJunction ( SCH_JUNCTION aJunction,
int  aNestLevel 
)
private

Definition at line 1106 of file sch_sexpr_plugin.cpp.

1107 {
1108  wxCHECK_RET( aJunction != nullptr && m_out != nullptr, "" );
1109 
1110  m_out->Print( aNestLevel, "(junction (at %s %s) (diameter %s) (color %d %d %d %s))\n",
1111  FormatInternalUnits( aJunction->GetPosition().x ).c_str(),
1112  FormatInternalUnits( aJunction->GetPosition().y ).c_str(),
1113  FormatInternalUnits( aJunction->GetDiameter() ).c_str(),
1114  KiROUND( aJunction->GetColor().r * 255.0 ),
1115  KiROUND( aJunction->GetColor().g * 255.0 ),
1116  KiROUND( aJunction->GetColor().b * 255.0 ),
1117  Double2Str( aJunction->GetColor().a ).c_str() );
1118 }
int GetDiameter() const
double g
Green component.
Definition: color4d.h:367
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:62
double b
Blue component.
Definition: color4d.h:368
COLOR4D GetColor() const
double a
Alpha component.
Definition: color4d.h:369
wxPoint GetPosition() const override
Definition: sch_junction.h:97
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
double r
Red component.
Definition: color4d.h:366
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

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, Double2Str(), FormatInternalUnits(), KIGFX::COLOR4D::g, SCH_JUNCTION::GetColor(), SCH_JUNCTION::GetDiameter(), SCH_JUNCTION::GetPosition(), KiROUND(), KIGFX::COLOR4D::r, wxPoint::x, and wxPoint::y.

◆ SaveLibrary()

void SCH_SEXPR_PLUGIN::SaveLibrary ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Reimplemented from SCH_PLUGIN.

Definition at line 2156 of file sch_sexpr_plugin.cpp.

2157 {
2158  if( !m_cache )
2159  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
2160 
2161  wxString oldFileName = m_cache->GetFileName();
2162 
2163  if( !m_cache->IsFile( aLibraryPath ) )
2164  {
2165  m_cache->SetFileName( aLibraryPath );
2166  }
2167 
2168  // This is a forced save.
2169  m_cache->SetModified();
2170  m_cache->Save();
2171  m_cache->SetFileName( oldFileName );
2172 }
void Save()
Save the entire library to file m_libFileName;.
wxString GetFileName() const
SCH_SEXPR_PLUGIN_CACHE * m_cache
void SetFileName(const wxString &aFileName)
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PLUG...
void SetModified(bool aModified=true)
bool IsFile(const wxString &aFullPathAndFileName) const

References SCH_SEXPR_PLUGIN_CACHE::GetFileName(), SCH_SEXPR_PLUGIN_CACHE::IsFile(), m_cache, SCH_SEXPR_PLUGIN_CACHE::Save(), SCH_SEXPR_PLUGIN_CACHE::SetFileName(), and SCH_SEXPR_PLUGIN_CACHE::SetModified().

◆ saveLine()

void SCH_SEXPR_PLUGIN::saveLine ( SCH_LINE aLine,
int  aNestLevel 
)
private

Definition at line 1159 of file sch_sexpr_plugin.cpp.

1160 {
1161  wxCHECK_RET( aLine != nullptr && m_out != nullptr, "" );
1162 
1163  wxString lineType;
1164 
1165  switch( aLine->GetLayer() )
1166  {
1167  case LAYER_BUS: lineType = "bus"; break;
1168  case LAYER_WIRE: lineType = "wire"; break;
1169  case LAYER_NOTES:
1170  default: lineType = "polyline"; break;
1171  }
1172 
1173  m_out->Print( aNestLevel, "(%s (pts (xy %s %s) (xy %s %s))\n",
1174  TO_UTF8( lineType ),
1175  FormatInternalUnits( aLine->GetStartPoint().x ).c_str(),
1176  FormatInternalUnits( aLine->GetStartPoint().y ).c_str(),
1177  FormatInternalUnits( aLine->GetEndPoint().x ).c_str(),
1178  FormatInternalUnits( aLine->GetEndPoint().y ).c_str() );
1179 
1180  formatStroke( m_out, aNestLevel + 1, aLine->GetStroke() );
1181  m_out->Print( 0, "\n" );
1182  m_out->Print( aNestLevel, ")\n" );
1183 }
wxPoint GetStartPoint() const
Definition: sch_line.h:94
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:272
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
#define TO_UTF8(wxstring)
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:128
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
wxPoint GetEndPoint() const
Definition: sch_line.h:97

References FormatInternalUnits(), formatStroke(), SCH_LINE::GetEndPoint(), SCH_ITEM::GetLayer(), SCH_LINE::GetStartPoint(), SCH_LINE::GetStroke(), LAYER_BUS, LAYER_NOTES, LAYER_WIRE, TO_UTF8, wxPoint::x, and wxPoint::y.

◆ saveNoConnect()

void SCH_SEXPR_PLUGIN::saveNoConnect ( SCH_NO_CONNECT aNoConnect,
int  aNestLevel 
)
private

Definition at line 1121 of file sch_sexpr_plugin.cpp.

1122 {
1123  wxCHECK_RET( aNoConnect != nullptr && m_out != nullptr, "" );
1124 
1125  m_out->Print( aNestLevel, "(no_connect (at %s %s))\n",
1126  FormatInternalUnits( aNoConnect->GetPosition().x ).c_str(),
1127  FormatInternalUnits( aNoConnect->GetPosition().y ).c_str() );
1128 }
wxPoint GetPosition() const override
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
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

References FormatInternalUnits(), SCH_NO_CONNECT::GetPosition(), wxPoint::x, and wxPoint::y.

◆ saveSheet()

void SCH_SEXPR_PLUGIN::saveSheet ( SCH_SHEET aSheet,
int  aNestLevel 
)
private

Definition at line 1056 of file sch_sexpr_plugin.cpp.

1057 {
1058  wxCHECK_RET( aSheet != nullptr && m_out != nullptr, "" );
1059 
1060  m_out->Print( aNestLevel, "(sheet (at %s %s) (size %s %s)\n",
1061  FormatInternalUnits( aSheet->GetPosition().x ).c_str(),
1062  FormatInternalUnits( aSheet->GetPosition().y ).c_str(),
1063  FormatInternalUnits( aSheet->GetSize().GetWidth() ).c_str(),
1064  FormatInternalUnits( aSheet->GetSize().GetHeight() ).c_str() );
1065 
1067  aSheet->GetBorderColor() );
1068 
1069  stroke.SetWidth( aSheet->GetBorderWidth() );
1070  formatStroke( m_out, aNestLevel + 1, stroke );
1071 
1072  m_out->Print( 0, "\n" );
1073 
1074  m_out->Print( aNestLevel + 1, "(fill (color %d %d %d %0.4f))\n",
1075  KiROUND( aSheet->GetBackgroundColor().r * 255.0 ),
1076  KiROUND( aSheet->GetBackgroundColor().g * 255.0 ),
1077  KiROUND( aSheet->GetBackgroundColor().b * 255.0 ),
1078  aSheet->GetBackgroundColor().a );
1079 
1080  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSheet->m_Uuid.AsString() ) );
1081 
1083 
1084  for( SCH_FIELD& field : aSheet->GetFields() )
1085  {
1086  saveField( &field, aNestLevel + 1 );
1087  }
1088 
1089  for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
1090  {
1091  m_out->Print( aNestLevel + 1, "(pin %s %s (at %s %s %s)\n",
1092  EscapedUTF8( pin->GetText() ).c_str(),
1093  getSheetPinShapeToken( pin->GetShape() ),
1094  FormatInternalUnits( pin->GetPosition().x ).c_str(),
1095  FormatInternalUnits( pin->GetPosition().y ).c_str(),
1096  FormatAngle( getSheetPinAngle( pin->GetEdge() ) * 10.0 ).c_str() );
1097 
1098  pin->Format( m_out, aNestLevel + 1, 0 );
1099  m_out->Print( aNestLevel + 1, ")\n" ); // Closes pin token with font effects.
1100  }
1101 
1102  m_out->Print( aNestLevel, ")\n" ); // Closes sheet token.
1103 }
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
void SetWidth(int aWidth)
Definition: sch_item.h:170
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:70
int m_fieldId
Non-mandatory schematic field ID counter.
wxString AsString() const
Definition: common.cpp:165
double g
Green component.
Definition: color4d.h:367
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:290
void saveField(SCH_FIELD *aField, int aNestLevel)
double b
Blue component.
Definition: color4d.h:368
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:293
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:277
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:268
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
int GetBorderWidth() const
Definition: sch_sheet.h:287
double a
Alpha component.
Definition: color4d.h:369
static double getSheetPinAngle(SHEET_SIDE aSide)
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
wxPoint GetPosition() const override
Definition: sch_sheet.h:570
const KIID m_Uuid
Definition: base_struct.h:162
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:362
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
Simple container to manage line stroke parameters.
Definition: sch_item.h:153
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
#define TO_UTF8(wxstring)
double r
Red component.
Definition: color4d.h:366
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxSize GetSize()
Definition: sch_sheet.h:284
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:560
static const char * getSheetPinShapeToken(PINSHEETLABEL_SHAPE aShape)

References KIGFX::COLOR4D::a, KIID::AsString(), KIGFX::COLOR4D::b, EscapedUTF8(), FormatAngle(), FormatInternalUnits(), formatStroke(), KIGFX::COLOR4D::g, SCH_SHEET::GetBackgroundColor(), SCH_SHEET::GetBorderColor(), SCH_SHEET::GetBorderWidth(), SCH_SHEET::GetFields(), SCH_SHEET::GetPins(), SCH_SHEET::GetPosition(), getSheetPinAngle(), getSheetPinShapeToken(), SCH_SHEET::GetSize(), KiROUND(), EDA_ITEM::m_Uuid, KIGFX::COLOR4D::r, STROKE_PARAMS::SetWidth(), SHEET_MANDATORY_FIELDS, SOLID, TO_UTF8, wxPoint::x, and wxPoint::y.

◆ SaveSymbol()

void SCH_SEXPR_PLUGIN::SaveSymbol ( const wxString &  aLibraryPath,
const LIB_PART aSymbol,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Write aSymbol to an existing library located at aLibraryPath.

If a LIB_PART by the same name already exists or there are any conflicting alias names, the new LIB_PART will silently overwrite any existing aliases and/or part becaue libraries cannot have duplicate alias names. It is the responsibility of the caller to check the library for conflicts before saving.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aSymbolis what to store in the library. The library is refreshed and the caller must update any LIB_PART pointers that may have changed.
aPropertiesis an associative array that can be used to tell the saver how to save the symbol, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving.

Reimplemented from SCH_PLUGIN.

Definition at line 2080 of file sch_sexpr_plugin.cpp.

2082 {
2083  m_props = aProperties;
2084 
2085  cacheLib( aLibraryPath );
2086 
2087  m_cache->AddSymbol( aSymbol );
2088 
2089  if( !isBuffering( aProperties ) )
2090  m_cache->Save();
2091 }
void Save()
Save the entire library to file m_libFileName;.
SCH_SEXPR_PLUGIN_CACHE * m_cache
void AddSymbol(const LIB_PART *aPart)
void cacheLib(const wxString &aLibraryFileName)
bool isBuffering(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

References SCH_SEXPR_PLUGIN_CACHE::AddSymbol(), cacheLib(), isBuffering(), m_cache, m_props, and SCH_SEXPR_PLUGIN_CACHE::Save().

◆ saveSymbol()

void SCH_SEXPR_PLUGIN::saveSymbol ( SCH_COMPONENT aComponent,
int  aNestLevel 
)
private

Definition at line 876 of file sch_sexpr_plugin.cpp.

877 {
878  wxCHECK_RET( aSymbol != nullptr && m_out != nullptr, "" );
879 
880  std::string libName;
881  wxArrayString reference_fields;
882 
883  static wxString delimiters( wxT( " " ) );
884 
885  wxString part_name = aSymbol->GetLibId().Format();
886 
887  if( part_name.size() )
888  {
889  libName = toUTFTildaText( part_name );
890  }
891  else
892  {
893  libName = "_NONAME_";
894  }
895 
896  double angle;
897  int orientation = aSymbol->GetOrientation() & ~( CMP_MIRROR_X | CMP_MIRROR_Y );
898 
899  if( orientation == CMP_ORIENT_90 )
900  angle = 90.0;
901  else if( orientation == CMP_ORIENT_180 )
902  angle = 180.0;
903  else if( orientation == CMP_ORIENT_270 )
904  angle = 270.0;
905  else
906  angle = 0.0;
907 
908  m_out->Print( aNestLevel, "(symbol" );
909 
910  if( !aSymbol->UseLibIdLookup() )
911  m_out->Print( 0, " (lib_name %s)",
912  m_out->Quotew( aSymbol->GetSchSymbolLibraryName() ).c_str() );
913 
914  m_out->Print( 0, " (lib_id %s) (at %s %s %s)",
915  m_out->Quotew( aSymbol->GetLibId().Format().wx_str() ).c_str(),
916  FormatInternalUnits( aSymbol->GetPosition().x ).c_str(),
917  FormatInternalUnits( aSymbol->GetPosition().y ).c_str(),
918  FormatAngle( angle * 10.0 ).c_str() );
919 
920  bool mirrorX = aSymbol->GetOrientation() & CMP_MIRROR_X;
921  bool mirrorY = aSymbol->GetOrientation() & CMP_MIRROR_Y;
922 
923  if( mirrorX || mirrorY )
924  {
925  m_out->Print( 0, " (mirror" );
926 
927  if( mirrorX )
928  m_out->Print( 0, " x" );
929 
930  if( mirrorY )
931  m_out->Print( 0, " y" );
932 
933  m_out->Print( 0, ")" );
934  }
935 
936  if( !( aSymbol->GetInstanceReferences().size() > 1 ) )
937  m_out->Print( 0, " (unit %d)", aSymbol->GetUnit() );
938 
939  if( aSymbol->GetConvert() == LIB_ITEM::LIB_CONVERT::DEMORGAN )
940  m_out->Print( 0, " (convert %d)", aSymbol->GetConvert() );
941 
942  m_out->Print( 0, "\n" );
943 
944  m_out->Print( aNestLevel + 1, "(in_bom %s)", ( aSymbol->GetIncludeInBom() ) ? "yes" : "no" );
945  m_out->Print( 0, " (on_board %s)", ( aSymbol->GetIncludeOnBoard() ) ? "yes" : "no" );
946 
947  m_out->Print( 0, "\n" );
948 
949  // @todo Convert to full UUID if current UUID is a legacy time stamp.
950  m_out->Print( aNestLevel + 1, "(uuid %s)\n",
951  m_out->Quotew( aSymbol->m_Uuid.AsString() ).c_str() );
952 
954 
955  for( SCH_FIELD& field : aSymbol->GetFields() )
956  {
957  saveField( &field, aNestLevel + 1 );
958  }
959 
960  m_out->Print( aNestLevel, ")\n" );
961 }
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
int m_fieldId
Non-mandatory schematic field ID counter.
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
void saveField(SCH_FIELD *aField, int aNestLevel)
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
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
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

References PNS::angle(), KIID::AsString(), CMP_MIRROR_X, CMP_MIRROR_Y, CMP_ORIENT_180, CMP_ORIENT_270, CMP_ORIENT_90, LIB_ID::Format(), FormatAngle(), FormatInternalUnits(), SCH_COMPONENT::GetConvert(), SCH_COMPONENT::GetFields(), SCH_COMPONENT::GetIncludeInBom(), SCH_COMPONENT::GetIncludeOnBoard(), SCH_COMPONENT::GetInstanceReferences(), SCH_COMPONENT::GetLibId(), SCH_COMPONENT::GetOrientation(), SCH_COMPONENT::GetPosition(), SCH_COMPONENT::GetSchSymbolLibraryName(), SCH_COMPONENT::GetUnit(), EDA_ITEM::m_Uuid, MANDATORY_FIELDS, toUTFTildaText(), SCH_COMPONENT::UseLibIdLookup(), UTF8::wx_str(), wxPoint::x, and wxPoint::y.

◆ saveText()

void SCH_SEXPR_PLUGIN::saveText ( SCH_TEXT aText,
int  aNestLevel 
)
private

Definition at line 1186 of file sch_sexpr_plugin.cpp.

1187 {
1188  wxCHECK_RET( aText != nullptr && m_out != nullptr, "" );
1189 
1190  double angle;
1191 
1192  switch( aText->GetLabelSpinStyle() )
1193  {
1194  case LABEL_SPIN_STYLE::RIGHT: angle = 0.0; break;
1195  case LABEL_SPIN_STYLE::UP: angle = 90.0; break;
1196  case LABEL_SPIN_STYLE::LEFT: angle = 180.0; break;
1197  case LABEL_SPIN_STYLE::BOTTOM: angle = 270.0; break;
1198  default: wxFAIL; angle = 0.0; break;
1199  }
1200 
1201  m_out->Print( aNestLevel, "(%s %s",
1202  getTextTypeToken( aText->Type() ),
1203  m_out->Quotew( aText->GetText() ).c_str() );
1204 
1205  if( ( aText->Type() == SCH_GLOBAL_LABEL_T ) || ( aText->Type() == SCH_HIER_LABEL_T ) )
1206  m_out->Print( 0, " (shape %s)", getSheetPinShapeToken( aText->GetShape() ) );
1207 
1208  if( aText->GetText().Length() < 50 )
1209  {
1210  m_out->Print( 0, " (at %s %s %s)",
1211  FormatInternalUnits( aText->GetPosition().x ).c_str(),
1212  FormatInternalUnits( aText->GetPosition().y ).c_str(),
1213  FormatAngle( angle * 10.0 ).c_str() );
1214  }
1215  else
1216  {
1217  m_out->Print( 0, "\n" );
1218  m_out->Print( aNestLevel + 1, "(at %s %s %s)",
1219  FormatInternalUnits( aText->GetPosition().x ).c_str(),
1220  FormatInternalUnits( aText->GetPosition().y ).c_str(),
1221  FormatAngle( aText->GetTextAngle() ).c_str() );
1222  }
1223 
1224  m_out->Print( 0, "\n" );
1225  aText->Format( m_out, aNestLevel, 0 );
1226  m_out->Print( aNestLevel, ")\n" ); // Closes text token.
1227 }
static const char * getTextTypeToken(KICAD_T aType)
double GetTextAngle() const
Definition: eda_text.h:174
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
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:519
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:232
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
wxPoint GetPosition() const override
Definition: sch_text.h:313
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
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
static const char * getSheetPinShapeToken(PINSHEETLABEL_SHAPE aShape)
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:237
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References PNS::angle(), LABEL_SPIN_STYLE::BOTTOM, EDA_TEXT::Format(), FormatAngle(), FormatInternalUnits(), SCH_TEXT::GetLabelSpinStyle(), SCH_TEXT::GetPosition(), SCH_TEXT::GetShape(), getSheetPinShapeToken(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), getTextTypeToken(), LABEL_SPIN_STYLE::LEFT, LABEL_SPIN_STYLE::RIGHT, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, EDA_ITEM::Type(), LABEL_SPIN_STYLE::UP, wxPoint::x, and wxPoint::y.

◆ SymbolLibOptions()

void SCH_PLUGIN::SymbolLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.

Options are typically appended so that a derived SCH_PLUGIN can call its base class function by the same name first, thus inheriting options declared there. (Some base class options could pertain to all Symbol*() functions in all derived SCH_PLUGINs.) Note that since aListToAppendTo is a PROPERTIES object, all options will be unique and last guy wins.

Parameters
aListToAppendToholds a tuple of
option
This eventually is what shows up into the fp-lib-table "options" field, possibly combined with others.
internationalized description
The internationalized description is displayed in DIALOG_FP_SCH_PLUGIN_OPTIONS. It may be multi-line and be quite explanatory of the option.

In the future perhaps aListToAppendTo evolves to something capable of also holding a wxValidator for the cells in said dialog: http://forums.wxwidgets.org/viewtopic.php?t=23277&p=104180. This would require a 3 column list, and introducing wx GUI knowledge to SCH_PLUGIN, which has been avoided to date.

Definition at line 132 of file sch_plugin.cpp.

133 {
134  // disable all these in another couple of months, after everyone has seen them:
135 #if 1
136  (*aListToAppendTo)["debug_level"] = UTF8( _(
137  "Enable <b>debug</b> logging for Symbol*() functions in this SCH_PLUGIN."
138  ) );
139 
140  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
141  "Regular expression <b>symbol name</b> filter."
142  ) );
143 
144  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
145  "Enable transaction logging. The mere presence of this option turns on the "
146  "logging, no need to set a Value."
147  ) );
148 
149  (*aListToAppendTo)["username"] = UTF8( _(
150  "User name for <b>login</b> to some special library server."
151  ));
152 
153  (*aListToAppendTo)["password"] = UTF8( _(
154  "Password for <b>login</b> to some special library server."
155  ) );
156 #endif
157 
158 #if 1
159  // Suitable for a C++ to python SCH_PLUGIN::Footprint*() adapter, move it to the adapter
160  // if and when implemented.
161  (*aListToAppendTo)["python_symbol_plugin"] = UTF8( _(
162  "Enter the python symbol which implements the SCH_PLUGIN::Symbol*() functions."
163  ) );
164 #endif
165 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
#define _(s)
Definition: 3d_actions.cpp:33

References _.

Member Data Documentation

◆ m_cache

◆ m_currentPath

std::stack<wxString> SCH_SEXPR_PLUGIN::m_currentPath
protected

Stack to maintain nested sheet paths.

Definition at line 155 of file sch_sexpr_plugin.h.

◆ m_error

wxString SCH_SEXPR_PLUGIN::m_error
protected

For throwing exceptions or errors on partial schematic loads.

Definition at line 152 of file sch_sexpr_plugin.h.

Referenced by GetError().

◆ m_fieldId

int SCH_SEXPR_PLUGIN::m_fieldId
protected

Non-mandatory schematic field ID counter.

Definition at line 149 of file sch_sexpr_plugin.h.

◆ m_out

OUTPUTFORMATTER* SCH_SEXPR_PLUGIN::m_out
protected

The output formatter for saving SCH_SCREEN objects.

Definition at line 159 of file sch_sexpr_plugin.h.

◆ m_path

wxString SCH_SEXPR_PLUGIN::m_path
protected

Root project path for loading child sheets.

Definition at line 154 of file sch_sexpr_plugin.h.

◆ m_props

const PROPERTIES* SCH_SEXPR_PLUGIN::m_props
protected

Passed via Save() or Load(), no ownership, may be nullptr.

Definition at line 156 of file sch_sexpr_plugin.h.

Referenced by cacheLib(), CreateSymbolLib(), DeleteSymbol(), EnumerateSymbolLib(), LoadSymbol(), and SaveSymbol().

◆ m_rootSheet

SCH_SHEET* SCH_SEXPR_PLUGIN::m_rootSheet
protected

The root sheet of the schematic being loaded..

Definition at line 157 of file sch_sexpr_plugin.h.

◆ m_schematic

SCHEMATIC* SCH_SEXPR_PLUGIN::m_schematic
protected

Passed to Load(), the schematic object being loaded.

Definition at line 158 of file sch_sexpr_plugin.h.

◆ m_version

int SCH_SEXPR_PLUGIN::m_version
protected

Version of file being loaded.

Definition at line 148 of file sch_sexpr_plugin.h.

◆ PropBuffering

const char * SCH_SEXPR_PLUGIN::PropBuffering = "buffering"
static

The property used internally by the plugin to enable cache buffering which prevents the library file from being written every time the cache is changed.

This is useful when writing the schematic cache library file or saving a library to a new file name.

Definition at line 83 of file sch_sexpr_plugin.h.

Referenced by isBuffering().


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