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=nullptr, const PROPERTIES *aProperties=nullptr) override
 Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one. More...
 
void LoadContent (LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
 
void Save (const wxString &aFileName, SCH_SCREEN *aScreen, KIWAY *aKiway, const PROPERTIES *aProperties=nullptr) override
 Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file. More...
 
void Format (SCH_SCREEN *aScreen)
 
void Format (SELECTION *aSelection, OUTPUTFORMATTER *aFormatter)
 
void EnumerateSymbolLib (wxArrayString &aAliasNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Populate a list of LIB_PART alias names contained within the library aLibraryPath. More...
 
void EnumerateSymbolLib (std::vector< LIB_ALIAS * > &aAliasList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) 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=nullptr) 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=nullptr) override
 Write aSymbol to an existing library located at aLibraryPath. More...
 
void DeleteAlias (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=nullptr) override
 Delete aAliasName from the library at aLibraryPath. More...
 
void DeleteSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=nullptr) override
 Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath. More...
 
void CreateSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Create a new empty symbol library at aLibraryPath. More...
 
bool DeleteSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Delete an existing symbol library and returns true if successful, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 
void SaveLibrary (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 
bool CheckHeader (const wxString &aFileName) override
 Return true if the first line in aFileName begins with the expected header. More...
 
bool IsSymbolLibWritable (const wxString &aLibraryPath) override
 Return true if the library at aLibraryPath is writable. More...
 
const wxString & GetError () const override
 Return an error string to the caller. More...
 
virtual void SymbolLibOptions (PROPERTIES *aListToAppendTo) const
 Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Static Public Member Functions

static LIB_PARTParsePart (LINE_READER &aReader, int majorVersion=0, int minorVersion=0)
 
static void FormatPart (LIB_PART *aPart, OUTPUTFORMATTER &aFormatter)
 

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=nullptr)
 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 nullptr. More...
 
KIWAYm_kiway
 Required for path to legacy component libraries. More...
 
SCH_SHEETm_rootSheet
 The root sheet of the schematic being loaded.. More...
 
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 (LINE_READER &aReader, SCH_SCREEN *aScreen)
 
void loadPageSettings (LINE_READER &aReader, SCH_SCREEN *aScreen)
 
void loadFile (const wxString &aFileName, SCH_SCREEN *aScreen)
 
SCH_SHEETloadSheet (LINE_READER &aReader)
 
SCH_BITMAPloadBitmap (LINE_READER &aReader)
 
SCH_JUNCTIONloadJunction (LINE_READER &aReader)
 
SCH_NO_CONNECTloadNoConnect (LINE_READER &aReader)
 
SCH_LINEloadWire (LINE_READER &aReader)
 
SCH_BUS_ENTRY_BASEloadBusEntry (LINE_READER &aReader)
 
SCH_TEXTloadText (LINE_READER &aReader)
 
SCH_COMPONENTloadComponent (LINE_READER &aReader)
 
std::shared_ptr< BUS_ALIASloadBusAlias (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 64 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=nullptr)
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 4232 of file sch_legacy_plugin.cpp.

4233 {
4234  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
4235  {
4236  // a spectacular episode in memory management:
4237  delete m_cache;
4238  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
4239 
4240  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
4241  // to modify the hash value that indicate component to symbol links
4242  // must be updated.
4244 
4245  if( !isBuffering( m_props ) )
4246  m_cache->Load();
4247  }
4248 }
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 nullptr.

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(), 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 4449 of file sch_legacy_plugin.cpp.

4450 {
4451  // Open file and check first line
4452  wxTextFile tempFile;
4453 
4454  tempFile.Open( aFileName );
4455  wxString firstline;
4456  // read the first line
4457  firstline = tempFile.GetFirstLine();
4458  tempFile.Close();
4459 
4460  return firstline.StartsWith( "EESchema" );
4461 }

◆ CreateSymbolLib()

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

Create a new empty symbol library at aLibraryPath.

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4382 of file sch_legacy_plugin.cpp.

4384 {
4385  if( wxFileExists( aLibraryPath ) )
4386  {
4388  _( "symbol library \"%s\" already exists, cannot create a new library" ),
4389  aLibraryPath.GetData() ) );
4390  }
4391 
4392  LOCALE_IO toggle;
4393 
4394  m_props = aProperties;
4395 
4396  delete m_cache;
4397  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4398  m_cache->SetModified();
4399  m_cache->Save( writeDocFile( aProperties ) );
4400  m_cache->Load(); // update m_writable and m_mod_time
4401 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:154
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)
#define _(s)
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 nullptr.

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 = nullptr 
)
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 4354 of file sch_legacy_plugin.cpp.

4356 {
4357  m_props = aProperties;
4358 
4359  cacheLib( aLibraryPath );
4360 
4361  m_cache->DeleteAlias( aAliasName );
4362 
4363  if( !isBuffering( aProperties ) )
4364  m_cache->Save( writeDocFile( aProperties ) );
4365 }
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 nullptr.

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 = nullptr 
)
overridevirtual

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

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

4370 {
4371  m_props = aProperties;
4372 
4373  cacheLib( aLibraryPath );
4374 
4375  m_cache->DeleteSymbol( aAliasName );
4376 
4377  if( !isBuffering( aProperties ) )
4378  m_cache->Save( writeDocFile( aProperties ) );
4379 }
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 nullptr.

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 = nullptr 
)
overridevirtual

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4404 of file sch_legacy_plugin.cpp.

4406 {
4407  wxFileName fn = aLibraryPath;
4408 
4409  if( !fn.FileExists() )
4410  return false;
4411 
4412  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
4413  // we don't want that. we want bare metal portability with no UI here.
4414  if( wxRemove( aLibraryPath ) )
4415  {
4416  THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
4417  aLibraryPath.GetData() ) );
4418  }
4419 
4420  if( m_cache && m_cache->IsFile( aLibraryPath ) )
4421  {
4422  delete m_cache;
4423  m_cache = 0;
4424  }
4425 
4426  return true;
4427 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
#define THROW_IO_ERROR(msg)
#define _(s)
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 = nullptr 
)
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 4278 of file sch_legacy_plugin.cpp.

4281 {
4282  LOCALE_IO toggle; // toggles on, then off, the C locale.
4283 
4284  m_props = aProperties;
4285 
4286  bool powerSymbolsOnly = ( aProperties &&
4287  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4288  cacheLib( aLibraryPath );
4289 
4290  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
4291 
4292  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
4293  {
4294  if( !powerSymbolsOnly || it->second->GetPart()->IsPower() )
4295  aAliasNameList.Add( it->first );
4296  }
4297 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:154
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 nullptr.

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 = nullptr 
)
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 4300 of file sch_legacy_plugin.cpp.

4303 {
4304  LOCALE_IO toggle; // toggles on, then off, the C locale.
4305 
4306  m_props = aProperties;
4307 
4308  bool powerSymbolsOnly = ( aProperties &&
4309  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4310  cacheLib( aLibraryPath );
4311 
4312  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
4313 
4314  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
4315  {
4316  if( !powerSymbolsOnly || it->second->GetPart()->IsPower() )
4317  aAliasList.push_back( it->second );
4318  }
4319 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:154
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 nullptr.

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

◆ Format() [1/2]

void SCH_LEGACY_PLUGIN::Format ( SCH_SCREEN aScreen)

Definition at line 1808 of file sch_legacy_plugin.cpp.

1809 {
1810  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN* object." );
1811  wxCHECK_RET( m_kiway != NULL, "NULL KIWAY* object." );
1812 
1813  // Write the header
1814  m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1815 
1816  // This section is not used, but written for file compatibility
1817  m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1818  m_out->Print( 0, "EELAYER END\n" );
1819 
1820  /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1821  * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1822  * simple hierarchy and flat hierarchy. Used also to search the root
1823  * sheet ( ScreenNumber = 1 ) within the files
1824  */
1825  const TITLE_BLOCK& tb = aScreen->GetTitleBlock();
1826  const PAGE_INFO& page = aScreen->GetPageSettings();
1827 
1828  m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1829  page.GetWidthMils(),
1830  page.GetHeightMils(),
1831  !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1832  m_out->Print( 0, "encoding utf-8\n" );
1833  m_out->Print( 0, "Sheet %d %d\n", aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens );
1834  m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1835  m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1836  m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1837  m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1838  m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment( 0 ) ).c_str() );
1839  m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment( 1 ) ).c_str() );
1840  m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment( 2 ) ).c_str() );
1841  m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment( 3 ) ).c_str() );
1842  m_out->Print( 0, "Comment5 %s\n", EscapedUTF8( tb.GetComment( 4 ) ).c_str() );
1843  m_out->Print( 0, "Comment6 %s\n", EscapedUTF8( tb.GetComment( 5 ) ).c_str() );
1844  m_out->Print( 0, "Comment7 %s\n", EscapedUTF8( tb.GetComment( 6 ) ).c_str() );
1845  m_out->Print( 0, "Comment8 %s\n", EscapedUTF8( tb.GetComment( 7 ) ).c_str() );
1846  m_out->Print( 0, "Comment9 %s\n", EscapedUTF8( tb.GetComment( 8 ) ).c_str() );
1847  m_out->Print( 0, "$EndDescr\n" );
1848 
1849  for( auto alias : aScreen->GetBusAliases() )
1850  {
1851  saveBusAlias( alias );
1852  }
1853 
1854  for( SCH_ITEM* item = aScreen->GetDrawItems(); item; item = item->Next() )
1855  {
1856  switch( item->Type() )
1857  {
1858  case SCH_COMPONENT_T:
1859  saveComponent( static_cast< SCH_COMPONENT* >( item ) );
1860  break;
1861  case SCH_BITMAP_T:
1862  saveBitmap( static_cast< SCH_BITMAP* >( item ) );
1863  break;
1864  case SCH_SHEET_T:
1865  saveSheet( static_cast< SCH_SHEET* >( item ) );
1866  break;
1867  case SCH_JUNCTION_T:
1868  saveJunction( static_cast< SCH_JUNCTION* >( item ) );
1869  break;
1870  case SCH_NO_CONNECT_T:
1871  saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
1872  break;
1873  case SCH_BUS_WIRE_ENTRY_T:
1874  case SCH_BUS_BUS_ENTRY_T:
1875  saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1876  break;
1877  case SCH_LINE_T:
1878  saveLine( static_cast< SCH_LINE* >( item ) );
1879  break;
1880  case SCH_TEXT_T:
1881  case SCH_LABEL_T:
1882  case SCH_GLOBAL_LABEL_T:
1883  case SCH_HIER_LABEL_T:
1884  saveText( static_cast< SCH_TEXT* >( item ) );
1885  break;
1886  default:
1887  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1888  }
1889  }
1890 
1891  m_out->Print( 0, "$EndSCHEMATC\n" );
1892 }
int m_ScreenNumber
Definition: base_screen.h:135
SCH_ITEM * Next() const
Definition: sch_item.h:153
void saveLine(SCH_LINE *aLine)
const wxString & GetComment(int aIdx) const
Definition: title_block.h:110
int GetHeightMils() const
Definition: page_info.h:140
void saveText(SCH_TEXT *aText)
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:128
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:118
void saveSheet(SCH_SHEET *aSheet)
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:249
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:48
#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
void saveBitmap(SCH_BITMAP *aBitmap)
void saveComponent(SCH_COMPONENT *aComponent)
const wxString & GetDate() const
Definition: title_block.h:79
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
bool IsPortrait() const
Definition: page_info.h:121
int m_NumberOfScreens
Definition: base_screen.h:136
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
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
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:464
int GetWidthMils() const
Definition: page_info.h:137
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:152

References EESCHEMA_VERSION, EscapedUTF8(), SCH_SCREEN::GetBusAliases(), TITLE_BLOCK::GetComment(), 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(), 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 SCH_EDITOR_CONTROL::doCopy(), and Save().

◆ Format() [2/2]

void SCH_LEGACY_PLUGIN::Format ( SELECTION aSelection,
OUTPUTFORMATTER aFormatter 
)

Definition at line 1895 of file sch_legacy_plugin.cpp.

1896 {
1897  m_out = aFormatter;
1898 
1899  for( unsigned i = 0; i < aSelection->GetSize(); ++i )
1900  {
1901  SCH_ITEM* item = (SCH_ITEM*) aSelection->GetItem( i );
1902 
1903  switch( item->Type() )
1904  {
1905  case SCH_COMPONENT_T:
1906  saveComponent( static_cast< SCH_COMPONENT* >( item ) );
1907  break;
1908  case SCH_BITMAP_T:
1909  saveBitmap( static_cast< SCH_BITMAP* >( item ) );
1910  break;
1911  case SCH_SHEET_T:
1912  saveSheet( static_cast< SCH_SHEET* >( item ) );
1913  break;
1914  case SCH_JUNCTION_T:
1915  saveJunction( static_cast< SCH_JUNCTION* >( item ) );
1916  break;
1917  case SCH_NO_CONNECT_T:
1918  saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
1919  break;
1920  case SCH_BUS_WIRE_ENTRY_T:
1921  case SCH_BUS_BUS_ENTRY_T:
1922  saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1923  break;
1924  case SCH_LINE_T:
1925  saveLine( static_cast< SCH_LINE* >( item ) );
1926  break;
1927  case SCH_TEXT_T:
1928  case SCH_LABEL_T:
1929  case SCH_GLOBAL_LABEL_T:
1930  case SCH_HIER_LABEL_T:
1931  saveText( static_cast< SCH_TEXT* >( item ) );
1932  break;
1933  default:
1934  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1935  }
1936  }
1937 }
void saveLine(SCH_LINE *aLine)
void saveText(SCH_TEXT *aText)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
void saveSheet(SCH_SHEET *aSheet)
void saveJunction(SCH_JUNCTION *aJunction)
void saveBitmap(SCH_BITMAP *aBitmap)
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.h:103
void saveComponent(SCH_COMPONENT *aComponent)
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:98
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
size_t i
Definition: json11.cpp:649
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

References SELECTION::GetItem(), SELECTION::GetSize(), i, m_out, saveBitmap(), 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_LINE_T, SCH_NO_CONNECT_T, SCH_SHEET_T, SCH_TEXT_T, and EDA_ITEM::Type().

◆ FormatPart()

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

Definition at line 4477 of file sch_legacy_plugin.cpp.

4478 {
4479  SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( part, formatter );
4480 }
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter)

References SCH_LEGACY_PLUGIN_CACHE::SaveSymbol().

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

◆ 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 138 of file sch_legacy_plugin.h.

138 { 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 76 of file sch_legacy_plugin.h.

77  {
78  return wxT( "sch" );
79  }

◆ 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 4268 of file sch_legacy_plugin.cpp.

4269 {
4270  if( m_cache )
4271  return m_cache->GetModifyHash();
4272 
4273  // If the cache hasn't been loaded, it hasn't been modified.
4274  return 0;
4275 }
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 71 of file sch_legacy_plugin.h.

72  {
73  return wxT( "Eeschema-Legacy" );
74  }

◆ init()

void SCH_LEGACY_PLUGIN::init ( KIWAY aKiway,
const PROPERTIES aProperties = nullptr 
)
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 }
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.
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
KIWAY * m_kiway
Required for path to legacy component libraries.
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

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 4262 of file sch_legacy_plugin.cpp.

4263 {
4264  return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
4265 }
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 4464 of file sch_legacy_plugin.cpp.

4465 {
4466  return wxFileName::IsFileWritable( aLibraryPath );
4467 }

◆ Load()

SCH_SHEET * SCH_LEGACY_PLUGIN::Load ( const wxString &  aFileName,
KIWAY aKiway,
SCH_SHEET aAppendToMe = nullptr,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 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 }
void init(KIWAY *aKiway, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:154
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:170
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)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:646
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 ( LINE_READER aReader)
private

Definition at line 1089 of file sch_legacy_plugin.cpp.

1090 {
1091  std::unique_ptr< SCH_BITMAP > bitmap( new SCH_BITMAP );
1092 
1093  const char* line = aReader.Line();
1094 
1095  wxCHECK( strCompare( "$Bitmap", line, &line ), NULL );
1096 
1097  line = aReader.ReadLine();
1098 
1099  while( line != NULL )
1100  {
1101  if( strCompare( "Pos", line, &line ) )
1102  {
1103  wxPoint position;
1104 
1105  position.x = parseInt( aReader, line, &line );
1106  position.y = parseInt( aReader, line, &line );
1107  bitmap->SetPosition( position );
1108  }
1109  else if( strCompare( "Scale", line, &line ) )
1110  {
1111  auto scalefactor = parseDouble( aReader, line, &line );
1112 
1113  // Prevent scalefactor values that cannot be displayed.
1114  // In the case of a bad value, we accept that the image might be mis-scaled
1115  // rather than removing the full image. Users can then edit the scale factor in
1116  // Eeschema to the appropriate value
1117  if( !std::isnormal( scalefactor ) )
1118  scalefactor = 1.0;
1119 
1120  bitmap->GetImage()->SetScale( scalefactor );
1121  }
1122  else if( strCompare( "Data", line, &line ) )
1123  {
1124  wxMemoryOutputStream stream;
1125 
1126  while( line )
1127  {
1128  if( !aReader.ReadLine() )
1129  SCH_PARSE_ERROR( _( "Unexpected end of file" ), aReader, line );
1130 
1131  line = aReader.Line();
1132 
1133  if( strCompare( "EndData", line ) )
1134  {
1135  // all the PNG date is read.
1136  // We expect here m_image and m_bitmap are void
1137  wxImage* image = new wxImage();
1138  wxMemoryInputStream istream( stream );
1139  image->LoadFile( istream, wxBITMAP_TYPE_PNG );
1140  bitmap->GetImage()->SetImage( image );
1141  bitmap->GetImage()->SetBitmap( new wxBitmap( *image ) );
1142  break;
1143  }
1144 
1145  // Read PNG data, stored in hexadecimal,
1146  // each byte = 2 hexadecimal digits and a space between 2 bytes
1147  // and put it in memory stream buffer
1148  int len = strlen( line );
1149 
1150  for( ; len > 0 && !isspace( *line ); len -= 3, line += 3 )
1151  {
1152  int value = 0;
1153 
1154  if( sscanf( line, "%X", &value ) == 1 )
1155  stream.PutC( (char) value );
1156  else
1157  THROW_IO_ERROR( "invalid PNG data" );
1158  }
1159  }
1160 
1161  if( line == NULL )
1162  THROW_IO_ERROR( _( "unexpected end of file" ) );
1163  }
1164  else if( strCompare( "$EndBitmap", line ) )
1165  return bitmap.release();
1166 
1167  line = aReader.ReadLine();
1168  }
1169 
1170  THROW_IO_ERROR( _( "unexpected end of file" ) );
1171 }
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...
#define _(s)
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#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(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, strCompare(), and THROW_IO_ERROR.

Referenced by LoadContent().

◆ loadBusAlias()

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

Definition at line 1758 of file sch_legacy_plugin.cpp.

1760 {
1761  auto busAlias = std::make_shared< BUS_ALIAS >( aScreen );
1762  const char* line = aReader.Line();
1763 
1764  wxCHECK( strCompare( "BusAlias", line, &line ), NULL );
1765 
1766  wxString buf;
1767  parseUnquotedString( buf, aReader, line, &line );
1768  busAlias->SetName( buf );
1769 
1770  while( *line != '\0' )
1771  {
1772  buf.clear();
1773  parseUnquotedString( buf, aReader, line, &line, true );
1774  if( buf.Len() > 0 )
1775  {
1776  busAlias->AddMember( buf );
1777  }
1778  }
1779 
1780  return busAlias;
1781 }
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 LoadContent().

◆ loadBusEntry()

SCH_BUS_ENTRY_BASE * SCH_LEGACY_PLUGIN::loadBusEntry ( LINE_READER aReader)
private

Definition at line 1316 of file sch_legacy_plugin.cpp.

1317 {
1318  const char* line = aReader.Line();
1319 
1320  wxCHECK( strCompare( "Entry", line, &line ), NULL );
1321 
1322  std::unique_ptr< SCH_BUS_ENTRY_BASE > busEntry;
1323 
1324  if( strCompare( "Wire", line, &line ) )
1325  {
1326  busEntry.reset( new SCH_BUS_WIRE_ENTRY );
1327 
1328  if( !strCompare( "Line", line, &line ) )
1329  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
1330  }
1331  else if( strCompare( "Bus", line, &line ) )
1332  {
1333  busEntry.reset( new SCH_BUS_BUS_ENTRY );
1334 
1335  if( !strCompare( "Bus", line, &line ) )
1336  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
1337  }
1338  else
1339  SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
1340 
1341  line = aReader.ReadLine();
1342 
1343  wxPoint pos;
1344  wxSize size;
1345 
1346  pos.x = parseInt( aReader, line, &line );
1347  pos.y = parseInt( aReader, line, &line );
1348  size.x = parseInt( aReader, line, &line );
1349  size.y = parseInt( aReader, line, &line );
1350 
1351  size.x -= pos.x;
1352  size.y -= pos.y;
1353 
1354  busEntry->SetPosition( pos );
1355  busEntry->SetSize( size );
1356 
1357  return busEntry.release();
1358 }
Class for a bus to bus entry.
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...
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#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(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by LoadContent().

◆ loadComponent()

SCH_COMPONENT * SCH_LEGACY_PLUGIN::loadComponent ( LINE_READER aReader)
private

Definition at line 1461 of file sch_legacy_plugin.cpp.

1462 {
1463  const char* line = aReader.Line();
1464 
1465  wxCHECK( strCompare( "$Comp", line, &line ), NULL );
1466 
1467  std::unique_ptr< SCH_COMPONENT > component( new SCH_COMPONENT() );
1468 
1469  line = aReader.ReadLine();
1470 
1471  while( line != NULL )
1472  {
1473  if( strCompare( "L", line, &line ) )
1474  {
1475  wxString libName;
1476  size_t pos = 2; // "X" plus ' ' space character.
1477  wxString utf8Line = wxString::FromUTF8( line );
1478  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
1479 
1480  if( tokens.CountTokens() < 2 )
1481  THROW_PARSE_ERROR( "invalid symbol library definition", aReader.GetSource(),
1482  aReader.Line(), aReader.LineNumber(), pos );
1483 
1484  libName = tokens.GetNextToken();
1485  libName.Replace( "~", " " );
1486 
1487  LIB_ID libId;
1488 
1489  // Prior to schematic version 4, library IDs did not have a library nickname so
1490  // parsing the symbol name with LIB_ID::Parse() would break symbol library links
1491  // that contained '/' and ':' characters.
1492  if( m_version > 3 )
1493  libId.Parse( libName, LIB_ID::ID_SCH, true );
1494  else
1495  libId.SetLibItemName( libName, false );
1496 
1497  component->SetLibId( libId );
1498 
1499  wxString refDesignator = tokens.GetNextToken();
1500 
1501  refDesignator.Replace( "~", " " );
1502 
1503  wxString prefix = refDesignator;
1504 
1505  while( prefix.Length() )
1506  {
1507  if( ( prefix.Last() < '0' || prefix.Last() > '9') && prefix.Last() != '?' )
1508  break;
1509 
1510  prefix.RemoveLast();
1511  }
1512 
1513  // Avoid a prefix containing trailing/leading spaces
1514  prefix.Trim( true );
1515  prefix.Trim( false );
1516 
1517  if( prefix.IsEmpty() )
1518  component->SetPrefix( wxString( "U" ) );
1519  else
1520  component->SetPrefix( prefix );
1521  }
1522  else if( strCompare( "U", line, &line ) )
1523  {
1524  // This fixes a potentially buggy files caused by unit being set to zero which
1525  // causes netlist issues. See https://bugs.launchpad.net/kicad/+bug/1677282.
1526  int unit = parseInt( aReader, line, &line );
1527 
1528  if( unit == 0 )
1529  {
1530  unit = 1;
1531 
1532  // Set the file as modified so the user can be warned.
1533  if( m_rootSheet && m_rootSheet->GetScreen() )
1535  }
1536 
1537  component->SetUnit( unit );
1538 
1539  // Same can also happen with the convert parameter
1540  int convert = parseInt( aReader, line, &line );
1541 
1542  if( convert == 0 )
1543  {
1544  convert = 1;
1545 
1546  // Set the file as modified so the user can be warned.
1547  if( m_rootSheet && m_rootSheet->GetScreen() )
1549  }
1550 
1551  component->SetConvert( convert );
1552 
1553  component->SetTimeStamp( parseHex( aReader, line, &line ) );
1554  }
1555  else if( strCompare( "P", line, &line ) )
1556  {
1557  wxPoint pos;
1558 
1559  pos.x = parseInt( aReader, line, &line );
1560  pos.y = parseInt( aReader, line, &line );
1561  component->SetPosition( pos );
1562  }
1563  else if( strCompare( "AR", line, &line ) )
1564  {
1565  const char* strCompare = "Path=";
1566  int len = strlen( strCompare );
1567 
1568  if( strncasecmp( strCompare, line, len ) != 0 )
1569  SCH_PARSE_ERROR( "missing 'Path=' token", aReader, line );
1570 
1571  line += len;
1572  wxString path, reference, unit;
1573 
1574  parseQuotedString( path, aReader, line, &line );
1575 
1576  strCompare = "Ref=";
1577  len = strlen( strCompare );
1578 
1579  if( strncasecmp( strCompare, line, len ) != 0 )
1580  SCH_PARSE_ERROR( "missing 'Ref=' token", aReader, line );
1581 
1582  line+= len;
1583  parseQuotedString( reference, aReader, line, &line );
1584 
1585  strCompare = "Part=";
1586  len = strlen( strCompare );
1587 
1588  if( strncasecmp( strCompare, line, len ) != 0 )
1589  SCH_PARSE_ERROR( "missing 'Part=' token", aReader, line );
1590 
1591  line+= len;
1592  parseQuotedString( unit, aReader, line, &line );
1593 
1594  long tmp;
1595 
1596  if( !unit.ToLong( &tmp, 10 ) )
1597  SCH_PARSE_ERROR( "expected integer value", aReader, line );
1598 
1599  if( tmp < 0 || tmp > MAX_UNIT_COUNT_PER_PACKAGE )
1600  SCH_PARSE_ERROR( "unit value out of range", aReader, line );
1601 
1602  component->AddHierarchicalReference( path, reference, (int)tmp );
1603  component->GetField( REFERENCE )->SetText( reference );
1604 
1605  }
1606  else if( strCompare( "F", line, &line ) )
1607  {
1608  int index = parseInt( aReader, line, &line );
1609 
1610  wxString text, name;
1611 
1612  parseQuotedString( text, aReader, line, &line, true );
1613 
1614  char orientation = parseChar( aReader, line, &line );
1615  wxPoint pos;
1616  pos.x = parseInt( aReader, line, &line );
1617  pos.y = parseInt( aReader, line, &line );
1618  int size = parseInt( aReader, line, &line );
1619  int attributes = parseHex( aReader, line, &line );
1620 
1621  if( index >= component->GetFieldCount() )
1622  {
1623  // The first MANDATOR_FIELDS _must_ be constructed within
1624  // the SCH_COMPONENT constructor. This assert is simply here
1625  // to guard against a change in that constructor.
1626  wxASSERT( component->GetFieldCount() >= MANDATORY_FIELDS );
1627 
1628  // Ignore the _supplied_ fieldNdx. It is not important anymore
1629  // if within the user defined fields region (i.e. >= MANDATORY_FIELDS).
1630  // We freely renumber the index to fit the next available field slot.
1631  index = component->GetFieldCount(); // new has this index after insertion
1632 
1633  SCH_FIELD field( wxPoint( 0, 0 ), -1, component.get(), name );
1634  component->AddField( field );
1635  }
1636 
1637  // Prior to version 2 of the schematic file format, none of the following existed.
1638  if( m_version > 1 )
1639  {
1640  wxString textAttrs;
1641  char hjustify = parseChar( aReader, line, &line );
1642 
1643  parseUnquotedString( textAttrs, aReader, line, &line );
1644 
1645  // The name of the field is optional.
1646  parseQuotedString( name, aReader, line, &line, true );
1647 
1648  if( hjustify == 'L' )
1649  component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
1650  else if( hjustify == 'R' )
1651  component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
1652  else if( hjustify != 'C' )
1653  SCH_PARSE_ERROR( "component field text horizontal justification must be "
1654  "L, R, or C", aReader, line );
1655 
1656  // We are guaranteed to have a least one character here for older file formats
1657  // otherwise an exception would have been raised..
1658  if( textAttrs[0] == 'T' )
1659  component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
1660  else if( textAttrs[0] == 'B' )
1661  component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
1662  else if( textAttrs[0] != 'C' )
1663  SCH_PARSE_ERROR( "component field text vertical justification must be "
1664  "B, T, or C", aReader, line );
1665 
1666  // Newer file formats include the bold and italics text attribute.
1667  if( textAttrs.Length() > 1 )
1668  {
1669  if( textAttrs.Length() != 3 )
1670  SCH_PARSE_ERROR( _( "component field text attributes must be 3 characters wide" ),
1671  aReader, line );
1672 
1673  if( textAttrs[1] == 'I' )
1674  component->GetField( index )->SetItalic( true );
1675  else if( textAttrs[1] != 'N' )
1676  SCH_PARSE_ERROR( "component field text italics indicator must be I or N",
1677  aReader, line );
1678 
1679  if( textAttrs[2] == 'B' )
1680  component->GetField( index )->SetBold( true );
1681  else if( textAttrs[2] != 'N' )
1682  SCH_PARSE_ERROR( "component field text bold indicator must be B or N",
1683  aReader, line );
1684  }
1685  }
1686 
1687  component->GetField( index )->SetText( text );
1688  component->GetField( index )->SetTextPos( pos );
1689  component->GetField( index )->SetVisible( !attributes );
1690  component->GetField( index )->SetTextSize( wxSize( size, size ) );
1691 
1692  if( orientation == 'H' )
1693  component->GetField( index )->SetTextAngle( TEXT_ANGLE_HORIZ );
1694  else if( orientation == 'V' )
1695  component->GetField( index )->SetTextAngle( TEXT_ANGLE_VERT );
1696  else
1697  SCH_PARSE_ERROR( "component field orientation must be H or V",
1698  aReader, line );
1699 
1700  if( name.IsEmpty() )
1702 
1703  component->GetField( index )->SetName( name );
1704  }
1705  else if( strCompare( "$EndComp", line ) )
1706  {
1707  // Ensure all flags (some are set by previous initializations) are reset:
1708  component->ClearFlags();
1709  return component.release();
1710  }
1711  else
1712  {
1713  // There are two lines that begin with a tab or spaces that includes a line with the
1714  // redundant position information and the transform matrix settings.
1715 
1716  // Parse the redundant position information just the same to check for formatting
1717  // errors.
1718  parseInt( aReader, line, &line ); // Always 1.
1719  parseInt( aReader, line, &line ); // The X coordinate.
1720  parseInt( aReader, line, &line ); // The Y coordinate.
1721 
1722  line = aReader.ReadLine();
1723 
1724  TRANSFORM transform;
1725 
1726  transform.x1 = parseInt( aReader, line, &line );
1727 
1728  if( transform.x1 < -1 || transform.x1 > 1 )
1729  SCH_PARSE_ERROR( "invalid component X1 transform value", aReader, line );
1730 
1731  transform.y1 = parseInt( aReader, line, &line );
1732 
1733  if( transform.y1 < -1 || transform.y1 > 1 )
1734  SCH_PARSE_ERROR( "invalid component Y1 transform value", aReader, line );
1735 
1736  transform.x2 = parseInt( aReader, line, &line );
1737 
1738  if( transform.x2 < -1 || transform.x2 > 1 )
1739  SCH_PARSE_ERROR( "invalid component X2 transform value", aReader, line );
1740 
1741  transform.y2 = parseInt( aReader, line, &line );
1742 
1743  if( transform.y2 < -1 || transform.y2 > 1 )
1744  SCH_PARSE_ERROR( "invalid component Y2 transform value", aReader, line );
1745 
1746  component->SetTransform( transform );
1747  }
1748 
1749  line = aReader.ReadLine();
1750  }
1751 
1752  SCH_PARSE_ERROR( "invalid component line", aReader, line );
1753 
1754  return NULL; // Prevents compiler warning. Should never get here.
1755 }
#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:52
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:281
Field Reference of part, i.e. "IC21".
int m_version
Version of file being loaded.
int y1
Definition: transform.h:49
Class for transforming 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...
#define _(s)
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
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#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:73
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:224
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(), 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 LoadContent().

◆ LoadContent()

void SCH_LEGACY_PLUGIN::LoadContent ( LINE_READER aReader,
SCH_SCREEN aScreen,
int  version = EESCHEMA_VERSION 
)

Definition at line 755 of file sch_legacy_plugin.cpp.

756 {
757  m_version = version;
758 
759  while( aReader.ReadLine() )
760  {
761  char* line = aReader.Line();
762 
763  while( *line == ' ' )
764  line++;
765 
766  // Either an object will be loaded properly or the file load will fail and raise
767  // an exception.
768  if( strCompare( "$Descr", line ) )
769  loadPageSettings( aReader, aScreen );
770  else if( strCompare( "$Comp", line ) )
771  aScreen->Append( loadComponent( aReader ) );
772  else if( strCompare( "$Sheet", line ) )
773  aScreen->Append( loadSheet( aReader ) );
774  else if( strCompare( "$Bitmap", line ) )
775  aScreen->Append( loadBitmap( aReader ) );
776  else if( strCompare( "Connection", line ) )
777  aScreen->Append( loadJunction( aReader ) );
778  else if( strCompare( "NoConn", line ) )
779  aScreen->Append( loadNoConnect( aReader ) );
780  else if( strCompare( "Wire", line ) )
781  aScreen->Append( loadWire( aReader ) );
782  else if( strCompare( "Entry", line ) )
783  aScreen->Append( loadBusEntry( aReader ) );
784  else if( strCompare( "Text", line ) )
785  aScreen->Append( loadText( aReader ) );
786  else if( strCompare( "BusAlias", line ) )
787  aScreen->AddBusAlias( loadBusAlias( aReader, aScreen ) );
788  else if( strCompare( "$EndSCHEMATC", line ) )
789  return;
790  else
791  SCH_PARSE_ERROR( "unrecognized token", aReader, line );
792  }
793 }
SCH_SHEET * loadSheet(LINE_READER &aReader)
SCH_JUNCTION * loadJunction(LINE_READER &aReader)
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
SCH_COMPONENT * loadComponent(LINE_READER &aReader)
SCH_BUS_ENTRY_BASE * loadBusEntry(LINE_READER &aReader)
int m_version
Version of file being loaded.
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_BITMAP * loadBitmap(LINE_READER &aReader)
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Adds a bus alias definition (and transfers ownership of the pointer)
Definition: sch_screen.cpp:913
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:154
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_NO_CONNECT * loadNoConnect(LINE_READER &aReader)
SCH_LINE * loadWire(LINE_READER &aReader)
SCH_TEXT * loadText(LINE_READER &aReader)
std::shared_ptr< BUS_ALIAS > loadBusAlias(LINE_READER &aReader, SCH_SCREEN *aScreen)

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

Referenced by loadFile(), and SCH_EDITOR_CONTROL::Paste().

◆ 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  LoadContent( reader, aScreen, m_version );
739 
740  // Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
741  // so checking for it's existance will fail so just exit here and take our chances. :(
742  if( m_version > 1 )
743  {
744  char* line = reader.Line();
745 
746  while( *line == ' ' )
747  line++;
748 
749  if( !strCompare( "$EndSCHEMATC", line ) )
750  THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
751  }
752 }
void LoadContent(LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
int m_version
Version of file being loaded.
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
#define THROW_IO_ERROR(msg)
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 loadHeader(LINE_READER &aReader, SCH_SCREEN *aScreen)

References LINE_READER::Line(), LoadContent(), loadHeader(), m_version, strCompare(), and THROW_IO_ERROR.

Referenced by loadHierarchy().

◆ loadHeader()

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

Definition at line 796 of file sch_legacy_plugin.cpp.

797 {
798  const char* line = aReader.ReadLine();
799 
800  if( !line || !strCompare( "Eeschema Schematic File Version", line, &line ) )
801  {
802  m_error.Printf( _( "\"%s\" does not appear to be an Eeschema file" ),
803  GetChars( aScreen->GetFileName() ) );
805  }
806 
807  // get the file version here.
808  m_version = parseInt( aReader, line, &line );
809 
810  // The next lines are the lib list section, and are mainly comments, like:
811  // LIBS:power
812  // the lib list is not used, but is in schematic file just in case.
813  // It is usually not empty, but we accept empty list.
814  // If empty, there is a legacy section, not used
815  // EELAYER i j
816  // and the last line is
817  // EELAYER END
818  // Skip all lines until the end of header "EELAYER END" is found
819  while( aReader.ReadLine() )
820  {
821  line = aReader.Line();
822 
823  while( *line == ' ' )
824  line++;
825 
826  if( strCompare( "EELAYER END", line ) )
827  return;
828  }
829 
830  THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
831 }
const wxString & GetFileName() const
Definition: sch_screen.h:123
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...
#define _(s)
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
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:101
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(), 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:559
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:281
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:225
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:646
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:121
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:152

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 ( LINE_READER aReader)
private

Definition at line 1174 of file sch_legacy_plugin.cpp.

1175 {
1176  std::unique_ptr< SCH_JUNCTION > junction( new SCH_JUNCTION );
1177 
1178  const char* line = aReader.Line();
1179 
1180  wxCHECK( strCompare( "Connection", line, &line ), NULL );
1181 
1182  wxString name;
1183 
1184  parseUnquotedString( name, aReader, line, &line );
1185 
1186  wxPoint position;
1187 
1188  position.x = parseInt( aReader, line, &line );
1189  position.y = parseInt( aReader, line, &line );
1190  junction->SetPosition( position );
1191 
1192  return junction.release();
1193 }
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 LoadContent().

◆ loadNoConnect()

SCH_NO_CONNECT * SCH_LEGACY_PLUGIN::loadNoConnect ( LINE_READER aReader)
private

Definition at line 1196 of file sch_legacy_plugin.cpp.

1197 {
1198  std::unique_ptr< SCH_NO_CONNECT > no_connect( new SCH_NO_CONNECT );
1199 
1200  const char* line = aReader.Line();
1201 
1202  wxCHECK( strCompare( "NoConn", line, &line ), NULL );
1203 
1204  wxString name;
1205 
1206  parseUnquotedString( name, aReader, line, &line );
1207 
1208  wxPoint position;
1209 
1210  position.x = parseInt( aReader, line, &line );
1211  position.y = parseInt( aReader, line, &line );
1212  no_connect->SetPosition( position );
1213 
1214  return no_connect.release();
1215 }
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 LoadContent().

◆ loadPageSettings()

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

Definition at line 834 of file sch_legacy_plugin.cpp.

835 {
836  wxASSERT( aScreen != NULL );
837 
838  wxString buf;
839  const char* line = aReader.Line();
840 
841  PAGE_INFO pageInfo;
842  TITLE_BLOCK tb;
843 
844  wxCHECK_RET( strCompare( "$Descr", line, &line ), "Invalid sheet description" );
845 
846  parseUnquotedString( buf, aReader, line, &line );
847 
848  if( !pageInfo.SetType( buf ) )
849  SCH_PARSE_ERROR( "invalid page size", aReader, line );
850 
851  int pagew = parseInt( aReader, line, &line );
852  int pageh = parseInt( aReader, line, &line );
853 
854  if( buf == PAGE_INFO::Custom )
855  {
856  pageInfo.SetWidthMils( pagew );
857  pageInfo.SetHeightMils( pageh );
858  }
859  else
860  {
861  wxString orientation;
862 
863  // Non custom size, set portrait if its present. Can be empty string which defaults
864  // to landscape.
865  parseUnquotedString( orientation, aReader, line, &line, true );
866 
867  if( orientation == "portrait" )
868  pageInfo.SetPortrait( true );
869  }
870 
871  aScreen->SetPageSettings( pageInfo );
872 
873  while( line != NULL )
874  {
875  buf.clear();
876 
877  if( !aReader.ReadLine() )
878  SCH_PARSE_ERROR( _( "unexpected end of file" ), aReader, line );
879 
880  line = aReader.Line();
881 
882  if( strCompare( "Sheet", line, &line ) )
883  {
884  aScreen->m_ScreenNumber = parseInt( aReader, line, &line );
885  aScreen->m_NumberOfScreens = parseInt( aReader, line, &line );
886  }
887  else if( strCompare( "Title", line, &line ) )
888  {
889  parseQuotedString( buf, aReader, line, &line, true );
890  tb.SetTitle( buf );
891  }
892  else if( strCompare( "Date", line, &line ) )
893  {
894  parseQuotedString( buf, aReader, line, &line, true );
895  tb.SetDate( buf );
896  }
897  else if( strCompare( "Rev", line, &line ) )
898  {
899  parseQuotedString( buf, aReader, line, &line, true );
900  tb.SetRevision( buf );
901  }
902  else if( strCompare( "Comp", line, &line ) )
903  {
904  parseQuotedString( buf, aReader, line, &line, true );
905  tb.SetCompany( buf );
906  }
907  else if( strCompare( "Comment1", line, &line ) )
908  {
909  parseQuotedString( buf, aReader, line, &line, true );
910  tb.SetComment( 0, buf );
911  }
912  else if( strCompare( "Comment2", line, &line ) )
913  {
914  parseQuotedString( buf, aReader, line, &line, true );
915  tb.SetComment( 1, buf );
916  }
917  else if( strCompare( "Comment3", line, &line ) )
918  {
919  parseQuotedString( buf, aReader, line, &line, true );
920  tb.SetComment( 2, buf );
921  }
922  else if( strCompare( "Comment4", line, &line ) )
923  {
924  parseQuotedString( buf, aReader, line, &line, true );
925  tb.SetComment( 3, buf );
926  }
927  else if( strCompare( "Comment5", line, &line ) )
928  {
929  parseQuotedString( buf, aReader, line, &line, true );
930  tb.SetComment( 4, buf );
931  }
932  else if( strCompare( "Comment6", line, &line ) )
933  {
934  parseQuotedString( buf, aReader, line, &line, true );
935  tb.SetComment( 5, buf );
936  }
937  else if( strCompare( "Comment7", line, &line ) )
938  {
939  parseQuotedString( buf, aReader, line, &line, true );
940  tb.SetComment( 6, buf );
941  }
942  else if( strCompare( "Comment8", line, &line ) )
943  {
944  parseQuotedString( buf, aReader, line, &line, true );
945  tb.SetComment( 7, buf );
946  }
947  else if( strCompare( "Comment9", line, &line ) )
948  {
949  parseQuotedString( buf, aReader, line, &line, true );
950  tb.SetComment( 8, buf );
951  }
952  else if( strCompare( "$EndDescr", line ) )
953  {
954  aScreen->SetTitleBlock( tb );
955  return;
956  }
957  }
958 
959  SCH_PARSE_ERROR( "missing 'EndDescr'", aReader, line );
960 }
int m_ScreenNumber
Definition: base_screen.h:135
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:119
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 SetComment(int aIdx, const wxString &aComment)
Definition: title_block.h:104
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:130
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
#define _(s)
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:253
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#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:136
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(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, TITLE_BLOCK::SetComment(), 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 LoadContent().

◆ loadSheet()

SCH_SHEET * SCH_LEGACY_PLUGIN::loadSheet ( LINE_READER aReader)
private

Definition at line 963 of file sch_legacy_plugin.cpp.

964 {
965  std::unique_ptr< SCH_SHEET > sheet( new SCH_SHEET() );
966 
967  sheet->SetTimeStamp( GetNewTimeStamp() );
968 
969  const char* line = aReader.ReadLine();
970 
971  while( line != NULL )
972  {
973  if( strCompare( "S", line, &line ) ) // Sheet dimensions.
974  {
975  wxPoint position;
976 
977  position.x = parseInt( aReader, line, &line );
978  position.y = parseInt( aReader, line, &line );
979  sheet->SetPosition( position );
980 
981  wxSize size;
982 
983  size.SetWidth( parseInt( aReader, line, &line ) );
984  size.SetHeight( parseInt( aReader, line, &line ) );
985  sheet->SetSize( size );
986  }
987  else if( strCompare( "U", line, &line ) ) // Sheet time stamp.
988  {
989  sheet->SetTimeStamp( parseHex( aReader, line ) );
990  }
991  else if( *line == 'F' ) // Sheet field.
992  {
993  line++;
994 
995  wxString text;
996  int size;
997  int fieldId = parseInt( aReader, line, &line );
998 
999  if( fieldId == 0 || fieldId == 1 ) // Sheet name and file name.
1000  {
1001  parseQuotedString( text, aReader, line, &line );
1002  size = parseInt( aReader, line, &line );
1003 
1004  if( fieldId == 0 )
1005  {
1006  sheet->SetName( text );
1007  sheet->SetSheetNameSize( size );
1008  }
1009  else
1010  {
1011  sheet->SetFileName( text );
1012  sheet->SetFileNameSize( size );
1013  }
1014  }
1015  else // Sheet pin.
1016  {
1017  std::unique_ptr< SCH_SHEET_PIN > sheetPin( new SCH_SHEET_PIN( sheet.get() ) );
1018 
1019  sheetPin->SetNumber( fieldId );
1020 
1021  // Can be empty fields.
1022  parseQuotedString( text, aReader, line, &line, true );
1023 
1024  sheetPin->SetText( text );
1025 
1026  if( line == NULL )
1027  THROW_IO_ERROR( _( "unexpected end of line" ) );
1028 
1029  switch( parseChar( aReader, line, &line ) )
1030  {
1031  case 'I':
1032  sheetPin->SetShape( NET_INPUT );
1033  break;
1034 
1035  case 'O':
1036  sheetPin->SetShape( NET_OUTPUT );
1037  break;
1038 
1039  case 'B':
1040  sheetPin->SetShape( NET_BIDI );
1041  break;
1042 
1043  case 'T':
1044  sheetPin->SetShape( NET_TRISTATE );
1045  break;
1046 
1047  case 'U':
1048  sheetPin->SetShape( NET_UNSPECIFIED );
1049  break;
1050  default:
1051  SCH_PARSE_ERROR( "invalid sheet pin type", aReader, line );
1052  }
1053 
1054  switch( parseChar( aReader, line, &line ) )
1055  {
1056  case 'R': sheetPin->SetEdge( SHEET_RIGHT_SIDE ); break;
1057  case 'T': sheetPin->SetEdge( SHEET_TOP_SIDE ); break;
1058  case 'B': sheetPin->SetEdge( SHEET_BOTTOM_SIDE ); break;
1059  case 'L': sheetPin->SetEdge( SHEET_LEFT_SIDE ); break;
1060  default:
1061  SCH_PARSE_ERROR( "invalid sheet pin side", aReader, line );
1062  }
1063 
1064  wxPoint position;
1065 
1066  position.x = parseInt( aReader, line, &line );
1067  position.y = parseInt( aReader, line, &line );
1068  sheetPin->SetPosition( position );
1069 
1070  size = parseInt( aReader, line, &line );
1071 
1072  sheetPin->SetTextSize( wxSize( size, size ) );
1073 
1074  sheet->AddPin( sheetPin.release() );
1075  }
1076  }
1077  else if( strCompare( "$EndSheet", line ) )
1078  return sheet.release();
1079 
1080  line = aReader.ReadLine();
1081  }
1082 
1083  SCH_PARSE_ERROR( "missing '$EndSheet`", aReader, line );
1084 
1085  return NULL; // Prevents compiler warning. Should never get here.
1086 }
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:217
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:75
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 _(s)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#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(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, SHEET_BOTTOM_SIDE, SHEET_LEFT_SIDE, SHEET_RIGHT_SIDE, SHEET_TOP_SIDE, strCompare(), and THROW_IO_ERROR.

Referenced by LoadContent().

◆ LoadSymbol()

LIB_ALIAS * SCH_LEGACY_PLUGIN::LoadSymbol ( const wxString &  aLibraryPath,
const wxString &  aAliasName,
const PROPERTIES aProperties = nullptr 
)
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 4322 of file sch_legacy_plugin.cpp.

4324 {
4325  LOCALE_IO toggle; // toggles on, then off, the C locale.
4326 
4327  m_props = aProperties;
4328 
4329  cacheLib( aLibraryPath );
4330 
4331  LIB_ALIAS_MAP::const_iterator it = m_cache->m_aliases.find( aAliasName );
4332 
4333  if( it == m_cache->m_aliases.end() )
4334  return NULL;
4335 
4336  return it->second;
4337 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:154
SCH_LEGACY_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

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

◆ loadText()

SCH_TEXT * SCH_LEGACY_PLUGIN::loadText ( LINE_READER aReader)
private

Definition at line 1361 of file sch_legacy_plugin.cpp.

1362 {
1363  const char* line = aReader.Line();
1364 
1365  wxCHECK( strCompare( "Text", line, &line ), NULL );
1366 
1367  std::unique_ptr< SCH_TEXT> text;
1368 
1369  if( strCompare( "Notes", line, &line ) )
1370  text.reset( new SCH_TEXT );
1371  else if( strCompare( "Label", line, &line ) )
1372  text.reset( new SCH_LABEL );
1373  else if( strCompare( "HLabel", line, &line ) )
1374  text.reset( new SCH_HIERLABEL );
1375  else if( strCompare( "GLabel", line, &line ) )
1376  {
1377  // Prior to version 2, the SCH_GLOBALLABEL object did not exist.
1378  if( m_version == 1 )
1379  text.reset( new SCH_HIERLABEL );
1380  else
1381  text.reset( new SCH_GLOBALLABEL );
1382  }
1383  else
1384  SCH_PARSE_ERROR( "unknown Text type", aReader, line );
1385 
1386  // Parse the parameters common to all text objects.
1387  wxPoint position;
1388 
1389  position.x = parseInt( aReader, line, &line );
1390  position.y = parseInt( aReader, line, &line );
1391  text->SetPosition( position );
1392  text->SetLabelSpinStyle( parseInt( aReader, line, &line ) );
1393 
1394  int size = parseInt( aReader, line, &line );
1395 
1396  text->SetTextSize( wxSize( size, size ) );
1397 
1398  // Parse the global and hierarchical label type.
1399  if( text->Type() == SCH_HIER_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
1400  {
1401  if( strCompare( SheetLabelType[NET_INPUT], line, &line ) )
1402  text->SetShape( NET_INPUT );
1403  else if( strCompare( SheetLabelType[NET_OUTPUT], line, &line ) )
1404  text->SetShape( NET_OUTPUT );
1405  else if( strCompare( SheetLabelType[NET_BIDI], line, &line ) )
1406  text->SetShape( NET_BIDI );
1407  else if( strCompare( SheetLabelType[NET_TRISTATE], line, &line ) )
1408  text->SetShape( NET_TRISTATE );
1409  else if( strCompare( SheetLabelType[NET_UNSPECIFIED], line, &line ) )
1410  text->SetShape( NET_UNSPECIFIED );
1411  else
1412  SCH_PARSE_ERROR( "invalid label type", aReader, line );
1413  }
1414 
1415  int thickness = 0;
1416 
1417  // The following tokens do not exist in version 1 schematic files,
1418  // and not always in version 2 for HLabels and GLabels
1419  if( m_version > 1 )
1420  {
1421  if( m_version > 2 || *line >= ' ' )
1422  {
1423  if( strCompare( "Italic", line, &line ) )
1424  text->SetItalic( true );
1425  else if( !strCompare( "~", line, &line ) )
1426  SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
1427  }
1428 
1429  // The thickness token does not exist in older versions of the schematic file format
1430  // so calling parseInt will be made only if the EOL is not reached.
1431  if( *line >= ' ' )
1432  thickness = parseInt( aReader, line, &line );
1433  }
1434 
1435  text->SetBold( thickness != 0 );
1436  text->SetThickness( thickness != 0 ? GetPenSizeForBold( size ) : 0 );
1437 
1438  // Read the text string for the text.
1439  char* tmp = aReader.ReadLine();
1440 
1441  tmp = strtok( tmp, "\r\n" );
1442  wxString val = FROM_UTF8( tmp );
1443 
1444  for( ; ; )
1445  {
1446  int i = val.find( wxT( "\\n" ) );
1447 
1448  if( i == wxNOT_FOUND )
1449  break;
1450 
1451  val.erase( i, 2 );
1452  val.insert( i, wxT( "\n" ) );
1453  }
1454 
1455  text->SetText( val );
1456 
1457  return text.release();
1458 }
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:62
int GetPenSizeForBold(int aTextSize)
Function GetPensizeForBold.
Definition: gr_text.cpp:49
const char * SheetLabelType[]
Definition: sch_text.cpp:59
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 _(s)
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
size_t i
Definition: json11.cpp:649
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(), LINE_READER::ReadLine(), SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_PARSE_ERROR, SheetLabelType, and strCompare().

Referenced by LoadContent().

◆ loadWire()

SCH_LINE * SCH_LEGACY_PLUGIN::loadWire ( LINE_READER aReader)
private

Definition at line 1218 of file sch_legacy_plugin.cpp.

1219 {
1220  std::unique_ptr< SCH_LINE > wire( new SCH_LINE );
1221 
1222  const char* line = aReader.Line();
1223 
1224  wxCHECK( strCompare( "Wire", line, &line ), NULL );
1225 
1226  if( strCompare( "Wire", line, &line ) )
1227  wire->SetLayer( LAYER_WIRE );
1228  else if( strCompare( "Bus", line, &line ) )
1229  wire->SetLayer( LAYER_BUS );
1230  else if( strCompare( "Notes", line, &line ) )
1231  wire->SetLayer( LAYER_NOTES );
1232  else
1233  SCH_PARSE_ERROR( "invalid line type", aReader, line );
1234 
1235  if( !strCompare( "Line", line, &line ) )
1236  SCH_PARSE_ERROR( "invalid wire definition", aReader, line );
1237 
1238  // Since Sept 15, 2017, a line style is alloved (width, style, color)
1239  // Only non default values are stored
1240  while( !is_eol( *line ) )
1241  {
1242  wxString buf;
1243 
1244  parseUnquotedString( buf, aReader, line, &line );
1245 
1246  if( buf == ")" )
1247  continue;
1248 
1249  else if( buf == T_WIDTH )
1250  {
1251  int size = parseInt( aReader, line, &line );
1252  wire->SetLineWidth( size );
1253  }
1254  else if( buf == T_STYLE )
1255  {
1256  parseUnquotedString( buf, aReader, line, &line );
1257  int style = SCH_LINE::GetLineStyleInternalId( buf );
1258  wire->SetLineStyle( style );
1259  }
1260  else // should be the color parameter.
1261  {
1262  // The color param is something like rgb(150, 40, 191)
1263  // and because there is no space between ( and 150
1264  // the first param is inside buf.
1265  // So break keyword and the first param into 2 separate strings.
1266  wxString prm, keyword;
1267  keyword = buf.BeforeLast( '(', &prm );
1268 
1269  if( ( keyword == T_COLOR ) || ( keyword == T_COLORA ) )
1270  {
1271  long color[4] = { 0 };
1272 
1273  int ii = 0;
1274 
1275  if( !prm.IsEmpty() )
1276  {
1277  prm.ToLong( &color[ii] );
1278  ii++;
1279  }
1280 
1281  int prm_count = ( keyword == T_COLORA ) ? 4 : 3;
1282  // fix opacity to 1.0 or 255, when not exists in file
1283  color[3] = 255;
1284 
1285  for(; ii < prm_count && !is_eol( *line ); ii++ )
1286  {
1287  color[ii] = parseInt( aReader, line, &line );
1288 
1289  // Skip the separator between values
1290  if( *line == ',' || *line == ' ')
1291  line++;
1292  }
1293 
1294  wire->SetLineColor( color[0]/255.0, color[1]/255.0, color[2]/255.0,color[3]/255.0 );
1295  }
1296  }
1297  }
1298 
1299  // Read the segment en points coordinates:
1300  line = aReader.ReadLine();
1301 
1302  wxPoint begin, end;
1303 
1304  begin.x = parseInt( aReader, line, &line );
1305  begin.y = parseInt( aReader, line, &line );
1306  end.x = parseInt( aReader, line, &line );
1307  end.y = parseInt( aReader, line, &line );
1308 
1309  wire->SetStartPoint( begin );
1310  wire->SetEndPoint( end );
1311 
1312  return wire.release();
1313 }
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:137
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#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:37
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(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, strCompare(), T_COLOR, T_COLORA, T_STYLE, and T_WIDTH.

Referenced by LoadContent().

◆ ParsePart()

LIB_PART * SCH_LEGACY_PLUGIN::ParsePart ( LINE_READER aReader,
int  majorVersion = 0,
int  minorVersion = 0 
)
static

Definition at line 4470 of file sch_legacy_plugin.cpp.

4472 {
4473  return SCH_LEGACY_PLUGIN_CACHE::LoadPart( reader, aMajorVersion, aMinorVersion );
4474 }
static LIB_PART * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion)

References SCH_LEGACY_PLUGIN_CACHE::LoadPart().

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

◆ Save()

void SCH_LEGACY_PLUGIN::Save ( const wxString &  aFileName,
SCH_SCREEN aSchematic,
KIWAY aKiway,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

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

Parameters
aFileNameis the name of a file to save to on disk.
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 1784 of file sch_legacy_plugin.cpp.

1786 {
1787  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN object." );
1788  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1789 
1790  LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
1791 
1792  init( aKiway, aProperties );
1793 
1794  wxFileName fn = aFileName;
1795 
1796  // File names should be absolute. Don't assume everything relative to the project path
1797  // works properly.
1798  wxASSERT( fn.IsAbsolute() );
1799 
1800  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1801 
1802  m_out = &formatter; // no ownership
1803 
1804  Format( aScreen );
1805 }
void init(KIWAY *aKiway, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:154
void Format(SCH_SCREEN *aScreen)
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
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 2077 of file sch_legacy_plugin.cpp.

2078 {
2079  wxCHECK_RET( aBitmap != NULL, "SCH_BITMAP* is NULL" );
2080 
2081  const wxImage* image = aBitmap->GetImage()->GetImageData();
2082 
2083  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
2084 
2085  m_out->Print( 0, "$Bitmap\n" );
2086  m_out->Print( 0, "Pos %-4d %-4d\n", aBitmap->GetPosition().x, aBitmap->GetPosition().y );
2087  m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
2088  m_out->Print( 0, "Data\n" );
2089 
2090  wxMemoryOutputStream stream;
2091 
2092  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
2093 
2094  // Write binary data in hexadecimal form (ASCII)
2095  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
2096  char* begin = (char*) buffer->GetBufferStart();
2097 
2098  for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
2099  {
2100  if( ii >= 32 )
2101  {
2102  ii = 0;
2103 
2104  m_out->Print( 0, "\n" );
2105  }
2106 
2107  m_out->Print( 0, "%2.2X ", *begin & 0xFF );
2108  }
2109 
2110  m_out->Print( 0, "\nEndData\n" );
2111  m_out->Print( 0, "$EndBitmap\n" );
2112 }
double GetScale() const
Definition: bitmap_base.h:92
wxImage * GetImageData()
Definition: bitmap_base.h:83
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_bitmap.h:140
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:59
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

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 2303 of file sch_legacy_plugin.cpp.

2304 {
2305  wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" );
2306 
2307  wxString members = boost::algorithm::join( aAlias->Members(), " " );
2308 
2309  m_out->Print( 0, "BusAlias %s %s\n",
2310  TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
2311 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

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 2188 of file sch_legacy_plugin.cpp.

2189 {
2190  wxCHECK_RET( aBusEntry != NULL, "SCH_BUS_ENTRY_BASE* is NULL" );
2191 
2192  if( aBusEntry->GetLayer() == LAYER_WIRE )
2193  m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
2194  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
2195  aBusEntry->m_End().x, aBusEntry->m_End().y );
2196  else
2197  m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
2198  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
2199  aBusEntry->m_End().x, aBusEntry->m_End().y );
2200 }
wxPoint m_End() const
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:193
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
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 1940 of file sch_legacy_plugin.cpp.

1941 {
1942  std::string name1;
1943  std::string name2;
1944  wxArrayString reference_fields;
1945 
1946  static wxString delimiters( wxT( " " ) );
1947 
1948  // This is redundant with the AR entries below, but it makes the files backwards-compatible.
1949  if( aComponent->GetPathsAndReferences().GetCount() > 0 )
1950  {
1951  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[0], delimiters );
1952  name1 = toUTFTildaText( reference_fields[1] );
1953  }
1954  else
1955  {
1956  if( aComponent->GetField( REFERENCE )->GetText().IsEmpty() )
1957  name1 = toUTFTildaText( aComponent->GetPrefix() );
1958  else
1959  name1 = toUTFTildaText( aComponent->GetField( REFERENCE )->GetText() );
1960  }
1961 
1962  wxString part_name = aComponent->GetLibId().Format();
1963 
1964  if( part_name.size() )
1965  {
1966  name2 = toUTFTildaText( part_name );
1967  }
1968  else
1969  {
1970  name2 = "_NONAME_";
1971  }
1972 
1973  m_out->Print( 0, "$Comp\n" );
1974  m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
1975 
1976  // Generate unit number, convert and time stamp
1977  m_out->Print( 0, "U %d %d %8.8X\n", aComponent->GetUnit(), aComponent->GetConvert(),
1978  aComponent->GetTimeStamp() );
1979 
1980  // Save the position
1981  m_out->Print( 0, "P %d %d\n", aComponent->GetPosition().x, aComponent->GetPosition().y );
1982 
1983  /* If this is a complex hierarchy; save hierarchical references.
1984  * but for simple hierarchies it is not necessary.
1985  * the reference inf is already saved
1986  * this is useful for old Eeschema version compatibility
1987  */
1988  if( aComponent->GetPathsAndReferences().GetCount() > 1 )
1989  {
1990  for( unsigned int ii = 0; ii < aComponent->GetPathsAndReferences().GetCount(); ii++ )
1991  {
1992  /*format:
1993  * AR Path="/140/2" Ref="C99" Part="1"
1994  * where 140 is the uid of the containing sheet
1995  * and 2 is the timestamp of this component.
1996  * (timestamps are actually 8 hex chars)
1997  * Ref is the conventional component reference for this 'path'
1998  * Part is the conventional component part selection for this 'path'
1999  */
2000  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[ii],
2001  delimiters );
2002 
2003  m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%s\" \n",
2004  TO_UTF8( reference_fields[0] ),
2005  TO_UTF8( reference_fields[1] ),
2006  TO_UTF8( reference_fields[2] ) );
2007  }
2008  }
2009 
2010  // update the ugly field index, which I would like to see go away someday soon.
2011  for( int i = 0; i < aComponent->GetFieldCount(); ++i )
2012  aComponent->GetField( i )->SetId( i );
2013 
2014  // Fixed fields:
2015  // Save mandatory fields even if they are blank,
2016  // because the visibility, size and orientation are set from library editor.
2017  for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
2018  saveField( aComponent->GetField( i ) );
2019 
2020  // User defined fields:
2021  // The *policy* about which user defined fields are part of a symbol is now
2022  // only in the dialog editors. No policy should be enforced here, simply
2023  // save all the user defined fields, they are present because a dialog editor
2024  // thought they should be. If you disagree, go fix the dialog editors.
2025  for( int i = MANDATORY_FIELDS; i < aComponent->GetFieldCount(); ++i )
2026  saveField( aComponent->GetField( i ) );
2027 
2028  // Unit number, position, box ( old standard )
2029  m_out->Print( 0, "\t%-4d %-4d %-4d\n", aComponent->GetUnit(), aComponent->GetPosition().x,
2030  aComponent->GetPosition().y );
2031 
2032  TRANSFORM transform = aComponent->GetTransform();
2033 
2034  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
2035  transform.x1, transform.y1, transform.x2, transform.y2 );
2036  m_out->Print( 0, "$EndComp\n" );
2037 }
int y2
Definition: transform.h:51
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:48
int y1
Definition: transform.h:49
int GetUnit() const
Class for transforming 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:216
int GetFieldCount() const
Return the number of fields in this symbol.
UTF8 Format() const
Definition: lib_id.cpp:237
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
size_t i
Definition: json11.cpp:649
wxPoint GetPosition() const override
Function GetPosition.
int GetConvert() const
void SetId(int aId)
Definition: sch_field.h:110
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
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124

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(), EDA_TEXT::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 2040 of file sch_legacy_plugin.cpp.

2041 {
2042  char hjustify = 'C';
2043 
2044  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
2045  hjustify = 'L';
2046  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
2047  hjustify = 'R';
2048 
2049  char vjustify = 'C';
2050 
2051  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
2052  vjustify = 'B';
2053  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
2054  vjustify = 'T';
2055 
2056  m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
2057  aField->GetId(),
2058  EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
2059  aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
2060  aField->GetLibPosition().x, aField->GetLibPosition().y,
2061  aField->GetTextWidth(),
2062  !aField->IsVisible(),
2063  hjustify, vjustify,
2064  aField->IsItalic() ? 'I' : 'N',
2065  aField->IsBold() ? 'B' : 'N' );
2066 
2067  // Save field name, if the name is user definable
2068  if( aField->GetId() >= FIELD1 )
2069  {
2070  m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
2071  }
2072 
2073  m_out->Print( 0, "\n" );
2074 }
#define TEXT_ANGLE_HORIZ
bool IsBold() const
Definition: eda_text.h:167
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:185
bool IsVisible() const
Definition: eda_text.h:170
double GetTextAngle() const
Definition: eda_text.h:158
int GetId() const
Definition: sch_field.h:108
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:249
bool IsItalic() const
Definition: eda_text.h:164
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:184
wxPoint GetLibPosition() const
Definition: sch_field.h:192
int GetTextWidth() const
Definition: eda_text.h:226
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:370
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124

References EscapedUTF8(), FIELD1, EDA_TEXT::GetHorizJustify(), SCH_FIELD::GetId(), SCH_FIELD::GetLibPosition(), SCH_FIELD::GetName(), EDA_TEXT::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 2170 of file sch_legacy_plugin.cpp.

2171 {
2172  wxCHECK_RET( aJunction != NULL, "SCH_JUNCTION* is NULL" );
2173 
2174  m_out->Print( 0, "Connection ~ %-4d %-4d\n",
2175  aJunction->GetPosition().x, aJunction->GetPosition().y );
2176 }
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_junction.h:100
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

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

Referenced by Format().

◆ SaveLibrary()

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

Reimplemented from SCH_PLUGIN.

Definition at line 4430 of file sch_legacy_plugin.cpp.

4431 {
4432  if( !m_cache )
4433  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4434 
4435  wxString oldFileName = m_cache->GetFileName();
4436 
4437  if( !m_cache->IsFile( aLibraryPath ) )
4438  {
4439  m_cache->SetFileName( aLibraryPath );
4440  }
4441 
4442  // This is a forced save.
4443  m_cache->SetModified();
4444  m_cache->Save( writeDocFile( aProperties ) );
4445  m_cache->SetFileName( oldFileName );
4446 }
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 2203 of file sch_legacy_plugin.cpp.

2204 {
2205  wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" );
2206 
2207  const char* layer = "Notes";
2208  const char* width = "Line";
2209 
2210  if( aLine->GetLayer() == LAYER_WIRE )
2211  layer = "Wire";
2212  else if( aLine->GetLayer() == LAYER_BUS )
2213  layer = "Bus";
2214 
2215  m_out->Print( 0, "Wire %s %s", layer, width );
2216 
2217  // Write line style (width, type, color) only for non default values
2218  if( aLine->GetLayer() == LAYER_NOTES )
2219  {
2220  if( aLine->GetPenSize() != aLine->GetDefaultWidth() )
2221  m_out->Print( 0, " %s %d", T_WIDTH, aLine->GetLineSize() );
2222 
2223  if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
2224  m_out->Print( 0, " %s %s", T_STYLE, SCH_LINE::GetLineStyleName( aLine->GetLineStyle() ) );
2225 
2226  if( aLine->GetLineColor() != aLine->GetDefaultColor() )
2227  m_out->Print( 0, " %s",
2228  TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
2229  }
2230 
2231  m_out->Print( 0, "\n" );
2232 
2233  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
2234  aLine->GetStartPoint().x, aLine->GetStartPoint().y,
2235  aLine->GetEndPoint().x, aLine->GetEndPoint().y );
2236 
2237  m_out->Print( 0, "\n");
2238 }
COLOR4D GetLineColor() const
Definition: sch_line.cpp:263
wxPoint GetStartPoint() const
Definition: sch_line.h:95
#define T_WIDTH
int GetDefaultWidth() const
Definition: sch_line.cpp:298
#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:48
int GetDefaultStyle() const
Definition: sch_line.cpp:271
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:193
int GetLineSize() const
Definition: sch_line.h:126
COLOR4D GetDefaultColor() const
Definition: sch_line.cpp:233
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
static const char * GetLineStyleName(int aStyle)
Definition: sch_line.cpp:109
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:318
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:289
wxPoint GetEndPoint() const
Definition: sch_line.h:98

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 2179 of file sch_legacy_plugin.cpp.

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

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 2115 of file sch_legacy_plugin.cpp.

2116 {
2117  wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" );
2118 
2119  m_out->Print( 0, "$Sheet\n" );
2120  m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
2121  aSheet->GetPosition().x, aSheet->GetPosition().y,
2122  aSheet->GetSize().x, aSheet->GetSize().y );
2123 
2124  m_out->Print( 0, "U %8.8X\n", aSheet->GetTimeStamp() );
2125 
2126  if( !aSheet->GetName().IsEmpty() )
2127  m_out->Print( 0, "F0 %s %d\n", EscapedUTF8( aSheet->GetName() ).c_str(),
2128  aSheet->GetSheetNameSize() );
2129 
2130  if( !aSheet->GetFileName().IsEmpty() )
2131  m_out->Print( 0, "F1 %s %d\n", EscapedUTF8( aSheet->GetFileName() ).c_str(),
2132  aSheet->GetFileNameSize() );
2133 
2134  for( const SCH_SHEET_PIN& pin : aSheet->GetPins() )
2135  {
2136  int type, side;
2137 
2138  if( pin.GetText().IsEmpty() )
2139  break;
2140 
2141  switch( pin.GetEdge() )
2142  {
2143  default:
2144  case SHEET_LEFT_SIDE: side = 'L'; break;
2145  case SHEET_RIGHT_SIDE: side = 'R'; break;
2146  case SHEET_TOP_SIDE: side = 'T'; break;
2147  case SHEET_BOTTOM_SIDE: side = 'B'; break;
2148  }
2149 
2150  switch( pin.GetShape() )
2151  {
2152  case NET_INPUT: type = 'I'; break;
2153  case NET_OUTPUT: type = 'O'; break;
2154  case NET_BIDI: type = 'B'; break;
2155  case NET_TRISTATE: type = 'T'; break;
2156  default:
2157  case NET_UNSPECIFIED: type = 'U'; break;
2158  }
2159 
2160  m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n", pin.GetNumber(),
2161  EscapedUTF8( pin.GetText() ).c_str(), // supplies wrapping quotes
2162  type, side, pin.GetPosition().x, pin.GetPosition().y,
2163  pin.GetTextWidth() );
2164  }
2165 
2166  m_out->Print( 0, "$EndSheet\n" );
2167 }
SCH_SHEET_PINS & GetPins()
Definition: sch_sheet.h:335
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:249
int GetFileNameSize() const
Definition: sch_sheet.h:278
int GetSheetNameSize() const
Definition: sch_sheet.h:275
wxString GetName() const
Definition: sch_sheet.h:272
timestamp_t GetTimeStamp() const
Definition: base_struct.h:216
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:75
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:543
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:646
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxSize GetSize()
Definition: sch_sheet.h:283

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(), SHEET_BOTTOM_SIDE, SHEET_LEFT_SIDE, SHEET_RIGHT_SIDE, and SHEET_TOP_SIDE.

Referenced by Format().

◆ SaveSymbol()

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

Write aSymbol to an existing library located at aLibraryPath.

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4340 of file sch_legacy_plugin.cpp.

4342 {
4343  m_props = aProperties;
4344 
4345  cacheLib( aLibraryPath );
4346 
4347  m_cache->AddSymbol( aSymbol );
4348 
4349  if( !isBuffering( aProperties ) )
4350  m_cache->Save( writeDocFile( aProperties ) );
4351 }
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 nullptr.

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 2241 of file sch_legacy_plugin.cpp.

2242 {
2243  wxCHECK_RET( aText != NULL, "SCH_TEXT* is NULL" );
2244 
2245  const char* italics = "~";
2246  const char* textType = "Notes";
2247 
2248  if( aText->IsItalic() )
2249  italics = "Italic";
2250 
2251  wxString text = aText->GetText();
2252 
2253  SCH_LAYER_ID layer = aText->GetLayer();
2254 
2255  if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
2256  {
2257  if( layer == LAYER_NOTES )
2258  {
2259  // For compatibility reasons, the text must be saved in only one text line
2260  // so replace all EOLs with \\n
2261  text.Replace( wxT( "\n" ), wxT( "\\n" ) );
2262 
2263  // Here we should have no CR or LF character in line
2264  // This is not always the case if a multiline text was copied (using a copy/paste
2265  // function) from a text that uses E.O.L characters that differs from the current
2266  // EOL format. This is mainly the case under Linux using LF symbol when copying
2267  // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
2268  // (or LF left under MacOSX)
2269  for( unsigned ii = 0; ii < text.Len(); )
2270  {
2271  if( text[ii] == 0x0A || text[ii] == 0x0D )
2272  text.erase( ii, 1 );
2273  else
2274  ii++;
2275  }
2276  }
2277  else
2278  {
2279  textType = "Label";
2280  }
2281 
2282  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2283  aText->GetPosition().x, aText->GetPosition().y,
2284  aText->GetLabelSpinStyle(),
2285  aText->GetTextWidth(),
2286  italics, aText->GetThickness(), TO_UTF8( text ) );
2287  }
2288  else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2289  {
2290  textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2291 
2292  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2293  aText->GetPosition().x, aText->GetPosition().y,
2294  aText->GetLabelSpinStyle(),
2295  aText->GetTextWidth(),
2296  SheetLabelType[aText->GetShape()],
2297  italics,
2298  aText->GetThickness(), TO_UTF8( text ) );
2299  }
2300 }
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:148
const char * SheetLabelType[]
Definition: sch_text.cpp:59
bool IsItalic() const
Definition: eda_text.h:164
int GetLabelSpinStyle() const
Definition: sch_text.h:124
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
SCH_LAYER_ID
Eeschema drawing layers.
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_text.h:198
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:193
int GetTextWidth() const
Definition: eda_text.h:226
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:126

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

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

References _.

◆ writeDocFile()

bool SCH_LEGACY_PLUGIN::writeDocFile ( const PROPERTIES aProperties)
private

Definition at line 4251 of file sch_legacy_plugin.cpp.

4252 {
4253  std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
4254 
4255  if( aProperties && aProperties->find( propName ) != aProperties->end() )
4256  return false;
4257 
4258  return true;
4259 }
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 180 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 177 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 182 of file sch_legacy_plugin.h.

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

◆ m_out

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 179 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 nullptr.

Definition at line 181 of file sch_legacy_plugin.h.

Referenced by cacheLib(), CreateSymbolLib(), DeleteAlias(), DeleteSymbol(), EnumerateSymbolLib(), 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 183 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 174 of file sch_legacy_plugin.h.

Referenced by init(), loadComponent(), LoadContent(), 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 88 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 96 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: