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
 Return a brief hard coded name for this SCH_PLUGIN. More...
 
const wxString GetFileExtension () const override
 Return the file extension for the SCH_PLUGIN. More...
 
const wxString GetLibraryFileExtension () const override
 Return the library file extension for the SCH_PLUGIN object. More...
 
void SetProgressReporter (PROGRESS_REPORTER *aReporter) override
 Set an optional progress reporter. 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, SCH_SHEET_PATH *aSelectionPath, SCH_SHEET_LIST *aFullSheetHierarchy, OUTPUTFORMATTER *aFormatter)
 
void EnumerateSymbolLib (wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath. More...
 
void EnumerateSymbolLib (std::vector< LIB_SYMBOL * > &aSymbolList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Populate a list of LIB_SYMBOL aliases contained within the library aLibraryPath. More...
 
LIB_SYMBOLLoadSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=nullptr) override
 Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this SCH_PLUGIN knows about. More...
 
void SaveSymbol (const wxString &aLibraryPath, const LIB_SYMBOL *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_SYMBOL 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 SetReporter (REPORTER *aReporter)
 Set an optional reporter for warnings/errors. 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_SYMBOLParseLibSymbol (LINE_READER &aReader, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
 
static void FormatLibSymbol (LIB_SYMBOL *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_nextFreeFieldId
 
wxString m_error
 For throwing exceptions or errors on partial loads. More...
 
PROGRESS_REPORTERm_progressReporter
 
wxString m_path
 Root project path for loading child sheets. More...
 
std::stack< wxString > m_currentPath
 Stack to maintain nested sheet paths. More...
 
SCH_SHEETm_rootSheet
 The root sheet of the schematic being loaded. More...
 
SCHEMATICm_schematic
 
OUTPUTFORMATTERm_out
 The 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_SYMBOL *aSymbol, SCH_SHEET_PATH *aSheetPath, 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 saveInstances (const std::vector< SCH_SHEET_INSTANCE > &aSheets, const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbols, int aNestLevel)
 
void cacheLib (const wxString &aLibraryFileName, const PROPERTIES *aProperties)
 
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 60 of file sch_sexpr_plugin.h.

Constructor & Destructor Documentation

◆ SCH_SEXPR_PLUGIN()

SCH_SEXPR_PLUGIN::SCH_SEXPR_PLUGIN ( )

Definition at line 498 of file sch_sexpr_plugin.cpp.

498  :
499  m_progressReporter( nullptr )
500 {
501  init( nullptr );
502 }
PROGRESS_REPORTER * m_progressReporter
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.

References init().

◆ ~SCH_SEXPR_PLUGIN()

SCH_SEXPR_PLUGIN::~SCH_SEXPR_PLUGIN ( )
virtual

Definition at line 505 of file sch_sexpr_plugin.cpp.

506 {
507  delete m_cache;
508 }
SCH_SEXPR_PLUGIN_CACHE * m_cache

References m_cache.

Member Function Documentation

◆ cacheLib()

void SCH_SEXPR_PLUGIN::cacheLib ( const wxString &  aLibraryFileName,
const PROPERTIES aProperties 
)
private

Definition at line 2161 of file sch_sexpr_plugin.cpp.

2162 {
2163  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
2164  {
2165  // a spectacular episode in memory management:
2166  delete m_cache;
2167  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryFileName );
2168 
2169  // Because m_cache is rebuilt, increment SYMBOL_LIBS::s_modify_generation
2170  // to modify the hash value that indicate symbol to symbol links
2171  // must be updated.
2173 
2174  if( !isBuffering( aProperties ) )
2175  m_cache->Load();
2176  }
2177 }
SCH_SEXPR_PLUGIN_CACHE * m_cache
A cache assistant for the symbol library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PL...
bool IsFile(const wxString &aFullPathAndFileName) const
static void IncrementModifyGeneration()
bool isBuffering(const PROPERTIES *aProperties)

References SYMBOL_LIBS::IncrementModifyGeneration(), isBuffering(), SCH_SEXPR_PLUGIN_CACHE::IsFile(), SCH_SEXPR_PLUGIN_CACHE::IsFileChanged(), SCH_SEXPR_PLUGIN_CACHE::Load(), and m_cache.

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 2346 of file sch_sexpr_plugin.cpp.

2347 {
2348  // Open file and check first line
2349  wxTextFile tempFile;
2350 
2351  tempFile.Open( aFileName );
2352  wxString firstline;
2353  // read the first line
2354  firstline = tempFile.GetFirstLine();
2355  tempFile.Close();
2356 
2357  return firstline.StartsWith( "EESchema" );
2358 }

◆ 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 2282 of file sch_sexpr_plugin.cpp.

2284 {
2285  if( wxFileExists( aLibraryPath ) )
2286  {
2287  THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' already exists." ),
2288  aLibraryPath.GetData() ) );
2289  }
2290 
2291  LOCALE_IO toggle;
2292 
2293  delete m_cache;
2294  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
2295  m_cache->SetModified();
2296  m_cache->Save();
2297  m_cache->Load(); // update m_writable and m_mod_time
2298 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void Save()
Save the entire library to file m_libFileName;.
SCH_SEXPR_PLUGIN_CACHE * m_cache
A cache assistant for the symbol library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PL...
void SetModified(bool aModified=true)
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), SCH_SEXPR_PLUGIN_CACHE::Load(), m_cache, 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_SYMBOL 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_SYMBOL associated with it's root LIB_SYMBOL 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 2268 of file sch_sexpr_plugin.cpp.

2270 {
2271  LOCALE_IO toggle; // toggles on, then off, the C locale.
2272 
2273  cacheLib( aLibraryPath, aProperties );
2274 
2275  m_cache->DeleteSymbol( aSymbolName );
2276 
2277  if( !isBuffering( aProperties ) )
2278  m_cache->Save();
2279 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
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, const PROPERTIES *aProperties)
bool isBuffering(const PROPERTIES *aProperties)

References cacheLib(), SCH_SEXPR_PLUGIN_CACHE::DeleteSymbol(), isBuffering(), m_cache, 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 2301 of file sch_sexpr_plugin.cpp.

2303 {
2304  wxFileName fn = aLibraryPath;
2305 
2306  if( !fn.FileExists() )
2307  return false;
2308 
2309  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2310  // we don't want that. we want bare metal portability with no UI here.
2311  if( wxRemove( aLibraryPath ) )
2312  {
2313  THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' cannot be deleted." ),
2314  aLibraryPath.GetData() ) );
2315  }
2316 
2317  if( m_cache && m_cache->IsFile( aLibraryPath ) )
2318  {
2319  delete m_cache;
2320  m_cache = nullptr;
2321  }
2322 
2323  return true;
2324 }
SCH_SEXPR_PLUGIN_CACHE * m_cache
bool IsFile(const wxString &aFullPathAndFileName) const
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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_SYMBOL alias names contained within the library aLibraryPath.

Parameters
aSymbolNameListis an array to populate with the LIB_SYMBOL names associated with the library.
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing one or more LIB_SYMBOL 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 2196 of file sch_sexpr_plugin.cpp.

2199 {
2200  LOCALE_IO toggle; // toggles on, then off, the C locale.
2201 
2202  bool powerSymbolsOnly = ( aProperties &&
2203  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2204 
2205  cacheLib( aLibraryPath, aProperties );
2206 
2207  const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
2208 
2209  for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2210  {
2211  if( !powerSymbolsOnly || it->second->IsPower() )
2212  aSymbolNameList.Add( it->first );
2213  }
2214 }
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
Symbol map used by symbol library object.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
SCH_SEXPR_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)
static const char * PropPowerSymsOnly

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

◆ EnumerateSymbolLib() [2/2]

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

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

Note
It is the responsibility 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_SYMBOL pointers associated with the library.
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing one or more LIB_SYMBOL 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 2217 of file sch_sexpr_plugin.cpp.

2220 {
2221  LOCALE_IO toggle; // toggles on, then off, the C locale.
2222 
2223  bool powerSymbolsOnly = ( aProperties &&
2224  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2225 
2226  cacheLib( aLibraryPath, aProperties );
2227 
2228  const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
2229 
2230  for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2231  {
2232  if( !powerSymbolsOnly || it->second->IsPower() )
2233  aSymbolList.push_back( it->second );
2234  }
2235 }
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
Symbol map used by symbol library object.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
SCH_SEXPR_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)
static const char * PropPowerSymsOnly

References cacheLib(), m_cache, 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 742 of file sch_sexpr_plugin.cpp.

743 {
744  wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." );
745  wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." );
746 
747  SCH_SCREEN* screen = aSheet->GetScreen();
748 
749  wxCHECK( screen, /* void */ );
750 
751  m_out->Print( 0, "(kicad_sch (version %d) (generator eeschema)\n\n",
753 
754  m_out->Print( 1, "(uuid %s)\n\n", TO_UTF8( screen->m_uuid.AsString() ) );
755 
756  screen->GetPageSettings().Format( m_out, 1, 0 );
757  m_out->Print( 0, "\n" );
758  screen->GetTitleBlock().Format( m_out, 1, 0 );
759 
760  // Save cache library.
761  m_out->Print( 1, "(lib_symbols\n" );
762 
763  for( auto libSymbol : screen->GetLibSymbols() )
764  SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( libSymbol.second, *m_out, 2, libSymbol.first );
765 
766  m_out->Print( 1, ")\n\n" );
767 
768  for( const auto& alias : screen->GetBusAliases() )
769  {
770  saveBusAlias( alias, 1 );
771  }
772 
773  // Enforce item ordering
774  auto cmp =
775  []( const SCH_ITEM* a, const SCH_ITEM* b )
776  {
777  if( a->Type() != b->Type() )
778  return a->Type() < b->Type();
779 
780  return a->m_Uuid < b->m_Uuid;
781  };
782 
783  std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
784 
785  for( SCH_ITEM* item : screen->Items() )
786  save_map.insert( item );
787 
788  KICAD_T itemType = TYPE_NOT_INIT;
790 
791  for( SCH_ITEM* item : save_map )
792  {
793  if( itemType != item->Type() )
794  {
795  itemType = item->Type();
796 
797  if( itemType != SCH_SYMBOL_T
798  && itemType != SCH_JUNCTION_T
799  && itemType != SCH_SHEET_T )
800  {
801  m_out->Print( 0, "\n" );
802  }
803  }
804 
805  switch( item->Type() )
806  {
807  case SCH_SYMBOL_T:
808  m_out->Print( 0, "\n" );
809  saveSymbol( static_cast<SCH_SYMBOL*>( item ), nullptr, 1 );
810  break;
811 
812  case SCH_BITMAP_T:
813  saveBitmap( static_cast<SCH_BITMAP*>( item ), 1 );
814  break;
815 
816  case SCH_SHEET_T:
817  m_out->Print( 0, "\n" );
818  saveSheet( static_cast<SCH_SHEET*>( item ), 1 );
819  break;
820 
821  case SCH_JUNCTION_T:
822  saveJunction( static_cast<SCH_JUNCTION*>( item ), 1 );
823  break;
824 
825  case SCH_NO_CONNECT_T:
826  saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ), 1 );
827  break;
828 
830  case SCH_BUS_BUS_ENTRY_T:
831  saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ), 1 );
832  break;
833 
834  case SCH_LINE_T:
835  if( layer != item->GetLayer() )
836  {
837  if( layer == SCH_LAYER_ID_START )
838  {
839  layer = item->GetLayer();
840  }
841  else
842  {
843  layer = item->GetLayer();
844  m_out->Print( 0, "\n" );
845  }
846  }
847 
848  saveLine( static_cast<SCH_LINE*>( item ), 1 );
849  break;
850 
851  case SCH_TEXT_T:
852  case SCH_LABEL_T:
853  case SCH_GLOBAL_LABEL_T:
854  case SCH_HIER_LABEL_T:
855  saveText( static_cast<SCH_TEXT*>( item ), 1 );
856  break;
857 
858  default:
859  wxASSERT( "Unexpected schematic object type in SCH_SEXPR_PLUGIN::Format()" );
860  }
861  }
862 
863  // If this is the root sheet, save all of the sheet paths.
864  if( aSheet->IsRootSheet() )
865  {
866  SCH_SHEET_LIST sheetPaths( aSheet, true );
867 
868  SCH_REFERENCE_LIST symbolInstances;
869 
870  for( const SCH_SHEET_PATH& sheetPath : sheetPaths )
871  sheetPath.GetSymbols( symbolInstances, true, true );
872 
873  symbolInstances.SortByReferenceOnly();
874 
875  saveInstances( sheetPaths.GetSheetInstances(), symbolInstances.GetSymbolInstances(), 1 );
876  }
877  else
878  {
879  // Schematic files (SCH_SCREEN objects) can be shared so we have to save and restore
880  // symbol and sheet instance data even if the file being saved is not the root sheet
881  // because it is possible that the file is the root sheet of another project.
882  saveInstances( screen->m_sheetInstances, screen->m_symbolInstances, 1 );
883  }
884 
885  m_out->Print( 0, ")\n" );
886 }
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCHEMATIC * m_schematic
void saveLine(SCH_LINE *aLine, int aNestLevel)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect, int aNestLevel)
std::vector< SYMBOL_INSTANCE_REFERENCE > m_symbolInstances
The list of symbol instances loaded from the schematic file.
Definition: sch_screen.h:571
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
std::vector< SYMBOL_INSTANCE_REFERENCE > GetSymbolInstances() const
void saveText(SCH_TEXT *aText, int aNestLevel)
void saveInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheets, const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbols, int aNestLevel)
wxString AsString() const
Definition: kiid.cpp:236
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:156
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the page class to aFormatter in s-expression form.
Definition: page_info.cpp:271
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:102
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:132
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:335
std::vector< SCH_SHEET_INSTANCE > m_sheetInstances
Definition: sch_screen.h:572
bool IsRootSheet() const
Definition: sch_sheet.cpp:207
std::map< wxString, LIB_SYMBOL * > & GetLibSymbols()
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition: sch_screen.h:451
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: title_block.cpp:29
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
const KIID m_Uuid
Definition: eda_item.h:474
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
std::unordered_set< std::shared_ptr< BUS_ALIAS > > GetBusAliases() const
Return a list of bus aliases defined in this screen.
Definition: sch_screen.h:481
void SortByReferenceOnly()
Sort the list of references by reference.
KIID m_uuid
A unique identifier for each schematic file.
Definition: sch_screen.h:580
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
void saveSheet(SCH_SHEET *aSheet, int aNestLevel)
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
void saveSymbol(SCH_SYMBOL *aSymbol, SCH_SHEET_PATH *aSheetPath, int aNestLevel)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
void saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References KIID::AsString(), TITLE_BLOCK::Format(), PAGE_INFO::Format(), SCH_SCREEN::GetBusAliases(), SCH_SCREEN::GetLibSymbols(), SCH_SCREEN::GetPageSettings(), SCH_SHEET::GetScreen(), SCH_REFERENCE_LIST::GetSymbolInstances(), SCH_SCREEN::GetTitleBlock(), SCH_SHEET::IsRootSheet(), SCH_SCREEN::Items(), m_out, m_schematic, SCH_SCREEN::m_sheetInstances, SCH_SCREEN::m_symbolInstances, EDA_ITEM::m_Uuid, SCH_SCREEN::m_uuid, OUTPUTFORMATTER::Print(), saveBitmap(), saveBusAlias(), saveBusEntry(), saveInstances(), saveJunction(), saveLine(), saveNoConnect(), saveSheet(), saveSymbol(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), saveText(), SCH_BITMAP_T, SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_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_SYMBOL_T, SCH_TEXT_T, SEXPR_SCHEMATIC_FILE_VERSION, SCH_REFERENCE_LIST::SortByReferenceOnly(), TO_UTF8, EDA_ITEM::Type(), and TYPE_NOT_INIT.

Referenced by SCH_EDITOR_CONTROL::doCopy(), and Save().

◆ Format() [2/2]

void SCH_SEXPR_PLUGIN::Format ( EE_SELECTION aSelection,
SCH_SHEET_PATH aSelectionPath,
SCH_SHEET_LIST aFullSheetHierarchy,
OUTPUTFORMATTER aFormatter 
)

Definition at line 889 of file sch_sexpr_plugin.cpp.

892 {
893  wxCHECK( aSelection && aSelectionPath && aFullSheetHierarchy && aFormatter, /* void */ );
894 
895  LOCALE_IO toggle;
896 
897  m_out = aFormatter;
898 
899  size_t i;
900  SCH_ITEM* item;
901  std::map<wxString, LIB_SYMBOL*> libSymbols;
902  SCH_SCREEN* screen = aSelection->GetScreen();
903 
904  for( i = 0; i < aSelection->GetSize(); ++i )
905  {
906  item = dynamic_cast<SCH_ITEM*>( aSelection->GetItem( i ) );
907 
908  wxCHECK2( item, continue );
909 
910  if( item->Type() != SCH_SYMBOL_T )
911  continue;
912 
913  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
914 
915  wxCHECK2( symbol, continue );
916 
917  wxString libSymbolLookup = symbol->GetLibId().Format().wx_str();
918 
919  if( !symbol->UseLibIdLookup() )
920  libSymbolLookup = symbol->GetSchSymbolLibraryName();
921 
922  auto it = screen->GetLibSymbols().find( libSymbolLookup );
923 
924  if( it != screen->GetLibSymbols().end() )
925  libSymbols[ libSymbolLookup ] = it->second;
926  }
927 
928  if( !libSymbols.empty() )
929  {
930  m_out->Print( 0, "(lib_symbols\n" );
931 
932  for( auto libSymbol : libSymbols )
933  SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( libSymbol.second, *m_out, 1, libSymbol.first );
934 
935  m_out->Print( 0, ")\n\n" );
936  }
937 
938  // Store the selected sheets instance information
939  SCH_SHEET_LIST selectedSheets;
940  selectedSheets.push_back( *aSelectionPath ); // Include the "root" of the selection
941 
942  SCH_REFERENCE_LIST selectedSymbols;
943 
944  for( i = 0; i < aSelection->GetSize(); ++i )
945  {
946  item = (SCH_ITEM*) aSelection->GetItem( i );
947 
948  switch( item->Type() )
949  {
950  case SCH_SYMBOL_T:
951  saveSymbol( static_cast<SCH_SYMBOL*>( item ), aSelectionPath, 0 );
952 
953  aSelectionPath->AppendSymbol( selectedSymbols, static_cast<SCH_SYMBOL*>( item ),
954  true, true );
955  break;
956 
957  case SCH_BITMAP_T:
958  saveBitmap( static_cast< SCH_BITMAP* >( item ), 0 );
959  break;
960 
961  case SCH_SHEET_T:
962  saveSheet( static_cast< SCH_SHEET* >( item ), 0 );
963 
964  {
965  SCH_SHEET_PATH subSheetPath = *aSelectionPath;
966  subSheetPath.push_back( static_cast<SCH_SHEET*>( item ) );
967 
968  aFullSheetHierarchy->GetSheetsWithinPath( selectedSheets, subSheetPath );
969  aFullSheetHierarchy->GetSymbolsWithinPath( selectedSymbols, subSheetPath, true,
970  true );
971  }
972 
973  break;
974 
975  case SCH_JUNCTION_T:
976  saveJunction( static_cast< SCH_JUNCTION* >( item ), 0 );
977  break;
978 
979  case SCH_NO_CONNECT_T:
980  saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ), 0 );
981  break;
982 
984  case SCH_BUS_BUS_ENTRY_T:
985  saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ), 0 );
986  break;
987 
988  case SCH_LINE_T:
989  saveLine( static_cast< SCH_LINE* >( item ), 0 );
990  break;
991 
992  case SCH_TEXT_T:
993  case SCH_LABEL_T:
994  case SCH_GLOBAL_LABEL_T:
995  case SCH_HIER_LABEL_T:
996  saveText( static_cast< SCH_TEXT* >( item ), 0 );
997  break;
998 
999  default:
1000  wxASSERT( "Unexpected schematic object type in SCH_SEXPR_PLUGIN::Format()" );
1001  }
1002  }
1003 
1004  // Make all instance information relative to the selection path
1005  KIID_PATH selectionPath = aSelectionPath->PathWithoutRootUuid();
1006 
1007  selectedSheets.SortByPageNumbers();
1008  std::vector<SCH_SHEET_INSTANCE> sheetinstances = selectedSheets.GetSheetInstances();
1009 
1010  for( SCH_SHEET_INSTANCE& sheetInstance : sheetinstances )
1011  {
1012  wxASSERT_MSG( sheetInstance.m_Path.MakeRelativeTo( selectionPath ),
1013  "Sheet is not inside the selection path?" );
1014  }
1015 
1016 
1017  selectedSymbols.SortByReferenceOnly();
1018  std::vector<SYMBOL_INSTANCE_REFERENCE> symbolInstances = selectedSymbols.GetSymbolInstances();
1019 
1020  for( SYMBOL_INSTANCE_REFERENCE& symbolInstance : symbolInstances )
1021  {
1022  wxASSERT_MSG( symbolInstance.m_Path.MakeRelativeTo( selectionPath ),
1023  "Symbol is not inside the selection path?" );
1024  }
1025 
1026  saveInstances( sheetinstances, symbolInstances, 0 );
1027 }
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
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: locale_io.h:40
SCH_SCREEN * GetScreen()
Definition: ee_selection.h:51
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
std::vector< SYMBOL_INSTANCE_REFERENCE > GetSymbolInstances() const
void saveText(SCH_TEXT *aText, int aNestLevel)
void saveInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheets, const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbols, int aNestLevel)
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:271
A simple container for schematic symbol instance information.
std::vector< SCH_SHEET_INSTANCE > GetSheetInstances() const
Fetch the instance information for all of the sheets in the hiearchy.
std::map< wxString, LIB_SYMBOL * > & GetLibSymbols()
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition: sch_screen.h:451
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void AppendSymbol(SCH_REFERENCE_LIST &aReferences, SCH_SYMBOL *aSymbol, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Append a SCH_REFERENCE object to aReferences based on aSymbol.
KIID_PATH PathWithoutRootUuid() const
Get the sheet path as an KIID_PATH without the root sheet UUID prefix.
UTF8 Format() const
Definition: lib_id.cpp:116
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:88
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
A simple container for sheet instance information.
Schematic symbol object.
Definition: sch_symbol.h:78
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:53
void SortByReferenceOnly()
Sort the list of references by reference.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
wxString wx_str() const
Definition: utf8.cpp:46
void saveSheet(SCH_SHEET *aSheet, int aNestLevel)
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
void saveSymbol(SCH_SYMBOL *aSymbol, SCH_SHEET_PATH *aSheetPath, int aNestLevel)
void GetSymbolsWithinPath(SCH_REFERENCE_LIST &aReferences, const SCH_SHEET_PATH &aSheetPath, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets that are contained wi...
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
void saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)
bool UseLibIdLookup() const
Definition: sch_symbol.h:163
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:148
void GetSheetsWithinPath(SCH_SHEET_PATHS &aSheets, const SCH_SHEET_PATH &aSheetPath) const
Add a SCH_SHEET_PATH object to aSheets for each sheet in the list that are contained within aSheetPat...

References SCH_SHEET_PATH::AppendSymbol(), LIB_ID::Format(), SELECTION::GetItem(), SCH_SYMBOL::GetLibId(), SCH_SCREEN::GetLibSymbols(), SCH_SYMBOL::GetSchSymbolLibraryName(), EE_SELECTION::GetScreen(), SCH_SHEET_LIST::GetSheetInstances(), SCH_SHEET_LIST::GetSheetsWithinPath(), SELECTION::GetSize(), SCH_REFERENCE_LIST::GetSymbolInstances(), SCH_SHEET_LIST::GetSymbolsWithinPath(), m_out, SCH_SHEET_PATH::PathWithoutRootUuid(), OUTPUTFORMATTER::Print(), SCH_SHEET_PATH::push_back(), saveBitmap(), saveBusEntry(), saveInstances(), saveJunction(), saveLine(), saveNoConnect(), saveSheet(), saveSymbol(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), saveText(), SCH_BITMAP_T, SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_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_SYMBOL_T, SCH_TEXT_T, SCH_SHEET_LIST::SortByPageNumbers(), SCH_REFERENCE_LIST::SortByReferenceOnly(), EDA_ITEM::Type(), SCH_SYMBOL::UseLibIdLookup(), and UTF8::wx_str().

◆ FormatLibSymbol()

void SCH_SEXPR_PLUGIN::FormatLibSymbol ( LIB_SYMBOL aPart,
OUTPUTFORMATTER aFormatter 
)
static

Definition at line 2382 of file sch_sexpr_plugin.cpp.

2383 {
2384 
2385  LOCALE_IO toggle; // toggles on, then off, the C locale.
2386  SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( symbol, formatter );
2387 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)

References SCH_SEXPR_PLUGIN_CACHE::SaveSymbol().

Referenced by SYMBOL_EDITOR_EDIT_TOOL::Copy(), and SYMBOL_EDIT_FRAME::CopySymbolToClipboard().

◆ 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 133 of file sch_sexpr_plugin.h.

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

References m_error.

◆ GetFileExtension()

const wxString SCH_SEXPR_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Return the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 72 of file sch_sexpr_plugin.h.

73  {
74  return wxT( "kicad_sch" );
75  }

◆ 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 77 of file sch_sexpr_plugin.h.

78  {
79  return wxT( "kicad_sym" );
80  }

◆ 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 2186 of file sch_sexpr_plugin.cpp.

2187 {
2188  if( m_cache )
2189  return m_cache->GetModifyHash();
2190 
2191  // If the cache hasn't been loaded, it hasn't been modified.
2192  return 0;
2193 }
SCH_SEXPR_PLUGIN_CACHE * m_cache

References SCH_SEXPR_PLUGIN_CACHE::GetModifyHash(), and m_cache.

◆ GetName()

const wxString SCH_SEXPR_PLUGIN::GetName ( ) const
inlineoverridevirtual

Return a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 67 of file sch_sexpr_plugin.h.

68  {
69  return wxT( "Eeschema s-expression" );
70  }

◆ init()

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

initialize PLUGIN like a constructor would.

Definition at line 511 of file sch_sexpr_plugin.cpp.

512 {
513  m_version = 0;
514  m_rootSheet = nullptr;
515  m_schematic = aSchematic;
516  m_cache = nullptr;
517  m_out = nullptr;
518  m_nextFreeFieldId = 100; // number arbitrarily > MANDATORY_FIELDS or SHEET_MANDATORY_FIELDS
519 }
SCHEMATIC * m_schematic
int m_version
Version of file being loaded.
SCH_SEXPR_PLUGIN_CACHE * m_cache
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.

References m_cache, m_nextFreeFieldId, m_out, m_rootSheet, m_schematic, and m_version.

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

◆ isBuffering()

bool SCH_SEXPR_PLUGIN::isBuffering ( const PROPERTIES aProperties)
private

Definition at line 2180 of file sch_sexpr_plugin.cpp.

2181 {
2182  return ( aProperties && aProperties->Exists( SCH_SEXPR_PLUGIN::PropBuffering ) );
2183 }
bool Exists(const std::string &aProperty) const
Definition: properties.h:41
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 2361 of file sch_sexpr_plugin.cpp.

2362 {
2363  wxFileName fn( aLibraryPath );
2364 
2365  return ( fn.FileExists() && fn.IsFileWritable() ) || fn.IsDirWritable();
2366 }

◆ 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 symbol 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 522 of file sch_sexpr_plugin.cpp.

524 {
525  wxASSERT( !aFileName || aSchematic != nullptr );
526 
527  LOCALE_IO toggle; // toggles on, then off, the C locale.
528  SCH_SHEET* sheet;
529 
530  wxFileName fn = aFileName;
531 
532  // Unfortunately child sheet file names the legacy schematic file format are not fully
533  // qualified and are always appended to the project path. The aFileName attribute must
534  // always be an absolute path so the project path can be used for load child sheet files.
535  wxASSERT( fn.IsAbsolute() );
536 
537  if( aAppendToMe )
538  {
539  wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
540  aFileName, aAppendToMe->GetFileName() );
541 
542  wxFileName normedFn = aAppendToMe->GetFileName();
543 
544  if( !normedFn.IsAbsolute() )
545  {
546  if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
547  m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
548  }
549 
550  if( m_path.IsEmpty() )
551  m_path = aSchematic->Prj().GetProjectPath();
552 
553  wxLogTrace( traceSchLegacyPlugin, "Normalized append path \"%s\".", m_path );
554  }
555  else
556  {
557  m_path = aSchematic->Prj().GetProjectPath();
558  }
559 
560  m_currentPath.push( m_path );
561  init( aSchematic, aProperties );
562 
563  if( aAppendToMe == nullptr )
564  {
565  // Clean up any allocated memory if an exception occurs loading the schematic.
566  std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
567 
568  wxFileName relPath( aFileName );
569  // Do not use wxPATH_UNIX as option in MakeRelativeTo(). It can create incorrect
570  // relative paths on Windows, because paths have a disk identifier (C:, D: ...)
571  relPath.MakeRelativeTo( aSchematic->Prj().GetProjectPath() );
572 
573  newSheet->SetFileName( relPath.GetFullPath() );
574  m_rootSheet = newSheet.get();
575  loadHierarchy( newSheet.get() );
576 
577  // If we got here, the schematic loaded successfully.
578  sheet = newSheet.release();
579  m_rootSheet = nullptr; // Quiet Coverity warning.
580  }
581  else
582  {
583  wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
584  m_rootSheet = &aSchematic->Root();
585  sheet = aAppendToMe;
586  loadHierarchy( sheet );
587  }
588 
589  wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
590 
591  m_currentPath.pop(); // Clear the path stack for next call to Load
592 
593  return sheet;
594 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
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:108
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:122
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:314
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
SCH_SHEET & Root() const
Definition: schematic.h:92
wxString m_path
Root project path for loading child sheets.
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(), init(), SCHEMATIC::IsValid(), loadHierarchy(), m_currentPath, m_path, m_rootSheet, 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 705 of file sch_sexpr_plugin.cpp.

706 {
707  wxCHECK( aSheet, /* void */ );
708 
709  LOCALE_IO toggle;
710  SCH_SEXPR_PARSER parser( &aReader );
711 
712  parser.ParseSchematic( aSheet, true, aFileVersion );
713 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
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 680 of file sch_sexpr_plugin.cpp.

681 {
682  FILE_LINE_READER reader( aFileName );
683 
684  size_t lineCount = 0;
685 
686  if( m_progressReporter )
687  {
688  m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
689 
691  THROW_IO_ERROR( ( "Open cancelled by user." ) );
692 
693  while( reader.ReadLine() )
694  lineCount++;
695 
696  reader.Rewind();
697  }
698 
699  SCH_SEXPR_PARSER parser( &reader, m_progressReporter, lineCount );
700 
701  parser.ParseSchematic( aSheet );
702 }
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
A LINE_READER that reads from an open file.
Definition: richio.h:172
#define _(s)
Object to parser s-expression symbol library and schematic file formats.
PROGRESS_REPORTER * m_progressReporter
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), PROGRESS_REPORTER::KeepRefreshing(), m_progressReporter, SCH_SEXPR_PARSER::ParseSchematic(), FILE_LINE_READER::ReadLine(), PROGRESS_REPORTER::Report(), FILE_LINE_READER::Rewind(), and THROW_IO_ERROR.

Referenced by loadHierarchy().

◆ loadHierarchy()

void SCH_SEXPR_PLUGIN::loadHierarchy ( SCH_SHEET aSheet)
private

Definition at line 599 of file sch_sexpr_plugin.cpp.

600 {
601  SCH_SCREEN* screen = nullptr;
602 
603  if( !aSheet->GetScreen() )
604  {
605  // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
606  // stores the file name and extension. Add the project path to the file name and
607  // extension to compare when calling SCH_SHEET::SearchHierarchy().
608  wxFileName fileName = aSheet->GetFileName();
609 
610  if( !fileName.IsAbsolute() )
611  fileName.MakeAbsolute( m_currentPath.top() );
612 
613  // Save the current path so that it gets restored when descending and ascending the
614  // sheet hierarchy which allows for sheet schematic files to be nested in folders
615  // relative to the last path a schematic was loaded from.
616  wxLogTrace( traceSchLegacyPlugin, "Saving path '%s'", m_currentPath.top() );
617  m_currentPath.push( fileName.GetPath() );
618  wxLogTrace( traceSchLegacyPlugin, "Current path '%s'", m_currentPath.top() );
619  wxLogTrace( traceSchLegacyPlugin, "Loading '%s'", fileName.GetFullPath() );
620 
621  m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
622 
623  if( screen )
624  {
625  aSheet->SetScreen( screen );
626  aSheet->GetScreen()->SetParent( m_schematic );
627  // Do not need to load the sub-sheets - this has already been done.
628  }
629  else
630  {
631  aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
632  aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
633 
634  try
635  {
636  loadFile( fileName.GetFullPath(), aSheet );
637  }
638  catch( const IO_ERROR& ioe )
639  {
640  // If there is a problem loading the root sheet, there is no recovery.
641  if( aSheet == m_rootSheet )
642  throw;
643 
644  // For all subsheets, queue up the error message for the caller.
645  if( !m_error.IsEmpty() )
646  m_error += "\n";
647 
648  m_error += ioe.What();
649  }
650 
651  if( fileName.FileExists() )
652  {
653  aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() );
654  aSheet->GetScreen()->SetFileExists( true );
655  }
656  else
657  {
658  aSheet->GetScreen()->SetFileReadOnly( !fileName.IsDirWritable() );
659  aSheet->GetScreen()->SetFileExists( false );
660  }
661 
662  // This was moved out of the try{} block so that any sheets definitionsthat
663  // the plugin fully parsed before the exception was raised will be loaded.
664  for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
665  {
666  wxCHECK2( aItem->Type() == SCH_SHEET_T, /* do nothing */ );
667  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
668 
669  // Recursion starts here.
670  loadHierarchy( sheet );
671  }
672  }
673 
674  m_currentPath.pop();
675  wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
676  }
677 }
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:230
SCHEMATIC * m_schematic
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:693
wxString m_error
For throwing exceptions or errors on partial 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:175
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
void SetFileExists(bool aFileExists)
Definition: sch_screen.h:150
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:102
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:115
void SetFileReadOnly(bool aIsReadOnly)
Definition: sch_screen.h:147
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:314
void loadFile(const wxString &aFileName, SCH_SHEET *aSheet)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
void loadHierarchy(SCH_SHEET *aSheet)
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:110
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182

References SCH_SHEET::GetFileName(), SCH_SHEET::GetScreen(), SCH_SCREEN::Items(), loadFile(), m_currentPath, m_error, m_rootSheet, m_schematic, EE_RTREE::OfType(), SCH_SHEET_T, SCH_SHEET::SearchHierarchy(), SCH_SCREEN::SetFileExists(), SCH_SCREEN::SetFileName(), SCH_SCREEN::SetFileReadOnly(), EDA_ITEM::SetParent(), SCH_SHEET::SetScreen(), traceSchLegacyPlugin, and IO_ERROR::What().

Referenced by Load().

◆ LoadSymbol()

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

Load a LIB_SYMBOL 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_SYMBOL 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 2238 of file sch_sexpr_plugin.cpp.

2240 {
2241  LOCALE_IO toggle; // toggles on, then off, the C locale.
2242 
2243  cacheLib( aLibraryPath, aProperties );
2244 
2245  LIB_SYMBOL_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
2246 
2247  if( it == m_cache->m_symbols.end() )
2248  return nullptr;
2249 
2250  return it->second;
2251 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
SCH_SEXPR_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)

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

◆ ParseLibSymbol()

LIB_SYMBOL * SCH_SEXPR_PLUGIN::ParseLibSymbol ( LINE_READER aReader,
int  aVersion = SEXPR_SCHEMATIC_FILE_VERSION 
)
static

Definition at line 2369 of file sch_sexpr_plugin.cpp.

2370 {
2371  LOCALE_IO toggle; // toggles on, then off, the C locale.
2372  LIB_SYMBOL_MAP map;
2373  SCH_SEXPR_PARSER parser( &aReader );
2374 
2375  parser.NeedLEFT();
2376  parser.NextTok();
2377 
2378  return parser.ParseSymbol( map, aFileVersion );
2379 }
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
Symbol map used by symbol library object.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
Object to parser s-expression symbol library and schematic file formats.

References SCH_SEXPR_PARSER::ParseSymbol().

Referenced by SYMBOL_EDIT_FRAME::DuplicateSymbol(), and SYMBOL_EDITOR_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 hierarchical sheets are saved.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented from SCH_PLUGIN.

Definition at line 716 of file sch_sexpr_plugin.cpp.

718 {
719  wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
720  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
721 
722  LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
723 
724  init( aSchematic, aProperties );
725 
726  wxFileName fn = aFileName;
727 
728  // File names should be absolute. Don't assume everything relative to the project path
729  // works properly.
730  wxASSERT( fn.IsAbsolute() );
731 
732  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
733 
734  m_out = &formatter; // no ownership
735 
736  Format( aSheet );
737 
738  aSheet->GetScreen()->SetFileExists( true );
739 }
void Format(SCH_SHEET *aSheet)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void SetFileExists(bool aFileExists)
Definition: sch_screen.h:150
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:102
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
Used for text file output.
Definition: richio.h:456
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.

References Format(), SCH_SHEET::GetScreen(), init(), m_out, and SCH_SCREEN::SetFileExists().

◆ saveBitmap()

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

Definition at line 1232 of file sch_sexpr_plugin.cpp.

1233 {
1234  wxCHECK_RET( aBitmap != nullptr && m_out != nullptr, "" );
1235 
1236  const wxImage* image = aBitmap->GetImage()->GetImageData();
1237 
1238  wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
1239 
1240  m_out->Print( aNestLevel, "(image (at %s %s)",
1241  FormatInternalUnits( aBitmap->GetPosition().x ).c_str(),
1242  FormatInternalUnits( aBitmap->GetPosition().y ).c_str() );
1243 
1244  if( aBitmap->GetImage()->GetScale() != 1.0 )
1245  m_out->Print( 0, " (scale %g)", aBitmap->GetImage()->GetScale() );
1246 
1247  m_out->Print( 0, "\n" );
1248 
1249  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aBitmap->m_Uuid.AsString() ) );
1250 
1251  m_out->Print( aNestLevel + 1, "(data" );
1252 
1253  wxMemoryOutputStream stream;
1254 
1255  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1256 
1257  // Write binary data in hexadecimal form (ASCII)
1258  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1259  wxString out = wxBase64Encode( buffer->GetBufferStart(), buffer->GetBufferSize() );
1260 
1261  // Apparently the MIME standard character width for base64 encoding is 76 (unconfirmed)
1262  // so use it in a vein attempt to be standard like.
1263 #define MIME_BASE64_LENGTH 76
1264 
1265  size_t first = 0;
1266 
1267  while( first < out.Length() )
1268  {
1269  m_out->Print( 0, "\n" );
1270  m_out->Print( aNestLevel + 2, "%s", TO_UTF8( out( first, MIME_BASE64_LENGTH ) ) );
1271  first += MIME_BASE64_LENGTH;
1272  }
1273 
1274  m_out->Print( 0, "\n" );
1275  m_out->Print( aNestLevel + 1, ")\n" ); // Closes data token.
1276  m_out->Print( aNestLevel, ")\n" ); // Closes image token.
1277 }
double GetScale() const
Definition: bitmap_base.h:79
wxImage * GetImageData()
Definition: bitmap_base.h:70
wxString AsString() const
Definition: kiid.cpp:236
wxPoint GetPosition() const override
Definition: sch_bitmap.h:136
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
BITMAP_BASE * GetImage() const
Definition: sch_bitmap.h:54
#define MIME_BASE64_LENGTH
const KIID m_Uuid
Definition: eda_item.h:474
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480

References KIID::AsString(), FormatInternalUnits(), SCH_BITMAP::GetImage(), BITMAP_BASE::GetImageData(), SCH_BITMAP::GetPosition(), BITMAP_BASE::GetScale(), image, m_out, EDA_ITEM::m_Uuid, MIME_BASE64_LENGTH, OUTPUTFORMATTER::Print(), and TO_UTF8.

Referenced by Format().

◆ saveBusAlias()

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

Definition at line 1487 of file sch_sexpr_plugin.cpp.

1488 {
1489  wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" );
1490 
1491  wxString members;
1492 
1493  for( auto member : aAlias->Members() )
1494  {
1495  if( members.IsEmpty() )
1496  members = m_out->Quotew( member );
1497  else
1498  members += " " + m_out->Quotew( member );
1499  }
1500 
1501  m_out->Print( aNestLevel, "(bus_alias %s (members %s))\n",
1502  m_out->Quotew( aAlias->GetName() ).c_str(),
1503  TO_UTF8( members ) );
1504 }
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:494

References m_out, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), and TO_UTF8.

Referenced by Format().

◆ saveBusEntry()

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

Definition at line 1368 of file sch_sexpr_plugin.cpp.

1369 {
1370  wxCHECK_RET( aBusEntry != nullptr && m_out != nullptr, "" );
1371 
1372  // Bus to bus entries are converted to bus line segments.
1373  if( aBusEntry->GetClass() == "SCH_BUS_BUS_ENTRY" )
1374  {
1375  SCH_LINE busEntryLine( aBusEntry->GetPosition(), LAYER_BUS );
1376 
1377  busEntryLine.SetEndPoint( aBusEntry->GetEnd() );
1378  saveLine( &busEntryLine, aNestLevel );
1379  }
1380  else
1381  {
1382  m_out->Print( aNestLevel, "(bus_entry (at %s %s) (size %s %s)\n",
1383  FormatInternalUnits( aBusEntry->GetPosition().x ).c_str(),
1384  FormatInternalUnits( aBusEntry->GetPosition().y ).c_str(),
1385  FormatInternalUnits( aBusEntry->GetSize().GetWidth() ).c_str(),
1386  FormatInternalUnits( aBusEntry->GetSize().GetHeight() ).c_str() );
1387 
1388  formatStroke( m_out, aNestLevel + 1, aBusEntry->GetStroke() );
1389 
1390  m_out->Print( 0, "\n" );
1391 
1392  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aBusEntry->m_Uuid.AsString() ) );
1393 
1394  m_out->Print( aNestLevel, ")\n" );
1395  }
1396 }
void saveLine(SCH_LINE *aLine, int aNestLevel)
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_bus_entry.h:81
wxString AsString() const
Definition: kiid.cpp:236
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
const KIID m_Uuid
Definition: eda_item.h:474
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
wxSize GetSize() const
Definition: sch_bus_entry.h:75
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
virtual wxString GetClass() const override
Return the class name.
Definition: sch_item.h:193
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
wxPoint GetEnd() const
wxPoint GetPosition() const override

References KIID::AsString(), FormatInternalUnits(), formatStroke(), SCH_ITEM::GetClass(), SCH_BUS_ENTRY_BASE::GetEnd(), SCH_BUS_ENTRY_BASE::GetPosition(), SCH_BUS_ENTRY_BASE::GetSize(), SCH_BUS_ENTRY_BASE::GetStroke(), LAYER_BUS, m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), saveLine(), SCH_LINE::SetEndPoint(), and TO_UTF8.

Referenced by Format().

◆ saveField()

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

Definition at line 1181 of file sch_sexpr_plugin.cpp.

1182 {
1183  wxCHECK_RET( aField != nullptr && m_out != nullptr, "" );
1184 
1185  wxString fieldName = aField->GetName();
1186 
1187  // For some reason (bug in legacy parser?) the field ID for non-mandatory fields is -1 so
1188  // check for this in order to correctly use the field name.
1189  if( aField->GetParent()->Type() == SCH_SYMBOL_T )
1190  {
1191  if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
1192  fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(), false );
1193  }
1194  else if( aField->GetParent()->Type() == SCH_SHEET_T )
1195  {
1196  if( aField->GetId() >= 0 && aField->GetId() < SHEET_MANDATORY_FIELDS )
1197  fieldName = SCH_SHEET::GetDefaultFieldName( aField->GetId(), false );
1198  }
1199 
1200  if( aField->GetId() == -1 /* undefined ID */ )
1201  {
1202  aField->SetId( m_nextFreeFieldId );
1203  m_nextFreeFieldId += 1;
1204  }
1205  else if( aField->GetId() >= m_nextFreeFieldId )
1206  {
1207  m_nextFreeFieldId = aField->GetId() + 1;
1208  }
1209 
1210  m_out->Print( aNestLevel, "(property %s %s (id %d) (at %s %s %s)",
1211  m_out->Quotew( fieldName ).c_str(),
1212  m_out->Quotew( aField->GetText() ).c_str(),
1213  aField->GetId(),
1214  FormatInternalUnits( aField->GetPosition().x ).c_str(),
1215  FormatInternalUnits( aField->GetPosition().y ).c_str(),
1216  FormatAngle( aField->GetTextAngleDegrees() * 10.0 ).c_str() );
1217 
1218  if( !aField->IsDefaultFormatting()
1219  || ( aField->GetTextHeight() != Mils2iu( DEFAULT_SIZE_TEXT ) ) )
1220  {
1221  m_out->Print( 0, "\n" );
1222  aField->Format( m_out, aNestLevel, 0 );
1223  m_out->Print( aNestLevel, ")\n" ); // Closes property token with font effects.
1224  }
1225  else
1226  {
1227  m_out->Print( 0, ")\n" ); // Closes property token without font effects.
1228  }
1229 }
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:101
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:47
wxPoint GetPosition() const override
Definition: sch_field.cpp:842
int GetId() const
Definition: sch_field.h:113
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
Definition: sch_sheet.cpp:53
int GetTextHeight() const
Definition: eda_text.h:265
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:515
EDA_ITEM * GetParent() const
Definition: eda_item.h:114
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:539
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
bool IsDefaultFormatting() const
Definition: eda_text.cpp:525
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
double GetTextAngleDegrees() const
Definition: eda_text.h:197
wxString GetName(bool aUseDefaultName=true) const
Return the field name.
Definition: sch_field.cpp:678
void SetId(int aId)
Definition: sch_field.cpp:80
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:154
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:494

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(), m_nextFreeFieldId, m_out, MANDATORY_FIELDS, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), SCH_SHEET_T, SCH_SYMBOL_T, SCH_FIELD::SetId(), SHEET_MANDATORY_FIELDS, and EDA_ITEM::Type().

Referenced by saveSheet(), saveSymbol(), and saveText().

◆ saveInstances()

void SCH_SEXPR_PLUGIN::saveInstances ( const std::vector< SCH_SHEET_INSTANCE > &  aSheets,
const std::vector< SYMBOL_INSTANCE_REFERENCE > &  aSymbols,
int  aNestLevel 
)
private

Definition at line 1507 of file sch_sexpr_plugin.cpp.

1510 {
1511  if( aSheets.size() )
1512  {
1513  m_out->Print( 0, "\n" );
1514  m_out->Print( aNestLevel, "(sheet_instances\n" );
1515 
1516  for( const SCH_SHEET_INSTANCE& instance : aSheets )
1517  {
1518  wxString path = instance.m_Path.AsString();
1519 
1520  if( path.IsEmpty() )
1521  path = wxT( "/" ); // Root path
1522 
1523  m_out->Print( aNestLevel + 1, "(path %s (page %s))\n",
1524  m_out->Quotew( path ).c_str(),
1525  m_out->Quotew( instance.m_PageNumber ).c_str() );
1526  }
1527 
1528  m_out->Print( aNestLevel, ")\n" ); // Close sheet instances token.
1529  }
1530 
1531  if( aSymbols.size() )
1532  {
1533  m_out->Print( 0, "\n" );
1534  m_out->Print( aNestLevel, "(symbol_instances\n" );
1535 
1536  for( const SYMBOL_INSTANCE_REFERENCE& instance : aSymbols )
1537  {
1538  m_out->Print( aNestLevel + 1, "(path %s\n",
1539  m_out->Quotew( instance.m_Path.AsString() ).c_str() );
1540  m_out->Print( aNestLevel + 2, "(reference %s) (unit %d) (value %s) (footprint %s)\n",
1541  m_out->Quotew( instance.m_Reference ).c_str(),
1542  instance.m_Unit,
1543  m_out->Quotew( instance.m_Value ).c_str(),
1544  m_out->Quotew( instance.m_Footprint ).c_str() );
1545  m_out->Print( aNestLevel + 1, ")\n" );
1546  }
1547 
1548  m_out->Print( aNestLevel, ")\n" ); // Close symbol instances token.
1549  }
1550 }
A simple container for schematic symbol instance information.
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
A simple container for sheet instance information.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:494

References m_out, path, OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

Referenced by Format().

◆ saveJunction()

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

Definition at line 1338 of file sch_sexpr_plugin.cpp.

1339 {
1340  wxCHECK_RET( aJunction != nullptr && m_out != nullptr, "" );
1341 
1342  m_out->Print( aNestLevel, "(junction (at %s %s) (diameter %s) (color %d %d %d %s)\n",
1343  FormatInternalUnits( aJunction->GetPosition().x ).c_str(),
1344  FormatInternalUnits( aJunction->GetPosition().y ).c_str(),
1345  FormatInternalUnits( aJunction->GetDiameter() ).c_str(),
1346  KiROUND( aJunction->GetColor().r * 255.0 ),
1347  KiROUND( aJunction->GetColor().g * 255.0 ),
1348  KiROUND( aJunction->GetColor().b * 255.0 ),
1349  Double2Str( aJunction->GetColor().a ).c_str() );
1350 
1351  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aJunction->m_Uuid.AsString() ) );
1352 
1353  m_out->Print( aNestLevel, ")\n" );
1354 }
wxString AsString() const
Definition: kiid.cpp:236
int GetDiameter() const
Definition: sch_junction.h:110
double g
Green component.
Definition: color4d.h:385
double b
Blue component.
Definition: color4d.h:386
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
COLOR4D GetColor() const
Definition: sch_junction.h:115
double a
Alpha component.
Definition: color4d.h:387
wxPoint GetPosition() const override
Definition: sch_junction.h:103
const KIID m_Uuid
Definition: eda_item.h:474
OUTPUTFORMATTER * m_out
The 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:73
std::string Double2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 We want to avoid scientific ...
double r
Red component.
Definition: color4d.h:384
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480

References KIGFX::COLOR4D::a, KIID::AsString(), KIGFX::COLOR4D::b, Double2Str(), FormatInternalUnits(), KIGFX::COLOR4D::g, SCH_JUNCTION::GetColor(), SCH_JUNCTION::GetDiameter(), SCH_JUNCTION::GetPosition(), KiROUND(), m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), KIGFX::COLOR4D::r, and TO_UTF8.

Referenced by Format().

◆ SaveLibrary()

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

Reimplemented from SCH_PLUGIN.

Definition at line 2327 of file sch_sexpr_plugin.cpp.

2328 {
2329  if( !m_cache )
2330  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
2331 
2332  wxString oldFileName = m_cache->GetFileName();
2333 
2334  if( !m_cache->IsFile( aLibraryPath ) )
2335  {
2336  m_cache->SetFileName( aLibraryPath );
2337  }
2338 
2339  // This is a forced save.
2340  m_cache->SetModified();
2341  m_cache->Save();
2342  m_cache->SetFileName( oldFileName );
2343 }
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 symbol library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PL...
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 1399 of file sch_sexpr_plugin.cpp.

1400 {
1401  wxCHECK_RET( aLine != nullptr && m_out != nullptr, "" );
1402 
1403  wxString lineType;
1404 
1405  STROKE_PARAMS line_stroke = aLine->GetStroke();
1406 
1407  switch( aLine->GetLayer() )
1408  {
1409  case LAYER_BUS: lineType = "bus"; break;
1410  case LAYER_WIRE: lineType = "wire"; break;
1411  case LAYER_NOTES:
1412  default: lineType = "polyline"; break;
1413  }
1414 
1415  m_out->Print( aNestLevel, "(%s (pts (xy %s %s) (xy %s %s))\n",
1416  TO_UTF8( lineType ),
1417  FormatInternalUnits( aLine->GetStartPoint().x ).c_str(),
1418  FormatInternalUnits( aLine->GetStartPoint().y ).c_str(),
1419  FormatInternalUnits( aLine->GetEndPoint().x ).c_str(),
1420  FormatInternalUnits( aLine->GetEndPoint().y ).c_str() );
1421 
1422  formatStroke( m_out, aNestLevel + 1, line_stroke );
1423  m_out->Print( 0, "\n" );
1424 
1425  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aLine->m_Uuid.AsString() ) );
1426 
1427  m_out->Print( aNestLevel, ")\n" );
1428 }
wxPoint GetStartPoint() const
Definition: sch_line.h:90
wxString AsString() const
Definition: kiid.cpp:236
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
const KIID m_Uuid
Definition: eda_item.h:474
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:259
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
Simple container to manage line stroke parameters.
Definition: sch_item.h:140
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:136
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
wxPoint GetEndPoint() const
Definition: sch_line.h:93

References KIID::AsString(), FormatInternalUnits(), formatStroke(), SCH_LINE::GetEndPoint(), SCH_ITEM::GetLayer(), SCH_LINE::GetStartPoint(), SCH_LINE::GetStroke(), LAYER_BUS, LAYER_NOTES, LAYER_WIRE, m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), and TO_UTF8.

Referenced by Format(), and saveBusEntry().

◆ saveNoConnect()

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

Definition at line 1357 of file sch_sexpr_plugin.cpp.

1358 {
1359  wxCHECK_RET( aNoConnect != nullptr && m_out != nullptr, "" );
1360 
1361  m_out->Print( aNestLevel, "(no_connect (at %s %s) (uuid %s))\n",
1362  FormatInternalUnits( aNoConnect->GetPosition().x ).c_str(),
1363  FormatInternalUnits( aNoConnect->GetPosition().y ).c_str(),
1364  TO_UTF8( aNoConnect->m_Uuid.AsString() ) );
1365 }
wxPoint GetPosition() const override
wxString AsString() const
Definition: kiid.cpp:236
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
const KIID m_Uuid
Definition: eda_item.h:474
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480

References KIID::AsString(), FormatInternalUnits(), SCH_NO_CONNECT::GetPosition(), m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), and TO_UTF8.

Referenced by Format().

◆ saveSheet()

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

Definition at line 1280 of file sch_sexpr_plugin.cpp.

1281 {
1282  wxCHECK_RET( aSheet != nullptr && m_out != nullptr, "" );
1283 
1284  m_out->Print( aNestLevel, "(sheet (at %s %s) (size %s %s)",
1285  FormatInternalUnits( aSheet->GetPosition().x ).c_str(),
1286  FormatInternalUnits( aSheet->GetPosition().y ).c_str(),
1287  FormatInternalUnits( aSheet->GetSize().GetWidth() ).c_str(),
1288  FormatInternalUnits( aSheet->GetSize().GetHeight() ).c_str() );
1289 
1290  if( aSheet->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO )
1291  m_out->Print( 0, " (fields_autoplaced)" );
1292 
1293  m_out->Print( 0, "\n" );
1294 
1296  aSheet->GetBorderColor() );
1297 
1298  stroke.SetWidth( aSheet->GetBorderWidth() );
1299  formatStroke( m_out, aNestLevel + 1, stroke );
1300 
1301  m_out->Print( 0, "\n" );
1302 
1303  m_out->Print( aNestLevel + 1, "(fill (color %d %d %d %0.4f))\n",
1304  KiROUND( aSheet->GetBackgroundColor().r * 255.0 ),
1305  KiROUND( aSheet->GetBackgroundColor().g * 255.0 ),
1306  KiROUND( aSheet->GetBackgroundColor().b * 255.0 ),
1307  aSheet->GetBackgroundColor().a );
1308 
1309  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSheet->m_Uuid.AsString() ) );
1310 
1312 
1313  for( SCH_FIELD& field : aSheet->GetFields() )
1314  {
1315  saveField( &field, aNestLevel + 1 );
1316  }
1317 
1318  for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
1319  {
1320  m_out->Print( aNestLevel + 1, "(pin %s %s (at %s %s %s)\n",
1321  EscapedUTF8( pin->GetText() ).c_str(),
1322  getSheetPinShapeToken( pin->GetShape() ),
1323  FormatInternalUnits( pin->GetPosition().x ).c_str(),
1324  FormatInternalUnits( pin->GetPosition().y ).c_str(),
1325  FormatAngle( getSheetPinAngle( pin->GetSide() ) * 10.0 ).c_str() );
1326 
1327  pin->Format( m_out, aNestLevel + 1, 0 );
1328 
1329  m_out->Print( aNestLevel + 2, "(uuid %s)\n", TO_UTF8( pin->m_Uuid.AsString() ) );
1330 
1331  m_out->Print( aNestLevel + 1, ")\n" ); // Closes pin token.
1332  }
1333 
1334  m_out->Print( aNestLevel, ")\n" ); // Closes sheet token.
1335 }
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
void SetWidth(int aWidth)
Definition: sch_item.h:153
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:47
wxString AsString() const
Definition: kiid.cpp:236
double g
Green component.
Definition: color4d.h:385
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:110
void saveField(SCH_FIELD *aField, int aNestLevel)
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:424
double b
Blue component.
Definition: color4d.h:386
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:113
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:90
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:515
int GetBorderWidth() const
Definition: sch_sheet.h:107
double a
Alpha component.
Definition: color4d.h:387
static double getSheetPinAngle(SHEET_SIDE aSide)
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
wxPoint GetPosition() const override
Definition: sch_sheet.h:379
const KIID m_Uuid
Definition: eda_item.h:474
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:183
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
Simple container to manage line stroke parameters.
Definition: sch_item.h:140
wxSize GetSize() const
Definition: sch_sheet.h:104
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:73
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
double r
Red component.
Definition: color4d.h:384
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
static const char * getSheetPinShapeToken(PINSHEETLABEL_SHAPE aShape)

References KIGFX::COLOR4D::a, KIID::AsString(), KIGFX::COLOR4D::b, EscapedUTF8(), FIELDS_AUTOPLACED_NO, FormatAngle(), FormatInternalUnits(), formatStroke(), KIGFX::COLOR4D::g, SCH_SHEET::GetBackgroundColor(), SCH_SHEET::GetBorderColor(), SCH_SHEET::GetBorderWidth(), SCH_SHEET::GetFields(), SCH_ITEM::GetFieldsAutoplaced(), SCH_SHEET::GetPins(), SCH_SHEET::GetPosition(), getSheetPinAngle(), getSheetPinShapeToken(), SCH_SHEET::GetSize(), KiROUND(), m_nextFreeFieldId, m_out, EDA_ITEM::m_Uuid, pin, OUTPUTFORMATTER::Print(), KIGFX::COLOR4D::r, saveField(), STROKE_PARAMS::SetWidth(), SHEET_MANDATORY_FIELDS, SOLID, and TO_UTF8.

Referenced by Format().

◆ SaveSymbol()

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

Write aSymbol to an existing library located at aLibraryPath.

If a LIB_SYMBOL by the same name already exists or there are any conflicting alias names, the new LIB_SYMBOL will silently overwrite any existing aliases and/or part because 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_SYMBOL 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 2254 of file sch_sexpr_plugin.cpp.

2256 {
2257  LOCALE_IO toggle; // toggles on, then off, the C locale.
2258 
2259  cacheLib( aLibraryPath, aProperties );
2260 
2261  m_cache->AddSymbol( aSymbol );
2262 
2263  if( !isBuffering( aProperties ) )
2264  m_cache->Save();
2265 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void Save()
Save the entire library to file m_libFileName;.
SCH_SEXPR_PLUGIN_CACHE * m_cache
void AddSymbol(const LIB_SYMBOL *aSymbol)
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)
bool isBuffering(const PROPERTIES *aProperties)

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

◆ saveSymbol()

void SCH_SEXPR_PLUGIN::saveSymbol ( SCH_SYMBOL aSymbol,
SCH_SHEET_PATH aSheetPath,
int  aNestLevel 
)
private

Definition at line 1030 of file sch_sexpr_plugin.cpp.

1032 {
1033  wxCHECK_RET( aSymbol != nullptr && m_out != nullptr, "" );
1034 
1035  std::string libName;
1036  wxArrayString reference_fields;
1037 
1038  static wxString delimiters( wxT( " " ) );
1039 
1040  wxString symbol_name = aSymbol->GetLibId().Format();
1041 
1042  if( symbol_name.size() )
1043  {
1044  libName = toUTFTildaText( symbol_name );
1045  }
1046  else
1047  {
1048  libName = "_NONAME_";
1049  }
1050 
1051  double angle;
1052  int orientation = aSymbol->GetOrientation() & ~( SYM_MIRROR_X | SYM_MIRROR_Y );
1053 
1054  if( orientation == SYM_ORIENT_90 )
1055  angle = 90.0;
1056  else if( orientation == SYM_ORIENT_180 )
1057  angle = 180.0;
1058  else if( orientation == SYM_ORIENT_270 )
1059  angle = 270.0;
1060  else
1061  angle = 0.0;
1062 
1063  m_out->Print( aNestLevel, "(symbol" );
1064 
1065  if( !aSymbol->UseLibIdLookup() )
1066  {
1067  m_out->Print( 0, " (lib_name %s)",
1068  m_out->Quotew( aSymbol->GetSchSymbolLibraryName() ).c_str() );
1069  }
1070 
1071  m_out->Print( 0, " (lib_id %s) (at %s %s %s)",
1072  m_out->Quotew( aSymbol->GetLibId().Format().wx_str() ).c_str(),
1073  FormatInternalUnits( aSymbol->GetPosition().x ).c_str(),
1074  FormatInternalUnits( aSymbol->GetPosition().y ).c_str(),
1075  FormatAngle( angle * 10.0 ).c_str() );
1076 
1077  bool mirrorX = aSymbol->GetOrientation() & SYM_MIRROR_X;
1078  bool mirrorY = aSymbol->GetOrientation() & SYM_MIRROR_Y;
1079 
1080  if( mirrorX || mirrorY )
1081  {
1082  m_out->Print( 0, " (mirror" );
1083 
1084  if( mirrorX )
1085  m_out->Print( 0, " x" );
1086 
1087  if( mirrorY )
1088  m_out->Print( 0, " y" );
1089 
1090  m_out->Print( 0, ")" );
1091  }
1092 
1093  int unit = ( aSymbol->GetInstanceReferences().size() == 0 ) ?
1094  aSymbol->GetUnit() :
1095  aSymbol->GetInstanceReferences()[0].m_Unit;
1096 
1097  m_out->Print( 0, " (unit %d)", unit );
1098 
1099  if( aSymbol->GetConvert() == LIB_ITEM::LIB_CONVERT::DEMORGAN )
1100  m_out->Print( 0, " (convert %d)", aSymbol->GetConvert() );
1101 
1102  m_out->Print( 0, "\n" );
1103 
1104  m_out->Print( aNestLevel + 1, "(in_bom %s)", ( aSymbol->GetIncludeInBom() ) ? "yes" : "no" );
1105  m_out->Print( 0, " (on_board %s)", ( aSymbol->GetIncludeOnBoard() ) ? "yes" : "no" );
1106 
1107  if( aSymbol->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO )
1108  m_out->Print( 0, " (fields_autoplaced)" );
1109 
1110  m_out->Print( 0, "\n" );
1111 
1112  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSymbol->m_Uuid.AsString() ) );
1113 
1115 
1116  for( SCH_FIELD& field : aSymbol->GetFields() )
1117  {
1118  int id = field.GetId();
1119  wxString value = field.GetText();
1120 
1121  // The instance fields are always set to the first sheet instance of the project to
1122  // schematic file changes when switching sheet instances with the current project
1123  // schematic. It does not solve the problem for schematics shared between projects.
1124  if( id == REFERENCE_FIELD )
1125  {
1126  field.SetText( ( aSymbol->GetInstanceReferences().size() == 0 ) ?
1127  value :
1128  aSymbol->GetInstanceReferences()[0].m_Reference );
1129  }
1130  else if( id == VALUE_FIELD )
1131  {
1132  field.SetText( ( aSymbol->GetInstanceReferences().size() == 0 ) ?
1133  value :
1134  aSymbol->GetInstanceReferences()[0].m_Value );
1135  }
1136  else if( id == FOOTPRINT_FIELD )
1137  {
1138  field.SetText( ( aSymbol->GetInstanceReferences().size() == 0 ) ?
1139  value :
1140  aSymbol->GetInstanceReferences()[0].m_Footprint );
1141  }
1142 
1143  try
1144  {
1145  saveField( &field, aNestLevel + 1 );
1146  }
1147  catch( ... )
1148  {
1149  // Restore the changed field text on write error.
1150  if( id == REFERENCE_FIELD || id == VALUE_FIELD || id == FOOTPRINT_FIELD )
1151  field.SetText( value );
1152 
1153  throw;
1154  }
1155 
1156  if( id == REFERENCE_FIELD || id == VALUE_FIELD || id == FOOTPRINT_FIELD )
1157  field.SetText( value );
1158  }
1159 
1160  for( const std::unique_ptr<SCH_PIN>& pin : aSymbol->GetRawPins() )
1161  {
1162  if( pin->GetAlt().IsEmpty() )
1163  {
1164  m_out->Print( aNestLevel + 1, "(pin %s (uuid %s))\n",
1165  m_out->Quotew( pin->GetNumber() ).c_str(),
1166  TO_UTF8( pin->m_Uuid.AsString() ) );
1167  }
1168  else
1169  {
1170  m_out->Print( aNestLevel + 1, "(pin %s (uuid %s) (alternate %s))\n",
1171  m_out->Quotew( pin->GetNumber() ).c_str(),
1172  TO_UTF8( pin->m_Uuid.AsString() ),
1173  m_out->Quotew( pin->GetAlt() ).c_str() );
1174  }
1175  }
1176 
1177  m_out->Print( aNestLevel, ")\n" );
1178 }
Field Reference of part, i.e. "IC21".
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:741
bool GetIncludeInBom() const
Definition: sch_symbol.h:663
wxString AsString() const
Definition: kiid.cpp:236
void saveField(SCH_FIELD *aField, int aNestLevel)
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
Definition: sch_symbol.cpp:46
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:424
const std::vector< SYMBOL_INSTANCE_REFERENCE > & GetInstanceReferences()
Definition: sch_symbol.h:123
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:515
Field Value of part, i.e. "3.3K".
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:271
UTF8 Format() const
Definition: lib_id.cpp:116
std::vector< std::unique_ptr< SCH_PIN > > & GetRawPins()
Definition: sch_symbol.h:471
const KIID m_Uuid
Definition: eda_item.h:474
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
wxString wx_str() const
Definition: utf8.cpp:46
wxPoint GetPosition() const override
Definition: sch_symbol.h:645
bool GetIncludeOnBoard() const
Definition: sch_symbol.h:666
int GetOrientation()
Get the display symbol orientation.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
int GetUnit() const
Definition: sch_symbol.h:196
int GetConvert() const
Definition: sch_symbol.h:224
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
bool UseLibIdLookup() const
Definition: sch_symbol.h:163
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:494
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:148
Field Name Module PCB, i.e. "16DIP300".

References PNS::angle(), KIID::AsString(), FIELDS_AUTOPLACED_NO, FOOTPRINT_FIELD, LIB_ID::Format(), FormatAngle(), FormatInternalUnits(), SCH_SYMBOL::GetConvert(), SCH_SYMBOL::GetFields(), SCH_ITEM::GetFieldsAutoplaced(), SCH_SYMBOL::GetIncludeInBom(), SCH_SYMBOL::GetIncludeOnBoard(), SCH_SYMBOL::GetInstanceReferences(), SCH_SYMBOL::GetLibId(), SCH_SYMBOL::GetOrientation(), SCH_SYMBOL::GetPosition(), SCH_SYMBOL::GetRawPins(), SCH_SYMBOL::GetSchSymbolLibraryName(), SCH_SYMBOL::GetUnit(), m_nextFreeFieldId, m_out, EDA_ITEM::m_Uuid, MANDATORY_FIELDS, pin, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), REFERENCE_FIELD, saveField(), SYM_MIRROR_X, SYM_MIRROR_Y, SYM_ORIENT_180, SYM_ORIENT_270, SYM_ORIENT_90, TO_UTF8, toUTFTildaText(), SCH_SYMBOL::UseLibIdLookup(), VALUE_FIELD, and UTF8::wx_str().

Referenced by Format().

◆ saveText()

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

Definition at line 1431 of file sch_sexpr_plugin.cpp.

1432 {
1433  wxCHECK_RET( aText != nullptr && m_out != nullptr, "" );
1434 
1435  double angle;
1436 
1437  switch( aText->GetLabelSpinStyle() )
1438  {
1439  case LABEL_SPIN_STYLE::RIGHT: angle = 0.0; break;
1440  case LABEL_SPIN_STYLE::UP: angle = 90.0; break;
1441  case LABEL_SPIN_STYLE::LEFT: angle = 180.0; break;
1442  case LABEL_SPIN_STYLE::BOTTOM: angle = 270.0; break;
1443  default: wxFAIL; angle = 0.0; break;
1444  }
1445 
1446  m_out->Print( aNestLevel, "(%s %s",
1447  getTextTypeToken( aText->Type() ),
1448  m_out->Quotew( aText->GetText() ).c_str() );
1449 
1450  if( ( aText->Type() == SCH_GLOBAL_LABEL_T ) || ( aText->Type() == SCH_HIER_LABEL_T ) )
1451  m_out->Print( 0, " (shape %s)", getSheetPinShapeToken( aText->GetShape() ) );
1452 
1453  if( aText->GetText().Length() < 50 )
1454  {
1455  m_out->Print( 0, " (at %s %s %s)",
1456  FormatInternalUnits( aText->GetPosition().x ).c_str(),
1457  FormatInternalUnits( aText->GetPosition().y ).c_str(),
1458  FormatAngle( angle * 10.0 ).c_str() );
1459  }
1460  else
1461  {
1462  m_out->Print( 0, "\n" );
1463  m_out->Print( aNestLevel + 1, "(at %s %s %s)",
1464  FormatInternalUnits( aText->GetPosition().x ).c_str(),
1465  FormatInternalUnits( aText->GetPosition().y ).c_str(),
1466  FormatAngle( aText->GetTextAngle() ).c_str() );
1467  }
1468 
1469  if( aText->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO )
1470  m_out->Print( 0, " (fields_autoplaced)" );
1471 
1472  m_out->Print( 0, "\n" );
1473  aText->Format( m_out, aNestLevel, 0 );
1474 
1475  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aText->m_Uuid.AsString() ) );
1476 
1477  if( ( aText->Type() == SCH_GLOBAL_LABEL_T ) )
1478  {
1479  SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( aText );
1480  saveField( label->GetIntersheetRefs(), aNestLevel + 1 );
1481  }
1482 
1483  m_out->Print( aNestLevel, ")\n" ); // Closes text token.
1484 }
static const char * getTextTypeToken(KICAD_T aType)
double GetTextAngle() const
Definition: eda_text.h:195
wxString AsString() const
Definition: kiid.cpp:236
void saveField(SCH_FIELD *aField, int aNestLevel)
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:424
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:515
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:539
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:159
wxPoint GetPosition() const override
Definition: sch_text.h:241
const KIID m_Uuid
Definition: eda_item.h:474
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
SCH_FIELD * GetIntersheetRefs()
Definition: sch_text.h:415
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:154
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:480
static const char * getSheetPinShapeToken(PINSHEETLABEL_SHAPE aShape)
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:161
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:494

References PNS::angle(), KIID::AsString(), LABEL_SPIN_STYLE::BOTTOM, FIELDS_AUTOPLACED_NO, EDA_TEXT::Format(), FormatAngle(), FormatInternalUnits(), SCH_ITEM::GetFieldsAutoplaced(), SCH_GLOBALLABEL::GetIntersheetRefs(), SCH_TEXT::GetLabelSpinStyle(), SCH_TEXT::GetPosition(), SCH_TEXT::GetShape(), getSheetPinShapeToken(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), getTextTypeToken(), LABEL_SPIN_STYLE::LEFT, m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), LABEL_SPIN_STYLE::RIGHT, saveField(), SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, TO_UTF8, EDA_ITEM::Type(), and LABEL_SPIN_STYLE::UP.

Referenced by Format().

◆ SetProgressReporter()

void SCH_SEXPR_PLUGIN::SetProgressReporter ( PROGRESS_REPORTER aReporter)
inlineoverridevirtual

Set an optional progress reporter.

Reimplemented from SCH_PLUGIN.

Definition at line 82 of file sch_sexpr_plugin.h.

83  {
84  m_progressReporter = aReporter;
85  }
PROGRESS_REPORTER * m_progressReporter

References m_progressReporter.

◆ SetReporter()

virtual void SCH_PLUGIN::SetReporter ( REPORTER aReporter)
inlinevirtualinherited

Set an optional reporter for warnings/errors.

Reimplemented in SCH_EAGLE_PLUGIN, SCH_ALTIUM_PLUGIN, and CADSTAR_SCH_ARCHIVE_PLUGIN.

Definition at line 166 of file sch_io_mgr.h.

166 {}

◆ 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 133 of file sch_plugin.cpp.

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

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 168 of file sch_sexpr_plugin.h.

Referenced by Load(), and loadHierarchy().

◆ m_error

wxString SCH_SEXPR_PLUGIN::m_error
protected

For throwing exceptions or errors on partial loads.

Definition at line 163 of file sch_sexpr_plugin.h.

Referenced by GetError(), and loadHierarchy().

◆ m_nextFreeFieldId

int SCH_SEXPR_PLUGIN::m_nextFreeFieldId
protected

Definition at line 161 of file sch_sexpr_plugin.h.

Referenced by init(), saveField(), saveSheet(), and saveSymbol().

◆ m_out

OUTPUTFORMATTER* SCH_SEXPR_PLUGIN::m_out
protected

◆ m_path

wxString SCH_SEXPR_PLUGIN::m_path
protected

Root project path for loading child sheets.

Definition at line 167 of file sch_sexpr_plugin.h.

Referenced by Load().

◆ m_progressReporter

PROGRESS_REPORTER* SCH_SEXPR_PLUGIN::m_progressReporter
protected

Definition at line 165 of file sch_sexpr_plugin.h.

Referenced by loadFile(), and SetProgressReporter().

◆ m_rootSheet

SCH_SHEET* SCH_SEXPR_PLUGIN::m_rootSheet
protected

The root sheet of the schematic being loaded.

Definition at line 169 of file sch_sexpr_plugin.h.

Referenced by init(), Load(), and loadHierarchy().

◆ m_schematic

SCHEMATIC* SCH_SEXPR_PLUGIN::m_schematic
protected

Definition at line 170 of file sch_sexpr_plugin.h.

Referenced by Format(), init(), and loadHierarchy().

◆ m_version

int SCH_SEXPR_PLUGIN::m_version
protected

Version of file being loaded.

Definition at line 160 of file sch_sexpr_plugin.h.

Referenced by init().

◆ 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 92 of file sch_sexpr_plugin.h.

Referenced by isBuffering().


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