KiCad PCB EDA Suite
SCH_SEXPR_PLUGIN Class Reference

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

#include <sch_sexpr_plugin.h>

Inheritance diagram for SCH_SEXPR_PLUGIN:
SCH_PLUGIN

Public Member Functions

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

Static Public Member Functions

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

Static Public Attributes

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

Protected Member Functions

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

Protected Attributes

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

Private Member Functions

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

Detailed Description

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

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

Definition at line 56 of file sch_sexpr_plugin.h.

Constructor & Destructor Documentation

◆ SCH_SEXPR_PLUGIN()

SCH_SEXPR_PLUGIN::SCH_SEXPR_PLUGIN ( )

Definition at line 366 of file sch_sexpr_plugin.cpp.

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

References NULL.

◆ ~SCH_SEXPR_PLUGIN()

SCH_SEXPR_PLUGIN::~SCH_SEXPR_PLUGIN ( )
virtual

Definition at line 372 of file sch_sexpr_plugin.cpp.

373 {
374  delete m_cache;
375 }
SCH_SEXPR_PLUGIN_CACHE * m_cache

Member Function Documentation

◆ cacheLib()

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

Definition at line 2029 of file sch_sexpr_plugin.cpp.

2030 {
2031  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
2032  {
2033  // a spectacular episode in memory management:
2034  delete m_cache;
2035  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryFileName );
2036 
2037  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
2038  // to modify the hash value that indicate component to symbol links
2039  // must be updated.
2041 
2042  if( !isBuffering( m_props ) )
2043  m_cache->Load();
2044  }
2045 }
static int s_modify_generation
helper for GetModifyHash()
SCH_SEXPR_PLUGIN_CACHE * m_cache
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PLUG...
bool IsFile(const wxString &aFullPathAndFileName) const
bool isBuffering(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

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

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

◆ CheckHeader()

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

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

Parameters
aFileNameis the name of the file to use as input

Reimplemented from SCH_PLUGIN.

Definition at line 2221 of file sch_sexpr_plugin.cpp.

2222 {
2223  // Open file and check first line
2224  wxTextFile tempFile;
2225 
2226  tempFile.Open( aFileName );
2227  wxString firstline;
2228  // read the first line
2229  firstline = tempFile.GetFirstLine();
2230  tempFile.Close();
2231 
2232  return firstline.StartsWith( "EESchema" );
2233 }

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

2156 {
2157  if( wxFileExists( aLibraryPath ) )
2158  {
2160  _( "symbol library \"%s\" already exists, cannot create a new library" ),
2161  aLibraryPath.GetData() ) );
2162  }
2163 
2164  LOCALE_IO toggle;
2165 
2166  m_props = aProperties;
2167 
2168  delete m_cache;
2169  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
2170  m_cache->SetModified();
2171  m_cache->Save();
2172  m_cache->Load(); // update m_writable and m_mod_time
2173 }
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 part library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PLUG...
void SetModified(bool aModified=true)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

◆ DeleteSymbol()

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 2140 of file sch_sexpr_plugin.cpp.

2142 {
2143  m_props = aProperties;
2144 
2145  cacheLib( aLibraryPath );
2146 
2147  m_cache->DeleteSymbol( aSymbolName );
2148 
2149  if( !isBuffering( aProperties ) )
2150  m_cache->Save();
2151 }
void Save()
Save the entire library to file m_libFileName;.
SCH_SEXPR_PLUGIN_CACHE * m_cache
void DeleteSymbol(const wxString &aName)
void cacheLib(const wxString &aLibraryFileName)
bool isBuffering(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

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

◆ DeleteSymbolLib()

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 2176 of file sch_sexpr_plugin.cpp.

2178 {
2179  wxFileName fn = aLibraryPath;
2180 
2181  if( !fn.FileExists() )
2182  return false;
2183 
2184  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2185  // we don't want that. we want bare metal portability with no UI here.
2186  if( wxRemove( aLibraryPath ) )
2187  {
2188  THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
2189  aLibraryPath.GetData() ) );
2190  }
2191 
2192  if( m_cache && m_cache->IsFile( aLibraryPath ) )
2193  {
2194  delete m_cache;
2195  m_cache = 0;
2196  }
2197 
2198  return true;
2199 }
SCH_SEXPR_PLUGIN_CACHE * m_cache
bool IsFile(const wxString &aFullPathAndFileName) const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

◆ EnumerateSymbolLib() [1/2]

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 2064 of file sch_sexpr_plugin.cpp.

2067 {
2068  LOCALE_IO toggle; // toggles on, then off, the C locale.
2069 
2070  m_props = aProperties;
2071 
2072  bool powerSymbolsOnly = ( aProperties &&
2073  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2074  cacheLib( aLibraryPath );
2075 
2076  const LIB_PART_MAP& symbols = m_cache->m_symbols;
2077 
2078  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2079  {
2080  if( !powerSymbolsOnly || it->second->IsPower() )
2081  aSymbolNameList.Add( it->first );
2082  }
2083 }
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
std::map< wxString, LIB_PART *, LibPartMapSort > LIB_PART_MAP
Part map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.
static const char * PropPowerSymsOnly

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

◆ EnumerateSymbolLib() [2/2]

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 2086 of file sch_sexpr_plugin.cpp.

2089 {
2090  LOCALE_IO toggle; // toggles on, then off, the C locale.
2091 
2092  m_props = aProperties;
2093 
2094  bool powerSymbolsOnly = ( aProperties &&
2095  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2096  cacheLib( aLibraryPath );
2097 
2098  const LIB_PART_MAP& symbols = m_cache->m_symbols;
2099 
2100  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2101  {
2102  if( !powerSymbolsOnly || it->second->IsPower() )
2103  aSymbolList.push_back( it->second );
2104  }
2105 }
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
std::map< wxString, LIB_PART *, LibPartMapSort > LIB_PART_MAP
Part map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.
static const char * PropPowerSymsOnly

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

◆ Format() [1/2]

void SCH_SEXPR_PLUGIN::Format ( SCH_SHEET aSheet)

Definition at line 574 of file sch_sexpr_plugin.cpp.

575 {
576  wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET* object." );
577  wxCHECK_RET( m_schematic != NULL, "NULL SCHEMATIC* object." );
578 
579  SCH_SCREEN* screen = aSheet->GetScreen();
580 
581  wxCHECK( screen, /* void */ );
582 
583  m_out->Print( 0, "(kicad_sch (version %d) (generator eeschema)\n\n",
585 
586  // Root sheet must have a permanent UUID.
587  // if( aSheet->IsRootSheet() && aSheet->m_Uuid.IsLegacyTimestamp() )
588  // const_cast<KIID&>( aSheet->m_Uuid ).ConvertTimestampToUuid();
589 
590  // m_out->Print( 1, "(uuid %s)\n\n", m_out->Quotew( aSheet->m_Uuid.AsString() ).c_str() );
591 
592  m_out->Print( 1, "(page %d %d)\n\n",
593  screen->GetVirtualPageNumber(),
594  screen->GetPageCount() );
595 
596  screen->GetPageSettings().Format( m_out, 1, 0 );
597  m_out->Print( 0, "\n" );
598  screen->GetTitleBlock().Format( m_out, 1, 0 );
599 
600  // Save cache library.
601  m_out->Print( 1, "(lib_symbols\n" );
602 
603  for( auto libSymbol : screen->GetLibSymbols() )
604  SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( libSymbol.second, *m_out, 2, libSymbol.first );
605 
606  m_out->Print( 1, ")\n\n" );
607 
608  for( const auto& alias : screen->GetBusAliases() )
609  {
610  saveBusAlias( alias, 1 );
611  }
612 
613  // Enforce item ordering
614  auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b )
615  {
616  return *a < *b;
617  };
618 
619  std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
620 
621  for( SCH_ITEM* item : screen->Items() )
622  save_map.insert( item );
623 
624  KICAD_T itemType = TYPE_NOT_INIT;
626 
627  for( SCH_ITEM* item : save_map )
628  {
629  if( itemType != item->Type() )
630  {
631  itemType = item->Type();
632 
633  if( itemType != SCH_COMPONENT_T
634  && itemType != SCH_JUNCTION_T
635  && itemType != SCH_SHEET_T )
636  m_out->Print( 0, "\n" );
637  }
638 
639  switch( item->Type() )
640  {
641  case SCH_COMPONENT_T:
642  m_out->Print( 0, "\n" );
643  saveSymbol( static_cast<SCH_COMPONENT*>( item ), 1 );
644  break;
645 
646  case SCH_BITMAP_T:
647  saveBitmap( static_cast<SCH_BITMAP*>( item ), 1 );
648  break;
649 
650  case SCH_SHEET_T:
651  m_out->Print( 0, "\n" );
652  saveSheet( static_cast<SCH_SHEET*>( item ), 1 );
653  break;
654 
655  case SCH_JUNCTION_T:
656  saveJunction( static_cast<SCH_JUNCTION*>( item ), 1 );
657  break;
658 
659  case SCH_NO_CONNECT_T:
660  saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ), 1 );
661  break;
662 
664  case SCH_BUS_BUS_ENTRY_T:
665  saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ), 1 );
666  break;
667 
668  case SCH_LINE_T:
669  if( layer != item->GetLayer() )
670  {
671  if( layer == SCH_LAYER_ID_START )
672  {
673  layer = item->GetLayer();
674  }
675  else
676  {
677  layer = item->GetLayer();
678  m_out->Print( 0, "\n" );
679  }
680  }
681 
682  saveLine( static_cast<SCH_LINE*>( item ), 1 );
683  break;
684 
685  case SCH_TEXT_T:
686  case SCH_LABEL_T:
687  case SCH_GLOBAL_LABEL_T:
688  case SCH_HIER_LABEL_T:
689  saveText( static_cast<SCH_TEXT*>( item ), 1 );
690  break;
691 
692  default:
693  wxASSERT( "Unexpected schematic object type in SCH_SEXPR_PLUGIN::Format()" );
694  }
695  }
696 
697  // If this is the root sheet, save all of the sheet paths.
698  if( aSheet->IsRootSheet() )
699  {
700  SCH_SHEET_LIST sheetPaths( aSheet, true );
701 
702  m_out->Print( 0, "\n" );
703  m_out->Print( 1, "(sheet_instances\n" );
704 
705  for( const SCH_SHEET_PATH& sheetPath : sheetPaths )
706  {
707  SCH_SHEET* sheet = sheetPath.Last();
708 
709  wxCHECK2( sheet, continue );
710 
711  m_out->Print( 2, "(path %s (page %s))\n",
712  m_out->Quotew( sheetPath.PathAsString() ).c_str(),
713  m_out->Quotew( sheet->GetPageNumber( sheetPath ) ).c_str() );
714  }
715 
716  m_out->Print( 1, ")\n" ); // Close sheet instances token.
717  m_out->Print( 0, "\n" );
718  m_out->Print( 1, "(symbol_instances\n" );
719 
720  for( const SCH_SHEET_PATH& sheetPath : sheetPaths )
721  {
722  SCH_REFERENCE_LIST instances;
723 
724  sheetPath.GetComponents( instances, true, true );
725  instances.SortByReferenceOnly();
726 
727  for( size_t i = 0; i < instances.GetCount(); i++ )
728  {
729  m_out->Print( 2, "(path %s\n",
730  m_out->Quotew( instances[i].GetPath() ).c_str() );
731  m_out->Print( 3, "(reference %s) (unit %d) (value %s) (footprint %s)\n",
732  m_out->Quotew( instances[i].GetRef() ).c_str(),
733  instances[i].GetUnit(),
734  m_out->Quotew( instances[i].GetValue() ).c_str(),
735  m_out->Quotew( instances[i].GetFootprint() ).c_str() );
736  m_out->Print( 2, ")\n" );
737  }
738  }
739 
740  m_out->Print( 1, ")\n" ); // Close symbol instances token.
741  }
742  else
743  {
744  // Schematic files (SCH_SCREEN objects) can be shared so we have to save and restore
745  // symbol and sheet instance data even if the file being saved is not the root sheet
746  // because it is possible that the file is the root sheet of another project.
747  if( screen->m_sheetInstances.size() )
748  {
749  m_out->Print( 0, "\n" );
750  m_out->Print( 1, "(sheet_instances\n" );
751 
752  for( const SCH_SHEET_INSTANCE& instance : screen->m_sheetInstances )
753  {
754  m_out->Print( 2, "(path %s (page %s))\n",
755  m_out->Quotew( instance.m_Path.AsString() ).c_str(),
756  m_out->Quotew( instance.m_PageNumber ).c_str() );
757  }
758 
759  m_out->Print( 1, ")\n" ); // Close sheet instances token.
760  }
761 
762  if( screen->m_symbolInstances.size() )
763  {
764  m_out->Print( 0, "\n" );
765  m_out->Print( 1, "(symbol_instances\n" );
766 
767  for( const COMPONENT_INSTANCE_REFERENCE& instance : screen->m_symbolInstances )
768  {
769  m_out->Print( 2, "(path %s (reference %s) (unit %d))\n",
770  m_out->Quotew( instance.m_Path.AsString() ).c_str(),
771  m_out->Quotew( instance.m_Reference ).c_str(),
772  instance.m_Unit );
773  }
774 
775  m_out->Print( 1, ")\n" ); // Close instances token.
776  }
777  }
778 
779  m_out->Print( 0, ")\n" );
780 }
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
void saveLine(SCH_LINE *aLine, int aNestLevel)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect, int aNestLevel)
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
int GetVirtualPageNumber() const
Definition: base_screen.h:143
int GetPageCount() const
Definition: base_screen.h:140
void saveText(SCH_TEXT *aText, int aNestLevel)
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:191
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function GetStandardSizes returns the standard page types, such as "A4", "A3", etc.
Definition: page_info.cpp:271
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:284
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:181
void saveSymbol(SCH_COMPONENT *aComponent, int aNestLevel)
std::map< wxString, LIB_PART * > & GetLibSymbols()
Fetch a list of unique LIB_PART object pointers required to properly render each SCH_COMPONENT in thi...
Definition: sch_screen.h:462
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierarchy,...
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
#define NULL
std::vector< SCH_SHEET_INSTANCE > m_sheetInstances
Definition: sch_screen.h:140
A simple container for schematic symbol instance infromation.
bool IsRootSheet() const
Definition: sch_sheet.cpp:182
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: title_block.cpp:28
SCH_LAYER_ID
Eeschema drawing layers.
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::vector< COMPONENT_INSTANCE_REFERENCE > m_symbolInstances
The list of symbol instances loaded from the schematic file.
Definition: sch_screen.h:139
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
unsigned GetCount() const
Function GetCount.
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
A simple container for sheet instance infromation.
void SortByReferenceOnly()
Function SortByReferenceOnly sorts the list of references by reference.
wxString AsString() const
Definition: kiid.cpp:206
EE_RTREE & Items()
Definition: sch_screen.h:159
void saveSheet(SCH_SHEET *aSheet, int aNestLevel)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
#define SEXPR_SCHEMATIC_FILE_VERSION
Symbol library file version.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1063
std::unordered_set< std::shared_ptr< BUS_ALIAS > > GetBusAliases()
Returns a list of bus aliases defined in this screen.
Definition: sch_screen.h:491
void saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)

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

Referenced by SCH_EDITOR_CONTROL::doCopy().

◆ Format() [2/2]

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

Definition at line 783 of file sch_sexpr_plugin.cpp.

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

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

◆ FormatPart()

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

Definition at line 2257 of file sch_sexpr_plugin.cpp.

2258 {
2259 
2260  LOCALE_IO toggle; // toggles on, then off, the C locale.
2261  SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( part, formatter );
2262 }
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_PART *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)

References SCH_SEXPR_PLUGIN_CACHE::SaveSymbol().

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

◆ GetError()

const wxString& SCH_SEXPR_PLUGIN::GetError ( ) const
inlineoverridevirtual

Return an error string to the caller.

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

Returns
an unformatted string containing errors if any.

Reimplemented from SCH_PLUGIN.

Definition at line 123 of file sch_sexpr_plugin.h.

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

References m_error.

◆ GetFileExtension()

const wxString SCH_SEXPR_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Returns the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 68 of file sch_sexpr_plugin.h.

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

◆ GetLibraryFileExtension()

const wxString SCH_SEXPR_PLUGIN::GetLibraryFileExtension ( ) const
inlineoverridevirtual

Return the library file extension for the SCH_PLUGIN object.

Implements SCH_PLUGIN.

Definition at line 73 of file sch_sexpr_plugin.h.

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

◆ GetModifyHash()

int SCH_SEXPR_PLUGIN::GetModifyHash ( ) const
overridevirtual

Return the modification hash from the library cache.

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

Implements SCH_PLUGIN.

Definition at line 2054 of file sch_sexpr_plugin.cpp.

2055 {
2056  if( m_cache )
2057  return m_cache->GetModifyHash();
2058 
2059  // If the cache hasn't been loaded, it hasn't been modified.
2060  return 0;
2061 }
SCH_SEXPR_PLUGIN_CACHE * m_cache

References SCH_SEXPR_PLUGIN_CACHE::GetModifyHash(), and m_cache.

◆ GetName()

const wxString SCH_SEXPR_PLUGIN::GetName ( ) const
inlineoverridevirtual

Returns a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 63 of file sch_sexpr_plugin.h.

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

◆ init()

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

initialize PLUGIN like a constructor would.

Definition at line 378 of file sch_sexpr_plugin.cpp.

379 {
380  m_version = 0;
381  m_rootSheet = nullptr;
382  m_props = aProperties;
383  m_schematic = aSchematic;
384  m_cache = nullptr;
385  m_out = nullptr;
386  m_fieldId = 100; // number arbitrarily > MANDATORY_FIELDS or SHEET_MANDATORY_FIELDS
387 }
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
int m_version
Version of file being loaded.
int m_fieldId
Non-mandatory schematic field ID counter.
SCH_SEXPR_PLUGIN_CACHE * m_cache
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

◆ isBuffering()

bool SCH_SEXPR_PLUGIN::isBuffering ( const PROPERTIES aProperties)
private

Definition at line 2048 of file sch_sexpr_plugin.cpp.

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

References PROPERTIES::Exists(), and PropBuffering.

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

◆ IsSymbolLibWritable()

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

Return true if the library at aLibraryPath is writable.

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 2236 of file sch_sexpr_plugin.cpp.

2237 {
2238  wxFileName fn( aLibraryPath );
2239 
2240  return ( fn.FileExists() && fn.IsFileWritable() ) || fn.IsDirWritable();
2241 }

◆ Load()

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

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 390 of file sch_sexpr_plugin.cpp.

392 {
393  wxASSERT( !aFileName || aSchematic != nullptr );
394 
395  LOCALE_IO toggle; // toggles on, then off, the C locale.
396  SCH_SHEET* sheet;
397 
398  wxFileName fn = aFileName;
399 
400  // Unfortunately child sheet file names the legacy schematic file format are not fully
401  // qualified and are always appended to the project path. The aFileName attribute must
402  // always be an absolute path so the project path can be used for load child sheet files.
403  wxASSERT( fn.IsAbsolute() );
404 
405  if( aAppendToMe )
406  {
407  wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
408  aFileName, aAppendToMe->GetFileName() );
409 
410  wxFileName normedFn = aAppendToMe->GetFileName();
411 
412  if( !normedFn.IsAbsolute() )
413  {
414  if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
415  m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
416  }
417 
418  if( m_path.IsEmpty() )
419  m_path = aSchematic->Prj().GetProjectPath();
420 
421  wxLogTrace( traceSchLegacyPlugin, "Normalized append path \"%s\".", m_path );
422  }
423  else
424  {
425  m_path = aSchematic->Prj().GetProjectPath();
426  }
427 
428  m_currentPath.push( m_path );
429  init( aSchematic, aProperties );
430 
431  if( aAppendToMe == NULL )
432  {
433  // Clean up any allocated memory if an exception occurs loading the schematic.
434  std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
435  newSheet->SetFileName( aFileName );
436  m_rootSheet = newSheet.get();
437  loadHierarchy( newSheet.get() );
438 
439  // If we got here, the schematic loaded successfully.
440  sheet = newSheet.release();
441  m_rootSheet = nullptr; // Quiet Coverity warning.
442  }
443  else
444  {
445  wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
446  m_rootSheet = &aSchematic->Root();
447  sheet = aAppendToMe;
448  loadHierarchy( sheet );
449  }
450 
451  wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
452 
453  return sheet;
454 }
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:110
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:121
#define NULL
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:498
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
SCH_SHEET & Root() const
Definition: schematic.h:96
wxString m_path
Root project path for loading child sheets.
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:79
void loadHierarchy(SCH_SHEET *aSheet)
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.

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

◆ LoadContent()

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

Definition at line 539 of file sch_sexpr_plugin.cpp.

540 {
541  wxCHECK( aSheet, /* void */ );
542 
543  LOCALE_IO toggle;
544  SCH_SEXPR_PARSER parser( &aReader );
545 
546  parser.ParseSchematic( aSheet, true, aFileVersion );
547 }
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 529 of file sch_sexpr_plugin.cpp.

530 {
531  FILE_LINE_READER reader( aFileName );
532 
533  SCH_SEXPR_PARSER parser( &reader );
534 
535  parser.ParseSchematic( aSheet );
536 }
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:181
Object to parser s-expression symbol library and schematic file formats.

References SCH_SEXPR_PARSER::ParseSchematic().

◆ loadHierarchy()

void SCH_SEXPR_PLUGIN::loadHierarchy ( SCH_SHEET aSheet)
private

Definition at line 459 of file sch_sexpr_plugin.cpp.

460 {
461  SCH_SCREEN* screen = NULL;
462 
463  if( !aSheet->GetScreen() )
464  {
465  // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
466  // stores the file name and extension. Add the project path to the file name and
467  // extension to compare when calling SCH_SHEET::SearchHierarchy().
468  wxFileName fileName = aSheet->GetFileName();
469 
470  if( !fileName.IsAbsolute() )
471  fileName.MakeAbsolute( m_currentPath.top() );
472 
473  // Save the current path so that it gets restored when decending and ascending the
474  // sheet hierarchy which allows for sheet schematic files to be nested in folders
475  // relative to the last path a schematic was loaded from.
476  wxLogTrace( traceSchLegacyPlugin, "Saving path \"%s\"", m_currentPath.top() );
477  m_currentPath.push( fileName.GetPath() );
478  wxLogTrace( traceSchLegacyPlugin, "Current path \"%s\"", m_currentPath.top() );
479  wxLogTrace( traceSchLegacyPlugin, "Loading \"%s\"", fileName.GetFullPath() );
480 
481  m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
482 
483  if( screen )
484  {
485  aSheet->SetScreen( screen );
486  aSheet->GetScreen()->SetParent( m_schematic );
487  // Do not need to load the sub-sheets - this has already been done.
488  }
489  else
490  {
491  aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
492  aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
493 
494  try
495  {
496  loadFile( fileName.GetFullPath(), aSheet );
497  }
498  catch( const IO_ERROR& ioe )
499  {
500  // If there is a problem loading the root sheet, there is no recovery.
501  if( aSheet == m_rootSheet )
502  throw( ioe );
503 
504  // For all subsheets, queue up the error message for the caller.
505  if( !m_error.IsEmpty() )
506  m_error += "\n";
507 
508  m_error += ioe.What();
509  }
510 
511  // This was moved out of the try{} block so that any sheets definitionsthat
512  // the plugin fully parsed before the exception was raised will be loaded.
513  for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
514  {
515  wxCHECK2( aItem->Type() == SCH_SHEET_T, /* do nothing */ );
516  auto sheet = static_cast<SCH_SHEET*>( aItem );
517 
518  // Recursion starts here.
519  loadHierarchy( sheet );
520  }
521  }
522 
523  m_currentPath.pop();
524  wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
525  }
526 }
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:630
wxString m_error
For throwing exceptions or errors on partial schematic loads.
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:150
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:284
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:185
#define NULL
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:498
void loadFile(const wxString &aFileName, SCH_SHEET *aSheet)
EE_RTREE & Items()
Definition: sch_screen.h:159
void loadHierarchy(SCH_SHEET *aSheet)
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:184
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

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

◆ LoadSymbol()

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 2108 of file sch_sexpr_plugin.cpp.

2110 {
2111  LOCALE_IO toggle; // toggles on, then off, the C locale.
2112 
2113  m_props = aProperties;
2114 
2115  cacheLib( aLibraryPath );
2116 
2117  LIB_PART_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
2118 
2119  if( it == m_cache->m_symbols.end() )
2120  return nullptr;
2121 
2122  return it->second;
2123 }
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 * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

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

◆ ParsePart()

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

Definition at line 2244 of file sch_sexpr_plugin.cpp.

2245 {
2246  LOCALE_IO toggle; // toggles on, then off, the C locale.
2247  LIB_PART_MAP map;
2248  SCH_SEXPR_PARSER parser( &aReader );
2249 
2250  parser.NeedLEFT();
2251  parser.NextTok();
2252 
2253  return parser.ParseSymbol( map, aFileVersion );
2254 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
std::map< wxString, LIB_PART *, LibPartMapSort > LIB_PART_MAP
Part map used by part library object.
Object to parser s-expression symbol library and schematic file formats.

References SCH_SEXPR_PARSER::ParseSymbol().

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

◆ Save()

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 550 of file sch_sexpr_plugin.cpp.

552 {
553  wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET object." );
554  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
555 
556  LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
557 
558  init( aSchematic, aProperties );
559 
560  wxFileName fn = aFileName;
561 
562  // File names should be absolute. Don't assume everything relative to the project path
563  // works properly.
564  wxASSERT( fn.IsAbsolute() );
565 
566  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
567 
568  m_out = &formatter; // no ownership
569 
570  Format( aSheet );
571 }
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
#define NULL
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:493
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.

References Format(), and NULL.

◆ saveBitmap()

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

Definition at line 1024 of file sch_sexpr_plugin.cpp.

1025 {
1026  wxCHECK_RET( aBitmap != nullptr && m_out != nullptr, "" );
1027 
1028  const wxImage* image = aBitmap->GetImage()->GetImageData();
1029 
1030  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
1031 
1032  m_out->Print( aNestLevel, "(image (at %s %s)",
1033  FormatInternalUnits( aBitmap->GetPosition().x ).c_str(),
1034  FormatInternalUnits( aBitmap->GetPosition().y ).c_str() );
1035 
1036  if( aBitmap->GetImage()->GetScale() != 1.0 )
1037  m_out->Print( 0, " (scale %g)", aBitmap->GetImage()->GetScale() );
1038 
1039  m_out->Print( 0, "\n" );
1040  m_out->Print( aNestLevel + 1, "(data" );
1041 
1042  wxMemoryOutputStream stream;
1043 
1044  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1045 
1046  // Write binary data in hexadecimal form (ASCII)
1047  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1048  wxString out = wxBase64Encode( buffer->GetBufferStart(), buffer->GetBufferSize() );
1049 
1050  // Apparently the MIME standard character width for base64 encoding is 76 (unconfirmed)
1051  // so use it in a vein attempt to be standard like.
1052 #define MIME_BASE64_LENGTH 76
1053 
1054  size_t first = 0;
1055 
1056  while( first < out.Length() )
1057  {
1058  m_out->Print( 0, "\n" );
1059  m_out->Print( aNestLevel + 2, "%s", TO_UTF8( out( first, MIME_BASE64_LENGTH ) ) );
1060  first += MIME_BASE64_LENGTH;
1061  }
1062 
1063  m_out->Print( 0, "\n" );
1064  m_out->Print( aNestLevel + 1, ")\n" ); // Closes data token.
1065  m_out->Print( aNestLevel, ")\n" ); // Closes image token.
1066 }
double GetScale() const
Definition: bitmap_base.h:92
wxImage * GetImageData()
Definition: bitmap_base.h:83
wxPoint GetPosition() const override
Definition: sch_bitmap.h:140
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
#define NULL
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:59
#define MIME_BASE64_LENGTH
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528

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

◆ saveBusAlias()

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

Definition at line 1265 of file sch_sexpr_plugin.cpp.

1266 {
1267  wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" );
1268 
1269  wxString members;
1270 
1271  for( auto member : aAlias->Members() )
1272  {
1273  if( members.IsEmpty() )
1274  members = m_out->Quotew( member );
1275  else
1276  members += " " + m_out->Quotew( member );
1277  }
1278 
1279  m_out->Print( aNestLevel, "(bus_alias %s (members %s))\n",
1280  m_out->Quotew( aAlias->GetName() ).c_str(),
1281  TO_UTF8( members ) );
1282 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
#define NULL
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

References NULL, and TO_UTF8.

◆ saveBusEntry()

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

Definition at line 1144 of file sch_sexpr_plugin.cpp.

1145 {
1146  wxCHECK_RET( aBusEntry != nullptr && m_out != nullptr, "" );
1147 
1148  // Bus to bus entries are converted to bus line segments.
1149  if( aBusEntry->GetClass() == "SCH_BUS_BUS_ENTRY" )
1150  {
1151  SCH_LINE busEntryLine( aBusEntry->GetPosition(), LAYER_BUS );
1152 
1153  busEntryLine.SetEndPoint( aBusEntry->GetEnd() );
1154  saveLine( &busEntryLine, aNestLevel );
1155  }
1156  else
1157  {
1158  m_out->Print( aNestLevel, "(bus_entry (at %s %s) (size %s %s)\n",
1159  FormatInternalUnits( aBusEntry->GetPosition().x ).c_str(),
1160  FormatInternalUnits( aBusEntry->GetPosition().y ).c_str(),
1161  FormatInternalUnits( aBusEntry->GetSize().GetWidth() ).c_str(),
1162  FormatInternalUnits( aBusEntry->GetSize().GetHeight() ).c_str() );
1163 
1164  formatStroke( m_out, aNestLevel + 1, aBusEntry->GetStroke() );
1165 
1166  m_out->Print( 0, "\n" );
1167  m_out->Print( aNestLevel, ")\n" );
1168  }
1169 }
void saveLine(SCH_LINE *aLine, int aNestLevel)
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_bus_entry.h:77
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:98
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxSize GetSize() const
Definition: sch_bus_entry.h:70
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_item.h:221
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
wxPoint GetEnd() const
wxPoint GetPosition() const override

References 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, and SCH_LINE::SetEndPoint().

◆ saveField()

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

Definition at line 977 of file sch_sexpr_plugin.cpp.

978 {
979  wxCHECK_RET( aField != nullptr && m_out != nullptr, "" );
980 
981  wxString fieldName = aField->GetName();
982 
983  // For some reason (bug in legacy parser?) the field ID for non-mandatory fields is -1 so
984  // check for this in order to correctly use the field name.
985  if( aField->GetParent()->Type() == SCH_COMPONENT_T )
986  {
987  if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
988  fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(), false );
989  }
990  else if( aField->GetParent()->Type() == SCH_SHEET_T )
991  {
992  if( aField->GetId() >= 0 && aField->GetId() < SHEET_MANDATORY_FIELDS )
993  fieldName = SCH_SHEET::GetDefaultFieldName( aField->GetId() );
994  }
995 
996  if( aField->GetId() == -1 /* undefined ID */ )
997  {
998  aField->SetId( m_fieldId );
999  m_fieldId += 1;
1000  }
1001 
1002  m_out->Print( aNestLevel, "(property %s %s (id %d) (at %s %s %s)",
1003  m_out->Quotew( fieldName ).c_str(),
1004  m_out->Quotew( aField->GetText() ).c_str(),
1005  aField->GetId(),
1006  FormatInternalUnits( aField->GetPosition().x ).c_str(),
1007  FormatInternalUnits( aField->GetPosition().y ).c_str(),
1008  FormatAngle( aField->GetTextAngleDegrees() * 10.0 ).c_str() );
1009 
1010  if( !aField->IsDefaultFormatting()
1011  || ( aField->GetTextHeight() != Mils2iu( DEFAULT_SIZE_TEXT ) ) )
1012  {
1013  m_out->Print( 0, "\n" );
1014  aField->Format( m_out, aNestLevel, 0 );
1015  m_out->Print( aNestLevel, ")\n" ); // Closes property token with font effects.
1016  }
1017  else
1018  {
1019  m_out->Print( 0, ")\n" ); // Closes property token without font effects.
1020  }
1021 }
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:80
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:71
int m_fieldId
Non-mandatory schematic field ID counter.
wxPoint GetPosition() const override
Definition: sch_field.cpp:601
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
int GetId() const
Definition: sch_field.h:114
int GetTextHeight() const
Definition: eda_text.h:251
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:557
EDA_ITEM * GetParent() const
Definition: eda_item.h:184
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:43
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:519
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
bool IsDefaultFormatting() const
Definition: eda_text.cpp:505
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
double GetTextAngleDegrees() const
Definition: eda_text.h:182
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:440
void SetId(int aId)
Definition: sch_field.cpp:74
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182

References DEFAULT_SIZE_TEXT, EDA_TEXT::Format(), FormatAngle(), FormatInternalUnits(), TEMPLATE_FIELDNAME::GetDefaultFieldName(), SCH_SHEET::GetDefaultFieldName(), SCH_FIELD::GetId(), SCH_FIELD::GetName(), EDA_ITEM::GetParent(), SCH_FIELD::GetPosition(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngleDegrees(), EDA_TEXT::GetTextHeight(), EDA_TEXT::IsDefaultFormatting(), MANDATORY_FIELDS, SCH_COMPONENT_T, SCH_SHEET_T, SCH_FIELD::SetId(), SHEET_MANDATORY_FIELDS, and EDA_ITEM::Type().

◆ saveJunction()

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

Definition at line 1119 of file sch_sexpr_plugin.cpp.

1120 {
1121  wxCHECK_RET( aJunction != nullptr && m_out != nullptr, "" );
1122 
1123  m_out->Print( aNestLevel, "(junction (at %s %s) (diameter %s) (color %d %d %d %s))\n",
1124  FormatInternalUnits( aJunction->GetPosition().x ).c_str(),
1125  FormatInternalUnits( aJunction->GetPosition().y ).c_str(),
1126  FormatInternalUnits( aJunction->GetDiameter() ).c_str(),
1127  KiROUND( aJunction->GetColor().r * 255.0 ),
1128  KiROUND( aJunction->GetColor().g * 255.0 ),
1129  KiROUND( aJunction->GetColor().b * 255.0 ),
1130  Double2Str( aJunction->GetColor().a ).c_str() );
1131 }
int GetDiameter() const
double g
Green component.
Definition: color4d.h:375
std::string Double2Str(double aValue)
Helper function Double2Str to print a float number without using scientific notation and no trailing ...
Definition: base_units.cpp:61
double b
Blue component.
Definition: color4d.h:376
COLOR4D GetColor() const
double a
Alpha component.
Definition: color4d.h:377
wxPoint GetPosition() const override
Definition: sch_junction.h:95
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
double r
Red component.
Definition: color4d.h:374
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528

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

◆ SaveLibrary()

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

Reimplemented from SCH_PLUGIN.

Definition at line 2202 of file sch_sexpr_plugin.cpp.

2203 {
2204  if( !m_cache )
2205  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
2206 
2207  wxString oldFileName = m_cache->GetFileName();
2208 
2209  if( !m_cache->IsFile( aLibraryPath ) )
2210  {
2211  m_cache->SetFileName( aLibraryPath );
2212  }
2213 
2214  // This is a forced save.
2215  m_cache->SetModified();
2216  m_cache->Save();
2217  m_cache->SetFileName( oldFileName );
2218 }
void Save()
Save the entire library to file m_libFileName;.
wxString GetFileName() const
SCH_SEXPR_PLUGIN_CACHE * m_cache
void SetFileName(const wxString &aFileName)
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PLUG...
void SetModified(bool aModified=true)
bool IsFile(const wxString &aFullPathAndFileName) const

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

◆ saveLine()

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

Definition at line 1172 of file sch_sexpr_plugin.cpp.

1173 {
1174  wxCHECK_RET( aLine != nullptr && m_out != nullptr, "" );
1175 
1176  wxString lineType;
1177 
1178  // Lines having the plot style == PLOT_DASH_TYPE::DEFAULT are saved in file
1179  // as SOLID by formatStroke().
1180  // This is incorrect for graphic lines that use the DASH style for default
1181  // So the plot style need adjustments to use the right style
1182  // (TODO perhaps use "default" as keyword for line style in .kicad_sch file)
1183  STROKE_PARAMS line_stroke = aLine->GetStroke();
1184 
1185  if( line_stroke.GetPlotStyle() == PLOT_DASH_TYPE::DEFAULT )
1186  line_stroke.SetPlotStyle( aLine->GetDefaultStyle() );
1187 
1188  switch( aLine->GetLayer() )
1189  {
1190  case LAYER_BUS: lineType = "bus"; break;
1191  case LAYER_WIRE: lineType = "wire"; break;
1192  case LAYER_NOTES:
1193  default: lineType = "polyline"; break;
1194  }
1195 
1196  m_out->Print( aNestLevel, "(%s (pts (xy %s %s) (xy %s %s))\n",
1197  TO_UTF8( lineType ),
1198  FormatInternalUnits( aLine->GetStartPoint().x ).c_str(),
1199  FormatInternalUnits( aLine->GetStartPoint().y ).c_str(),
1200  FormatInternalUnits( aLine->GetEndPoint().x ).c_str(),
1201  FormatInternalUnits( aLine->GetEndPoint().y ).c_str() );
1202 
1203  formatStroke( m_out, aNestLevel + 1, line_stroke );
1204  m_out->Print( 0, "\n" );
1205  m_out->Print( aNestLevel, ")\n" );
1206 }
wxPoint GetStartPoint() const
Definition: sch_line.h:94
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
Definition: sch_item.h:173
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:222
PLOT_DASH_TYPE GetPlotStyle() const
Definition: sch_item.h:172
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:279
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
Simple container to manage line stroke parameters.
Definition: sch_item.h:153
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:128
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
wxPoint GetEndPoint() const
Definition: sch_line.h:97

References DEFAULT, FormatInternalUnits(), formatStroke(), SCH_LINE::GetDefaultStyle(), SCH_LINE::GetEndPoint(), SCH_ITEM::GetLayer(), STROKE_PARAMS::GetPlotStyle(), SCH_LINE::GetStartPoint(), SCH_LINE::GetStroke(), LAYER_BUS, LAYER_NOTES, LAYER_WIRE, STROKE_PARAMS::SetPlotStyle(), and TO_UTF8.

◆ saveNoConnect()

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

Definition at line 1134 of file sch_sexpr_plugin.cpp.

1135 {
1136  wxCHECK_RET( aNoConnect != nullptr && m_out != nullptr, "" );
1137 
1138  m_out->Print( aNestLevel, "(no_connect (at %s %s))\n",
1139  FormatInternalUnits( aNoConnect->GetPosition().x ).c_str(),
1140  FormatInternalUnits( aNoConnect->GetPosition().y ).c_str() );
1141 }
wxPoint GetPosition() const override
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528

References FormatInternalUnits(), and SCH_NO_CONNECT::GetPosition().

◆ saveSheet()

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

Definition at line 1069 of file sch_sexpr_plugin.cpp.

1070 {
1071  wxCHECK_RET( aSheet != nullptr && m_out != nullptr, "" );
1072 
1073  m_out->Print( aNestLevel, "(sheet (at %s %s) (size %s %s)\n",
1074  FormatInternalUnits( aSheet->GetPosition().x ).c_str(),
1075  FormatInternalUnits( aSheet->GetPosition().y ).c_str(),
1076  FormatInternalUnits( aSheet->GetSize().GetWidth() ).c_str(),
1077  FormatInternalUnits( aSheet->GetSize().GetHeight() ).c_str() );
1078 
1080  aSheet->GetBorderColor() );
1081 
1082  stroke.SetWidth( aSheet->GetBorderWidth() );
1083  formatStroke( m_out, aNestLevel + 1, stroke );
1084 
1085  m_out->Print( 0, "\n" );
1086 
1087  m_out->Print( aNestLevel + 1, "(fill (color %d %d %d %0.4f))\n",
1088  KiROUND( aSheet->GetBackgroundColor().r * 255.0 ),
1089  KiROUND( aSheet->GetBackgroundColor().g * 255.0 ),
1090  KiROUND( aSheet->GetBackgroundColor().b * 255.0 ),
1091  aSheet->GetBackgroundColor().a );
1092 
1093  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSheet->m_Uuid.AsString() ) );
1094 
1096 
1097  for( SCH_FIELD& field : aSheet->GetFields() )
1098  {
1099  saveField( &field, aNestLevel + 1 );
1100  }
1101 
1102  for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
1103  {
1104  m_out->Print( aNestLevel + 1, "(pin %s %s (at %s %s %s)\n",
1105  EscapedUTF8( pin->GetText() ).c_str(),
1106  getSheetPinShapeToken( pin->GetShape() ),
1107  FormatInternalUnits( pin->GetPosition().x ).c_str(),
1108  FormatInternalUnits( pin->GetPosition().y ).c_str(),
1109  FormatAngle( getSheetPinAngle( pin->GetEdge() ) * 10.0 ).c_str() );
1110 
1111  pin->Format( m_out, aNestLevel + 1, 0 );
1112  m_out->Print( aNestLevel + 1, ")\n" ); // Closes pin token with font effects.
1113  }
1114 
1115  m_out->Print( aNestLevel, ")\n" ); // Closes sheet token.
1116 }
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
void SetWidth(int aWidth)
Definition: sch_item.h:170
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:71
int m_fieldId
Non-mandatory schematic field ID counter.
wxString AsString() const
Definition: kiid.cpp:174
double g
Green component.
Definition: color4d.h:375
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:292
void saveField(SCH_FIELD *aField, int aNestLevel)
double b
Blue component.
Definition: color4d.h:376
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:295
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:304
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:270
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:557
int GetBorderWidth() const
Definition: sch_sheet.h:289
double a
Alpha component.
Definition: color4d.h:377
static double getSheetPinAngle(SHEET_SIDE aSide)
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:85
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
wxPoint GetPosition() const override
Definition: sch_sheet.h:569
const KIID m_Uuid
Definition: eda_item.h:151
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:364
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
Simple container to manage line stroke parameters.
Definition: sch_item.h:153
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
double r
Red component.
Definition: color4d.h:374
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
wxSize GetSize()
Definition: sch_sheet.h:286
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
static const char * getSheetPinShapeToken(PINSHEETLABEL_SHAPE aShape)

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

◆ SaveSymbol()

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

Write aSymbol to an existing library located at aLibraryPath.

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 2126 of file sch_sexpr_plugin.cpp.

2128 {
2129  m_props = aProperties;
2130 
2131  cacheLib( aLibraryPath );
2132 
2133  m_cache->AddSymbol( aSymbol );
2134 
2135  if( !isBuffering( aProperties ) )
2136  m_cache->Save();
2137 }
void Save()
Save the entire library to file m_libFileName;.
SCH_SEXPR_PLUGIN_CACHE * m_cache
void AddSymbol(const LIB_PART *aPart)
void cacheLib(const wxString &aLibraryFileName)
bool isBuffering(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

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

◆ saveSymbol()

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

Definition at line 879 of file sch_sexpr_plugin.cpp.

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

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

◆ saveText()

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

Definition at line 1209 of file sch_sexpr_plugin.cpp.

1210 {
1211  wxCHECK_RET( aText != nullptr && m_out != nullptr, "" );
1212 
1213  double angle;
1214 
1215  switch( aText->GetLabelSpinStyle() )
1216  {
1217  case LABEL_SPIN_STYLE::RIGHT: angle = 0.0; break;
1218  case LABEL_SPIN_STYLE::UP: angle = 90.0; break;
1219  case LABEL_SPIN_STYLE::LEFT: angle = 180.0; break;
1220  case LABEL_SPIN_STYLE::BOTTOM: angle = 270.0; break;
1221  default: wxFAIL; angle = 0.0; break;
1222  }
1223 
1224  m_out->Print( aNestLevel, "(%s %s",
1225  getTextTypeToken( aText->Type() ),
1226  m_out->Quotew( aText->GetText() ).c_str() );
1227 
1228  if( ( aText->Type() == SCH_GLOBAL_LABEL_T ) || ( aText->Type() == SCH_HIER_LABEL_T ) )
1229  m_out->Print( 0, " (shape %s)", getSheetPinShapeToken( aText->GetShape() ) );
1230 
1231  if( ( aText->Type() == SCH_GLOBAL_LABEL_T ) )
1232  {
1233  SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( aText );
1234 
1235  if( label->GetIref() != nullptr )
1236  {
1237  SCH_IREF* iref = label->GetIref();
1238  m_out->Print( 0, " (iref %s %s)", FormatInternalUnits( iref->GetPosition().x ).c_str(),
1239  FormatInternalUnits( iref->GetPosition().y ).c_str() );
1240  }
1241  }
1242 
1243  if( aText->GetText().Length() < 50 )
1244  {
1245  m_out->Print( 0, " (at %s %s %s)",
1246  FormatInternalUnits( aText->GetPosition().x ).c_str(),
1247  FormatInternalUnits( aText->GetPosition().y ).c_str(),
1248  FormatAngle( angle * 10.0 ).c_str() );
1249  }
1250  else
1251  {
1252  m_out->Print( 0, "\n" );
1253  m_out->Print( aNestLevel + 1, "(at %s %s %s)",
1254  FormatInternalUnits( aText->GetPosition().x ).c_str(),
1255  FormatInternalUnits( aText->GetPosition().y ).c_str(),
1256  FormatAngle( aText->GetTextAngle() ).c_str() );
1257  }
1258 
1259  m_out->Print( 0, "\n" );
1260  aText->Format( m_out, aNestLevel, 0 );
1261  m_out->Print( aNestLevel, ")\n" ); // Closes text token.
1262 }
static const char * getTextTypeToken(KICAD_T aType)
double GetTextAngle() const
Definition: eda_text.h:180
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:557
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:519
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:233
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
wxPoint GetPosition() const override
Definition: sch_text.h:312
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
SCH_IREF * GetIref()
Definition: sch_text.h:422
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:528
static const char * getSheetPinShapeToken(PINSHEETLABEL_SHAPE aShape)
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:238
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182

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

◆ 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 }
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
#define _(s)
Definition: 3d_actions.cpp:33

References _.

Member Data Documentation

◆ m_cache

◆ m_currentPath

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

Stack to maintain nested sheet paths.

Definition at line 155 of file sch_sexpr_plugin.h.

◆ m_error

wxString SCH_SEXPR_PLUGIN::m_error
protected

For throwing exceptions or errors on partial schematic loads.

Definition at line 152 of file sch_sexpr_plugin.h.

Referenced by GetError().

◆ m_fieldId

int SCH_SEXPR_PLUGIN::m_fieldId
protected

Non-mandatory schematic field ID counter.

Definition at line 149 of file sch_sexpr_plugin.h.

◆ m_out

OUTPUTFORMATTER* SCH_SEXPR_PLUGIN::m_out
protected

The output formatter for saving SCH_SCREEN objects.

Definition at line 159 of file sch_sexpr_plugin.h.

◆ m_path

wxString SCH_SEXPR_PLUGIN::m_path
protected

Root project path for loading child sheets.

Definition at line 154 of file sch_sexpr_plugin.h.

◆ m_props

const PROPERTIES* SCH_SEXPR_PLUGIN::m_props
protected

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

Definition at line 156 of file sch_sexpr_plugin.h.

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

◆ m_rootSheet

SCH_SHEET* SCH_SEXPR_PLUGIN::m_rootSheet
protected

The root sheet of the schematic being loaded..

Definition at line 157 of file sch_sexpr_plugin.h.

◆ m_schematic

SCHEMATIC* SCH_SEXPR_PLUGIN::m_schematic
protected

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

Definition at line 158 of file sch_sexpr_plugin.h.

◆ m_version

int SCH_SEXPR_PLUGIN::m_version
protected

Version of file being loaded.

Definition at line 148 of file sch_sexpr_plugin.h.

◆ PropBuffering

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

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

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

Definition at line 83 of file sch_sexpr_plugin.h.

Referenced by isBuffering().


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