KiCad PCB EDA Suite
SCH_SEXPR_PLUGIN Class Reference

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

#include <sch_sexpr_plugin.h>

Inheritance diagram for SCH_SEXPR_PLUGIN:
SCH_PLUGIN

Public Member Functions

 SCH_SEXPR_PLUGIN ()
 
virtual ~SCH_SEXPR_PLUGIN ()
 
const wxString GetName () const override
 Return a brief hard coded name for this SCH_PLUGIN. More...
 
const wxString GetFileExtension () const override
 Return the file extension for the SCH_PLUGIN. More...
 
const wxString GetLibraryFileExtension () const override
 Return the library file extension for the SCH_PLUGIN object. More...
 
int GetModifyHash () const override
 Return the modification hash from the library cache. More...
 
SCH_SHEETLoad (const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr) override
 Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one. More...
 
void LoadContent (LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
 
void Save (const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr) override
 Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file. More...
 
void Format (SCH_SHEET *aSheet)
 
void Format (EE_SELECTION *aSelection, SCH_SHEET_PATH *aSheetPath, 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 SetReporter (REPORTER *aReporter)
 Set an optional reporter for warnings/errors. More...
 
virtual void SymbolLibOptions (PROPERTIES *aListToAppendTo) const
 Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Static Public Member Functions

static LIB_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_nextFreeFieldId
 
wxString m_error
 For throwing exceptions or errors on partial 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...
 
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, SCH_SHEET_PATH *aSheetPath, int aNestLevel)
 
void saveField (SCH_FIELD *aField, int aNestLevel)
 
void saveBitmap (SCH_BITMAP *aBitmap, int aNestLevel)
 
void saveSheet (SCH_SHEET *aSheet, int aNestLevel)
 
void saveJunction (SCH_JUNCTION *aJunction, int aNestLevel)
 
void saveNoConnect (SCH_NO_CONNECT *aNoConnect, int aNestLevel)
 
void saveBusEntry (SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
 
void saveLine (SCH_LINE *aLine, int aNestLevel)
 
void saveText (SCH_TEXT *aText, int aNestLevel)
 
void saveBusAlias (std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
 
void cacheLib (const wxString &aLibraryFileName, const PROPERTIES *aProperties)
 
bool isBuffering (const PROPERTIES *aProperties)
 

Detailed Description

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

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

Definition at line 56 of file sch_sexpr_plugin.h.

Constructor & Destructor Documentation

◆ SCH_SEXPR_PLUGIN()

SCH_SEXPR_PLUGIN::SCH_SEXPR_PLUGIN ( )

Definition at line 367 of file sch_sexpr_plugin.cpp.

368 {
369  init( NULL );
370 }
#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 373 of file sch_sexpr_plugin.cpp.

374 {
375  delete m_cache;
376 }
SCH_SEXPR_PLUGIN_CACHE * m_cache

Member Function Documentation

◆ cacheLib()

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

Definition at line 2086 of file sch_sexpr_plugin.cpp.

2087 {
2088  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
2089  {
2090  // a spectacular episode in memory management:
2091  delete m_cache;
2092  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryFileName );
2093 
2094  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
2095  // to modify the hash value that indicate component to symbol links
2096  // must be updated.
2098 
2099  if( !isBuffering( aProperties ) )
2100  m_cache->Load();
2101  }
2102 }
SCH_SEXPR_PLUGIN_CACHE * m_cache
static void IncrementModifyGeneration()
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)

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

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

◆ CheckHeader()

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

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

Parameters
aFileNameis the name of the file to use as input

Reimplemented from SCH_PLUGIN.

Definition at line 2272 of file sch_sexpr_plugin.cpp.

2273 {
2274  // Open file and check first line
2275  wxTextFile tempFile;
2276 
2277  tempFile.Open( aFileName );
2278  wxString firstline;
2279  // read the first line
2280  firstline = tempFile.GetFirstLine();
2281  tempFile.Close();
2282 
2283  return firstline.StartsWith( "EESchema" );
2284 }

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

2209 {
2210  if( wxFileExists( aLibraryPath ) )
2211  {
2213  _( "symbol library \"%s\" already exists, cannot create a new library" ),
2214  aLibraryPath.GetData() ) );
2215  }
2216 
2217  LOCALE_IO toggle;
2218 
2219  delete m_cache;
2220  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
2221  m_cache->SetModified();
2222  m_cache->Save();
2223  m_cache->Load(); // update m_writable and m_mod_time
2224 }
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, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define _(s)
Definition: 3d_actions.cpp:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

◆ DeleteSymbol()

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

Delete the entire LIB_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 2193 of file sch_sexpr_plugin.cpp.

2195 {
2196  LOCALE_IO toggle; // toggles on, then off, the C locale.
2197 
2198  cacheLib( aLibraryPath, aProperties );
2199 
2200  m_cache->DeleteSymbol( aSymbolName );
2201 
2202  if( !isBuffering( aProperties ) )
2203  m_cache->Save();
2204 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void Save()
Save the entire library to file m_libFileName;.
SCH_SEXPR_PLUGIN_CACHE * m_cache
void DeleteSymbol(const wxString &aName)
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)
bool isBuffering(const PROPERTIES *aProperties)

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

◆ DeleteSymbolLib()

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 2227 of file sch_sexpr_plugin.cpp.

2229 {
2230  wxFileName fn = aLibraryPath;
2231 
2232  if( !fn.FileExists() )
2233  return false;
2234 
2235  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2236  // we don't want that. we want bare metal portability with no UI here.
2237  if( wxRemove( aLibraryPath ) )
2238  {
2239  THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
2240  aLibraryPath.GetData() ) );
2241  }
2242 
2243  if( m_cache && m_cache->IsFile( aLibraryPath ) )
2244  {
2245  delete m_cache;
2246  m_cache = 0;
2247  }
2248 
2249  return true;
2250 }
SCH_SEXPR_PLUGIN_CACHE * m_cache
bool IsFile(const wxString &aFullPathAndFileName) const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define _(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 2121 of file sch_sexpr_plugin.cpp.

2124 {
2125  LOCALE_IO toggle; // toggles on, then off, the C locale.
2126 
2127  bool powerSymbolsOnly = ( aProperties &&
2128  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2129 
2130  cacheLib( aLibraryPath, aProperties );
2131 
2132  const LIB_PART_MAP& symbols = m_cache->m_symbols;
2133 
2134  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2135  {
2136  if( !powerSymbolsOnly || it->second->IsPower() )
2137  aSymbolNameList.Add( it->first );
2138  }
2139 }
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 *aProperties)
static const char * PropPowerSymsOnly

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

◆ EnumerateSymbolLib() [2/2]

void SCH_SEXPR_PLUGIN::EnumerateSymbolLib ( std::vector< LIB_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 responsibility of the caller to delete the returned object from the heap. Failure to do this will result in memory leaks.
Parameters
aSymbolListis an array to populate with the LIB_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 2142 of file sch_sexpr_plugin.cpp.

2145 {
2146  LOCALE_IO toggle; // toggles on, then off, the C locale.
2147 
2148  bool powerSymbolsOnly = ( aProperties &&
2149  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2150 
2151  cacheLib( aLibraryPath, aProperties );
2152 
2153  const LIB_PART_MAP& symbols = m_cache->m_symbols;
2154 
2155  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2156  {
2157  if( !powerSymbolsOnly || it->second->IsPower() )
2158  aSymbolList.push_back( it->second );
2159  }
2160 }
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 *aProperties)
static const char * PropPowerSymsOnly

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

◆ Format() [1/2]

void SCH_SEXPR_PLUGIN::Format ( SCH_SHEET aSheet)

Definition at line 579 of file sch_sexpr_plugin.cpp.

580 {
581  wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET* object." );
582  wxCHECK_RET( m_schematic != NULL, "NULL SCHEMATIC* object." );
583 
584  SCH_SCREEN* screen = aSheet->GetScreen();
585 
586  wxCHECK( screen, /* void */ );
587 
588  m_out->Print( 0, "(kicad_sch (version %d) (generator eeschema)\n\n",
590 
591  m_out->Print( 1, "(uuid %s)\n\n", TO_UTF8( screen->m_uuid.AsString() ) );
592 
593  screen->GetPageSettings().Format( m_out, 1, 0 );
594  m_out->Print( 0, "\n" );
595  screen->GetTitleBlock().Format( m_out, 1, 0 );
596 
597  // Save cache library.
598  m_out->Print( 1, "(lib_symbols\n" );
599 
600  for( auto libSymbol : screen->GetLibSymbols() )
601  SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( libSymbol.second, *m_out, 2, libSymbol.first );
602 
603  m_out->Print( 1, ")\n\n" );
604 
605  for( const auto& alias : screen->GetBusAliases() )
606  {
607  saveBusAlias( alias, 1 );
608  }
609 
610  // Enforce item ordering
611  auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b )
612  {
613  return *a < *b;
614  };
615 
616  std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
617 
618  for( SCH_ITEM* item : screen->Items() )
619  save_map.insert( item );
620 
621  KICAD_T itemType = TYPE_NOT_INIT;
623 
624  for( SCH_ITEM* item : save_map )
625  {
626  if( itemType != item->Type() )
627  {
628  itemType = item->Type();
629 
630  if( itemType != SCH_COMPONENT_T
631  && itemType != SCH_JUNCTION_T
632  && itemType != SCH_SHEET_T )
633  m_out->Print( 0, "\n" );
634  }
635 
636  switch( item->Type() )
637  {
638  case SCH_COMPONENT_T:
639  m_out->Print( 0, "\n" );
640  saveSymbol( static_cast<SCH_COMPONENT*>( item ), nullptr, 1 );
641  break;
642 
643  case SCH_BITMAP_T:
644  saveBitmap( static_cast<SCH_BITMAP*>( item ), 1 );
645  break;
646 
647  case SCH_SHEET_T:
648  m_out->Print( 0, "\n" );
649  saveSheet( static_cast<SCH_SHEET*>( item ), 1 );
650  break;
651 
652  case SCH_JUNCTION_T:
653  saveJunction( static_cast<SCH_JUNCTION*>( item ), 1 );
654  break;
655 
656  case SCH_NO_CONNECT_T:
657  saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ), 1 );
658  break;
659 
661  case SCH_BUS_BUS_ENTRY_T:
662  saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ), 1 );
663  break;
664 
665  case SCH_LINE_T:
666  if( layer != item->GetLayer() )
667  {
668  if( layer == SCH_LAYER_ID_START )
669  {
670  layer = item->GetLayer();
671  }
672  else
673  {
674  layer = item->GetLayer();
675  m_out->Print( 0, "\n" );
676  }
677  }
678 
679  saveLine( static_cast<SCH_LINE*>( item ), 1 );
680  break;
681 
682  case SCH_TEXT_T:
683  case SCH_LABEL_T:
684  case SCH_GLOBAL_LABEL_T:
685  case SCH_HIER_LABEL_T:
686  saveText( static_cast<SCH_TEXT*>( item ), 1 );
687  break;
688 
689  default:
690  wxASSERT( "Unexpected schematic object type in SCH_SEXPR_PLUGIN::Format()" );
691  }
692  }
693 
694  // If this is the root sheet, save all of the sheet paths.
695  if( aSheet->IsRootSheet() )
696  {
697  SCH_SHEET_LIST sheetPaths( aSheet, true );
698 
699  m_out->Print( 0, "\n" );
700  m_out->Print( 1, "(sheet_instances\n" );
701 
702  for( const SCH_SHEET_PATH& sheetPath : sheetPaths )
703  {
704  SCH_SHEET* sheet = sheetPath.Last();
705 
706  wxCHECK2( sheet, continue );
707 
708  m_out->Print( 2, "(path %s (page %s))\n",
709  m_out->Quotew( sheetPath.PathAsString() ).c_str(),
710  m_out->Quotew( sheet->GetPageNumber( sheetPath ) ).c_str() );
711  }
712 
713  m_out->Print( 1, ")\n" ); // Close sheet instances token.
714  m_out->Print( 0, "\n" );
715  m_out->Print( 1, "(symbol_instances\n" );
716 
717  for( const SCH_SHEET_PATH& sheetPath : sheetPaths )
718  {
719  SCH_REFERENCE_LIST instances;
720 
721  sheetPath.GetSymbols( instances, true, true );
722  instances.SortByReferenceOnly();
723 
724  for( size_t i = 0; i < instances.GetCount(); i++ )
725  {
726  m_out->Print( 2, "(path %s\n",
727  m_out->Quotew( instances[i].GetPath() ).c_str() );
728  m_out->Print( 3, "(reference %s) (unit %d) (value %s) (footprint %s)\n",
729  m_out->Quotew( instances[i].GetRef() ).c_str(),
730  instances[i].GetUnit(),
731  m_out->Quotew( instances[i].GetValue() ).c_str(),
732  m_out->Quotew( instances[i].GetFootprint() ).c_str() );
733  m_out->Print( 2, ")\n" );
734  }
735  }
736 
737  m_out->Print( 1, ")\n" ); // Close symbol instances token.
738  }
739  else
740  {
741  // Schematic files (SCH_SCREEN objects) can be shared so we have to save and restore
742  // symbol and sheet instance data even if the file being saved is not the root sheet
743  // because it is possible that the file is the root sheet of another project.
744  if( screen->m_sheetInstances.size() )
745  {
746  m_out->Print( 0, "\n" );
747  m_out->Print( 1, "(sheet_instances\n" );
748 
749  for( const SCH_SHEET_INSTANCE& instance : screen->m_sheetInstances )
750  {
751  m_out->Print( 2, "(path %s (page %s))\n",
752  m_out->Quotew( instance.m_Path.AsString() ).c_str(),
753  m_out->Quotew( instance.m_PageNumber ).c_str() );
754  }
755 
756  m_out->Print( 1, ")\n" ); // Close sheet instances token.
757  }
758 
759  if( screen->m_symbolInstances.size() )
760  {
761  m_out->Print( 0, "\n" );
762  m_out->Print( 1, "(symbol_instances\n" );
763 
764  for( const SYMBOL_INSTANCE_REFERENCE& instance : screen->m_symbolInstances )
765  {
766  m_out->Print( 2, "(path %s (reference %s) (unit %d))\n",
767  m_out->Quotew( instance.m_Path.AsString() ).c_str(),
768  m_out->Quotew( instance.m_Reference ).c_str(),
769  instance.m_Unit );
770  }
771 
772  m_out->Print( 1, ")\n" ); // Close instances token.
773  }
774  }
775 
776  m_out->Print( 0, ")\n" );
777 }
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)
std::vector< SYMBOL_INSTANCE_REFERENCE > m_symbolInstances
The list of symbol instances loaded from the schematic file.
Definition: sch_screen.h:527
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
void saveText(SCH_TEXT *aText, int aNestLevel)
wxString AsString() const
Definition: kiid.cpp:218
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:138
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the page class to aFormatter in s-expression form.
Definition: page_info.cpp:271
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:128
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:416
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
#define NULL
std::vector< SCH_SHEET_INSTANCE > m_sheetInstances
Definition: sch_screen.h:528
bool IsRootSheet() const
Definition: sch_sheet.cpp:188
A simple container for schematic symbol instance information.
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: title_block.cpp:29
SCH_LAYER_ID
Eeschema drawing layers.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
unsigned GetCount() const
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
std::unordered_set< std::shared_ptr< BUS_ALIAS > > GetBusAliases() const
Return a list of bus aliases defined in this screen.
Definition: sch_screen.h:446
A simple container for sheet instance information.
void SortByReferenceOnly()
Sort the list of references by reference.
KIID m_uuid
A unique identifier for each schematic file.
Definition: sch_screen.h:536
wxString AsString() const
Definition: kiid.cpp:256
EE_RTREE & Items()
Definition: sch_screen.h:103
void saveSheet(SCH_SHEET *aSheet, int aNestLevel)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write 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:197
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1117
void saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)
void saveSymbol(SCH_COMPONENT *aComponent, SCH_SHEET_PATH *aSheetPath, int aNestLevel)
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:476

References KIID::AsString(), KIID_PATH::AsString(), TITLE_BLOCK::Format(), PAGE_INFO::Format(), SCH_SCREEN::GetBusAliases(), SCH_REFERENCE_LIST::GetCount(), SCH_SCREEN::GetLibSymbols(), SCH_SHEET::GetPageNumber(), SCH_SCREEN::GetPageSettings(), SCH_SHEET::GetScreen(), SCH_SCREEN::GetTitleBlock(), SCH_SHEET::IsRootSheet(), SCH_SCREEN::Items(), SCH_SHEET_INSTANCE::m_PageNumber, SYMBOL_INSTANCE_REFERENCE::m_Path, SCH_SHEET_INSTANCE::m_Path, SYMBOL_INSTANCE_REFERENCE::m_Reference, SCH_SCREEN::m_sheetInstances, SCH_SCREEN::m_symbolInstances, SYMBOL_INSTANCE_REFERENCE::m_Unit, SCH_SCREEN::m_uuid, 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(), TO_UTF8, and TYPE_NOT_INIT.

Referenced by SCH_EDITOR_CONTROL::doCopy().

◆ Format() [2/2]

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

Definition at line 780 of file sch_sexpr_plugin.cpp.

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

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

2309 {
2310 
2311  LOCALE_IO toggle; // toggles on, then off, the C locale.
2312  SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( part, formatter );
2313 }
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 SYMBOL_EDITOR_EDIT_TOOL::Copy(), and SYMBOL_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 124 of file sch_sexpr_plugin.h.

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

References m_error.

◆ GetFileExtension()

const wxString SCH_SEXPR_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Return the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 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 2111 of file sch_sexpr_plugin.cpp.

2112 {
2113  if( m_cache )
2114  return m_cache->GetModifyHash();
2115 
2116  // If the cache hasn't been loaded, it hasn't been modified.
2117  return 0;
2118 }
SCH_SEXPR_PLUGIN_CACHE * m_cache

References SCH_SEXPR_PLUGIN_CACHE::GetModifyHash(), and m_cache.

◆ GetName()

const wxString SCH_SEXPR_PLUGIN::GetName ( ) const
inlineoverridevirtual

Return a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 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 379 of file sch_sexpr_plugin.cpp.

380 {
381  m_version = 0;
382  m_rootSheet = nullptr;
383  m_schematic = aSchematic;
384  m_cache = nullptr;
385  m_out = nullptr;
386  m_nextFreeFieldId = 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.
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.

◆ isBuffering()

bool SCH_SEXPR_PLUGIN::isBuffering ( const PROPERTIES aProperties)
private

Definition at line 2105 of file sch_sexpr_plugin.cpp.

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

References PROPERTIES::Exists(), and PropBuffering.

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

◆ IsSymbolLibWritable()

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

Return true if the library at aLibraryPath is writable.

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 2287 of file sch_sexpr_plugin.cpp.

2288 {
2289  wxFileName fn( aLibraryPath );
2290 
2291  return ( fn.FileExists() && fn.IsFileWritable() ) || fn.IsDirWritable();
2292 }

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

391 {
392  wxASSERT( !aFileName || aSchematic != nullptr );
393 
394  LOCALE_IO toggle; // toggles on, then off, the C locale.
395  SCH_SHEET* sheet;
396 
397  wxFileName fn = aFileName;
398 
399  // Unfortunately child sheet file names the legacy schematic file format are not fully
400  // qualified and are always appended to the project path. The aFileName attribute must
401  // always be an absolute path so the project path can be used for load child sheet files.
402  wxASSERT( fn.IsAbsolute() );
403 
404  if( aAppendToMe )
405  {
406  wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
407  aFileName, aAppendToMe->GetFileName() );
408 
409  wxFileName normedFn = aAppendToMe->GetFileName();
410 
411  if( !normedFn.IsAbsolute() )
412  {
413  if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
414  m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
415  }
416 
417  if( m_path.IsEmpty() )
418  m_path = aSchematic->Prj().GetProjectPath();
419 
420  wxLogTrace( traceSchLegacyPlugin, "Normalized append path \"%s\".", m_path );
421  }
422  else
423  {
424  m_path = aSchematic->Prj().GetProjectPath();
425  }
426 
427  m_currentPath.push( m_path );
428  init( aSchematic, aProperties );
429 
430  if( aAppendToMe == NULL )
431  {
432  // Clean up any allocated memory if an exception occurs loading the schematic.
433  std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
434 
435  wxFileName relPath( aFileName );
436  // Do not use wxPATH_UNIX as option in MakeRelativeTo(). It can create incorrect
437  // relative paths on Windows, because paths have a disk identifier (C:, D: ...)
438  relPath.MakeRelativeTo( aSchematic->Prj().GetProjectPath() );
439 
440  newSheet->SetFileName( relPath.GetFullPath() );
441  m_rootSheet = newSheet.get();
442  loadHierarchy( newSheet.get() );
443 
444  // If we got here, the schematic loaded successfully.
445  sheet = newSheet.release();
446  m_rootSheet = nullptr; // Quiet Coverity warning.
447  }
448  else
449  {
450  wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
451  m_rootSheet = &aSchematic->Root();
452  sheet = aAppendToMe;
453  loadHierarchy( sheet );
454  }
455 
456  wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
457 
458  return sheet;
459 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:108
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:123
#define NULL
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:315
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
SCH_SHEET & Root() const
Definition: schematic.h:92
wxString m_path
Root project path for loading child sheets.
void loadHierarchy(SCH_SHEET *aSheet)
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.

References SCH_SHEET::GetFileName(), PROJECT::GetProjectPath(), 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 544 of file sch_sexpr_plugin.cpp.

545 {
546  wxCHECK( aSheet, /* void */ );
547 
548  LOCALE_IO toggle;
549  SCH_SEXPR_PARSER parser( &aReader );
550 
551  parser.ParseSchematic( aSheet, true, aFileVersion );
552 }
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 534 of file sch_sexpr_plugin.cpp.

535 {
536  FILE_LINE_READER reader( aFileName );
537 
538  SCH_SEXPR_PARSER parser( &reader );
539 
540  parser.ParseSchematic( aSheet );
541 }
A LINE_READER that reads from an open file.
Definition: richio.h:172
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 464 of file sch_sexpr_plugin.cpp.

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

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

2165 {
2166  LOCALE_IO toggle; // toggles on, then off, the C locale.
2167 
2168  cacheLib( aLibraryPath, aProperties );
2169 
2170  LIB_PART_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
2171 
2172  if( it == m_cache->m_symbols.end() )
2173  return nullptr;
2174 
2175  return it->second;
2176 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
SCH_SEXPR_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)

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

◆ ParsePart()

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

Definition at line 2295 of file sch_sexpr_plugin.cpp.

2296 {
2297  LOCALE_IO toggle; // toggles on, then off, the C locale.
2298  LIB_PART_MAP map;
2299  SCH_SEXPR_PARSER parser( &aReader );
2300 
2301  parser.NeedLEFT();
2302  parser.NextTok();
2303 
2304  return parser.ParseSymbol( map, aFileVersion );
2305 }
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 SYMBOL_EDIT_FRAME::DuplicatePart(), and SYMBOL_EDITOR_EDIT_TOOL::Paste().

◆ Save()

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 555 of file sch_sexpr_plugin.cpp.

557 {
558  wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET object." );
559  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
560 
561  LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
562 
563  init( aSchematic, aProperties );
564 
565  wxFileName fn = aFileName;
566 
567  // File names should be absolute. Don't assume everything relative to the project path
568  // works properly.
569  wxASSERT( fn.IsAbsolute() );
570 
571  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
572 
573  m_out = &formatter; // no ownership
574 
575  Format( aSheet );
576 }
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.
Used for text file output.
Definition: richio.h:453
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 1043 of file sch_sexpr_plugin.cpp.

1044 {
1045  wxCHECK_RET( aBitmap != nullptr && m_out != nullptr, "" );
1046 
1047  const wxImage* image = aBitmap->GetImage()->GetImageData();
1048 
1049  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
1050 
1051  m_out->Print( aNestLevel, "(image (at %s %s)",
1052  FormatInternalUnits( aBitmap->GetPosition().x ).c_str(),
1053  FormatInternalUnits( aBitmap->GetPosition().y ).c_str() );
1054 
1055  if( aBitmap->GetImage()->GetScale() != 1.0 )
1056  m_out->Print( 0, " (scale %g)", aBitmap->GetImage()->GetScale() );
1057 
1058  m_out->Print( 0, "\n" );
1059 
1060  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aBitmap->m_Uuid.AsString() ) );
1061 
1062  m_out->Print( aNestLevel + 1, "(data" );
1063 
1064  wxMemoryOutputStream stream;
1065 
1066  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1067 
1068  // Write binary data in hexadecimal form (ASCII)
1069  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1070  wxString out = wxBase64Encode( buffer->GetBufferStart(), buffer->GetBufferSize() );
1071 
1072  // Apparently the MIME standard character width for base64 encoding is 76 (unconfirmed)
1073  // so use it in a vein attempt to be standard like.
1074 #define MIME_BASE64_LENGTH 76
1075 
1076  size_t first = 0;
1077 
1078  while( first < out.Length() )
1079  {
1080  m_out->Print( 0, "\n" );
1081  m_out->Print( aNestLevel + 2, "%s", TO_UTF8( out( first, MIME_BASE64_LENGTH ) ) );
1082  first += MIME_BASE64_LENGTH;
1083  }
1084 
1085  m_out->Print( 0, "\n" );
1086  m_out->Print( aNestLevel + 1, ")\n" ); // Closes data token.
1087  m_out->Print( aNestLevel, ")\n" ); // Closes image token.
1088 }
double GetScale() const
Definition: bitmap_base.h:79
wxImage * GetImageData()
Definition: bitmap_base.h:70
wxString AsString() const
Definition: kiid.cpp:218
wxPoint GetPosition() const override
Definition: sch_bitmap.h:136
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
#define NULL
BITMAP_BASE * GetImage() const
Definition: sch_bitmap.h:54
#define MIME_BASE64_LENGTH
const KIID m_Uuid
Definition: eda_item.h:525
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:471

References KIID::AsString(), FormatInternalUnits(), SCH_BITMAP::GetImage(), BITMAP_BASE::GetImageData(), SCH_BITMAP::GetPosition(), BITMAP_BASE::GetScale(), image, EDA_ITEM::m_Uuid, 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 1302 of file sch_sexpr_plugin.cpp.

1303 {
1304  wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" );
1305 
1306  wxString members;
1307 
1308  for( auto member : aAlias->Members() )
1309  {
1310  if( members.IsEmpty() )
1311  members = m_out->Quotew( member );
1312  else
1313  members += " " + m_out->Quotew( member );
1314  }
1315 
1316  m_out->Print( aNestLevel, "(bus_alias %s (members %s))\n",
1317  m_out->Quotew( aAlias->GetName() ).c_str(),
1318  TO_UTF8( members ) );
1319 }
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
#define NULL
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:476

References NULL, and TO_UTF8.

◆ saveBusEntry()

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

Definition at line 1175 of file sch_sexpr_plugin.cpp.

1176 {
1177  wxCHECK_RET( aBusEntry != nullptr && m_out != nullptr, "" );
1178 
1179  // Bus to bus entries are converted to bus line segments.
1180  if( aBusEntry->GetClass() == "SCH_BUS_BUS_ENTRY" )
1181  {
1182  SCH_LINE busEntryLine( aBusEntry->GetPosition(), LAYER_BUS );
1183 
1184  busEntryLine.SetEndPoint( aBusEntry->GetEnd() );
1185  saveLine( &busEntryLine, aNestLevel );
1186  }
1187  else
1188  {
1189  m_out->Print( aNestLevel, "(bus_entry (at %s %s) (size %s %s)\n",
1190  FormatInternalUnits( aBusEntry->GetPosition().x ).c_str(),
1191  FormatInternalUnits( aBusEntry->GetPosition().y ).c_str(),
1192  FormatInternalUnits( aBusEntry->GetSize().GetWidth() ).c_str(),
1193  FormatInternalUnits( aBusEntry->GetSize().GetHeight() ).c_str() );
1194 
1195  formatStroke( m_out, aNestLevel + 1, aBusEntry->GetStroke() );
1196 
1197  m_out->Print( 0, "\n" );
1198 
1199  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aBusEntry->m_Uuid.AsString() ) );
1200 
1201  m_out->Print( aNestLevel, ")\n" );
1202  }
1203 }
void saveLine(SCH_LINE *aLine, int aNestLevel)
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_bus_entry.h:69
wxString AsString() const
Definition: kiid.cpp:218
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
const KIID m_Uuid
Definition: eda_item.h:525
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxSize GetSize() const
Definition: sch_bus_entry.h:63
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
virtual wxString GetClass() const override
Return the class name.
Definition: sch_item.h:206
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write 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:471
wxPoint GetEnd() const
wxPoint GetPosition() const override

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

◆ saveField()

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

Definition at line 992 of file sch_sexpr_plugin.cpp.

993 {
994  wxCHECK_RET( aField != nullptr && m_out != nullptr, "" );
995 
996  wxString fieldName = aField->GetName();
997 
998  // For some reason (bug in legacy parser?) the field ID for non-mandatory fields is -1 so
999  // check for this in order to correctly use the field name.
1000  if( aField->GetParent()->Type() == SCH_COMPONENT_T )
1001  {
1002  if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
1003  fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(), false );
1004  }
1005  else if( aField->GetParent()->Type() == SCH_SHEET_T )
1006  {
1007  if( aField->GetId() >= 0 && aField->GetId() < SHEET_MANDATORY_FIELDS )
1008  fieldName = SCH_SHEET::GetDefaultFieldName( aField->GetId() );
1009  }
1010 
1011  if( aField->GetId() == -1 /* undefined ID */ )
1012  {
1013  aField->SetId( m_nextFreeFieldId );
1014  m_nextFreeFieldId += 1;
1015  }
1016  else if( aField->GetId() >= m_nextFreeFieldId )
1017  {
1018  m_nextFreeFieldId = aField->GetId() + 1;
1019  }
1020 
1021  m_out->Print( aNestLevel, "(property %s %s (id %d) (at %s %s %s)",
1022  m_out->Quotew( fieldName ).c_str(),
1023  m_out->Quotew( aField->GetText() ).c_str(),
1024  aField->GetId(),
1025  FormatInternalUnits( aField->GetPosition().x ).c_str(),
1026  FormatInternalUnits( aField->GetPosition().y ).c_str(),
1027  FormatAngle( aField->GetTextAngleDegrees() * 10.0 ).c_str() );
1028 
1029  if( !aField->IsDefaultFormatting()
1030  || ( aField->GetTextHeight() != Mils2iu( DEFAULT_SIZE_TEXT ) ) )
1031  {
1032  m_out->Print( 0, "\n" );
1033  aField->Format( m_out, aNestLevel, 0 );
1034  m_out->Print( aNestLevel, ")\n" ); // Closes property token with font effects.
1035  }
1036  else
1037  {
1038  m_out->Print( 0, ")\n" ); // Closes property token without font effects.
1039  }
1040 }
#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:47
wxPoint GetPosition() const override
Definition: sch_field.cpp:684
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:506
EDA_ITEM * GetParent() const
Definition: eda_item.h:165
static const wxString GetDefaultFieldName(int aFieldNdx)
Definition: sch_sheet.cpp:46
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:516
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
bool IsDefaultFormatting() const
Definition: eda_text.cpp:502
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
double GetTextAngleDegrees() const
Definition: eda_text.h:183
wxString GetName(bool aUseDefaultName=true) const
Return the field name.
Definition: sch_field.cpp:519
void SetId(int aId)
Definition: sch_field.cpp:80
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp: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:471
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:476

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

1150 {
1151  wxCHECK_RET( aJunction != nullptr && m_out != nullptr, "" );
1152 
1153  m_out->Print( aNestLevel, "(junction (at %s %s) (diameter %s) (color %d %d %d %s))\n",
1154  FormatInternalUnits( aJunction->GetPosition().x ).c_str(),
1155  FormatInternalUnits( aJunction->GetPosition().y ).c_str(),
1156  FormatInternalUnits( aJunction->GetDiameter() ).c_str(),
1157  KiROUND( aJunction->GetColor().r * 255.0 ),
1158  KiROUND( aJunction->GetColor().g * 255.0 ),
1159  KiROUND( aJunction->GetColor().b * 255.0 ),
1160  Double2Str( aJunction->GetColor().a ).c_str() );
1161 }
int GetDiameter() const
double g
Green component.
Definition: color4d.h:359
double b
Blue component.
Definition: color4d.h:360
COLOR4D GetColor() const
Definition: sch_junction.h:102
double a
Alpha component.
Definition: color4d.h:361
wxPoint GetPosition() const override
Definition: sch_junction.h:92
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:358
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write 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:471
std::string Double2Str(double aValue)
Prints a float number without using scientific notation and no trailing 0 We want to avoid scientific...
Definition: string.cpp:872

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

2254 {
2255  if( !m_cache )
2256  m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
2257 
2258  wxString oldFileName = m_cache->GetFileName();
2259 
2260  if( !m_cache->IsFile( aLibraryPath ) )
2261  {
2262  m_cache->SetFileName( aLibraryPath );
2263  }
2264 
2265  // This is a forced save.
2266  m_cache->SetModified();
2267  m_cache->Save();
2268  m_cache->SetFileName( oldFileName );
2269 }
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 1206 of file sch_sexpr_plugin.cpp.

1207 {
1208  wxCHECK_RET( aLine != nullptr && m_out != nullptr, "" );
1209 
1210  wxString lineType;
1211 
1212  // Lines having the plot style == PLOT_DASH_TYPE::DEFAULT are saved in file
1213  // as SOLID by formatStroke().
1214  // This is incorrect for graphic lines that use the DASH style for default
1215  // So the plot style need adjustments to use the right style
1216  // (TODO perhaps use "default" as keyword for line style in .kicad_sch file)
1217  STROKE_PARAMS line_stroke = aLine->GetStroke();
1218 
1219  if( line_stroke.GetPlotStyle() == PLOT_DASH_TYPE::DEFAULT )
1220  line_stroke.SetPlotStyle( aLine->GetDefaultStyle() );
1221 
1222  switch( aLine->GetLayer() )
1223  {
1224  case LAYER_BUS: lineType = "bus"; break;
1225  case LAYER_WIRE: lineType = "wire"; break;
1226  case LAYER_NOTES:
1227  default: lineType = "polyline"; break;
1228  }
1229 
1230  m_out->Print( aNestLevel, "(%s (pts (xy %s %s) (xy %s %s))\n",
1231  TO_UTF8( lineType ),
1232  FormatInternalUnits( aLine->GetStartPoint().x ).c_str(),
1233  FormatInternalUnits( aLine->GetStartPoint().y ).c_str(),
1234  FormatInternalUnits( aLine->GetEndPoint().x ).c_str(),
1235  FormatInternalUnits( aLine->GetEndPoint().y ).c_str() );
1236 
1237  formatStroke( m_out, aNestLevel + 1, line_stroke );
1238  m_out->Print( 0, "\n" );
1239 
1240  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aLine->m_Uuid.AsString() ) );
1241 
1242  m_out->Print( aNestLevel, ")\n" );
1243 }
wxPoint GetStartPoint() const
Definition: sch_line.h:90
wxString AsString() const
Definition: kiid.cpp:218
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
Definition: sch_item.h:171
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:224
PLOT_DASH_TYPE GetPlotStyle() const
Definition: sch_item.h:170
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
const KIID m_Uuid
Definition: eda_item.h:525
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:272
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
Simple container to manage line stroke parameters.
Definition: sch_item.h:155
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:124
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write 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:471
wxPoint GetEndPoint() const
Definition: sch_line.h:93

References KIID::AsString(), 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, EDA_ITEM::m_Uuid, STROKE_PARAMS::SetPlotStyle(), and TO_UTF8.

◆ saveNoConnect()

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

Definition at line 1164 of file sch_sexpr_plugin.cpp.

1165 {
1166  wxCHECK_RET( aNoConnect != nullptr && m_out != nullptr, "" );
1167 
1168  m_out->Print( aNestLevel, "(no_connect (at %s %s) (uuid %s))\n",
1169  FormatInternalUnits( aNoConnect->GetPosition().x ).c_str(),
1170  FormatInternalUnits( aNoConnect->GetPosition().y ).c_str(),
1171  TO_UTF8( aNoConnect->m_Uuid.AsString() ) );
1172 }
wxPoint GetPosition() const override
wxString AsString() const
Definition: kiid.cpp:218
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
const KIID m_Uuid
Definition: eda_item.h:525
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from internal units to a string appropriate for writing ...
Definition: base_units.cpp:471

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

◆ saveSheet()

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

Definition at line 1091 of file sch_sexpr_plugin.cpp.

1092 {
1093  wxCHECK_RET( aSheet != nullptr && m_out != nullptr, "" );
1094 
1095  m_out->Print( aNestLevel, "(sheet (at %s %s) (size %s %s)",
1096  FormatInternalUnits( aSheet->GetPosition().x ).c_str(),
1097  FormatInternalUnits( aSheet->GetPosition().y ).c_str(),
1098  FormatInternalUnits( aSheet->GetSize().GetWidth() ).c_str(),
1099  FormatInternalUnits( aSheet->GetSize().GetHeight() ).c_str() );
1100 
1101  if( aSheet->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO )
1102  m_out->Print( 0, " (fields_autoplaced)" );
1103 
1104  m_out->Print( 0, "\n" );
1105 
1107  aSheet->GetBorderColor() );
1108 
1109  stroke.SetWidth( aSheet->GetBorderWidth() );
1110  formatStroke( m_out, aNestLevel + 1, stroke );
1111 
1112  m_out->Print( 0, "\n" );
1113 
1114  m_out->Print( aNestLevel + 1, "(fill (color %d %d %d %0.4f))\n",
1115  KiROUND( aSheet->GetBackgroundColor().r * 255.0 ),
1116  KiROUND( aSheet->GetBackgroundColor().g * 255.0 ),
1117  KiROUND( aSheet->GetBackgroundColor().b * 255.0 ),
1118  aSheet->GetBackgroundColor().a );
1119 
1120  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSheet->m_Uuid.AsString() ) );
1121 
1123 
1124  for( SCH_FIELD& field : aSheet->GetFields() )
1125  {
1126  saveField( &field, aNestLevel + 1 );
1127  }
1128 
1129  for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
1130  {
1131  m_out->Print( aNestLevel + 1, "(pin %s %s (at %s %s %s)\n",
1132  EscapedUTF8( pin->GetText() ).c_str(),
1133  getSheetPinShapeToken( pin->GetShape() ),
1134  FormatInternalUnits( pin->GetPosition().x ).c_str(),
1135  FormatInternalUnits( pin->GetPosition().y ).c_str(),
1136  FormatAngle( getSheetPinAngle( pin->GetEdge() ) * 10.0 ).c_str() );
1137 
1138  pin->Format( m_out, aNestLevel + 1, 0 );
1139 
1140  m_out->Print( aNestLevel + 2, "(uuid %s)\n", TO_UTF8( pin->m_Uuid.AsString() ) );
1141 
1142  m_out->Print( aNestLevel + 1, ")\n" ); // Closes pin token.
1143  }
1144 
1145  m_out->Print( aNestLevel, ")\n" ); // Closes sheet token.
1146 }
Instances are attached to a symbol or sheet and provide a place for the component's value,...
Definition: sch_field.h:50
void SetWidth(int aWidth)
Definition: sch_item.h:168
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:47
wxString AsString() const
Definition: kiid.cpp:218
double g
Green component.
Definition: color4d.h:359
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:111
void saveField(SCH_FIELD *aField, int aNestLevel)
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:433
double b
Blue component.
Definition: color4d.h:360
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:114
std::string EscapedUTF8(wxString aString)
Return an 8 bit UTF8 string given aString in Unicode form.
Definition: string.cpp:329
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:88
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:506
int GetBorderWidth() const
Definition: sch_sheet.h:108
double a
Alpha component.
Definition: color4d.h:361
static double getSheetPinAngle(SHEET_SIDE aSide)
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
static void formatStroke(OUTPUTFORMATTER *aFormatter, int aNestLevel, const STROKE_PARAMS &aStroke)
Write stroke definition to aFormatter.
wxPoint GetPosition() const override
Definition: sch_sheet.h:378
const KIID m_Uuid
Definition: eda_item.h:525
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:184
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
Simple container to manage line stroke parameters.
Definition: sch_item.h:155
wxSize GetSize() const
Definition: sch_sheet.h:105
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:358
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write 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:471
static const char * getSheetPinShapeToken(PINSHEETLABEL_SHAPE aShape)

References KIGFX::COLOR4D::a, KIID::AsString(), KIGFX::COLOR4D::b, EscapedUTF8(), FIELDS_AUTOPLACED_NO, FormatAngle(), FormatInternalUnits(), formatStroke(), KIGFX::COLOR4D::g, SCH_SHEET::GetBackgroundColor(), SCH_SHEET::GetBorderColor(), SCH_SHEET::GetBorderWidth(), SCH_SHEET::GetFields(), SCH_ITEM::GetFieldsAutoplaced(), SCH_SHEET::GetPins(), SCH_SHEET::GetPosition(), getSheetPinAngle(), getSheetPinShapeToken(), SCH_SHEET::GetSize(), KiROUND(), EDA_ITEM::m_Uuid, pin, 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 because libraries cannot have duplicate alias names. It is the responsibility of the caller to check the library for conflicts before saving.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aSymbolis what to store in the library. The library is refreshed and the caller must update any LIB_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 2179 of file sch_sexpr_plugin.cpp.

2181 {
2182  LOCALE_IO toggle; // toggles on, then off, the C locale.
2183 
2184  cacheLib( aLibraryPath, aProperties );
2185 
2186  m_cache->AddSymbol( aSymbol );
2187 
2188  if( !isBuffering( aProperties ) )
2189  m_cache->Save();
2190 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void Save()
Save the entire library to file m_libFileName;.
SCH_SEXPR_PLUGIN_CACHE * m_cache
void AddSymbol(const LIB_PART *aPart)
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)
bool isBuffering(const PROPERTIES *aProperties)

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

◆ saveSymbol()

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

Definition at line 877 of file sch_sexpr_plugin.cpp.

879 {
880  wxCHECK_RET( aSymbol != nullptr && m_out != nullptr, "" );
881 
882  std::string libName;
883  wxArrayString reference_fields;
884 
885  static wxString delimiters( wxT( " " ) );
886 
887  wxString part_name = aSymbol->GetLibId().Format();
888 
889  if( part_name.size() )
890  {
891  libName = toUTFTildaText( part_name );
892  }
893  else
894  {
895  libName = "_NONAME_";
896  }
897 
898  double angle;
899  int orientation = aSymbol->GetOrientation() & ~( CMP_MIRROR_X | CMP_MIRROR_Y );
900 
901  if( orientation == CMP_ORIENT_90 )
902  angle = 90.0;
903  else if( orientation == CMP_ORIENT_180 )
904  angle = 180.0;
905  else if( orientation == CMP_ORIENT_270 )
906  angle = 270.0;
907  else
908  angle = 0.0;
909 
910  m_out->Print( aNestLevel, "(symbol" );
911 
912  if( !aSymbol->UseLibIdLookup() )
913  {
914  m_out->Print( 0, " (lib_name %s)",
915  m_out->Quotew( aSymbol->GetSchSymbolLibraryName() ).c_str() );
916  }
917 
918  m_out->Print( 0, " (lib_id %s) (at %s %s %s)",
919  m_out->Quotew( aSymbol->GetLibId().Format().wx_str() ).c_str(),
920  FormatInternalUnits( aSymbol->GetPosition().x ).c_str(),
921  FormatInternalUnits( aSymbol->GetPosition().y ).c_str(),
922  FormatAngle( angle * 10.0 ).c_str() );
923 
924  bool mirrorX = aSymbol->GetOrientation() & CMP_MIRROR_X;
925  bool mirrorY = aSymbol->GetOrientation() & CMP_MIRROR_Y;
926 
927  if( mirrorX || mirrorY )
928  {
929  m_out->Print( 0, " (mirror" );
930 
931  if( mirrorX )
932  m_out->Print( 0, " x" );
933 
934  if( mirrorY )
935  m_out->Print( 0, " y" );
936 
937  m_out->Print( 0, ")" );
938  }
939 
940  int unit = -1;
941 
942  if( !( aSymbol->GetInstanceReferences().size() > 1 ) )
943  unit = aSymbol->GetUnit();
944  else if( aSheetPath != nullptr )
945  unit = aSymbol->GetUnitSelection( aSheetPath );
946  if ( unit >= 0 )
947  m_out->Print( 0, " (unit %d)", unit );
948 
949  if( aSymbol->GetConvert() == LIB_ITEM::LIB_CONVERT::DEMORGAN )
950  m_out->Print( 0, " (convert %d)", aSymbol->GetConvert() );
951 
952  m_out->Print( 0, "\n" );
953 
954  m_out->Print( aNestLevel + 1, "(in_bom %s)", ( aSymbol->GetIncludeInBom() ) ? "yes" : "no" );
955  m_out->Print( 0, " (on_board %s)", ( aSymbol->GetIncludeOnBoard() ) ? "yes" : "no" );
956 
957  if( aSymbol->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO )
958  m_out->Print( 0, " (fields_autoplaced)" );
959 
960  m_out->Print( 0, "\n" );
961 
962  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSymbol->m_Uuid.AsString() ) );
963 
965 
966  for( SCH_FIELD& field : aSymbol->GetFields() )
967  {
968  saveField( &field, aNestLevel + 1 );
969  }
970 
971  for( const SCH_PIN* pin : aSymbol->GetPins() )
972  {
973  if( pin->GetAlt().IsEmpty() )
974  {
975  m_out->Print( aNestLevel + 1, "(pin %s (uuid %s))\n",
976  m_out->Quotew( pin->GetNumber() ).c_str(),
977  TO_UTF8( pin->m_Uuid.AsString() ) );
978  }
979  else
980  {
981  m_out->Print( aNestLevel + 1, "(pin %s (uuid %s) (alternate %s))\n",
982  m_out->Quotew( pin->GetNumber() ).c_str(),
983  TO_UTF8( pin->m_Uuid.AsString() ),
984  m_out->Quotew( pin->GetAlt() ).c_str() );
985  }
986  }
987 
988  m_out->Print( aNestLevel, ")\n" );
989 }
Instances are attached to a symbol or sheet and provide a place for the component's value,...
Definition: sch_field.h:50
void saveField(SCH_FIELD *aField, int aNestLevel)
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
Definition: sch_symbol.cpp:43
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:506
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
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,...)
Format and write 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:471
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:476

References PNS::angle(), KIID::AsString(), CMP_MIRROR_X, CMP_MIRROR_Y, CMP_ORIENT_180, CMP_ORIENT_270, CMP_ORIENT_90, FIELDS_AUTOPLACED_NO, LIB_ID::Format(), FormatAngle(), FormatInternalUnits(), SCH_COMPONENT::GetConvert(), SCH_COMPONENT::GetFields(), SCH_ITEM::GetFieldsAutoplaced(), 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(), SCH_COMPONENT::GetUnitSelection(), EDA_ITEM::m_Uuid, MANDATORY_FIELDS, pin, TO_UTF8, toUTFTildaText(), SCH_COMPONENT::UseLibIdLookup(), and UTF8::wx_str().

◆ saveText()

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

Definition at line 1246 of file sch_sexpr_plugin.cpp.

1247 {
1248  wxCHECK_RET( aText != nullptr && m_out != nullptr, "" );
1249 
1250  double angle;
1251 
1252  switch( aText->GetLabelSpinStyle() )
1253  {
1254  case LABEL_SPIN_STYLE::RIGHT: angle = 0.0; break;
1255  case LABEL_SPIN_STYLE::UP: angle = 90.0; break;
1256  case LABEL_SPIN_STYLE::LEFT: angle = 180.0; break;
1257  case LABEL_SPIN_STYLE::BOTTOM: angle = 270.0; break;
1258  default: wxFAIL; angle = 0.0; break;
1259  }
1260 
1261  m_out->Print( aNestLevel, "(%s %s",
1262  getTextTypeToken( aText->Type() ),
1263  m_out->Quotew( aText->GetText() ).c_str() );
1264 
1265  if( ( aText->Type() == SCH_GLOBAL_LABEL_T ) || ( aText->Type() == SCH_HIER_LABEL_T ) )
1266  m_out->Print( 0, " (shape %s)", getSheetPinShapeToken( aText->GetShape() ) );
1267 
1268  if( aText->GetText().Length() < 50 )
1269  {
1270  m_out->Print( 0, " (at %s %s %s)",
1271  FormatInternalUnits( aText->GetPosition().x ).c_str(),
1272  FormatInternalUnits( aText->GetPosition().y ).c_str(),
1273  FormatAngle( angle * 10.0 ).c_str() );
1274  }
1275  else
1276  {
1277  m_out->Print( 0, "\n" );
1278  m_out->Print( aNestLevel + 1, "(at %s %s %s)",
1279  FormatInternalUnits( aText->GetPosition().x ).c_str(),
1280  FormatInternalUnits( aText->GetPosition().y ).c_str(),
1281  FormatAngle( aText->GetTextAngle() ).c_str() );
1282  }
1283 
1284  if( aText->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO )
1285  m_out->Print( 0, " (fields_autoplaced)" );
1286 
1287  m_out->Print( 0, "\n" );
1288  aText->Format( m_out, aNestLevel, 0 );
1289 
1290  m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aText->m_Uuid.AsString() ) );
1291 
1292  if( ( aText->Type() == SCH_GLOBAL_LABEL_T ) )
1293  {
1294  SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( aText );
1295  saveField( label->GetIntersheetRefs(), aNestLevel + 1 );
1296  }
1297 
1298  m_out->Print( aNestLevel, ")\n" ); // Closes text token.
1299 }
static const char * getTextTypeToken(KICAD_T aType)
double GetTextAngle() const
Definition: eda_text.h:181
wxString AsString() const
Definition: kiid.cpp:218
void saveField(SCH_FIELD *aField, int aNestLevel)
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:433
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file.
Definition: base_units.cpp:506
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:516
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:215
wxPoint GetPosition() const override
Definition: sch_text.h:293
const KIID m_Uuid
Definition: eda_item.h:525
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
SCH_FIELD * GetIntersheetRefs()
Definition: sch_text.h:459
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp: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:471
static const char * getSheetPinShapeToken(PINSHEETLABEL_SHAPE aShape)
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:217
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:476

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

◆ SetReporter()

virtual void SCH_PLUGIN::SetReporter ( REPORTER aReporter)
inlinevirtualinherited

Set an optional reporter for warnings/errors.

Reimplemented in SCH_EAGLE_PLUGIN, SCH_ALTIUM_PLUGIN, and CADSTAR_SCH_ARCHIVE_PLUGIN.

Definition at line 165 of file sch_io_mgr.h.

165 {}

◆ SymbolLibOptions()

void SCH_PLUGIN::SymbolLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.

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

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

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

Definition at line 133 of file sch_plugin.cpp.

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

Definition at line 152 of file sch_sexpr_plugin.h.

Referenced by GetError().

◆ m_nextFreeFieldId

int SCH_SEXPR_PLUGIN::m_nextFreeFieldId
protected

Definition at line 150 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 158 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_rootSheet

SCH_SHEET* SCH_SEXPR_PLUGIN::m_rootSheet
protected

The root sheet of the schematic being loaded..

Definition at line 156 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 157 of file sch_sexpr_plugin.h.

◆ m_version

int SCH_SEXPR_PLUGIN::m_version
protected

Version of file being loaded.

Definition at line 149 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: