KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN Class Reference

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

#include <sch_legacy_plugin.h>

Inheritance diagram for SCH_LEGACY_PLUGIN:
SCH_PLUGIN

Public Member Functions

 SCH_LEGACY_PLUGIN ()
 
virtual ~SCH_LEGACY_PLUGIN ()
 
const wxString GetName () const override
 Returns a brief hard coded name for this SCH_PLUGIN. More...
 
const wxString GetFileExtension () const override
 Returns the file extension for the SCH_PLUGIN. More...
 
int GetModifyHash () const override
 Return the modification hash from the library cache. More...
 
SCH_SHEETLoad (const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL) 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 Save (const wxString &aFileName, SCH_SCREEN *aScreen, KIWAY *aKiway, const PROPERTIES *aProperties=NULL) 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_SCREEN *aScreen)
 
size_t GetSymbolLibCount (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 
void EnumerateSymbolLib (wxArrayString &aAliasNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Populate a list of LIB_PART alias names contained within the library aLibraryPath. More...
 
void EnumerateSymbolLib (std::vector< LIB_ALIAS * > &aAliasList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Populate a list of LIB_PART aliases contained within the library aLibraryPath. More...
 
LIB_ALIASLoadSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL) override
 Load a LIB_ALIAS object having aAliasName 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=NULL) override
 Write aSymbol to an existing library located at aLibraryPath. More...
 
void DeleteAlias (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL) override
 Delete aAliasName from the library at aLibraryPath. More...
 
void DeleteSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL) override
 Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath. More...
 
void CreateSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Create a new empty symbol library at aLibraryPath. More...
 
bool DeleteSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) 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=NULL) override
 
bool CheckHeader (const wxString &aFileName) override
 Return true if the first line in aFileName begins with the expected header. More...
 
bool IsSymbolLibWritable (const wxString &aLibraryPath) override
 Return true if the library at aLibraryPath is writable. More...
 
const wxString & GetError () const override
 Return an error string to the caller. More...
 
virtual void SymbolLibOptions (PROPERTIES *aListToAppendTo) const
 Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Static Public Member Functions

static LIB_PARTParsePart (LINE_READER &reader, int aMajorVersion=0, int aMinorVersion=0)
 
static void FormatPart (LIB_PART *part, OUTPUTFORMATTER &formatter)
 

Static Public Attributes

static const char * PropBuffering = "buffering"
 const char* PropBuffering More...
 
static const char * PropNoDocFile = "no_doc_file"
 const char* PropBuffering More...
 

Protected Member Functions

void init (KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
 initialize PLUGIN like a constructor would. More...
 

Protected Attributes

int m_version
 Version of file being loaded. More...
 
wxString m_error
 For throwing exceptions or errors on partial schematic loads. More...
 
wxString m_path
 Root project path for loading child sheets. More...
 
std::stack< wxString > m_currentPath
 Stack to maintain nested sheet paths. More...
 
const PROPERTIESm_props
 Passed via Save() or Load(), no ownership, may be NULL. More...
 
KIWAYm_kiway
 Required for path to legacy component libraries. More...
 
SCH_SHEETm_rootSheet
 The root sheet of the schematic being loaded.. More...
 
FILE_OUTPUTFORMATTERm_out
 The output formatter for saving SCH_SCREEN objects. More...
 
SCH_LEGACY_PLUGIN_CACHEm_cache
 

Private Member Functions

void loadHierarchy (SCH_SHEET *aSheet)
 
void loadHeader (FILE_LINE_READER &aReader, SCH_SCREEN *aScreen)
 
void loadPageSettings (FILE_LINE_READER &aReader, SCH_SCREEN *aScreen)
 
void loadFile (const wxString &aFileName, SCH_SCREEN *aScreen)
 
SCH_SHEETloadSheet (FILE_LINE_READER &aReader)
 
SCH_BITMAPloadBitmap (FILE_LINE_READER &aReader)
 
SCH_JUNCTIONloadJunction (FILE_LINE_READER &aReader)
 
SCH_NO_CONNECTloadNoConnect (FILE_LINE_READER &aReader)
 
SCH_LINEloadWire (FILE_LINE_READER &aReader)
 
SCH_BUS_ENTRY_BASEloadBusEntry (FILE_LINE_READER &aReader)
 
SCH_TEXTloadText (FILE_LINE_READER &aReader)
 
SCH_COMPONENTloadComponent (FILE_LINE_READER &aReader)
 
std::shared_ptr< BUS_ALIASloadBusAlias (FILE_LINE_READER &aReader, SCH_SCREEN *aScreen)
 
void saveComponent (SCH_COMPONENT *aComponent)
 
void saveField (SCH_FIELD *aField)
 
void saveBitmap (SCH_BITMAP *aBitmap)
 
void saveSheet (SCH_SHEET *aSheet)
 
void saveJunction (SCH_JUNCTION *aJunction)
 
void saveNoConnect (SCH_NO_CONNECT *aNoConnect)
 
void saveBusEntry (SCH_BUS_ENTRY_BASE *aBusEntry)
 
void saveLine (SCH_LINE *aLine)
 
void saveText (SCH_TEXT *aText)
 
void saveBusAlias (std::shared_ptr< BUS_ALIAS > aAlias)
 
void cacheLib (const wxString &aLibraryFileName)
 
bool writeDocFile (const PROPERTIES *aProperties)
 
bool isBuffering (const PROPERTIES *aProperties)
 

Detailed Description

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

The legacy parser and formatter attempt to be compatible with the legacy file format. The original parser was very forgiving in that it would parse only part of a keyword. So "$C", "$Co", and "$Com" could be used for "$Comp" and the old parser would allow this. This parser is not that forgiving and sticks to the legacy file format document.

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

Definition at line 62 of file sch_legacy_plugin.h.

Constructor & Destructor Documentation

◆ SCH_LEGACY_PLUGIN()

SCH_LEGACY_PLUGIN::SCH_LEGACY_PLUGIN ( )

Definition at line 560 of file sch_legacy_plugin.cpp.

561 {
562  init( NULL );
563 }
void init(KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
initialize PLUGIN like a constructor would.

References init().

◆ ~SCH_LEGACY_PLUGIN()

SCH_LEGACY_PLUGIN::~SCH_LEGACY_PLUGIN ( )
virtual

Definition at line 566 of file sch_legacy_plugin.cpp.

567 {
568  delete m_cache;
569 }
SCH_LEGACY_PLUGIN_CACHE * m_cache

References m_cache.

Member Function Documentation

◆ cacheLib()

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

Definition at line 4174 of file sch_legacy_plugin.cpp.

4175 {
4176  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
4177  {
4178  // a spectacular episode in memory management:
4179  delete m_cache;
4180  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
4181 
4182  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
4183  // to modify the hash value that indicate component to symbol links
4184  // must be updated.
4186 
4187  if( !isBuffering( m_props ) )
4188  m_cache->Load();
4189  }
4190 }
static int s_modify_generation
helper for GetModifyHash()
SCH_LEGACY_PLUGIN_CACHE * m_cache
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLU...
bool isBuffering(const PROPERTIES *aProperties)
bool IsFile(const wxString &aFullPathAndFileName) const
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.

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

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

◆ CheckHeader()

bool SCH_LEGACY_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 4404 of file sch_legacy_plugin.cpp.

4405 {
4406  // Open file and check first line
4407  wxTextFile tempFile;
4408 
4409  tempFile.Open( aFileName );
4410  wxString firstline;
4411  // read the first line
4412  firstline = tempFile.GetFirstLine();
4413  tempFile.Close();
4414 
4415  return firstline.StartsWith( "EESchema" );
4416 }

◆ CreateSymbolLib()

void SCH_LEGACY_PLUGIN::CreateSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
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 4337 of file sch_legacy_plugin.cpp.

4339 {
4340  if( wxFileExists( aLibraryPath ) )
4341  {
4343  _( "symbol library \"%s\" already exists, cannot create a new library" ),
4344  aLibraryPath.GetData() ) );
4345  }
4346 
4347  LOCALE_IO toggle;
4348 
4349  m_props = aProperties;
4350 
4351  delete m_cache;
4352  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4353  m_cache->SetModified();
4354  m_cache->Save( writeDocFile( aProperties ) );
4355  m_cache->Load(); // update m_writable and m_mod_time
4356 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:177
SCH_LEGACY_PLUGIN_CACHE * m_cache
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLU...
#define THROW_IO_ERROR(msg)
void SetModified(bool aModified=true)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
bool writeDocFile(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.

References Format(), SCH_LEGACY_PLUGIN_CACHE::Load(), m_cache, m_props, SCH_LEGACY_PLUGIN_CACHE::Save(), SCH_LEGACY_PLUGIN_CACHE::SetModified(), THROW_IO_ERROR, and writeDocFile().

◆ DeleteAlias()

void SCH_LEGACY_PLUGIN::DeleteAlias ( const wxString &  aLibraryPath,
const wxString &  aAliasName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Delete aAliasName from the library at aLibraryPath.

If aAliasName refers the the root LIB_PART object, the part is renamed to the next or previous LIB_ALIAS in the LIB_PART if one exists. If the LIB_ALIAS is the last alias referring to the root LIB_PART, the LIB_PART is also removed from the library.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aAliasNameis the name of a LIB_ALIAS 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 4309 of file sch_legacy_plugin.cpp.

4311 {
4312  m_props = aProperties;
4313 
4314  cacheLib( aLibraryPath );
4315 
4316  m_cache->DeleteAlias( aAliasName );
4317 
4318  if( !isBuffering( aProperties ) )
4319  m_cache->Save( writeDocFile( aProperties ) );
4320 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
bool isBuffering(const PROPERTIES *aProperties)
void DeleteAlias(const wxString &aAliasName)
void cacheLib(const wxString &aLibraryFileName)
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
bool writeDocFile(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.

References cacheLib(), SCH_LEGACY_PLUGIN_CACHE::DeleteAlias(), isBuffering(), m_cache, m_props, SCH_LEGACY_PLUGIN_CACHE::Save(), and writeDocFile().

◆ DeleteSymbol()

void SCH_LEGACY_PLUGIN::DeleteSymbol ( const wxString &  aLibraryPath,
const wxString &  aAliasName,
const PROPERTIES aProperties = NULL 
)
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.
aAliasNameis the name of a LIB_ALIAS 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 4323 of file sch_legacy_plugin.cpp.

4325 {
4326  m_props = aProperties;
4327 
4328  cacheLib( aLibraryPath );
4329 
4330  m_cache->DeleteSymbol( aAliasName );
4331 
4332  if( !isBuffering( aProperties ) )
4333  m_cache->Save( writeDocFile( aProperties ) );
4334 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
bool isBuffering(const PROPERTIES *aProperties)
void cacheLib(const wxString &aLibraryFileName)
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
void DeleteSymbol(const wxString &aAliasName)
bool writeDocFile(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.

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

◆ DeleteSymbolLib()

bool SCH_LEGACY_PLUGIN::DeleteSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
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 4359 of file sch_legacy_plugin.cpp.

4361 {
4362  wxFileName fn = aLibraryPath;
4363 
4364  if( !fn.FileExists() )
4365  return false;
4366 
4367  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
4368  // we don't want that. we want bare metal portability with no UI here.
4369  if( wxRemove( aLibraryPath ) )
4370  {
4371  THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
4372  aLibraryPath.GetData() ) );
4373  }
4374 
4375  if( m_cache && m_cache->IsFile( aLibraryPath ) )
4376  {
4377  delete m_cache;
4378  m_cache = 0;
4379  }
4380 
4381  return true;
4382 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
#define THROW_IO_ERROR(msg)
bool IsFile(const wxString &aFullPathAndFileName) const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References Format(), SCH_LEGACY_PLUGIN_CACHE::IsFile(), m_cache, and THROW_IO_ERROR.

◆ EnumerateSymbolLib() [1/2]

void SCH_LEGACY_PLUGIN::EnumerateSymbolLib ( wxArrayString &  aAliasNameList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

Parameters
aAliasNameListis an array to populate with the LIB_ALIAS 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 4233 of file sch_legacy_plugin.cpp.

4236 {
4237  LOCALE_IO toggle; // toggles on, then off, the C locale.
4238 
4239  m_props = aProperties;
4240 
4241  bool powerSymbolsOnly = ( aProperties &&
4242  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4243  cacheLib( aLibraryPath );
4244 
4245  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
4246 
4247  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
4248  {
4249  if( !powerSymbolsOnly || it->second->GetPart()->IsPower() )
4250  aAliasNameList.Add( it->first );
4251  }
4252 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:177
SCH_LEGACY_PLUGIN_CACHE * m_cache
std::map< wxString, LIB_ALIAS *, AliasMapSort > LIB_ALIAS_MAP
Alias map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
static const char * PropPowerSymsOnly
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.

References cacheLib(), SCH_LEGACY_PLUGIN_CACHE::m_aliases, m_cache, m_props, and SYMBOL_LIB_TABLE::PropPowerSymsOnly.

◆ EnumerateSymbolLib() [2/2]

void SCH_LEGACY_PLUGIN::EnumerateSymbolLib ( std::vector< LIB_ALIAS * > &  aAliasList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

Parameters
aAliasListis an array to populate with the LIB_ALIAS 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 4255 of file sch_legacy_plugin.cpp.

4258 {
4259  LOCALE_IO toggle; // toggles on, then off, the C locale.
4260 
4261  m_props = aProperties;
4262 
4263  bool powerSymbolsOnly = ( aProperties &&
4264  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4265  cacheLib( aLibraryPath );
4266 
4267  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
4268 
4269  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
4270  {
4271  if( !powerSymbolsOnly || it->second->GetPart()->IsPower() )
4272  aAliasList.push_back( it->second );
4273  }
4274 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:177
SCH_LEGACY_PLUGIN_CACHE * m_cache
std::map< wxString, LIB_ALIAS *, AliasMapSort > LIB_ALIAS_MAP
Alias map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
static const char * PropPowerSymsOnly
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.

References cacheLib(), SCH_LEGACY_PLUGIN_CACHE::m_aliases, m_cache, m_props, and SYMBOL_LIB_TABLE::PropPowerSymsOnly.

◆ Format()

void SCH_LEGACY_PLUGIN::Format ( SCH_SCREEN aScreen)

Definition at line 1776 of file sch_legacy_plugin.cpp.

1777 {
1778  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN* object." );
1779  wxCHECK_RET( m_kiway != NULL, "NULL KIWAY* object." );
1780 
1781  // Write the header
1782  m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1783 
1784  // Write the project libraries.
1785  for( const PART_LIB& lib : *m_kiway->Prj().SchLibs() )
1786  m_out->Print( 0, "LIBS:%s\n", TO_UTF8( lib.GetName() ) );
1787 
1788  // This section is not used, but written for file compatibility
1789  m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1790  m_out->Print( 0, "EELAYER END\n" );
1791 
1792  /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1793  * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1794  * simple hierarchy and flat hierarchy. Used also to search the root
1795  * sheet ( ScreenNumber = 1 ) within the files
1796  */
1797  const TITLE_BLOCK& tb = aScreen->GetTitleBlock();
1798  const PAGE_INFO& page = aScreen->GetPageSettings();
1799 
1800  m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1801  page.GetWidthMils(),
1802  page.GetHeightMils(),
1803  !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1804  m_out->Print( 0, "encoding utf-8\n" );
1805  m_out->Print( 0, "Sheet %d %d\n", aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens );
1806  m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1807  m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1808  m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1809  m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1810  m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment1() ).c_str() );
1811  m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment2() ).c_str() );
1812  m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment3() ).c_str() );
1813  m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment4() ).c_str() );
1814  m_out->Print( 0, "$EndDescr\n" );
1815 
1816  for( auto alias : aScreen->GetBusAliases() )
1817  {
1818  saveBusAlias( alias );
1819  }
1820 
1821  for( SCH_ITEM* item = aScreen->GetDrawItems(); item; item = item->Next() )
1822  {
1823  switch( item->Type() )
1824  {
1825  case SCH_COMPONENT_T:
1826  saveComponent( static_cast< SCH_COMPONENT* >( item ) );
1827  break;
1828  case SCH_BITMAP_T:
1829  saveBitmap( static_cast< SCH_BITMAP* >( item ) );
1830  break;
1831  case SCH_SHEET_T:
1832  saveSheet( static_cast< SCH_SHEET* >( item ) );
1833  break;
1834  case SCH_JUNCTION_T:
1835  saveJunction( static_cast< SCH_JUNCTION* >( item ) );
1836  break;
1837  case SCH_NO_CONNECT_T:
1838  saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
1839  break;
1840  case SCH_BUS_WIRE_ENTRY_T:
1841  case SCH_BUS_BUS_ENTRY_T:
1842  saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1843  break;
1844  case SCH_LINE_T:
1845  saveLine( static_cast< SCH_LINE* >( item ) );
1846  break;
1847  case SCH_TEXT_T:
1848  case SCH_LABEL_T:
1849  case SCH_GLOBAL_LABEL_T:
1850  case SCH_HIER_LABEL_T:
1851  saveText( static_cast< SCH_TEXT* >( item ) );
1852  break;
1853  default:
1854  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1855  }
1856  }
1857 
1858  m_out->Print( 0, "$EndSCHEMATC\n" );
1859 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int m_ScreenNumber
Definition: base_screen.h:216
SCH_ITEM * Next() const
void saveLine(SCH_LINE *aLine)
int GetHeightMils() const
Definition: page_info.h:140
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:156
const wxString & GetComment4() const
Definition: title_block.h:124
void saveText(SCH_TEXT *aText)
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:143
const wxString & GetType() const
Definition: page_info.h:97
#define SCH_LAYER_ID_COUNT
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
bool IsCustom() const
Function IsCustom returns true if the type is Custom.
Definition: page_info.cpp:176
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:133
void saveSheet(SCH_SHEET *aSheet)
void saveJunction(SCH_JUNCTION *aJunction)
#define SCHEMATIC_HEAD_STRING
Definition: general.h:43
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:47
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:241
#define EESCHEMA_VERSION
Definition: general.h:42
const wxString & GetRevision() const
Definition: title_block.h:89
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
const wxString & GetCompany() const
Definition: title_block.h:99
const wxString & GetComment3() const
Definition: title_block.h:123
void saveBitmap(SCH_BITMAP *aBitmap)
void saveComponent(SCH_COMPONENT *aComponent)
const wxString & GetDate() const
Definition: title_block.h:79
const wxString & GetComment2() const
Definition: title_block.h:122
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
bool IsPortrait() const
Definition: page_info.h:121
const wxString & GetComment1() const
Definition: title_block.h:121
int m_NumberOfScreens
Definition: base_screen.h:217
const wxString & GetTitle() const
Definition: title_block.h:65
KIWAY * m_kiway
Required for path to legacy component libraries.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
Object used to load, save, search, and otherwise manipulate symbol library files.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
std::unordered_set< std::shared_ptr< BUS_ALIAS > > GetBusAliases()
Returns a list of bus aliases defined in this screen.
Definition: sch_screen.h:532
int GetWidthMils() const
Definition: page_info.h:137
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:167

References EESCHEMA_VERSION, EscapedUTF8(), SCH_SCREEN::GetBusAliases(), TITLE_BLOCK::GetComment1(), TITLE_BLOCK::GetComment2(), TITLE_BLOCK::GetComment3(), TITLE_BLOCK::GetComment4(), TITLE_BLOCK::GetCompany(), TITLE_BLOCK::GetDate(), SCH_SCREEN::GetDrawItems(), PAGE_INFO::GetHeightMils(), SCH_SCREEN::GetPageSettings(), TITLE_BLOCK::GetRevision(), TITLE_BLOCK::GetTitle(), SCH_SCREEN::GetTitleBlock(), PAGE_INFO::GetType(), PAGE_INFO::GetWidthMils(), PAGE_INFO::IsCustom(), PAGE_INFO::IsPortrait(), m_kiway, BASE_SCREEN::m_NumberOfScreens, m_out, BASE_SCREEN::m_ScreenNumber, SCH_ITEM::Next(), OUTPUTFORMATTER::Print(), KIWAY::Prj(), saveBitmap(), saveBusAlias(), saveBusEntry(), saveComponent(), saveJunction(), saveLine(), saveNoConnect(), saveSheet(), saveText(), 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_COUNT, SCH_LINE_T, SCH_NO_CONNECT_T, SCH_SHEET_T, SCH_TEXT_T, SCHEMATIC_HEAD_STRING, and TO_UTF8.

Referenced by Save().

◆ FormatPart()

void SCH_LEGACY_PLUGIN::FormatPart ( LIB_PART part,
OUTPUTFORMATTER formatter 
)
static

Definition at line 4432 of file sch_legacy_plugin.cpp.

4433 {
4434  SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( part, formatter );
4435 }
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter)

References SCH_LEGACY_PLUGIN_CACHE::SaveSymbol().

Referenced by LIB_EDIT_FRAME::OnCopyCutPart().

◆ GetError()

const wxString& SCH_LEGACY_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 131 of file sch_legacy_plugin.h.

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

References m_error.

◆ GetFileExtension()

const wxString SCH_LEGACY_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Returns the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 74 of file sch_legacy_plugin.h.

75  {
76  return wxT( "sch" );
77  }

◆ GetModifyHash()

int SCH_LEGACY_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 4210 of file sch_legacy_plugin.cpp.

4211 {
4212  if( m_cache )
4213  return m_cache->GetModifyHash();
4214 
4215  // If the cache hasn't been loaded, it hasn't been modified.
4216  return 0;
4217 }
SCH_LEGACY_PLUGIN_CACHE * m_cache

References SCH_LEGACY_PLUGIN_CACHE::GetModifyHash(), and m_cache.

◆ GetName()

const wxString SCH_LEGACY_PLUGIN::GetName ( ) const
inlineoverridevirtual

Returns a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 69 of file sch_legacy_plugin.h.

70  {
71  return wxT( "Eeschema-Legacy" );
72  }

◆ GetSymbolLibCount()

size_t SCH_LEGACY_PLUGIN::GetSymbolLibCount ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Reimplemented from SCH_PLUGIN.

Definition at line 4220 of file sch_legacy_plugin.cpp.

4222 {
4223  LOCALE_IO toggle;
4224 
4225  m_props = aProperties;
4226 
4227  cacheLib( aLibraryPath );
4228 
4229  return m_cache->m_aliases.size();
4230 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:177
SCH_LEGACY_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.

References cacheLib(), SCH_LEGACY_PLUGIN_CACHE::m_aliases, m_cache, and m_props.

◆ init()

void SCH_LEGACY_PLUGIN::init ( KIWAY aKiway,
const PROPERTIES aProperties = NULL 
)
protected

initialize PLUGIN like a constructor would.

Definition at line 572 of file sch_legacy_plugin.cpp.

573 {
574  m_version = 0;
575  m_rootSheet = NULL;
576  m_props = aProperties;
577  m_kiway = aKiway;
578  m_cache = NULL;
579  m_out = NULL;
580 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
SCH_LEGACY_PLUGIN_CACHE * m_cache
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
int m_version
Version of file being loaded.
KIWAY * m_kiway
Required for path to legacy component libraries.
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.

References m_cache, m_kiway, m_out, m_props, m_rootSheet, and m_version.

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

◆ isBuffering()

bool SCH_LEGACY_PLUGIN::isBuffering ( const PROPERTIES aProperties)
private

Definition at line 4204 of file sch_legacy_plugin.cpp.

4205 {
4206  return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
4207 }
bool Exists(const std::string &aProperty) const
Definition: properties.h:44
static const char * PropBuffering
const char* PropBuffering

References PROPERTIES::Exists(), and PropBuffering.

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

◆ IsSymbolLibWritable()

bool SCH_LEGACY_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 4419 of file sch_legacy_plugin.cpp.

4420 {
4421  return wxFileName::IsFileWritable( aLibraryPath );
4422 }

◆ Load()

SCH_SHEET * SCH_LEGACY_PLUGIN::Load ( const wxString &  aFileName,
KIWAY aKiway,
SCH_SHEET aAppendToMe = NULL,
const PROPERTIES aProperties = NULL 
)
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 583 of file sch_legacy_plugin.cpp.

585 {
586  wxASSERT( !aFileName || aKiway != NULL );
587 
588  LOCALE_IO toggle; // toggles on, then off, the C locale.
589  SCH_SHEET* sheet;
590 
591  wxFileName fn = aFileName;
592 
593  // Unfortunately child sheet file names the legacy schematic file format are not fully
594  // qualified and are always appended to the project path. The aFileName attribute must
595  // always be an absolute path so the project path can be used for load child sheet files.
596  wxASSERT( fn.IsAbsolute() );
597 
598  if( aAppendToMe )
599  {
600  wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
601  aFileName, aAppendToMe->GetFileName() );
602 
603  wxFileName normedFn = aAppendToMe->GetFileName();
604 
605  if( !normedFn.IsAbsolute() )
606  {
607  if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
608  m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
609  }
610 
611  if( m_path.IsEmpty() )
612  m_path = aKiway->Prj().GetProjectPath();
613 
614  wxLogTrace( traceSchLegacyPlugin, "Normalized append path \"%s\".", m_path );
615  }
616  else
617  {
618  m_path = aKiway->Prj().GetProjectPath();
619  }
620 
621  m_currentPath.push( m_path );
622  init( aKiway, aProperties );
623 
624  if( aAppendToMe == NULL )
625  {
626  // Clean up any allocated memory if an exception occurs loading the schematic.
627  std::unique_ptr< SCH_SHEET > newSheet( new SCH_SHEET );
628  newSheet->SetFileName( aFileName );
629  m_rootSheet = newSheet.get();
630  loadHierarchy( newSheet.get() );
631 
632  // If we got here, the schematic loaded successfully.
633  sheet = newSheet.release();
634  }
635  else
636  {
637  m_rootSheet = aAppendToMe->GetRootSheet();
638  wxASSERT( m_rootSheet != NULL );
639  sheet = aAppendToMe;
640  loadHierarchy( sheet );
641  }
642 
643  wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
644 
645  return sheet;
646 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:177
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.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_SHEET * GetRootSheet()
Return the root sheet of this SCH_SHEET object.
Definition: sch_sheet.cpp:136
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:102
wxString m_path
Root project path for loading child sheets.
void loadHierarchy(SCH_SHEET *aSheet)
void init(KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
initialize PLUGIN like a constructor would.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:208
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:627
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.

References SCH_SHEET::GetFileName(), PROJECT::GetProjectPath(), SCH_SHEET::GetRootSheet(), init(), loadHierarchy(), m_currentPath, m_path, m_rootSheet, KIWAY::Prj(), and traceSchLegacyPlugin.

◆ loadBitmap()

SCH_BITMAP * SCH_LEGACY_PLUGIN::loadBitmap ( FILE_LINE_READER aReader)
private

Definition at line 1057 of file sch_legacy_plugin.cpp.

1058 {
1059  std::unique_ptr< SCH_BITMAP > bitmap( new SCH_BITMAP );
1060 
1061  const char* line = aReader.Line();
1062 
1063  wxCHECK( strCompare( "$Bitmap", line, &line ), NULL );
1064 
1065  line = aReader.ReadLine();
1066 
1067  while( line != NULL )
1068  {
1069  if( strCompare( "Pos", line, &line ) )
1070  {
1071  wxPoint position;
1072 
1073  position.x = parseInt( aReader, line, &line );
1074  position.y = parseInt( aReader, line, &line );
1075  bitmap->SetPosition( position );
1076  }
1077  else if( strCompare( "Scale", line, &line ) )
1078  {
1079  auto scalefactor = parseDouble( aReader, line, &line );
1080 
1081  // Prevent scalefactor values that cannot be displayed.
1082  // In the case of a bad value, we accept that the image might be mis-scaled
1083  // rather than removing the full image. Users can then edit the scale factor in
1084  // Eeschema to the appropriate value
1085  if( !std::isnormal( scalefactor ) )
1086  scalefactor = 1.0;
1087 
1088  bitmap->GetImage()->SetScale( scalefactor );
1089  }
1090  else if( strCompare( "Data", line, &line ) )
1091  {
1092  wxMemoryOutputStream stream;
1093 
1094  while( line )
1095  {
1096  if( !aReader.ReadLine() )
1097  SCH_PARSE_ERROR( _( "Unexpected end of file" ), aReader, line );
1098 
1099  line = aReader.Line();
1100 
1101  if( strCompare( "EndData", line ) )
1102  {
1103  // all the PNG date is read.
1104  // We expect here m_image and m_bitmap are void
1105  wxImage* image = new wxImage();
1106  wxMemoryInputStream istream( stream );
1107  image->LoadFile( istream, wxBITMAP_TYPE_PNG );
1108  bitmap->GetImage()->SetImage( image );
1109  bitmap->GetImage()->SetBitmap( new wxBitmap( *image ) );
1110  break;
1111  }
1112 
1113  // Read PNG data, stored in hexadecimal,
1114  // each byte = 2 hexadecimal digits and a space between 2 bytes
1115  // and put it in memory stream buffer
1116  int len = strlen( line );
1117 
1118  for( ; len > 0 && !isspace( *line ); len -= 3, line += 3 )
1119  {
1120  int value = 0;
1121 
1122  if( sscanf( line, "%X", &value ) == 1 )
1123  stream.PutC( (char) value );
1124  else
1125  THROW_IO_ERROR( "invalid PNG data" );
1126  }
1127  }
1128 
1129  if( line == NULL )
1130  THROW_IO_ERROR( _( "unexpected end of file" ) );
1131  }
1132  else if( strCompare( "$EndBitmap", line ) )
1133  return bitmap.release();
1134 
1135  line = aReader.ReadLine();
1136  }
1137 
1138  THROW_IO_ERROR( _( "unexpected end of file" ) );
1139 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static double parseDouble(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parses an ASCII point string with possible leading whitespace into a double precision floating point ...
#define THROW_IO_ERROR(msg)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), parseDouble(), parseInt(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, strCompare(), and THROW_IO_ERROR.

Referenced by loadFile().

◆ loadBusAlias()

std::shared_ptr< BUS_ALIAS > SCH_LEGACY_PLUGIN::loadBusAlias ( FILE_LINE_READER aReader,
SCH_SCREEN aScreen 
)
private

Definition at line 1726 of file sch_legacy_plugin.cpp.

1728 {
1729  auto busAlias = std::make_shared< BUS_ALIAS >( aScreen );
1730  const char* line = aReader.Line();
1731 
1732  wxCHECK( strCompare( "BusAlias", line, &line ), NULL );
1733 
1734  wxString buf;
1735  parseUnquotedString( buf, aReader, line, &line );
1736  busAlias->SetName( buf );
1737 
1738  while( *line != '\0' )
1739  {
1740  buf.clear();
1741  parseUnquotedString( buf, aReader, line, &line, true );
1742  if( buf.Len() > 0 )
1743  {
1744  busAlias->AddMember( buf );
1745  }
1746  }
1747 
1748  return busAlias;
1749 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), parseUnquotedString(), and strCompare().

Referenced by loadFile().

◆ loadBusEntry()

SCH_BUS_ENTRY_BASE * SCH_LEGACY_PLUGIN::loadBusEntry ( FILE_LINE_READER aReader)
private

Definition at line 1284 of file sch_legacy_plugin.cpp.

1285 {
1286  const char* line = aReader.Line();
1287 
1288  wxCHECK( strCompare( "Entry", line, &line ), NULL );
1289 
1290  std::unique_ptr< SCH_BUS_ENTRY_BASE > busEntry;
1291 
1292  if( strCompare( "Wire", line, &line ) )
1293  {
1294  busEntry.reset( new SCH_BUS_WIRE_ENTRY );
1295 
1296  if( !strCompare( "Line", line, &line ) )
1297  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
1298  }
1299  else if( strCompare( "Bus", line, &line ) )
1300  {
1301  busEntry.reset( new SCH_BUS_BUS_ENTRY );
1302 
1303  if( !strCompare( "Bus", line, &line ) )
1304  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
1305  }
1306  else
1307  SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
1308 
1309  line = aReader.ReadLine();
1310 
1311  wxPoint pos;
1312  wxSize size;
1313 
1314  pos.x = parseInt( aReader, line, &line );
1315  pos.y = parseInt( aReader, line, &line );
1316  size.x = parseInt( aReader, line, &line );
1317  size.y = parseInt( aReader, line, &line );
1318 
1319  size.x -= pos.x;
1320  size.y -= pos.y;
1321 
1322  busEntry->SetPosition( pos );
1323  busEntry->SetSize( size );
1324 
1325  return busEntry.release();
1326 }
Class for a bus to bus entry.
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
Class for a wire to bus entry.

References LINE_READER::Line(), parseInt(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by loadFile().

◆ loadComponent()

SCH_COMPONENT * SCH_LEGACY_PLUGIN::loadComponent ( FILE_LINE_READER aReader)
private

Definition at line 1429 of file sch_legacy_plugin.cpp.

1430 {
1431  const char* line = aReader.Line();
1432 
1433  wxCHECK( strCompare( "$Comp", line, &line ), NULL );
1434 
1435  std::unique_ptr< SCH_COMPONENT > component( new SCH_COMPONENT() );
1436 
1437  line = aReader.ReadLine();
1438 
1439  while( line != NULL )
1440  {
1441  if( strCompare( "L", line, &line ) )
1442  {
1443  wxString libName;
1444  size_t pos = 2; // "X" plus ' ' space character.
1445  wxString utf8Line = wxString::FromUTF8( line );
1446  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
1447 
1448  if( tokens.CountTokens() < 2 )
1449  THROW_PARSE_ERROR( "invalid symbol library definition", aReader.GetSource(),
1450  aReader.Line(), aReader.LineNumber(), pos );
1451 
1452  libName = tokens.GetNextToken();
1453  libName.Replace( "~", " " );
1454 
1455  LIB_ID libId;
1456 
1457  // Prior to schematic version 4, library IDs did not have a library nickname so
1458  // parsing the symbol name with LIB_ID::Parse() would break symbol library links
1459  // that contained '/' and ':' characters.
1460  if( m_version > 3 )
1461  libId.Parse( libName, LIB_ID::ID_SCH, true );
1462  else
1463  libId.SetLibItemName( libName, false );
1464 
1465  component->SetLibId( libId );
1466 
1467  wxString refDesignator = tokens.GetNextToken();
1468 
1469  refDesignator.Replace( "~", " " );
1470 
1471  wxString prefix = refDesignator;
1472 
1473  while( prefix.Length() )
1474  {
1475  if( ( prefix.Last() < '0' || prefix.Last() > '9') && prefix.Last() != '?' )
1476  break;
1477 
1478  prefix.RemoveLast();
1479  }
1480 
1481  // Avoid a prefix containing trailing/leading spaces
1482  prefix.Trim( true );
1483  prefix.Trim( false );
1484 
1485  if( prefix.IsEmpty() )
1486  component->SetPrefix( wxString( "U" ) );
1487  else
1488  component->SetPrefix( prefix );
1489  }
1490  else if( strCompare( "U", line, &line ) )
1491  {
1492  // This fixes a potentially buggy files caused by unit being set to zero which
1493  // causes netlist issues. See https://bugs.launchpad.net/kicad/+bug/1677282.
1494  int unit = parseInt( aReader, line, &line );
1495 
1496  if( unit == 0 )
1497  {
1498  unit = 1;
1499 
1500  // Set the file as modified so the user can be warned.
1501  if( m_rootSheet && m_rootSheet->GetScreen() )
1503  }
1504 
1505  component->SetUnit( unit );
1506 
1507  // Same can also happen with the convert parameter
1508  int convert = parseInt( aReader, line, &line );
1509 
1510  if( convert == 0 )
1511  {
1512  convert = 1;
1513 
1514  // Set the file as modified so the user can be warned.
1515  if( m_rootSheet && m_rootSheet->GetScreen() )
1517  }
1518 
1519  component->SetConvert( convert );
1520 
1521  component->SetTimeStamp( parseHex( aReader, line, &line ) );
1522  }
1523  else if( strCompare( "P", line, &line ) )
1524  {
1525  wxPoint pos;
1526 
1527  pos.x = parseInt( aReader, line, &line );
1528  pos.y = parseInt( aReader, line, &line );
1529  component->SetPosition( pos );
1530  }
1531  else if( strCompare( "AR", line, &line ) )
1532  {
1533  const char* strCompare = "Path=";
1534  int len = strlen( strCompare );
1535 
1536  if( strncasecmp( strCompare, line, len ) != 0 )
1537  SCH_PARSE_ERROR( "missing 'Path=' token", aReader, line );
1538 
1539  line += len;
1540  wxString path, reference, unit;
1541 
1542  parseQuotedString( path, aReader, line, &line );
1543 
1544  strCompare = "Ref=";
1545  len = strlen( strCompare );
1546 
1547  if( strncasecmp( strCompare, line, len ) != 0 )
1548  SCH_PARSE_ERROR( "missing 'Ref=' token", aReader, line );
1549 
1550  line+= len;
1551  parseQuotedString( reference, aReader, line, &line );
1552 
1553  strCompare = "Part=";
1554  len = strlen( strCompare );
1555 
1556  if( strncasecmp( strCompare, line, len ) != 0 )
1557  SCH_PARSE_ERROR( "missing 'Part=' token", aReader, line );
1558 
1559  line+= len;
1560  parseQuotedString( unit, aReader, line, &line );
1561 
1562  long tmp;
1563 
1564  if( !unit.ToLong( &tmp, 10 ) )
1565  SCH_PARSE_ERROR( "expected integer value", aReader, line );
1566 
1567  if( tmp < 0 || tmp > MAX_UNIT_COUNT_PER_PACKAGE )
1568  SCH_PARSE_ERROR( "unit value out of range", aReader, line );
1569 
1570  component->AddHierarchicalReference( path, reference, (int)tmp );
1571  component->GetField( REFERENCE )->SetText( reference );
1572 
1573  }
1574  else if( strCompare( "F", line, &line ) )
1575  {
1576  int index = parseInt( aReader, line, &line );
1577 
1578  wxString text, name;
1579 
1580  parseQuotedString( text, aReader, line, &line, true );
1581 
1582  char orientation = parseChar( aReader, line, &line );
1583  wxPoint pos;
1584  pos.x = parseInt( aReader, line, &line );
1585  pos.y = parseInt( aReader, line, &line );
1586  int size = parseInt( aReader, line, &line );
1587  int attributes = parseHex( aReader, line, &line );
1588 
1589  if( index >= component->GetFieldCount() )
1590  {
1591  // The first MANDATOR_FIELDS _must_ be constructed within
1592  // the SCH_COMPONENT constructor. This assert is simply here
1593  // to guard against a change in that constructor.
1594  wxASSERT( component->GetFieldCount() >= MANDATORY_FIELDS );
1595 
1596  // Ignore the _supplied_ fieldNdx. It is not important anymore
1597  // if within the user defined fields region (i.e. >= MANDATORY_FIELDS).
1598  // We freely renumber the index to fit the next available field slot.
1599  index = component->GetFieldCount(); // new has this index after insertion
1600 
1601  SCH_FIELD field( wxPoint( 0, 0 ), -1, component.get(), name );
1602  component->AddField( field );
1603  }
1604 
1605  // Prior to version 2 of the schematic file format, none of the following existed.
1606  if( m_version > 1 )
1607  {
1608  wxString textAttrs;
1609  char hjustify = parseChar( aReader, line, &line );
1610 
1611  parseUnquotedString( textAttrs, aReader, line, &line );
1612 
1613  // The name of the field is optional.
1614  parseQuotedString( name, aReader, line, &line, true );
1615 
1616  if( hjustify == 'L' )
1617  component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
1618  else if( hjustify == 'R' )
1619  component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
1620  else if( hjustify != 'C' )
1621  SCH_PARSE_ERROR( "component field text horizontal justification must be "
1622  "L, R, or C", aReader, line );
1623 
1624  // We are guaranteed to have a least one character here for older file formats
1625  // otherwise an exception would have been raised..
1626  if( textAttrs[0] == 'T' )
1627  component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
1628  else if( textAttrs[0] == 'B' )
1629  component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
1630  else if( textAttrs[0] != 'C' )
1631  SCH_PARSE_ERROR( "component field text vertical justification must be "
1632  "B, T, or C", aReader, line );
1633 
1634  // Newer file formats include the bold and italics text attribute.
1635  if( textAttrs.Length() > 1 )
1636  {
1637  if( textAttrs.Length() != 3 )
1638  SCH_PARSE_ERROR( _( "component field text attributes must be 3 characters wide" ),
1639  aReader, line );
1640 
1641  if( textAttrs[1] == 'I' )
1642  component->GetField( index )->SetItalic( true );
1643  else if( textAttrs[1] != 'N' )
1644  SCH_PARSE_ERROR( "component field text italics indicator must be I or N",
1645  aReader, line );
1646 
1647  if( textAttrs[2] == 'B' )
1648  component->GetField( index )->SetBold( true );
1649  else if( textAttrs[2] != 'N' )
1650  SCH_PARSE_ERROR( "component field text bold indicator must be B or N",
1651  aReader, line );
1652  }
1653  }
1654 
1655  component->GetField( index )->SetText( text );
1656  component->GetField( index )->SetTextPos( pos );
1657  component->GetField( index )->SetVisible( !attributes );
1658  component->GetField( index )->SetTextSize( wxSize( size, size ) );
1659 
1660  if( orientation == 'H' )
1661  component->GetField( index )->SetTextAngle( TEXT_ANGLE_HORIZ );
1662  else if( orientation == 'V' )
1663  component->GetField( index )->SetTextAngle( TEXT_ANGLE_VERT );
1664  else
1665  SCH_PARSE_ERROR( "component field orientation must be H or V",
1666  aReader, line );
1667 
1668  if( name.IsEmpty() )
1670 
1671  component->GetField( index )->SetName( name );
1672  }
1673  else if( strCompare( "$EndComp", line ) )
1674  {
1675  // Ensure all flags (some are set by previous initializations) are reset:
1676  component->ClearFlags();
1677  return component.release();
1678  }
1679  else
1680  {
1681  // There are two lines that begin with a tab or spaces that includes a line with the
1682  // redundant position information and the transform matrix settings.
1683 
1684  // Parse the redundant position information just the same to check for formatting
1685  // errors.
1686  parseInt( aReader, line, &line ); // Always 1.
1687  parseInt( aReader, line, &line ); // The X coordinate.
1688  parseInt( aReader, line, &line ); // The Y coordinate.
1689 
1690  line = aReader.ReadLine();
1691 
1692  TRANSFORM transform;
1693 
1694  transform.x1 = parseInt( aReader, line, &line );
1695 
1696  if( transform.x1 < -1 || transform.x1 > 1 )
1697  SCH_PARSE_ERROR( "invalid component X1 transform value", aReader, line );
1698 
1699  transform.y1 = parseInt( aReader, line, &line );
1700 
1701  if( transform.y1 < -1 || transform.y1 > 1 )
1702  SCH_PARSE_ERROR( "invalid component Y1 transform value", aReader, line );
1703 
1704  transform.x2 = parseInt( aReader, line, &line );
1705 
1706  if( transform.x2 < -1 || transform.x2 > 1 )
1707  SCH_PARSE_ERROR( "invalid component X2 transform value", aReader, line );
1708 
1709  transform.y2 = parseInt( aReader, line, &line );
1710 
1711  if( transform.y2 < -1 || transform.y2 > 1 )
1712  SCH_PARSE_ERROR( "invalid component Y2 transform value", aReader, line );
1713 
1714  component->SetTransform( transform );
1715  }
1716 
1717  line = aReader.ReadLine();
1718  }
1719 
1720  SCH_PARSE_ERROR( "invalid component line", aReader, line );
1721 
1722  return NULL; // Prevents compiler warning. Should never get here.
1723 }
#define TEXT_ANGLE_HORIZ
Class SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:56
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
int y2
Definition: transform.h:51
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
#define TEXT_ANGLE_VERT
static uint32_t parseHex(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII hex integer string with possible leading whitespace into a long integer and updates th...
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
int x2
Definition: transform.h:50
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
int x1
Definition: transform.h:48
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
#define MAX_UNIT_COUNT_PER_PACKAGE
The maximum number of units per package.
Definition: eeschema_id.h:44
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:278
Field Reference of part, i.e. "IC21".
int m_version
Version of file being loaded.
int y1
Definition: transform.h:49
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:206
#define SCH_PARSE_ERROR(text, reader, pos)
const char * name
Definition: DXF_plotter.cpp:61
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:72
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetModify()
Definition: base_screen.h:324
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122

References TEMPLATE_FIELDNAME::GetDefaultFieldName(), SCH_SHEET::GetScreen(), LINE_READER::GetSource(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, LIB_ID::ID_SCH, LINE_READER::Line(), LINE_READER::LineNumber(), m_rootSheet, m_version, MANDATORY_FIELDS, MAX_UNIT_COUNT_PER_PACKAGE, name, LIB_ID::Parse(), parseChar(), parseHex(), parseInt(), parseQuotedString(), parseUnquotedString(), FILE_LINE_READER::ReadLine(), REFERENCE, SCH_PARSE_ERROR, LIB_ID::SetLibItemName(), BASE_SCREEN::SetModify(), strCompare(), TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, THROW_PARSE_ERROR, TRANSFORM::x1, TRANSFORM::x2, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by loadFile().

◆ loadFile()

void SCH_LEGACY_PLUGIN::loadFile ( const wxString &  aFileName,
SCH_SCREEN aScreen 
)
private

Definition at line 732 of file sch_legacy_plugin.cpp.

733 {
734  FILE_LINE_READER reader( aFileName );
735 
736  loadHeader( reader, aScreen );
737 
738  while( reader.ReadLine() )
739  {
740  char* line = reader.Line();
741 
742  while( *line && *line == ' ' )
743  line++;
744 
745  // Either an object will be loaded properly or the file load will fail and raise
746  // an exception.
747  if( strCompare( "$Descr", line ) )
748  loadPageSettings( reader, aScreen );
749  else if( strCompare( "$Comp", line ) )
750  aScreen->Append( loadComponent( reader ) );
751  else if( strCompare( "$Sheet", line ) )
752  aScreen->Append( loadSheet( reader ) );
753  else if( strCompare( "$Bitmap", line ) )
754  aScreen->Append( loadBitmap( reader ) );
755  else if( strCompare( "Connection", line ) )
756  aScreen->Append( loadJunction( reader ) );
757  else if( strCompare( "NoConn", line ) )
758  aScreen->Append( loadNoConnect( reader ) );
759  else if( strCompare( "Wire", line ) )
760  aScreen->Append( loadWire( reader ) );
761  else if( strCompare( "Entry", line ) )
762  aScreen->Append( loadBusEntry( reader ) );
763  else if( strCompare( "Text", line ) )
764  aScreen->Append( loadText( reader ) );
765  else if( strCompare( "BusAlias", line ) )
766  aScreen->AddBusAlias( loadBusAlias( reader, aScreen ) );
767  else if( strCompare( "$EndSCHEMATC", line ) )
768  return;
769  }
770 
771  // Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
772  // so checking for it's existance will fail so just exit here and take our chances. :(
773  if( m_version > 1 )
774  THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
775 }
SCH_BITMAP * loadBitmap(FILE_LINE_READER &aReader)
std::shared_ptr< BUS_ALIAS > loadBusAlias(FILE_LINE_READER &aReader, SCH_SCREEN *aScreen)
void loadPageSettings(FILE_LINE_READER &aReader, SCH_SCREEN *aScreen)
int m_version
Version of file being loaded.
SCH_SHEET * loadSheet(FILE_LINE_READER &aReader)
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
SCH_TEXT * loadText(FILE_LINE_READER &aReader)
#define THROW_IO_ERROR(msg)
SCH_JUNCTION * loadJunction(FILE_LINE_READER &aReader)
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Adds a bus alias definition (and transfers ownership of the pointer)
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:169
void loadHeader(FILE_LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_BUS_ENTRY_BASE * loadBusEntry(FILE_LINE_READER &aReader)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
SCH_COMPONENT * loadComponent(FILE_LINE_READER &aReader)
SCH_LINE * loadWire(FILE_LINE_READER &aReader)
SCH_NO_CONNECT * loadNoConnect(FILE_LINE_READER &aReader)

References SCH_SCREEN::AddBusAlias(), SCH_SCREEN::Append(), LINE_READER::Line(), loadBitmap(), loadBusAlias(), loadBusEntry(), loadComponent(), loadHeader(), loadJunction(), loadNoConnect(), loadPageSettings(), loadSheet(), loadText(), loadWire(), m_version, FILE_LINE_READER::ReadLine(), strCompare(), and THROW_IO_ERROR.

Referenced by loadHierarchy().

◆ loadHeader()

void SCH_LEGACY_PLUGIN::loadHeader ( FILE_LINE_READER aReader,
SCH_SCREEN aScreen 
)
private

Definition at line 778 of file sch_legacy_plugin.cpp.

779 {
780  const char* line = aReader.ReadLine();
781 
782  if( !line || !strCompare( "Eeschema Schematic File Version", line, &line ) )
783  {
784  m_error.Printf( _( "\"%s\" does not appear to be an Eeschema file" ),
785  GetChars( aScreen->GetFileName() ) );
787  }
788 
789  // get the file version here.
790  m_version = parseInt( aReader, line, &line );
791 
792  // The next lines are the lib list section, and are mainly comments, like:
793  // LIBS:power
794  // the lib list is not used, but is in schematic file just in case.
795  // It is usually not empty, but we accept empty list.
796  // If empty, there is a legacy section, not used
797  // EELAYER i j
798  // and the last line is
799  // EELAYER END
800  // Skip all lines until the end of header "EELAYER END" is found
801  while( aReader.ReadLine() )
802  {
803  line = aReader.Line();
804 
805  while( *line == ' ' )
806  line++;
807 
808  if( strCompare( "EELAYER END", line ) )
809  return;
810  }
811 
812  THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
813 }
const wxString & GetFileName() const
Definition: sch_screen.h:138
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
wxString m_error
For throwing exceptions or errors on partial schematic loads.
int m_version
Version of file being loaded.
#define THROW_IO_ERROR(msg)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:100
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References GetChars(), SCH_SCREEN::GetFileName(), LINE_READER::Line(), m_error, m_version, parseInt(), FILE_LINE_READER::ReadLine(), strCompare(), and THROW_IO_ERROR.

Referenced by loadFile().

◆ loadHierarchy()

void SCH_LEGACY_PLUGIN::loadHierarchy ( SCH_SHEET aSheet)
private

Definition at line 651 of file sch_legacy_plugin.cpp.

652 {
653  SCH_SCREEN* screen = NULL;
654 
655  if( !aSheet->GetScreen() )
656  {
657  // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
658  // stores the file name and extension. Add the project path to the file name and
659  // extension to compare when calling SCH_SHEET::SearchHierarchy().
660  wxFileName fileName = aSheet->GetFileName();
661 
662  if( !fileName.IsAbsolute() )
663  fileName.MakeAbsolute( m_currentPath.top() );
664 
665  // Save the current path so that it gets restored when decending and ascending the
666  // sheet hierarchy which allows for sheet schematic files to be nested in folders
667  // relative to the last path a schematic was loaded from.
668  wxLogTrace( traceSchLegacyPlugin, "Saving path \"%s\"", m_currentPath.top() );
669  m_currentPath.push( fileName.GetPath() );
670  wxLogTrace( traceSchLegacyPlugin, "Current path \"%s\"", m_currentPath.top() );
671  wxLogTrace( traceSchLegacyPlugin, "Loading \"%s\"", fileName.GetFullPath() );
672 
673  m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
674 
675  if( screen )
676  {
677  aSheet->SetScreen( screen );
678 
679  // Do not need to load the sub-sheets - this has already been done.
680  }
681  else
682  {
683  aSheet->SetScreen( new SCH_SCREEN( m_kiway ) );
684  aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
685 
686  try
687  {
688  loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
689 
690  EDA_ITEM* item = aSheet->GetScreen()->GetDrawItems();
691 
692  while( item )
693  {
694  if( item->Type() == SCH_SHEET_T )
695  {
696  SCH_SHEET* sheet = (SCH_SHEET*) item;
697 
698  // Set the parent to aSheet. This effectively creates a method to find
699  // the root sheet from any sheet so a pointer to the root sheet does not
700  // need to be stored globally. Note: this is not the same as a hierarchy.
701  // Complex hierarchies can have multiple copies of a sheet. This only
702  // provides a simple tree to find the root sheet.
703  sheet->SetParent( aSheet );
704 
705  // Recursion starts here.
706  loadHierarchy( sheet );
707  }
708 
709  item = item->Next();
710  }
711  }
712  catch( const IO_ERROR& ioe )
713  {
714  // If there is a problem loading the root sheet, there is no recovery.
715  if( aSheet == m_rootSheet )
716  throw( ioe );
717 
718  // For all subsheets, queue up the error message for the caller.
719  if( !m_error.IsEmpty() )
720  m_error += "\n";
721 
722  m_error += ioe.What();
723  }
724  }
725 
726  m_currentPath.pop();
727  wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
728  }
729 }
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:544
wxString m_error
For throwing exceptions or errors on partial schematic loads.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:104
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()
Definition: sch_sheet.h:278
void loadFile(const wxString &aFileName, SCH_SCREEN *aScreen)
void loadHierarchy(SCH_SHEET *aSheet)
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:219
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:208
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:627
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:157
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:136
KIWAY * m_kiway
Required for path to legacy component libraries.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:167

References SCH_SCREEN::GetDrawItems(), SCH_SHEET::GetFileName(), SCH_SHEET::GetScreen(), loadFile(), m_currentPath, m_error, m_kiway, m_rootSheet, SCH_SHEET_T, SCH_SHEET::SearchHierarchy(), SCH_SCREEN::SetFileName(), EDA_ITEM::SetParent(), SCH_SHEET::SetScreen(), traceSchLegacyPlugin, and IO_ERROR::What().

Referenced by Load().

◆ loadJunction()

SCH_JUNCTION * SCH_LEGACY_PLUGIN::loadJunction ( FILE_LINE_READER aReader)
private

Definition at line 1142 of file sch_legacy_plugin.cpp.

1143 {
1144  std::unique_ptr< SCH_JUNCTION > junction( new SCH_JUNCTION );
1145 
1146  const char* line = aReader.Line();
1147 
1148  wxCHECK( strCompare( "Connection", line, &line ), NULL );
1149 
1150  wxString name;
1151 
1152  parseUnquotedString( name, aReader, line, &line );
1153 
1154  wxPoint position;
1155 
1156  position.x = parseInt( aReader, line, &line );
1157  position.y = parseInt( aReader, line, &line );
1158  junction->SetPosition( position );
1159 
1160  return junction.release();
1161 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
const char * name
Definition: DXF_plotter.cpp:61
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), name, parseInt(), parseUnquotedString(), and strCompare().

Referenced by loadFile().

◆ loadNoConnect()

SCH_NO_CONNECT * SCH_LEGACY_PLUGIN::loadNoConnect ( FILE_LINE_READER aReader)
private

Definition at line 1164 of file sch_legacy_plugin.cpp.

1165 {
1166  std::unique_ptr< SCH_NO_CONNECT > no_connect( new SCH_NO_CONNECT );
1167 
1168  const char* line = aReader.Line();
1169 
1170  wxCHECK( strCompare( "NoConn", line, &line ), NULL );
1171 
1172  wxString name;
1173 
1174  parseUnquotedString( name, aReader, line, &line );
1175 
1176  wxPoint position;
1177 
1178  position.x = parseInt( aReader, line, &line );
1179  position.y = parseInt( aReader, line, &line );
1180  no_connect->SetPosition( position );
1181 
1182  return no_connect.release();
1183 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
const char * name
Definition: DXF_plotter.cpp:61
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References LINE_READER::Line(), name, parseInt(), parseUnquotedString(), and strCompare().

Referenced by loadFile().

◆ loadPageSettings()

void SCH_LEGACY_PLUGIN::loadPageSettings ( FILE_LINE_READER aReader,
SCH_SCREEN aScreen 
)
private

Definition at line 816 of file sch_legacy_plugin.cpp.

817 {
818  wxASSERT( aScreen != NULL );
819 
820  wxString buf;
821  const char* line = aReader.Line();
822 
823  PAGE_INFO pageInfo;
824  TITLE_BLOCK tb;
825 
826  wxCHECK_RET( strCompare( "$Descr", line, &line ), "Invalid sheet description" );
827 
828  parseUnquotedString( buf, aReader, line, &line );
829 
830  if( !pageInfo.SetType( buf ) )
831  SCH_PARSE_ERROR( "invalid page size", aReader, line );
832 
833  int pagew = parseInt( aReader, line, &line );
834  int pageh = parseInt( aReader, line, &line );
835 
836  if( buf == PAGE_INFO::Custom )
837  {
838  pageInfo.SetWidthMils( pagew );
839  pageInfo.SetHeightMils( pageh );
840  }
841  else
842  {
843  wxString orientation;
844 
845  // Non custom size, set portrait if its present. Can be empty string which defaults
846  // to landscape.
847  parseUnquotedString( orientation, aReader, line, &line, true );
848 
849  if( orientation == "portrait" )
850  pageInfo.SetPortrait( true );
851  }
852 
853  aScreen->SetPageSettings( pageInfo );
854 
855  while( line != NULL )
856  {
857  buf.clear();
858 
859  if( !aReader.ReadLine() )
860  SCH_PARSE_ERROR( _( "unexpected end of file" ), aReader, line );
861 
862  line = aReader.Line();
863 
864  if( strCompare( "Sheet", line, &line ) )
865  {
866  aScreen->m_ScreenNumber = parseInt( aReader, line, &line );
867  aScreen->m_NumberOfScreens = parseInt( aReader, line, &line );
868  }
869  else if( strCompare( "Title", line, &line ) )
870  {
871  parseQuotedString( buf, aReader, line, &line, true );
872  tb.SetTitle( buf );
873  }
874  else if( strCompare( "Date", line, &line ) )
875  {
876  parseQuotedString( buf, aReader, line, &line, true );
877  tb.SetDate( buf );
878  }
879  else if( strCompare( "Rev", line, &line ) )
880  {
881  parseQuotedString( buf, aReader, line, &line, true );
882  tb.SetRevision( buf );
883  }
884  else if( strCompare( "Comp", line, &line ) )
885  {
886  parseQuotedString( buf, aReader, line, &line, true );
887  tb.SetCompany( buf );
888  }
889  else if( strCompare( "Comment1", line, &line ) )
890  {
891  parseQuotedString( buf, aReader, line, &line, true );
892  tb.SetComment1( buf );
893  }
894  else if( strCompare( "Comment2", line, &line ) )
895  {
896  parseQuotedString( buf, aReader, line, &line, true );
897  tb.SetComment2( buf );
898  }
899  else if( strCompare( "Comment3", line, &line ) )
900  {
901  parseQuotedString( buf, aReader, line, &line, true );
902  tb.SetComment3( buf );
903  }
904  else if( strCompare( "Comment4", line, &line ) )
905  {
906  parseQuotedString( buf, aReader, line, &line, true );
907  tb.SetComment4( buf );
908  }
909  else if( strCompare( "$EndDescr", line ) )
910  {
911  aScreen->SetTitleBlock( tb );
912  return;
913  }
914  }
915 
916  SCH_PARSE_ERROR( "missing 'EndDescr'", aReader, line );
917 }
void SetComment1(const wxString &aComment)
Definition: title_block.h:117
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
int m_ScreenNumber
Definition: base_screen.h:216
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
void SetRevision(const wxString &aRevision)
Definition: title_block.h:84
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
Definition: page_info.cpp:117
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
void SetDate(const wxString &aDate)
Function SetDate sets the date field, and defaults to the current time and date.
Definition: title_block.h:74
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:134
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:78
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot,...
Definition: title_block.h:40
void SetComment4(const wxString &aComment)
Definition: title_block.h:120
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
void SetCompany(const wxString &aCompany)
Definition: title_block.h:94
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:145
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetTitle(const wxString &aTitle)
Definition: title_block.h:60
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:253
void SetComment2(const wxString &aComment)
Definition: title_block.h:118
#define SCH_PARSE_ERROR(text, reader, pos)
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:239
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
int m_NumberOfScreens
Definition: base_screen.h:217
void SetComment3(const wxString &aComment)
Definition: title_block.h:119
void SetPortrait(bool aIsPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
Definition: page_info.cpp:182

References PAGE_INFO::Custom, LINE_READER::Line(), BASE_SCREEN::m_NumberOfScreens, BASE_SCREEN::m_ScreenNumber, parseInt(), parseQuotedString(), parseUnquotedString(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, TITLE_BLOCK::SetComment1(), TITLE_BLOCK::SetComment2(), TITLE_BLOCK::SetComment3(), TITLE_BLOCK::SetComment4(), TITLE_BLOCK::SetCompany(), TITLE_BLOCK::SetDate(), PAGE_INFO::SetHeightMils(), SCH_SCREEN::SetPageSettings(), PAGE_INFO::SetPortrait(), TITLE_BLOCK::SetRevision(), TITLE_BLOCK::SetTitle(), SCH_SCREEN::SetTitleBlock(), PAGE_INFO::SetType(), PAGE_INFO::SetWidthMils(), and strCompare().

Referenced by loadFile().

◆ loadSheet()

SCH_SHEET * SCH_LEGACY_PLUGIN::loadSheet ( FILE_LINE_READER aReader)
private

Definition at line 920 of file sch_legacy_plugin.cpp.

921 {
922  std::unique_ptr< SCH_SHEET > sheet( new SCH_SHEET() );
923 
924  sheet->SetTimeStamp( GetNewTimeStamp() );
925 
926  const char* line = aReader.ReadLine();
927 
928  while( line != NULL )
929  {
930  if( strCompare( "S", line, &line ) ) // Sheet dimensions.
931  {
932  wxPoint position;
933 
934  position.x = parseInt( aReader, line, &line );
935  position.y = parseInt( aReader, line, &line );
936  sheet->SetPosition( position );
937 
938  wxSize size;
939 
940  size.SetWidth( parseInt( aReader, line, &line ) );
941  size.SetHeight( parseInt( aReader, line, &line ) );
942  sheet->SetSize( size );
943  }
944  else if( strCompare( "U", line, &line ) ) // Sheet time stamp.
945  {
946  sheet->SetTimeStamp( parseHex( aReader, line ) );
947  }
948  else if( *line == 'F' ) // Sheet field.
949  {
950  line++;
951 
952  wxString text;
953  int size;
954  int fieldId = parseInt( aReader, line, &line );
955 
956  if( fieldId == 0 || fieldId == 1 ) // Sheet name and file name.
957  {
958  parseQuotedString( text, aReader, line, &line );
959  size = parseInt( aReader, line, &line );
960 
961  if( fieldId == 0 )
962  {
963  sheet->SetName( text );
964  sheet->SetSheetNameSize( size );
965  }
966  else
967  {
968  sheet->SetFileName( text );
969  sheet->SetFileNameSize( size );
970  }
971  }
972  else // Sheet pin.
973  {
974  std::unique_ptr< SCH_SHEET_PIN > sheetPin( new SCH_SHEET_PIN( sheet.get() ) );
975 
976  sheetPin->SetNumber( fieldId );
977 
978  // Can be empty fields.
979  parseQuotedString( text, aReader, line, &line, true );
980 
981  sheetPin->SetText( text );
982 
983  if( line == NULL )
984  THROW_IO_ERROR( _( "unexpected end of line" ) );
985 
986  switch( parseChar( aReader, line, &line ) )
987  {
988  case 'I':
989  sheetPin->SetShape( NET_INPUT );
990  break;
991 
992  case 'O':
993  sheetPin->SetShape( NET_OUTPUT );
994  break;
995 
996  case 'B':
997  sheetPin->SetShape( NET_BIDI );
998  break;
999 
1000  case 'T':
1001  sheetPin->SetShape( NET_TRISTATE );
1002  break;
1003 
1004  case 'U':
1005  sheetPin->SetShape( NET_UNSPECIFIED );
1006  break;
1007  default:
1008  SCH_PARSE_ERROR( "invalid sheet pin type", aReader, line );
1009  }
1010 
1011  switch( parseChar( aReader, line, &line ) )
1012  {
1013  case 'R': /* pin on right side */
1014  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_RIGHT_SIDE );
1015  break;
1016 
1017  case 'T': /* pin on top side */
1018  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_TOP_SIDE );
1019  break;
1020 
1021  case 'B': /* pin on bottom side */
1022  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_BOTTOM_SIDE );
1023  break;
1024 
1025  case 'L': /* pin on left side */
1026  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_LEFT_SIDE );
1027  break;
1028  default:
1029  SCH_PARSE_ERROR( "invalid sheet pin side", aReader, line );
1030  }
1031 
1032  wxPoint position;
1033 
1034  position.x = parseInt( aReader, line, &line );
1035  position.y = parseInt( aReader, line, &line );
1036  sheetPin->SetPosition( position );
1037 
1038  size = parseInt( aReader, line, &line );
1039 
1040  sheetPin->SetTextSize( wxSize( size, size ) );
1041 
1042  sheet->AddPin( sheetPin.release() );
1043  }
1044  }
1045  else if( strCompare( "$EndSheet", line ) )
1046  return sheet.release();
1047 
1048  line = aReader.ReadLine();
1049  }
1050 
1051  SCH_PARSE_ERROR( "missing '$EndSheet`", aReader, line );
1052 
1053  return NULL; // Prevents compiler warning. Should never get here.
1054 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
static uint32_t parseHex(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII hex integer string with possible leading whitespace into a long integer and updates th...
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
timestamp_t GetNewTimeStamp()
Definition: common.cpp:216
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
#define THROW_IO_ERROR(msg)
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:208
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References GetNewTimeStamp(), NET_BIDI, NET_INPUT, NET_OUTPUT, NET_TRISTATE, NET_UNSPECIFIED, parseChar(), parseHex(), parseInt(), parseQuotedString(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, SCH_SHEET_PIN::SHEET_BOTTOM_SIDE, SCH_SHEET_PIN::SHEET_LEFT_SIDE, SCH_SHEET_PIN::SHEET_RIGHT_SIDE, SCH_SHEET_PIN::SHEET_TOP_SIDE, strCompare(), and THROW_IO_ERROR.

Referenced by loadFile().

◆ LoadSymbol()

LIB_ALIAS * SCH_LEGACY_PLUGIN::LoadSymbol ( const wxString &  aLibraryPath,
const wxString &  aAliasName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

The LIB_PART should be accessed indirectly using the LIB_ALIAS it is associated with.

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aAliasNameis the alias 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 alias 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 4277 of file sch_legacy_plugin.cpp.

4279 {
4280  LOCALE_IO toggle; // toggles on, then off, the C locale.
4281 
4282  m_props = aProperties;
4283 
4284  cacheLib( aLibraryPath );
4285 
4286  LIB_ALIAS_MAP::const_iterator it = m_cache->m_aliases.find( aAliasName );
4287 
4288  if( it == m_cache->m_aliases.end() )
4289  return NULL;
4290 
4291  return it->second;
4292 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:177
SCH_LEGACY_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.

References cacheLib(), SCH_LEGACY_PLUGIN_CACHE::m_aliases, m_cache, and m_props.

◆ loadText()

SCH_TEXT * SCH_LEGACY_PLUGIN::loadText ( FILE_LINE_READER aReader)
private

Definition at line 1329 of file sch_legacy_plugin.cpp.

1330 {
1331  const char* line = aReader.Line();
1332 
1333  wxCHECK( strCompare( "Text", line, &line ), NULL );
1334 
1335  std::unique_ptr< SCH_TEXT> text;
1336 
1337  if( strCompare( "Notes", line, &line ) )
1338  text.reset( new SCH_TEXT );
1339  else if( strCompare( "Label", line, &line ) )
1340  text.reset( new SCH_LABEL );
1341  else if( strCompare( "HLabel", line, &line ) )
1342  text.reset( new SCH_HIERLABEL );
1343  else if( strCompare( "GLabel", line, &line ) )
1344  {
1345  // Prior to version 2, the SCH_GLOBALLABEL object did not exist.
1346  if( m_version == 1 )
1347  text.reset( new SCH_HIERLABEL );
1348  else
1349  text.reset( new SCH_GLOBALLABEL );
1350  }
1351  else
1352  SCH_PARSE_ERROR( "unknown Text type", aReader, line );
1353 
1354  // Parse the parameters common to all text objects.
1355  wxPoint position;
1356 
1357  position.x = parseInt( aReader, line, &line );
1358  position.y = parseInt( aReader, line, &line );
1359  text->SetPosition( position );
1360  text->SetLabelSpinStyle( parseInt( aReader, line, &line ) );
1361 
1362  int size = parseInt( aReader, line, &line );
1363 
1364  text->SetTextSize( wxSize( size, size ) );
1365 
1366  // Parse the global and hierarchical label type.
1367  if( text->Type() == SCH_HIER_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
1368  {
1369  if( strCompare( SheetLabelType[NET_INPUT], line, &line ) )
1370  text->SetShape( NET_INPUT );
1371  else if( strCompare( SheetLabelType[NET_OUTPUT], line, &line ) )
1372  text->SetShape( NET_OUTPUT );
1373  else if( strCompare( SheetLabelType[NET_BIDI], line, &line ) )
1374  text->SetShape( NET_BIDI );
1375  else if( strCompare( SheetLabelType[NET_TRISTATE], line, &line ) )
1376  text->SetShape( NET_TRISTATE );
1377  else if( strCompare( SheetLabelType[NET_UNSPECIFIED], line, &line ) )
1378  text->SetShape( NET_UNSPECIFIED );
1379  else
1380  SCH_PARSE_ERROR( "invalid label type", aReader, line );
1381  }
1382 
1383  int thickness = 0;
1384 
1385  // The following tokens do not exist in version 1 schematic files,
1386  // and not always in version 2 for HLabels and GLabels
1387  if( m_version > 1 )
1388  {
1389  if( m_version > 2 || *line >= ' ' )
1390  {
1391  if( strCompare( "Italic", line, &line ) )
1392  text->SetItalic( true );
1393  else if( !strCompare( "~", line, &line ) )
1394  SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
1395  }
1396 
1397  // The thickness token does not exist in older versions of the schematic file format
1398  // so calling parseInt will be made only if the EOL is not reached.
1399  if( *line >= ' ' )
1400  thickness = parseInt( aReader, line, &line );
1401  }
1402 
1403  text->SetBold( thickness != 0 );
1404  text->SetThickness( thickness != 0 ? GetPenSizeForBold( size ) : 0 );
1405 
1406  // Read the text string for the text.
1407  char* tmp = aReader.ReadLine();
1408 
1409  tmp = strtok( tmp, "\r\n" );
1410  wxString val = FROM_UTF8( tmp );
1411 
1412  for( ; ; )
1413  {
1414  int i = val.find( wxT( "\\n" ) );
1415 
1416  if( i == wxNOT_FOUND )
1417  break;
1418 
1419  val.erase( i, 2 );
1420  val.insert( i, wxT( "\n" ) );
1421  }
1422 
1423  text->SetText( val );
1424 
1425  return text.release();
1426 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:61
int GetPenSizeForBold(int aTextSize)
Function GetPensizeForBold.
const char * SheetLabelType[]
Definition: sch_text.cpp:58
int m_version
Version of file being loaded.
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define SCH_PARSE_ERROR(text, reader, pos)
size_t i
Definition: json11.cpp:597
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...

References FROM_UTF8(), GetPenSizeForBold(), i, LINE_READER::Line(), m_version, NET_BIDI, NET_INPUT, NET_OUTPUT, NET_TRISTATE, NET_UNSPECIFIED, parseInt(), FILE_LINE_READER::ReadLine(), SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_PARSE_ERROR, SheetLabelType, and strCompare().

Referenced by loadFile().

◆ loadWire()

SCH_LINE * SCH_LEGACY_PLUGIN::loadWire ( FILE_LINE_READER aReader)
private

Definition at line 1186 of file sch_legacy_plugin.cpp.

1187 {
1188  std::unique_ptr< SCH_LINE > wire( new SCH_LINE );
1189 
1190  const char* line = aReader.Line();
1191 
1192  wxCHECK( strCompare( "Wire", line, &line ), NULL );
1193 
1194  if( strCompare( "Wire", line, &line ) )
1195  wire->SetLayer( LAYER_WIRE );
1196  else if( strCompare( "Bus", line, &line ) )
1197  wire->SetLayer( LAYER_BUS );
1198  else if( strCompare( "Notes", line, &line ) )
1199  wire->SetLayer( LAYER_NOTES );
1200  else
1201  SCH_PARSE_ERROR( "invalid line type", aReader, line );
1202 
1203  if( !strCompare( "Line", line, &line ) )
1204  SCH_PARSE_ERROR( "invalid wire definition", aReader, line );
1205 
1206  // Since Sept 15, 2017, a line style is alloved (width, style, color)
1207  // Only non default values are stored
1208  while( !is_eol( *line ) )
1209  {
1210  wxString buf;
1211 
1212  parseUnquotedString( buf, aReader, line, &line );
1213 
1214  if( buf == ")" )
1215  continue;
1216 
1217  else if( buf == T_WIDTH )
1218  {
1219  int size = parseInt( aReader, line, &line );
1220  wire->SetLineWidth( size );
1221  }
1222  else if( buf == T_STYLE )
1223  {
1224  parseUnquotedString( buf, aReader, line, &line );
1225  int style = SCH_LINE::GetLineStyleInternalId( buf );
1226  wire->SetLineStyle( style );
1227  }
1228  else // should be the color parameter.
1229  {
1230  // The color param is something like rgb(150, 40, 191)
1231  // and because there is no space between ( and 150
1232  // the first param is inside buf.
1233  // So break keyword and the first param into 2 separate strings.
1234  wxString prm, keyword;
1235  keyword = buf.BeforeLast( '(', &prm );
1236 
1237  if( ( keyword == T_COLOR ) || ( keyword == T_COLORA ) )
1238  {
1239  long color[4] = { 0 };
1240 
1241  int ii = 0;
1242 
1243  if( !prm.IsEmpty() )
1244  {
1245  prm.ToLong( &color[ii] );
1246  ii++;
1247  }
1248 
1249  int prm_count = ( keyword == T_COLORA ) ? 4 : 3;
1250  // fix opacity to 1.0 or 255, when not exists in file
1251  color[3] = 255;
1252 
1253  for(; ii < prm_count && !is_eol( *line ); ii++ )
1254  {
1255  color[ii] = parseInt( aReader, line, &line );
1256 
1257  // Skip the separator between values
1258  if( *line == ',' || *line == ' ')
1259  line++;
1260  }
1261 
1262  wire->SetLineColor( color[0]/255.0, color[1]/255.0, color[2]/255.0,color[3]/255.0 );
1263  }
1264  }
1265  }
1266 
1267  // Read the segment en points coordinates:
1268  line = aReader.ReadLine();
1269 
1270  wxPoint begin, end;
1271 
1272  begin.x = parseInt( aReader, line, &line );
1273  begin.y = parseInt( aReader, line, &line );
1274  end.x = parseInt( aReader, line, &line );
1275  end.y = parseInt( aReader, line, &line );
1276 
1277  wire->SetStartPoint( begin );
1278  wire->SetEndPoint( end );
1279 
1280  return wire.release();
1281 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:194
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
int color
Definition: DXF_plotter.cpp:62
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
#define T_WIDTH
#define T_STYLE
static bool is_eol(char c)
#define T_COLOR
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static int GetLineStyleInternalId(const wxString &aStyleName)
Definition: sch_line.cpp:140
#define SCH_PARSE_ERROR(text, reader, pos)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define T_COLORA

References color, SCH_LINE::GetLineStyleInternalId(), is_eol(), LAYER_BUS, LAYER_NOTES, LAYER_WIRE, LINE_READER::Line(), parseInt(), parseUnquotedString(), FILE_LINE_READER::ReadLine(), SCH_PARSE_ERROR, strCompare(), T_COLOR, T_COLORA, T_STYLE, and T_WIDTH.

Referenced by loadFile().

◆ ParsePart()

LIB_PART * SCH_LEGACY_PLUGIN::ParsePart ( LINE_READER reader,
int  aMajorVersion = 0,
int  aMinorVersion = 0 
)
static

Definition at line 4425 of file sch_legacy_plugin.cpp.

4427 {
4428  return SCH_LEGACY_PLUGIN_CACHE::LoadPart( reader, aMajorVersion, aMinorVersion );
4429 }
static LIB_PART * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion)

References SCH_LEGACY_PLUGIN_CACHE::LoadPart().

Referenced by LIB_EDIT_FRAME::OnPasteDuplicatePart().

◆ Save()

void SCH_LEGACY_PLUGIN::Save ( const wxString &  aFileName,
SCH_SCREEN aSchematic,
KIWAY aKiway,
const PROPERTIES aProperties = NULL 
)
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.
aSchematicis the class SCH_SCREEN 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.
aKiwayis the KIWAY object used to access the component libraries loaded by the project.
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.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented from SCH_PLUGIN.

Definition at line 1752 of file sch_legacy_plugin.cpp.

1754 {
1755  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN object." );
1756  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1757 
1758  LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
1759 
1760  init( aKiway, aProperties );
1761 
1762  wxFileName fn = aFileName;
1763 
1764  // File names should be absolute. Don't assume everything relative to the project path
1765  // works properly.
1766  wxASSERT( fn.IsAbsolute() );
1767 
1768  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1769 
1770  m_out = &formatter; // no ownership
1771 
1772  Format( aScreen );
1773 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:177
void Format(SCH_SCREEN *aScreen)
void init(KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
initialize PLUGIN like a constructor would.
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492

References Format(), init(), and m_out.

◆ saveBitmap()

void SCH_LEGACY_PLUGIN::saveBitmap ( SCH_BITMAP aBitmap)
private

Definition at line 1999 of file sch_legacy_plugin.cpp.

2000 {
2001  wxCHECK_RET( aBitmap != NULL, "SCH_BITMAP* is NULL" );
2002 
2003  wxImage* image = aBitmap->GetImage()->GetImageData();
2004 
2005  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
2006 
2007  m_out->Print( 0, "$Bitmap\n" );
2008  m_out->Print( 0, "Pos %-4d %-4d\n", aBitmap->GetPosition().x, aBitmap->GetPosition().y );
2009  m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
2010  m_out->Print( 0, "Data\n" );
2011 
2012  wxMemoryOutputStream stream;
2013 
2014  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
2015 
2016  // Write binary data in hexadecimal form (ASCII)
2017  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
2018  char* begin = (char*) buffer->GetBufferStart();
2019 
2020  for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
2021  {
2022  if( ii >= 32 )
2023  {
2024  ii = 0;
2025 
2026  m_out->Print( 0, "\n" );
2027  }
2028 
2029  m_out->Print( 0, "%2.2X ", *begin & 0xFF );
2030  }
2031 
2032  m_out->Print( 0, "\nEndData\n" );
2033  m_out->Print( 0, "$EndBitmap\n" );
2034 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
double GetScale() const
Definition: bitmap_base.h:84
wxImage * GetImageData()
Definition: bitmap_base.h:77
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_bitmap.h:156
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:65
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References SCH_BITMAP::GetImage(), BITMAP_BASE::GetImageData(), SCH_BITMAP::GetPosition(), BITMAP_BASE::GetScale(), m_out, and OUTPUTFORMATTER::Print().

Referenced by Format().

◆ saveBusAlias()

void SCH_LEGACY_PLUGIN::saveBusAlias ( std::shared_ptr< BUS_ALIAS aAlias)
private

Definition at line 2245 of file sch_legacy_plugin.cpp.

2246 {
2247  wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" );
2248 
2249  wxString members = boost::algorithm::join( aAlias->Members(), " " );
2250 
2251  m_out->Print( 0, "BusAlias %s %s\n",
2252  TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
2253 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:47
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

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

Referenced by Format().

◆ saveBusEntry()

void SCH_LEGACY_PLUGIN::saveBusEntry ( SCH_BUS_ENTRY_BASE aBusEntry)
private

Definition at line 2130 of file sch_legacy_plugin.cpp.

2131 {
2132  wxCHECK_RET( aBusEntry != NULL, "SCH_BUS_ENTRY_BASE* is NULL" );
2133 
2134  if( aBusEntry->GetLayer() == LAYER_WIRE )
2135  m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
2136  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
2137  aBusEntry->m_End().x, aBusEntry->m_End().y );
2138  else
2139  m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
2140  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
2141  aBusEntry->m_End().x, aBusEntry->m_End().y );
2142 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxPoint m_End() const
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxPoint GetPosition() const override
Function GetPosition.

References SCH_ITEM::GetLayer(), SCH_BUS_ENTRY_BASE::GetPosition(), LAYER_WIRE, SCH_BUS_ENTRY_BASE::m_End(), m_out, and OUTPUTFORMATTER::Print().

Referenced by Format().

◆ saveComponent()

void SCH_LEGACY_PLUGIN::saveComponent ( SCH_COMPONENT aComponent)
private

Definition at line 1862 of file sch_legacy_plugin.cpp.

1863 {
1864  std::string name1;
1865  std::string name2;
1866  wxArrayString reference_fields;
1867 
1868  static wxString delimiters( wxT( " " ) );
1869 
1870  // This is redundant with the AR entries below, but it makes the files backwards-compatible.
1871  if( aComponent->GetPathsAndReferences().GetCount() > 0 )
1872  {
1873  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[0], delimiters );
1874  name1 = toUTFTildaText( reference_fields[1] );
1875  }
1876  else
1877  {
1878  if( aComponent->GetField( REFERENCE )->GetText().IsEmpty() )
1879  name1 = toUTFTildaText( aComponent->GetPrefix() );
1880  else
1881  name1 = toUTFTildaText( aComponent->GetField( REFERENCE )->GetText() );
1882  }
1883 
1884  wxString part_name = aComponent->GetLibId().Format();
1885 
1886  if( part_name.size() )
1887  {
1888  name2 = toUTFTildaText( part_name );
1889  }
1890  else
1891  {
1892  name2 = "_NONAME_";
1893  }
1894 
1895  m_out->Print( 0, "$Comp\n" );
1896  m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
1897 
1898  // Generate unit number, convert and time stamp
1899  m_out->Print( 0, "U %d %d %8.8X\n", aComponent->GetUnit(), aComponent->GetConvert(),
1900  aComponent->GetTimeStamp() );
1901 
1902  // Save the position
1903  m_out->Print( 0, "P %d %d\n", aComponent->GetPosition().x, aComponent->GetPosition().y );
1904 
1905  /* If this is a complex hierarchy; save hierarchical references.
1906  * but for simple hierarchies it is not necessary.
1907  * the reference inf is already saved
1908  * this is useful for old Eeschema version compatibility
1909  */
1910  if( aComponent->GetPathsAndReferences().GetCount() > 1 )
1911  {
1912  for( unsigned int ii = 0; ii < aComponent->GetPathsAndReferences().GetCount(); ii++ )
1913  {
1914  /*format:
1915  * AR Path="/140/2" Ref="C99" Part="1"
1916  * where 140 is the uid of the containing sheet
1917  * and 2 is the timestamp of this component.
1918  * (timestamps are actually 8 hex chars)
1919  * Ref is the conventional component reference for this 'path'
1920  * Part is the conventional component part selection for this 'path'
1921  */
1922  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[ii],
1923  delimiters );
1924 
1925  m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%s\" \n",
1926  TO_UTF8( reference_fields[0] ),
1927  TO_UTF8( reference_fields[1] ),
1928  TO_UTF8( reference_fields[2] ) );
1929  }
1930  }
1931 
1932  // update the ugly field index, which I would like to see go away someday soon.
1933  for( int i = 0; i < aComponent->GetFieldCount(); ++i )
1934  aComponent->GetField( i )->SetId( i );
1935 
1936  // Fixed fields:
1937  // Save mandatory fields even if they are blank,
1938  // because the visibility, size and orientation are set from libary editor.
1939  for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
1940  saveField( aComponent->GetField( i ) );
1941 
1942  // User defined fields:
1943  // The *policy* about which user defined fields are part of a symbol is now
1944  // only in the dialog editors. No policy should be enforced here, simply
1945  // save all the user defined fields, they are present because a dialog editor
1946  // thought they should be. If you disagree, go fix the dialog editors.
1947  for( int i = MANDATORY_FIELDS; i < aComponent->GetFieldCount(); ++i )
1948  saveField( aComponent->GetField( i ) );
1949 
1950  // Unit number, position, box ( old standard )
1951  m_out->Print( 0, "\t%-4d %-4d %-4d\n", aComponent->GetUnit(), aComponent->GetPosition().x,
1952  aComponent->GetPosition().y );
1953 
1954  TRANSFORM transform = aComponent->GetTransform();
1955 
1956  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
1957  transform.x1, transform.y1, transform.x2, transform.y2 );
1958  m_out->Print( 0, "$EndComp\n" );
1959 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int y2
Definition: transform.h:51
const wxString GetText() const override
Function GetText returns the string associated with the text object.
Definition: sch_field.cpp:105
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
int x2
Definition: transform.h:50
wxString GetPrefix() const
int x1
Definition: transform.h:48
Field Reference of part, i.e. "IC21".
const wxArrayString & GetPathsAndReferences() const
void saveField(SCH_FIELD *aField)
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:47
int y1
Definition: transform.h:49
int GetUnit() const
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
TRANSFORM & GetTransform() const
std::string toUTFTildaText(const wxString &txt)
Function toUTFTildaText convert a wxString to UTF8 and replace any control characters with a ~,...
timestamp_t GetTimeStamp() const
Definition: base_struct.h:210
int GetFieldCount() const
Return the number of fields in this symbol.
UTF8 Format() const
Definition: lib_id.cpp:237
size_t i
Definition: json11.cpp:597
wxPoint GetPosition() const override
Function GetPosition.
int GetConvert() const
void SetId(int aId)
Definition: sch_field.h:91
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
const LIB_ID & GetLibId() const

References LIB_ID::Format(), SCH_COMPONENT::GetConvert(), SCH_COMPONENT::GetField(), SCH_COMPONENT::GetFieldCount(), SCH_COMPONENT::GetLibId(), SCH_COMPONENT::GetPathsAndReferences(), SCH_COMPONENT::GetPosition(), SCH_COMPONENT::GetPrefix(), SCH_FIELD::GetText(), EDA_ITEM::GetTimeStamp(), SCH_COMPONENT::GetTransform(), SCH_COMPONENT::GetUnit(), i, m_out, MANDATORY_FIELDS, OUTPUTFORMATTER::Print(), REFERENCE, saveField(), SCH_FIELD::SetId(), TO_UTF8, toUTFTildaText(), TRANSFORM::x1, TRANSFORM::x2, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by Format().

◆ saveField()

void SCH_LEGACY_PLUGIN::saveField ( SCH_FIELD aField)
private

Definition at line 1962 of file sch_legacy_plugin.cpp.

1963 {
1964  char hjustify = 'C';
1965 
1966  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
1967  hjustify = 'L';
1968  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
1969  hjustify = 'R';
1970 
1971  char vjustify = 'C';
1972 
1973  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
1974  vjustify = 'B';
1975  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
1976  vjustify = 'T';
1977 
1978  m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1979  aField->GetId(),
1980  EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
1981  aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
1982  aField->GetLibPosition().x, aField->GetLibPosition().y,
1983  aField->GetTextWidth(),
1984  !aField->IsVisible(),
1985  hjustify, vjustify,
1986  aField->IsItalic() ? 'I' : 'N',
1987  aField->IsBold() ? 'B' : 'N' );
1988 
1989  // Save field name, if the name is user definable
1990  if( aField->GetId() >= FIELD1 )
1991  {
1992  m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
1993  }
1994 
1995  m_out->Print( 0, "\n" );
1996 }
#define TEXT_ANGLE_HORIZ
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
bool IsBold() const
Definition: eda_text.h:191
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:209
const wxString GetText() const override
Function GetText returns the string associated with the text object.
Definition: sch_field.cpp:105
bool IsVisible() const
Definition: eda_text.h:194
double GetTextAngle() const
Definition: eda_text.h:182
int GetId() const
Definition: sch_field.h:89
bool IsItalic() const
Definition: eda_text.h:188
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:241
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:208
wxPoint GetLibPosition() const
Definition: sch_field.h:179
int GetTextWidth() const
Definition: eda_text.h:236
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:428
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References EscapedUTF8(), FIELD1, EDA_TEXT::GetHorizJustify(), SCH_FIELD::GetId(), SCH_FIELD::GetLibPosition(), SCH_FIELD::GetName(), SCH_FIELD::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextWidth(), EDA_TEXT::GetVertJustify(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, EDA_TEXT::IsBold(), EDA_TEXT::IsItalic(), EDA_TEXT::IsVisible(), m_out, OUTPUTFORMATTER::Print(), and TEXT_ANGLE_HORIZ.

Referenced by saveComponent().

◆ saveJunction()

void SCH_LEGACY_PLUGIN::saveJunction ( SCH_JUNCTION aJunction)
private

Definition at line 2112 of file sch_legacy_plugin.cpp.

2113 {
2114  wxCHECK_RET( aJunction != NULL, "SCH_JUNCTION* is NULL" );
2115 
2116  m_out->Print( 0, "Connection ~ %-4d %-4d\n",
2117  aJunction->GetPosition().x, aJunction->GetPosition().y );
2118 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_junction.h:103
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References SCH_JUNCTION::GetPosition(), m_out, and OUTPUTFORMATTER::Print().

Referenced by Format().

◆ SaveLibrary()

void SCH_LEGACY_PLUGIN::SaveLibrary ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Reimplemented from SCH_PLUGIN.

Definition at line 4385 of file sch_legacy_plugin.cpp.

4386 {
4387  if( !m_cache )
4388  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4389 
4390  wxString oldFileName = m_cache->GetFileName();
4391 
4392  if( !m_cache->IsFile( aLibraryPath ) )
4393  {
4394  m_cache->SetFileName( aLibraryPath );
4395  }
4396 
4397  // This is a forced save.
4398  m_cache->SetModified();
4399  m_cache->Save( writeDocFile( aProperties ) );
4400  m_cache->SetFileName( oldFileName );
4401 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLU...
void SetModified(bool aModified=true)
void SetFileName(const wxString &aFileName)
bool IsFile(const wxString &aFullPathAndFileName) const
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
bool writeDocFile(const PROPERTIES *aProperties)

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

◆ saveLine()

void SCH_LEGACY_PLUGIN::saveLine ( SCH_LINE aLine)
private

Definition at line 2145 of file sch_legacy_plugin.cpp.

2146 {
2147  wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" );
2148 
2149  const char* layer = "Notes";
2150  const char* width = "Line";
2151 
2152  if( aLine->GetLayer() == LAYER_WIRE )
2153  layer = "Wire";
2154  else if( aLine->GetLayer() == LAYER_BUS )
2155  layer = "Bus";
2156 
2157  m_out->Print( 0, "Wire %s %s", layer, width );
2158 
2159  // Write line style (width, type, color) only for non default values
2160  if( aLine->GetLayer() == LAYER_NOTES )
2161  {
2162  if( aLine->GetPenSize() != aLine->GetDefaultWidth() )
2163  m_out->Print( 0, " %s %d", T_WIDTH, aLine->GetLineSize() );
2164 
2165  if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
2166  m_out->Print( 0, " %s %s", T_STYLE, SCH_LINE::GetLineStyleName( aLine->GetLineStyle() ) );
2167 
2168  if( aLine->GetLineColor() != aLine->GetDefaultColor() )
2169  m_out->Print( 0, " %s",
2170  TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
2171  }
2172 
2173  m_out->Print( 0, "\n" );
2174 
2175  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
2176  aLine->GetStartPoint().x, aLine->GetStartPoint().y,
2177  aLine->GetEndPoint().x, aLine->GetEndPoint().y );
2178 
2179  m_out->Print( 0, "\n");
2180 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
COLOR4D GetLineColor() const
Definition: sch_line.cpp:243
wxPoint GetStartPoint() const
Definition: sch_line.h:76
#define T_WIDTH
int GetDefaultWidth() const
Definition: sch_line.cpp:278
#define T_STYLE
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:47
int GetDefaultStyle() const
Definition: sch_line.cpp:251
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
int GetLineSize() const
Definition: sch_line.h:110
COLOR4D GetDefaultColor() const
Definition: sch_line.cpp:213
static const char * GetLineStyleName(int aStyle)
Definition: sch_line.cpp:112
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:296
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
int GetLineStyle() const
Definition: sch_line.cpp:269
wxPoint GetEndPoint() const
Definition: sch_line.h:80

References SCH_LINE::GetDefaultColor(), SCH_LINE::GetDefaultStyle(), SCH_LINE::GetDefaultWidth(), SCH_LINE::GetEndPoint(), SCH_ITEM::GetLayer(), SCH_LINE::GetLineColor(), SCH_LINE::GetLineSize(), SCH_LINE::GetLineStyle(), SCH_LINE::GetLineStyleName(), SCH_LINE::GetPenSize(), SCH_LINE::GetStartPoint(), LAYER_BUS, LAYER_NOTES, LAYER_WIRE, m_out, OUTPUTFORMATTER::Print(), T_STYLE, T_WIDTH, and TO_UTF8.

Referenced by Format().

◆ saveNoConnect()

void SCH_LEGACY_PLUGIN::saveNoConnect ( SCH_NO_CONNECT aNoConnect)
private

Definition at line 2121 of file sch_legacy_plugin.cpp.

2122 {
2123  wxCHECK_RET( aNoConnect != NULL, "SCH_NOCONNECT* is NULL" );
2124 
2125  m_out->Print( 0, "NoConn ~ %-4d %-4d\n", aNoConnect->GetPosition().x,
2126  aNoConnect->GetPosition().y );
2127 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxPoint GetPosition() const override
Function GetPosition.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References SCH_NO_CONNECT::GetPosition(), m_out, and OUTPUTFORMATTER::Print().

Referenced by Format().

◆ saveSheet()

void SCH_LEGACY_PLUGIN::saveSheet ( SCH_SHEET aSheet)
private

Definition at line 2037 of file sch_legacy_plugin.cpp.

2038 {
2039  wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" );
2040 
2041  m_out->Print( 0, "$Sheet\n" );
2042  m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
2043  aSheet->GetPosition().x, aSheet->GetPosition().y,
2044  aSheet->GetSize().x, aSheet->GetSize().y );
2045 
2046  m_out->Print( 0, "U %8.8X\n", aSheet->GetTimeStamp() );
2047 
2048  if( !aSheet->GetName().IsEmpty() )
2049  m_out->Print( 0, "F0 %s %d\n", EscapedUTF8( aSheet->GetName() ).c_str(),
2050  aSheet->GetSheetNameSize() );
2051 
2052  if( !aSheet->GetFileName().IsEmpty() )
2053  m_out->Print( 0, "F1 %s %d\n", EscapedUTF8( aSheet->GetFileName() ).c_str(),
2054  aSheet->GetFileNameSize() );
2055 
2056  for( const SCH_SHEET_PIN& pin : aSheet->GetPins() )
2057  {
2058  int type, side;
2059 
2060  if( pin.GetText().IsEmpty() )
2061  break;
2062 
2063  switch( pin.GetEdge() )
2064  {
2065  default:
2067  side = 'L';
2068  break;
2069 
2071  side = 'R';
2072  break;
2073 
2075  side = 'T';
2076  break;
2077 
2079  side = 'B';
2080  break;
2081  }
2082 
2083  switch( pin.GetShape() )
2084  {
2085  case NET_INPUT:
2086  type = 'I'; break;
2087 
2088  case NET_OUTPUT:
2089  type = 'O'; break;
2090 
2091  case NET_BIDI:
2092  type = 'B'; break;
2093 
2094  case NET_TRISTATE:
2095  type = 'T'; break;
2096 
2097  default:
2098  case NET_UNSPECIFIED:
2099  type = 'U'; break;
2100  }
2101 
2102  m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n", pin.GetNumber(),
2103  EscapedUTF8( pin.GetText() ).c_str(), // supplies wrapping quotes
2104  type, side, pin.GetPosition().x, pin.GetPosition().y,
2105  pin.GetTextWidth() );
2106  }
2107 
2108  m_out->Print( 0, "$EndSheet\n" );
2109 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
SCH_SHEET_PINS & GetPins()
Definition: sch_sheet.h:333
int GetFileNameSize() const
Definition: sch_sheet.h:274
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:241
int GetSheetNameSize() const
Definition: sch_sheet.h:270
wxString GetName() const
Definition: sch_sheet.h:266
timestamp_t GetTimeStamp() const
Definition: base_struct.h:210
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:545
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:627
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxSize GetSize()
Definition: sch_sheet.h:280

References EscapedUTF8(), SCH_SHEET::GetFileName(), SCH_SHEET::GetFileNameSize(), SCH_SHEET::GetName(), SCH_SHEET::GetPins(), SCH_SHEET::GetPosition(), SCH_SHEET::GetSheetNameSize(), SCH_SHEET::GetSize(), EDA_ITEM::GetTimeStamp(), m_out, NET_BIDI, NET_INPUT, NET_OUTPUT, NET_TRISTATE, NET_UNSPECIFIED, OUTPUTFORMATTER::Print(), SCH_SHEET_PIN::SHEET_BOTTOM_SIDE, SCH_SHEET_PIN::SHEET_LEFT_SIDE, SCH_SHEET_PIN::SHEET_RIGHT_SIDE, and SCH_SHEET_PIN::SHEET_TOP_SIDE.

Referenced by Format().

◆ SaveSymbol()

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

Write aSymbol to an existing library located at aLibraryPath.

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4295 of file sch_legacy_plugin.cpp.

4297 {
4298  m_props = aProperties;
4299 
4300  cacheLib( aLibraryPath );
4301 
4302  m_cache->AddSymbol( aSymbol );
4303 
4304  if( !isBuffering( aProperties ) )
4305  m_cache->Save( writeDocFile( aProperties ) );
4306 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
bool isBuffering(const PROPERTIES *aProperties)
void cacheLib(const wxString &aLibraryFileName)
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
void AddSymbol(const LIB_PART *aPart)
bool writeDocFile(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.

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

◆ saveText()

void SCH_LEGACY_PLUGIN::saveText ( SCH_TEXT aText)
private

Definition at line 2183 of file sch_legacy_plugin.cpp.

2184 {
2185  wxCHECK_RET( aText != NULL, "SCH_TEXT* is NULL" );
2186 
2187  const char* italics = "~";
2188  const char* textType = "Notes";
2189 
2190  if( aText->IsItalic() )
2191  italics = "Italic";
2192 
2193  wxString text = aText->GetText();
2194 
2195  SCH_LAYER_ID layer = aText->GetLayer();
2196 
2197  if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
2198  {
2199  if( layer == LAYER_NOTES )
2200  {
2201  // For compatibility reasons, the text must be saved in only one text line
2202  // so replace all EOLs with \\n
2203  text.Replace( wxT( "\n" ), wxT( "\\n" ) );
2204 
2205  // Here we should have no CR or LF character in line
2206  // This is not always the case if a multiline text was copied (using a copy/paste
2207  // function) from a text that uses E.O.L characters that differs from the current
2208  // EOL format. This is mainly the case under Linux using LF symbol when copying
2209  // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
2210  // (or LF left under MacOSX)
2211  for( unsigned ii = 0; ii < text.Len(); )
2212  {
2213  if( text[ii] == 0x0A || text[ii] == 0x0D )
2214  text.erase( ii, 1 );
2215  else
2216  ii++;
2217  }
2218  }
2219  else
2220  {
2221  textType = "Label";
2222  }
2223 
2224  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2225  aText->GetPosition().x, aText->GetPosition().y,
2226  aText->GetLabelSpinStyle(),
2227  aText->GetTextWidth(),
2228  italics, aText->GetThickness(), TO_UTF8( text ) );
2229  }
2230  else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2231  {
2232  textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2233 
2234  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2235  aText->GetPosition().x, aText->GetPosition().y,
2236  aText->GetLabelSpinStyle(),
2237  aText->GetTextWidth(),
2238  SheetLabelType[aText->GetShape()],
2239  italics,
2240  aText->GetThickness(), TO_UTF8( text ) );
2241  }
2242 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:172
virtual const wxString GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:148
const char * SheetLabelType[]
Definition: sch_text.cpp:58
bool IsItalic() const
Definition: eda_text.h:188
int GetLabelSpinStyle() const
Definition: sch_text.h:119
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:47
SCH_LAYER_ID
Eeschema drawing layers.
virtual wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_text.h:196
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
int GetTextWidth() const
Definition: eda_text.h:236
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:121

References SCH_TEXT::GetLabelSpinStyle(), SCH_ITEM::GetLayer(), SCH_TEXT::GetPosition(), SCH_TEXT::GetShape(), EDA_TEXT::GetText(), EDA_TEXT::GetTextWidth(), EDA_TEXT::GetThickness(), EDA_TEXT::IsItalic(), LAYER_GLOBLABEL, LAYER_HIERLABEL, LAYER_LOCLABEL, LAYER_NOTES, m_out, OUTPUTFORMATTER::Print(), SheetLabelType, and TO_UTF8.

Referenced by Format().

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

150 {
151  // disable all these in another couple of months, after everyone has seen them:
152 #if 1
153  (*aListToAppendTo)["debug_level"] = UTF8( _(
154  "Enable <b>debug</b> logging for Symbol*() functions in this SCH_PLUGIN."
155  ) );
156 
157  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
158  "Regular expression <b>symbol name</b> filter."
159  ) );
160 
161  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
162  "Enable transaction logging. The mere presence of this option turns on the "
163  "logging, no need to set a Value."
164  ) );
165 
166  (*aListToAppendTo)["username"] = UTF8( _(
167  "User name for <b>login</b> to some special library server."
168  ));
169 
170  (*aListToAppendTo)["password"] = UTF8( _(
171  "Password for <b>login</b> to some special library server."
172  ) );
173 #endif
174 
175 #if 1
176  // Suitable for a C++ to python SCH_PLUGIN::Footprint*() adapter, move it to the adapter
177  // if and when implemented.
178  (*aListToAppendTo)["python_symbol_plugin"] = UTF8( _(
179  "Enter the python symbol which implements the SCH_PLUGIN::Symbol*() functions."
180  ) );
181 #endif
182 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73

◆ writeDocFile()

bool SCH_LEGACY_PLUGIN::writeDocFile ( const PROPERTIES aProperties)
private

Definition at line 4193 of file sch_legacy_plugin.cpp.

4194 {
4195  std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
4196 
4197  if( aProperties && aProperties->find( propName ) != aProperties->end() )
4198  return false;
4199 
4200  return true;
4201 }
static const char * PropNoDocFile
const char* PropBuffering

References PropNoDocFile.

Referenced by CreateSymbolLib(), DeleteAlias(), DeleteSymbol(), SaveLibrary(), and SaveSymbol().

Member Data Documentation

◆ m_cache

◆ m_currentPath

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

Stack to maintain nested sheet paths.

Definition at line 174 of file sch_legacy_plugin.h.

Referenced by Load(), and loadHierarchy().

◆ m_error

wxString SCH_LEGACY_PLUGIN::m_error
protected

For throwing exceptions or errors on partial schematic loads.

Definition at line 171 of file sch_legacy_plugin.h.

Referenced by GetError(), loadHeader(), and loadHierarchy().

◆ m_kiway

KIWAY* SCH_LEGACY_PLUGIN::m_kiway
protected

Required for path to legacy component libraries.

Definition at line 176 of file sch_legacy_plugin.h.

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

◆ m_out

FILE_OUTPUTFORMATTER* SCH_LEGACY_PLUGIN::m_out
protected

◆ m_path

wxString SCH_LEGACY_PLUGIN::m_path
protected

Root project path for loading child sheets.

Definition at line 173 of file sch_legacy_plugin.h.

Referenced by Load().

◆ m_props

const PROPERTIES* SCH_LEGACY_PLUGIN::m_props
protected

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

Definition at line 175 of file sch_legacy_plugin.h.

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

◆ m_rootSheet

SCH_SHEET* SCH_LEGACY_PLUGIN::m_rootSheet
protected

The root sheet of the schematic being loaded..

Definition at line 177 of file sch_legacy_plugin.h.

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

◆ m_version

int SCH_LEGACY_PLUGIN::m_version
protected

Version of file being loaded.

Definition at line 168 of file sch_legacy_plugin.h.

Referenced by init(), loadComponent(), loadFile(), loadHeader(), and loadText().

◆ PropBuffering

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

const char* PropBuffering

is a 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 86 of file sch_legacy_plugin.h.

Referenced by PART_LIB::EnableBuffering(), isBuffering(), PART_LIB::IsBuffering(), SCH_EAGLE_PLUGIN::Load(), SYMBOL_LIB_TABLE_RESCUER::OpenRescueLibrary(), LIB_MANAGER::LIB_BUFFER::SaveBuffer(), and LIB_MANAGER::SaveLibrary().

◆ PropNoDocFile

const char * SCH_LEGACY_PLUGIN::PropNoDocFile = "no_doc_file"
static

const char* PropBuffering

is a property used internally by the plugin to disable writing the library documentation (.dcm) file when saving the library cache.

Definition at line 94 of file sch_legacy_plugin.h.

Referenced by PART_LIB::IsCache(), PART_LIB::Save(), LIB_EDIT_FRAME::SaveOneSymbol(), PART_LIB::SetCache(), and writeDocFile().


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