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 &aSymbolNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Populate a list of LIB_PART alias names contained within the library aLibraryPath. More...
 
void EnumerateSymbolLib (std::vector< LIB_PART * > &aSymbolList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Populate a list of LIB_PART aliases contained within the library aLibraryPath. More...
 
LIB_PARTLoadSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=nullptr) override
 Load a LIB_PART object having aPartName from the aLibraryPath containing a library format that this SCH_PLUGIN knows about. More...
 
void SaveSymbol (const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=nullptr) override
 Write aSymbol to an existing library located at aLibraryPath. More...
 
void DeleteSymbol (const wxString &aLibraryPath, const wxString &aSymbolName, const PROPERTIES *aProperties=nullptr) override
 Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath. More...
 
void CreateSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Create a new empty symbol library at aLibraryPath. More...
 
bool DeleteSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Delete an existing symbol library and returns true if successful, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 
void SaveLibrary (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 
bool CheckHeader (const wxString &aFileName) override
 Return true if the first line in aFileName begins with the expected header. More...
 
bool IsSymbolLibWritable (const wxString &aLibraryPath) override
 Return true if the library at aLibraryPath is writable. More...
 
const wxString & GetError () const override
 Return an error string to the caller. More...
 
virtual void SymbolLibOptions (PROPERTIES *aListToAppendTo) const
 Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Static Public Member Functions

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

Static Public Attributes

static const char * PropBuffering = "buffering"
 The property used internally by the plugin to enable cache buffering which prevents the library file from being written every time the cache is changed. More...
 
static const char * PropNoDocFile = "no_doc_file"
 The property used internally by the plugin to disable writing the library documentation (.dcm) file when saving the library cache. 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 63 of file sch_legacy_plugin.h.

Constructor & Destructor Documentation

◆ SCH_LEGACY_PLUGIN()

SCH_LEGACY_PLUGIN::SCH_LEGACY_PLUGIN ( )

Definition at line 564 of file sch_legacy_plugin.cpp.

565 {
566  init( NULL );
567 }
void init(KIWAY *aKiway, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.
#define NULL

References init(), and NULL.

◆ ~SCH_LEGACY_PLUGIN()

SCH_LEGACY_PLUGIN::~SCH_LEGACY_PLUGIN ( )
virtual

Definition at line 570 of file sch_legacy_plugin.cpp.

571 {
572  delete m_cache;
573 }
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 4286 of file sch_legacy_plugin.cpp.

4287 {
4288  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
4289  {
4290  // a spectacular episode in memory management:
4291  delete m_cache;
4292  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
4293 
4294  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
4295  // to modify the hash value that indicate component to symbol links
4296  // must be updated.
4298 
4299  if( !isBuffering( m_props ) )
4300  m_cache->Load();
4301  }
4302 }
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 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 4489 of file sch_legacy_plugin.cpp.

4490 {
4491  // Open file and check first line
4492  wxTextFile tempFile;
4493 
4494  tempFile.Open( aFileName );
4495  wxString firstline;
4496  // read the first line
4497  firstline = tempFile.GetFirstLine();
4498  tempFile.Close();
4499 
4500  return firstline.StartsWith( "EESchema" );
4501 }

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

4424 {
4425  if( wxFileExists( aLibraryPath ) )
4426  {
4428  _( "symbol library \"%s\" already exists, cannot create a new library" ),
4429  aLibraryPath.GetData() ) );
4430  }
4431 
4432  LOCALE_IO toggle;
4433 
4434  m_props = aProperties;
4435 
4436  delete m_cache;
4437  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4438  m_cache->SetModified();
4439  m_cache->Save( writeDocFile( aProperties ) );
4440  m_cache->Load(); // update m_writable and m_mod_time
4441 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
SCH_LEGACY_PLUGIN_CACHE * m_cache
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLU...
#define THROW_IO_ERROR(msg)
void SetModified(bool aModified=true)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:31
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().

◆ DeleteSymbol()

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4408 of file sch_legacy_plugin.cpp.

4410 {
4411  m_props = aProperties;
4412 
4413  cacheLib( aLibraryPath );
4414 
4415  m_cache->DeleteSymbol( aSymbolName );
4416 
4417  if( !isBuffering( aProperties ) )
4418  m_cache->Save( writeDocFile( aProperties ) );
4419 }
void DeleteSymbol(const wxString &aName)
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;.
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 4444 of file sch_legacy_plugin.cpp.

4446 {
4447  wxFileName fn = aLibraryPath;
4448 
4449  if( !fn.FileExists() )
4450  return false;
4451 
4452  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
4453  // we don't want that. we want bare metal portability with no UI here.
4454  if( wxRemove( aLibraryPath ) )
4455  {
4456  THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
4457  aLibraryPath.GetData() ) );
4458  }
4459 
4460  if( m_cache && m_cache->IsFile( aLibraryPath ) )
4461  {
4462  delete m_cache;
4463  m_cache = 0;
4464  }
4465 
4466  return true;
4467 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
#define THROW_IO_ERROR(msg)
bool IsFile(const wxString &aFullPathAndFileName) const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:31

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

◆ EnumerateSymbolLib() [1/2]

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4332 of file sch_legacy_plugin.cpp.

4335 {
4336  LOCALE_IO toggle; // toggles on, then off, the C locale.
4337 
4338  m_props = aProperties;
4339 
4340  bool powerSymbolsOnly = ( aProperties &&
4341  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4342  cacheLib( aLibraryPath );
4343 
4344  const LIB_PART_MAP& symbols = m_cache->m_symbols;
4345 
4346  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
4347  {
4348  if( !powerSymbolsOnly || it->second->IsPower() )
4349  aSymbolNameList.Add( it->first );
4350  }
4351 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
SCH_LEGACY_PLUGIN_CACHE * m_cache
std::map< wxString, LIB_PART *, LibPartMapSort > LIB_PART_MAP
Part map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
static const char * PropPowerSymsOnly
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

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

◆ EnumerateSymbolLib() [2/2]

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4354 of file sch_legacy_plugin.cpp.

4357 {
4358  LOCALE_IO toggle; // toggles on, then off, the C locale.
4359 
4360  m_props = aProperties;
4361 
4362  bool powerSymbolsOnly = ( aProperties &&
4363  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4364  cacheLib( aLibraryPath );
4365 
4366  const LIB_PART_MAP& symbols = m_cache->m_symbols;
4367 
4368  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
4369  {
4370  if( !powerSymbolsOnly || it->second->IsPower() )
4371  aSymbolList.push_back( it->second );
4372  }
4373 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
SCH_LEGACY_PLUGIN_CACHE * m_cache
std::map< wxString, LIB_PART *, LibPartMapSort > LIB_PART_MAP
Part map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
static const char * PropPowerSymsOnly
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

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

◆ Format() [1/2]

void SCH_LEGACY_PLUGIN::Format ( SCH_SCREEN aScreen)

Definition at line 1834 of file sch_legacy_plugin.cpp.

1835 {
1836  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN* object." );
1837  wxCHECK_RET( m_kiway != NULL, "NULL KIWAY* object." );
1838 
1839  // Write the header
1840  m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1841 
1842  // This section is not used, but written for file compatibility
1843  m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1844  m_out->Print( 0, "EELAYER END\n" );
1845 
1846  /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1847  * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1848  * simple hierarchy and flat hierarchy. Used also to search the root
1849  * sheet ( ScreenNumber = 1 ) within the files
1850  */
1851  const TITLE_BLOCK& tb = aScreen->GetTitleBlock();
1852  const PAGE_INFO& page = aScreen->GetPageSettings();
1853 
1854  m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1855  page.GetWidthMils(),
1856  page.GetHeightMils(),
1857  !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1858  m_out->Print( 0, "encoding utf-8\n" );
1859  m_out->Print( 0, "Sheet %d %d\n", aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens );
1860  m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1861  m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1862  m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1863  m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1864  m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment( 0 ) ).c_str() );
1865  m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment( 1 ) ).c_str() );
1866  m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment( 2 ) ).c_str() );
1867  m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment( 3 ) ).c_str() );
1868  m_out->Print( 0, "Comment5 %s\n", EscapedUTF8( tb.GetComment( 4 ) ).c_str() );
1869  m_out->Print( 0, "Comment6 %s\n", EscapedUTF8( tb.GetComment( 5 ) ).c_str() );
1870  m_out->Print( 0, "Comment7 %s\n", EscapedUTF8( tb.GetComment( 6 ) ).c_str() );
1871  m_out->Print( 0, "Comment8 %s\n", EscapedUTF8( tb.GetComment( 7 ) ).c_str() );
1872  m_out->Print( 0, "Comment9 %s\n", EscapedUTF8( tb.GetComment( 8 ) ).c_str() );
1873  m_out->Print( 0, "$EndDescr\n" );
1874 
1875  for( const auto& alias : aScreen->GetBusAliases() )
1876  {
1877  saveBusAlias( alias );
1878  }
1879 
1880  for( auto item : aScreen->Items() )
1881  {
1882  switch( item->Type() )
1883  {
1884  case SCH_COMPONENT_T:
1885  saveComponent( static_cast<SCH_COMPONENT*>( item ) );
1886  break;
1887  case SCH_BITMAP_T:
1888  saveBitmap( static_cast<SCH_BITMAP*>( item ) );
1889  break;
1890  case SCH_SHEET_T:
1891  saveSheet( static_cast<SCH_SHEET*>( item ) );
1892  break;
1893  case SCH_JUNCTION_T:
1894  saveJunction( static_cast<SCH_JUNCTION*>( item ) );
1895  break;
1896  case SCH_NO_CONNECT_T:
1897  saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ) );
1898  break;
1899  case SCH_BUS_WIRE_ENTRY_T:
1900  case SCH_BUS_BUS_ENTRY_T:
1901  saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ) );
1902  break;
1903  case SCH_LINE_T:
1904  saveLine( static_cast<SCH_LINE*>( item ) );
1905  break;
1906  case SCH_TEXT_T:
1907  case SCH_LABEL_T:
1908  case SCH_GLOBAL_LABEL_T:
1909  case SCH_HIER_LABEL_T:
1910  saveText( static_cast<SCH_TEXT*>( item ) );
1911  break;
1912  default:
1913  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1914  }
1915  }
1916 
1917  m_out->Print( 0, "$EndSCHEMATC\n" );
1918 }
int m_ScreenNumber
Definition: base_screen.h:135
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:162
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
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:152
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
#define NULL
const wxString & GetRevision() const
Definition: title_block.h:89
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
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
EE_RTREE & Items()
Definition: sch_screen.h:127
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
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:471
int GetWidthMils() const
Definition: page_info.h:137

References EESCHEMA_VERSION, EscapedUTF8(), SCH_SCREEN::GetBusAliases(), TITLE_BLOCK::GetComment(), TITLE_BLOCK::GetCompany(), TITLE_BLOCK::GetDate(), 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(), SCH_SCREEN::Items(), m_kiway, BASE_SCREEN::m_NumberOfScreens, m_out, BASE_SCREEN::m_ScreenNumber, NULL, 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 1921 of file sch_legacy_plugin.cpp.

1922 {
1923  m_out = aFormatter;
1924 
1925  for( unsigned i = 0; i < aSelection->GetSize(); ++i )
1926  {
1927  SCH_ITEM* item = (SCH_ITEM*) aSelection->GetItem( i );
1928 
1929  switch( item->Type() )
1930  {
1931  case SCH_COMPONENT_T:
1932  saveComponent( static_cast< SCH_COMPONENT* >( item ) );
1933  break;
1934  case SCH_BITMAP_T:
1935  saveBitmap( static_cast< SCH_BITMAP* >( item ) );
1936  break;
1937  case SCH_SHEET_T:
1938  saveSheet( static_cast< SCH_SHEET* >( item ) );
1939  break;
1940  case SCH_JUNCTION_T:
1941  saveJunction( static_cast< SCH_JUNCTION* >( item ) );
1942  break;
1943  case SCH_NO_CONNECT_T:
1944  saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
1945  break;
1946  case SCH_BUS_WIRE_ENTRY_T:
1947  case SCH_BUS_BUS_ENTRY_T:
1948  saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1949  break;
1950  case SCH_LINE_T:
1951  saveLine( static_cast< SCH_LINE* >( item ) );
1952  break;
1953  case SCH_TEXT_T:
1954  case SCH_LABEL_T:
1955  case SCH_GLOBAL_LABEL_T:
1956  case SCH_HIER_LABEL_T:
1957  saveText( static_cast< SCH_TEXT* >( item ) );
1958  break;
1959  default:
1960  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1961  }
1962  }
1963 }
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:104
void saveComponent(SCH_COMPONENT *aComponent)
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:136
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References SELECTION::GetItem(), SELECTION::GetSize(), 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 4517 of file sch_legacy_plugin.cpp.

4518 {
4519  SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( part, formatter );
4520 }
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_PART_MAP *aMap=nullptr)

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

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

References m_error.

◆ GetFileExtension()

const wxString SCH_LEGACY_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Returns the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 75 of file sch_legacy_plugin.h.

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

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

4323 {
4324  if( m_cache )
4325  return m_cache->GetModifyHash();
4326 
4327  // If the cache hasn't been loaded, it hasn't been modified.
4328  return 0;
4329 }
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 70 of file sch_legacy_plugin.h.

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

◆ init()

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

initialize PLUGIN like a constructor would.

Definition at line 576 of file sch_legacy_plugin.cpp.

577 {
578  m_version = 0;
579  m_rootSheet = NULL;
580  m_props = aProperties;
581  m_kiway = aKiway;
582  m_cache = NULL;
583  m_out = NULL;
584 }
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.
#define NULL
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, m_version, and NULL.

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

◆ isBuffering()

bool SCH_LEGACY_PLUGIN::isBuffering ( const PROPERTIES aProperties)
private

Definition at line 4316 of file sch_legacy_plugin.cpp.

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

References PROPERTIES::Exists(), and PropBuffering.

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

◆ IsSymbolLibWritable()

bool SCH_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 4504 of file sch_legacy_plugin.cpp.

4505 {
4506  return wxFileName::IsFileWritable( aLibraryPath );
4507 }

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

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

◆ loadBitmap()

SCH_BITMAP * SCH_LEGACY_PLUGIN::loadBitmap ( LINE_READER aReader)
private

Definition at line 1087 of file sch_legacy_plugin.cpp.

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

Referenced by LoadContent().

◆ loadBusAlias()

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

Definition at line 1784 of file sch_legacy_plugin.cpp.

1786 {
1787  auto busAlias = std::make_shared< BUS_ALIAS >( aScreen );
1788  const char* line = aReader.Line();
1789 
1790  wxCHECK( strCompare( "BusAlias", line, &line ), NULL );
1791 
1792  wxString buf;
1793  parseUnquotedString( buf, aReader, line, &line );
1794  busAlias->SetName( buf );
1795 
1796  while( *line != '\0' )
1797  {
1798  buf.clear();
1799  parseUnquotedString( buf, aReader, line, &line, true );
1800  if( buf.Len() > 0 )
1801  {
1802  busAlias->AddMember( buf );
1803  }
1804  }
1805 
1806  return busAlias;
1807 }
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.
#define 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(), NULL, parseUnquotedString(), and strCompare().

Referenced by LoadContent().

◆ loadBusEntry()

SCH_BUS_ENTRY_BASE * SCH_LEGACY_PLUGIN::loadBusEntry ( LINE_READER aReader)
private

Definition at line 1314 of file sch_legacy_plugin.cpp.

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

Referenced by LoadContent().

◆ loadComponent()

SCH_COMPONENT * SCH_LEGACY_PLUGIN::loadComponent ( LINE_READER aReader)
private

Definition at line 1487 of file sch_legacy_plugin.cpp.

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

753 {
754  m_version = version;
755 
756  while( aReader.ReadLine() )
757  {
758  char* line = aReader.Line();
759 
760  while( *line == ' ' )
761  line++;
762 
763  // Either an object will be loaded properly or the file load will fail and raise
764  // an exception.
765  if( strCompare( "$Descr", line ) )
766  loadPageSettings( aReader, aScreen );
767  else if( strCompare( "$Comp", line ) )
768  aScreen->Append( loadComponent( aReader ) );
769  else if( strCompare( "$Sheet", line ) )
770  aScreen->Append( loadSheet( aReader ) );
771  else if( strCompare( "$Bitmap", line ) )
772  aScreen->Append( loadBitmap( aReader ) );
773  else if( strCompare( "Connection", line ) )
774  aScreen->Append( loadJunction( aReader ) );
775  else if( strCompare( "NoConn", line ) )
776  aScreen->Append( loadNoConnect( aReader ) );
777  else if( strCompare( "Wire", line ) )
778  aScreen->Append( loadWire( aReader ) );
779  else if( strCompare( "Entry", line ) )
780  aScreen->Append( loadBusEntry( aReader ) );
781  else if( strCompare( "Text", line ) )
782  aScreen->Append( loadText( aReader ) );
783  else if( strCompare( "BusAlias", line ) )
784  aScreen->AddBusAlias( loadBusAlias( aReader, aScreen ) );
785  else if( strCompare( "$EndSCHEMATC", line ) )
786  return;
787  else
788  SCH_PARSE_ERROR( "unrecognized token", aReader, line );
789  }
790 }
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:901
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:175
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 729 of file sch_legacy_plugin.cpp.

730 {
731  FILE_LINE_READER reader( aFileName );
732 
733  loadHeader( reader, aScreen );
734 
735  LoadContent( reader, aScreen, m_version );
736 
737  // Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
738  // so checking for it's existance will fail so just exit here and take our chances. :(
739  if( m_version > 1 )
740  {
741  char* line = reader.Line();
742 
743  while( *line == ' ' )
744  line++;
745 
746  if( !strCompare( "$EndSCHEMATC", line ) )
747  THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
748  }
749 }
void LoadContent(LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
int m_version
Version of file being loaded.
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 793 of file sch_legacy_plugin.cpp.

794 {
795  const char* line = aReader.ReadLine();
796 
797  if( !line || !strCompare( "Eeschema Schematic File Version", line, &line ) )
798  {
799  m_error.Printf( _( "\"%s\" does not appear to be an Eeschema file" ),
800  GetChars( aScreen->GetFileName() ) );
802  }
803 
804  // get the file version here.
805  m_version = parseInt( aReader, line, &line );
806 
807  // The next lines are the lib list section, and are mainly comments, like:
808  // LIBS:power
809  // the lib list is not used, but is in schematic file just in case.
810  // It is usually not empty, but we accept empty list.
811  // If empty, there is a legacy section, not used
812  // EELAYER i j
813  // and the last line is
814  // EELAYER END
815  // Skip all lines until the end of header "EELAYER END" is found
816  while( aReader.ReadLine() )
817  {
818  line = aReader.Line();
819 
820  while( *line == ' ' )
821  line++;
822 
823  if( strCompare( "EELAYER END", line ) )
824  return;
825  }
826 
827  THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
828 }
const wxString & GetFileName() const
Definition: sch_screen.h:157
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...
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
#define _(s)
Definition: 3d_actions.cpp:31
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 655 of file sch_legacy_plugin.cpp.

656 {
657  SCH_SCREEN* screen = NULL;
658 
659  if( !aSheet->GetScreen() )
660  {
661  // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
662  // stores the file name and extension. Add the project path to the file name and
663  // extension to compare when calling SCH_SHEET::SearchHierarchy().
664  wxFileName fileName = aSheet->GetFileName();
665 
666  if( !fileName.IsAbsolute() )
667  fileName.MakeAbsolute( m_currentPath.top() );
668 
669  // Save the current path so that it gets restored when decending and ascending the
670  // sheet hierarchy which allows for sheet schematic files to be nested in folders
671  // relative to the last path a schematic was loaded from.
672  wxLogTrace( traceSchLegacyPlugin, "Saving path \"%s\"", m_currentPath.top() );
673  m_currentPath.push( fileName.GetPath() );
674  wxLogTrace( traceSchLegacyPlugin, "Current path \"%s\"", m_currentPath.top() );
675  wxLogTrace( traceSchLegacyPlugin, "Loading \"%s\"", fileName.GetFullPath() );
676 
677  m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
678 
679  if( screen )
680  {
681  aSheet->SetScreen( screen );
682 
683  // Do not need to load the sub-sheets - this has already been done.
684  }
685  else
686  {
687  aSheet->SetScreen( new SCH_SCREEN( m_kiway ) );
688  aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
689 
690  try
691  {
692  loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
693  for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
694  {
695  assert( aItem->Type() == SCH_SHEET_T );
696  auto sheet = static_cast<SCH_SHEET*>( aItem );
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  catch( const IO_ERROR& ioe )
710  {
711  // If there is a problem loading the root sheet, there is no recovery.
712  if( aSheet == m_rootSheet )
713  throw( ioe );
714 
715  // For all subsheets, queue up the error message for the caller.
716  if( !m_error.IsEmpty() )
717  m_error += "\n";
718 
719  m_error += ioe.What();
720  }
721  }
722 
723  m_currentPath.pop();
724  wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
725  }
726 }
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:540
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:111
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:278
void loadFile(const wxString &aFileName, SCH_SCREEN *aScreen)
#define NULL
void loadHierarchy(SCH_SHEET *aSheet)
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:616
EE_RTREE & Items()
Definition: sch_screen.h:127
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:155
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.

References SCH_SHEET::GetFileName(), SCH_SHEET::GetScreen(), SCH_SCREEN::Items(), loadFile(), m_currentPath, m_error, m_kiway, m_rootSheet, NULL, EE_RTREE::OfType(), SCH_SHEET_T, SCH_SHEET::SearchHierarchy(), SCH_SCREEN::SetFileName(), 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 1172 of file sch_legacy_plugin.cpp.

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

Referenced by LoadContent().

◆ loadNoConnect()

SCH_NO_CONNECT * SCH_LEGACY_PLUGIN::loadNoConnect ( LINE_READER aReader)
private

Definition at line 1194 of file sch_legacy_plugin.cpp.

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

Referenced by LoadContent().

◆ loadPageSettings()

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

Definition at line 831 of file sch_legacy_plugin.cpp.

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

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

Referenced by LoadContent().

◆ LoadSymbol()

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4376 of file sch_legacy_plugin.cpp.

4378 {
4379  LOCALE_IO toggle; // toggles on, then off, the C locale.
4380 
4381  m_props = aProperties;
4382 
4383  cacheLib( aLibraryPath );
4384 
4385  LIB_PART_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
4386 
4387  if( it == m_cache->m_symbols.end() )
4388  return nullptr;
4389 
4390  return it->second;
4391 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:90
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(), m_cache, m_props, and SCH_LEGACY_PLUGIN_CACHE::m_symbols.

◆ loadText()

SCH_TEXT * SCH_LEGACY_PLUGIN::loadText ( LINE_READER aReader)
private

Definition at line 1370 of file sch_legacy_plugin.cpp.

1371 {
1372  const char* line = aReader.Line();
1373 
1374  wxCHECK( strCompare( "Text", line, &line ), NULL );
1375 
1376  std::unique_ptr< SCH_TEXT> text;
1377 
1378  if( strCompare( "Notes", line, &line ) )
1379  text.reset( new SCH_TEXT );
1380  else if( strCompare( "Label", line, &line ) )
1381  text.reset( new SCH_LABEL );
1382  else if( strCompare( "HLabel", line, &line ) )
1383  text.reset( new SCH_HIERLABEL );
1384  else if( strCompare( "GLabel", line, &line ) )
1385  {
1386  // Prior to version 2, the SCH_GLOBALLABEL object did not exist.
1387  if( m_version == 1 )
1388  text.reset( new SCH_HIERLABEL );
1389  else
1390  text.reset( new SCH_GLOBALLABEL );
1391  }
1392  else
1393  SCH_PARSE_ERROR( "unknown Text type", aReader, line );
1394 
1395  // Parse the parameters common to all text objects.
1396  wxPoint position;
1397 
1398  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1399  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1400  text->SetPosition( position );
1401 
1402  int spinStyle = parseInt( aReader, line, &line );
1403 
1404  // Sadly we store the orientation of hierarchical and global labels using a different
1405  // int encoding than that for local labels:
1406  // Global Local
1407  // Left justified 0 2
1408  // Up 1 3
1409  // Right justified 2 0
1410  // Down 3 1
1411  // So we must flip it as the enum is setup with the "global" numbering
1412  if( text->Type() != SCH_GLOBAL_LABEL_T && text->Type() != SCH_HIER_LABEL_T )
1413  {
1414  if( spinStyle == 0 )
1415  spinStyle = 2;
1416  else if( spinStyle == 2 )
1417  spinStyle = 0;
1418  }
1419 
1420  text->SetLabelSpinStyle( spinStyle );
1421 
1422  int size = Mils2Iu( parseInt( aReader, line, &line ) );
1423 
1424  text->SetTextSize( wxSize( size, size ) );
1425 
1426  // Parse the global and hierarchical label type.
1427  if( text->Type() == SCH_HIER_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
1428  {
1429  auto resultIt = std::find_if( sheetLabelNames.begin(), sheetLabelNames.end(),
1430  [ &line ]( const auto& it )
1431  {
1432  return strCompare( it.second, line, &line );
1433  } );
1434 
1435  if( resultIt != sheetLabelNames.end() )
1436  text->SetShape( resultIt->first );
1437  else
1438  SCH_PARSE_ERROR( "invalid label type", aReader, line );
1439  }
1440 
1441  int thickness = 0;
1442 
1443  // The following tokens do not exist in version 1 schematic files,
1444  // and not always in version 2 for HLabels and GLabels
1445  if( m_version > 1 )
1446  {
1447  if( m_version > 2 || *line >= ' ' )
1448  {
1449  if( strCompare( "Italic", line, &line ) )
1450  text->SetItalic( true );
1451  else if( !strCompare( "~", line, &line ) )
1452  SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
1453  }
1454 
1455  // The thickness token does not exist in older versions of the schematic file format
1456  // so calling parseInt will be made only if the EOL is not reached.
1457  if( *line >= ' ' )
1458  thickness = parseInt( aReader, line, &line );
1459  }
1460 
1461  text->SetBold( thickness != 0 );
1462  text->SetThickness( thickness != 0 ? GetPenSizeForBold( size ) : 0 );
1463 
1464  // Read the text string for the text.
1465  char* tmp = aReader.ReadLine();
1466 
1467  tmp = strtok( tmp, "\r\n" );
1468  wxString val = FROM_UTF8( tmp );
1469 
1470  for( ; ; )
1471  {
1472  int i = val.find( wxT( "\\n" ) );
1473 
1474  if( i == wxNOT_FOUND )
1475  break;
1476 
1477  val.erase( i, 2 );
1478  val.insert( i, wxT( "\n" ) );
1479  }
1480 
1481  text->SetText( val );
1482 
1483  return text.release();
1484 }
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:66
#define Mils2Iu(x)
int m_version
Version of file being loaded.
#define 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...
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 std::map< PINSHEETLABEL_SHAPE, const char * > sheetLabelNames
#define _(s)
Definition: 3d_actions.cpp:31
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(), LINE_READER::Line(), m_version, Mils2Iu, NULL, parseInt(), LINE_READER::ReadLine(), SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_PARSE_ERROR, sheetLabelNames, strCompare(), wxPoint::x, and wxPoint::y.

Referenced by LoadContent().

◆ loadWire()

SCH_LINE * SCH_LEGACY_PLUGIN::loadWire ( LINE_READER aReader)
private

Definition at line 1216 of file sch_legacy_plugin.cpp.

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

Referenced by LoadContent().

◆ ParsePart()

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

Definition at line 4510 of file sch_legacy_plugin.cpp.

4512 {
4513  return SCH_LEGACY_PLUGIN_CACHE::LoadPart( reader, aMajorVersion, aMinorVersion );
4514 }
static LIB_PART * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_PART_MAP *aMap=nullptr)

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

1812 {
1813  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN object." );
1814  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1815 
1816  LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
1817 
1818  init( aKiway, aProperties );
1819 
1820  wxFileName fn = aFileName;
1821 
1822  // File names should be absolute. Don't assume everything relative to the project path
1823  // works properly.
1824  wxASSERT( fn.IsAbsolute() );
1825 
1826  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1827 
1828  m_out = &formatter; // no ownership
1829 
1830  Format( aScreen );
1831 }
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:90
void Format(SCH_SCREEN *aScreen)
#define NULL
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492

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

◆ saveBitmap()

void SCH_LEGACY_PLUGIN::saveBitmap ( SCH_BITMAP aBitmap)
private

Definition at line 2107 of file sch_legacy_plugin.cpp.

2108 {
2109  wxCHECK_RET( aBitmap != NULL, "SCH_BITMAP* is NULL" );
2110 
2111  const wxImage* image = aBitmap->GetImage()->GetImageData();
2112 
2113  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
2114 
2115  m_out->Print( 0, "$Bitmap\n" );
2116  m_out->Print( 0, "Pos %-4d %-4d\n",
2117  Iu2Mils( aBitmap->GetPosition().x ),
2118  Iu2Mils( aBitmap->GetPosition().y ) );
2119  m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
2120  m_out->Print( 0, "Data\n" );
2121 
2122  wxMemoryOutputStream stream;
2123 
2124  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
2125 
2126  // Write binary data in hexadecimal form (ASCII)
2127  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
2128  char* begin = (char*) buffer->GetBufferStart();
2129 
2130  for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
2131  {
2132  if( ii >= 32 )
2133  {
2134  ii = 0;
2135 
2136  m_out->Print( 0, "\n" );
2137  }
2138 
2139  m_out->Print( 0, "%2.2X ", *begin & 0xFF );
2140  }
2141 
2142  m_out->Print( 0, "\nEndData\n" );
2143  m_out->Print( 0, "$EndBitmap\n" );
2144 }
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
#define NULL
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, NULL, OUTPUTFORMATTER::Print(), wxPoint::x, and wxPoint::y.

Referenced by Format().

◆ saveBusAlias()

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

Definition at line 2360 of file sch_legacy_plugin.cpp.

2361 {
2362  wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" );
2363 
2364  wxString members = boost::algorithm::join( aAlias->Members(), " " );
2365 
2366  m_out->Print( 0, "BusAlias %s %s\n",
2367  TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
2368 }
#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 NULL
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, NULL, OUTPUTFORMATTER::Print(), and TO_UTF8.

Referenced by Format().

◆ saveBusEntry()

void SCH_LEGACY_PLUGIN::saveBusEntry ( SCH_BUS_ENTRY_BASE aBusEntry)
private

Definition at line 2231 of file sch_legacy_plugin.cpp.

2232 {
2233  wxCHECK_RET( aBusEntry != NULL, "SCH_BUS_ENTRY_BASE* is NULL" );
2234 
2235  if( aBusEntry->GetLayer() == LAYER_WIRE )
2236  m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
2237  Iu2Mils( aBusEntry->GetPosition().x ),
2238  Iu2Mils( aBusEntry->GetPosition().y ),
2239  Iu2Mils( aBusEntry->m_End().x ), Iu2Mils( aBusEntry->m_End().y ) );
2240  else
2241  m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
2242  Iu2Mils( aBusEntry->GetPosition().x ),
2243  Iu2Mils( aBusEntry->GetPosition().y ),
2244  Iu2Mils( aBusEntry->m_End().x ), Iu2Mils( aBusEntry->m_End().y ) );
2245 }
#define NULL
wxPoint m_End() const
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:212
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, NULL, OUTPUTFORMATTER::Print(), wxPoint::x, and wxPoint::y.

Referenced by Format().

◆ saveComponent()

void SCH_LEGACY_PLUGIN::saveComponent ( SCH_COMPONENT aComponent)
private

Definition at line 1966 of file sch_legacy_plugin.cpp.

1967 {
1968  std::string name1;
1969  std::string name2;
1970  wxArrayString reference_fields;
1971 
1972  static wxString delimiters( wxT( " " ) );
1973 
1974  // This is redundant with the AR entries below, but it makes the files backwards-compatible.
1975  if( aComponent->GetPathsAndReferences().GetCount() > 0 )
1976  {
1977  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[0], delimiters );
1978  name1 = toUTFTildaText( reference_fields[1] );
1979  }
1980  else
1981  {
1982  if( aComponent->GetField( REFERENCE )->GetText().IsEmpty() )
1983  name1 = toUTFTildaText( aComponent->GetPrefix() );
1984  else
1985  name1 = toUTFTildaText( aComponent->GetField( REFERENCE )->GetText() );
1986  }
1987 
1988  wxString part_name = aComponent->GetLibId().Format();
1989 
1990  if( part_name.size() )
1991  {
1992  name2 = toUTFTildaText( part_name );
1993  }
1994  else
1995  {
1996  name2 = "_NONAME_";
1997  }
1998 
1999  m_out->Print( 0, "$Comp\n" );
2000  m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
2001 
2002  // Generate unit number, convert and time stamp
2003  m_out->Print( 0, "U %d %d %8.8X\n", aComponent->GetUnit(), aComponent->GetConvert(),
2004  aComponent->GetTimeStamp() );
2005 
2006  // Save the position
2007  m_out->Print( 0, "P %d %d\n",
2008  Iu2Mils( aComponent->GetPosition().x ),
2009  Iu2Mils( aComponent->GetPosition().y ) );
2010 
2011  /* If this is a complex hierarchy; save hierarchical references.
2012  * but for simple hierarchies it is not necessary.
2013  * the reference inf is already saved
2014  * this is useful for old Eeschema version compatibility
2015  */
2016  if( aComponent->GetPathsAndReferences().GetCount() > 1 )
2017  {
2018  for( unsigned int ii = 0; ii < aComponent->GetPathsAndReferences().GetCount(); ii++ )
2019  {
2020  /*format:
2021  * AR Path="/140/2" Ref="C99" Part="1"
2022  * where 140 is the uid of the containing sheet
2023  * and 2 is the timestamp of this component.
2024  * (timestamps are actually 8 hex chars)
2025  * Ref is the conventional component reference for this 'path'
2026  * Part is the conventional component part selection for this 'path'
2027  */
2028  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[ii],
2029  delimiters );
2030 
2031  m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%s\" \n",
2032  TO_UTF8( reference_fields[0] ),
2033  TO_UTF8( reference_fields[1] ),
2034  TO_UTF8( reference_fields[2] ) );
2035  }
2036  }
2037 
2038  // update the ugly field index, which I would like to see go away someday soon.
2039  for( int i = 0; i < aComponent->GetFieldCount(); ++i )
2040  aComponent->GetField( i )->SetId( i );
2041 
2042  // Fixed fields:
2043  // Save mandatory fields even if they are blank,
2044  // because the visibility, size and orientation are set from library editor.
2045  for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
2046  saveField( aComponent->GetField( i ) );
2047 
2048  // User defined fields:
2049  // The *policy* about which user defined fields are part of a symbol is now
2050  // only in the dialog editors. No policy should be enforced here, simply
2051  // save all the user defined fields, they are present because a dialog editor
2052  // thought they should be. If you disagree, go fix the dialog editors.
2053  for( int i = MANDATORY_FIELDS; i < aComponent->GetFieldCount(); ++i )
2054  saveField( aComponent->GetField( i ) );
2055 
2056  // Unit number, position, box ( old standard )
2057  m_out->Print( 0, "\t%-4d %-4d %-4d\n", aComponent->GetUnit(),
2058  Iu2Mils( aComponent->GetPosition().x ),
2059  Iu2Mils( aComponent->GetPosition().y ) );
2060 
2061  TRANSFORM transform = aComponent->GetTransform();
2062 
2063  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
2064  transform.x1, transform.y1, transform.x2, transform.y2 );
2065  m_out->Print( 0, "$EndComp\n" );
2066 }
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
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
TRANSFORM & GetTransform() const
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
timestamp_t GetTimeStamp() const
Definition: base_struct.h:213
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.
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
Return the string associated with the text object.
Definition: eda_text.h:123

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(), m_out, MANDATORY_FIELDS, OUTPUTFORMATTER::Print(), REFERENCE, saveField(), SCH_FIELD::SetId(), TO_UTF8, toUTFTildaText(), wxPoint::x, TRANSFORM::x1, TRANSFORM::x2, wxPoint::y, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by Format().

◆ saveField()

void SCH_LEGACY_PLUGIN::saveField ( SCH_FIELD aField)
private

Definition at line 2069 of file sch_legacy_plugin.cpp.

2070 {
2071  char hjustify = 'C';
2072 
2073  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
2074  hjustify = 'L';
2075  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
2076  hjustify = 'R';
2077 
2078  char vjustify = 'C';
2079 
2080  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
2081  vjustify = 'B';
2082  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
2083  vjustify = 'T';
2084 
2085  m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
2086  aField->GetId(),
2087  EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
2088  aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
2089  Iu2Mils( aField->GetLibPosition().x ),
2090  Iu2Mils( aField->GetLibPosition().y ),
2091  Iu2Mils( aField->GetTextWidth() ),
2092  !aField->IsVisible(),
2093  hjustify, vjustify,
2094  aField->IsItalic() ? 'I' : 'N',
2095  aField->IsBold() ? 'B' : 'N' );
2096 
2097  // Save field name, if the name is user definable
2098  if( aField->GetId() >= FIELD1 )
2099  {
2100  m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
2101  }
2102 
2103  m_out->Print( 0, "\n" );
2104 }
#define TEXT_ANGLE_HORIZ
bool IsBold() const
Definition: eda_text.h:167
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:184
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:183
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:371
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
Return the string associated with the text object.
Definition: eda_text.h:123

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(), TEXT_ANGLE_HORIZ, wxPoint::x, and wxPoint::y.

Referenced by saveComponent().

◆ saveJunction()

void SCH_LEGACY_PLUGIN::saveJunction ( SCH_JUNCTION aJunction)
private

Definition at line 2213 of file sch_legacy_plugin.cpp.

2214 {
2215  wxCHECK_RET( aJunction != NULL, "SCH_JUNCTION* is NULL" );
2216 
2217  m_out->Print( 0, "Connection ~ %-4d %-4d\n",
2218  Iu2Mils( aJunction->GetPosition().x ), Iu2Mils( aJunction->GetPosition().y ) );
2219 }
#define NULL
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, NULL, OUTPUTFORMATTER::Print(), wxPoint::x, and wxPoint::y.

Referenced by Format().

◆ SaveLibrary()

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

Reimplemented from SCH_PLUGIN.

Definition at line 4470 of file sch_legacy_plugin.cpp.

4471 {
4472  if( !m_cache )
4473  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4474 
4475  wxString oldFileName = m_cache->GetFileName();
4476 
4477  if( !m_cache->IsFile( aLibraryPath ) )
4478  {
4479  m_cache->SetFileName( aLibraryPath );
4480  }
4481 
4482  // This is a forced save.
4483  m_cache->SetModified();
4484  m_cache->Save( writeDocFile( aProperties ) );
4485  m_cache->SetFileName( oldFileName );
4486 }
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 2248 of file sch_legacy_plugin.cpp.

2249 {
2250  wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" );
2251 
2252  const char* layer = "Notes";
2253  const char* width = "Line";
2254 
2255  if( aLine->GetLayer() == LAYER_WIRE )
2256  layer = "Wire";
2257  else if( aLine->GetLayer() == LAYER_BUS )
2258  layer = "Bus";
2259 
2260  m_out->Print( 0, "Wire %s %s", layer, width );
2261 
2262  // Write line style (width, type, color) only for non default values
2263  if( aLine->IsGraphicLine() )
2264  {
2265  if( aLine->GetPenSize() != aLine->GetDefaultWidth() )
2266  m_out->Print( 0, " %s %d", T_WIDTH, Iu2Mils( aLine->GetLineSize() ) );
2267 
2268  if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
2269  m_out->Print( 0, " %s %s", T_STYLE,
2271 
2272  if( aLine->GetLineColor() != aLine->GetDefaultColor() )
2273  m_out->Print( 0, " %s",
2274  TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
2275  }
2276 
2277  m_out->Print( 0, "\n" );
2278 
2279  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
2280  Iu2Mils( aLine->GetStartPoint().x ), Iu2Mils( aLine->GetStartPoint().y ),
2281  Iu2Mils( aLine->GetEndPoint().x ), Iu2Mils( aLine->GetEndPoint().y ) );
2282 
2283  m_out->Print( 0, "\n");
2284 }
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:121
COLOR4D GetLineColor() const
Definition: sch_line.cpp:255
bool IsGraphicLine() const
Returns if the line is a graphic (non electrical line)
Definition: sch_line.cpp:815
wxPoint GetStartPoint() const
Definition: sch_line.h:97
#define T_WIDTH
int GetDefaultWidth() const
Definition: sch_line.cpp:296
#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
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:263
#define NULL
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:287
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:212
int GetLineSize() const
Definition: sch_line.h:129
COLOR4D GetDefaultColor() const
Definition: sch_line.cpp:225
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:316
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxPoint GetEndPoint() const
Definition: sch_line.h:100

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(), SCH_LINE::IsGraphicLine(), LAYER_BUS, LAYER_WIRE, m_out, NULL, OUTPUTFORMATTER::Print(), T_STYLE, T_WIDTH, TO_UTF8, wxPoint::x, and wxPoint::y.

Referenced by Format().

◆ saveNoConnect()

void SCH_LEGACY_PLUGIN::saveNoConnect ( SCH_NO_CONNECT aNoConnect)
private

Definition at line 2222 of file sch_legacy_plugin.cpp.

2223 {
2224  wxCHECK_RET( aNoConnect != NULL, "SCH_NOCONNECT* is NULL" );
2225 
2226  m_out->Print( 0, "NoConn ~ %-4d %-4d\n", Iu2Mils( aNoConnect->GetPosition().x ),
2227  Iu2Mils( aNoConnect->GetPosition().y ) );
2228 }
wxPoint GetPosition() const override
Function GetPosition.
#define NULL
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, NULL, OUTPUTFORMATTER::Print(), wxPoint::x, and wxPoint::y.

Referenced by Format().

◆ saveSheet()

void SCH_LEGACY_PLUGIN::saveSheet ( SCH_SHEET aSheet)
private

Definition at line 2147 of file sch_legacy_plugin.cpp.

2148 {
2149  wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" );
2150 
2151  m_out->Print( 0, "$Sheet\n" );
2152  m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
2153  Iu2Mils( aSheet->GetPosition().x ), Iu2Mils( aSheet->GetPosition().y ),
2154  Iu2Mils( aSheet->GetSize().x ), Iu2Mils( aSheet->GetSize().y ) );
2155 
2156  m_out->Print( 0, "U %8.8X\n", aSheet->GetTimeStamp() );
2157 
2158  if( !aSheet->GetName().IsEmpty() )
2159  m_out->Print( 0, "F0 %s %d\n", EscapedUTF8( aSheet->GetName() ).c_str(),
2160  Iu2Mils( aSheet->GetSheetNameSize() ) );
2161 
2162  if( !aSheet->GetFileName().IsEmpty() )
2163  m_out->Print( 0, "F1 %s %d\n", EscapedUTF8( aSheet->GetFileName() ).c_str(),
2164  Iu2Mils( aSheet->GetFileNameSize() ) );
2165 
2166  for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
2167  {
2168  int type, side;
2169 
2170  if( pin->GetText().IsEmpty() )
2171  break;
2172 
2173  switch( pin->GetEdge() )
2174  {
2175  default:
2176  case SHEET_LEFT_SIDE: side = 'L'; break;
2177  case SHEET_RIGHT_SIDE: side = 'R'; break;
2178  case SHEET_TOP_SIDE: side = 'T'; break;
2179  case SHEET_BOTTOM_SIDE: side = 'B'; break;
2180  }
2181 
2182  switch( pin->GetShape() )
2183  {
2185  type = 'I';
2186  break;
2188  type = 'O';
2189  break;
2191  type = 'B';
2192  break;
2194  type = 'T';
2195  break;
2196  default:
2198  type = 'U';
2199  break;
2200  }
2201 
2202  m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n", pin->GetNumber(),
2203  EscapedUTF8( pin->GetText() ).c_str(), // supplies wrapping quotes
2204  type, side, Iu2Mils( pin->GetPosition().x ),
2205  Iu2Mils( pin->GetPosition().y ),
2206  Iu2Mils( pin->GetTextWidth() ) );
2207  }
2208 
2209  m_out->Print( 0, "$EndSheet\n" );
2210 }
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:275
int GetSheetNameSize() const
Definition: sch_sheet.h:272
wxString GetName() const
Definition: sch_sheet.h:269
#define NULL
timestamp_t GetTimeStamp() const
Definition: base_struct.h:213
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:538
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:616
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:332
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:280

References EscapedUTF8(), SCH_SHEET::GetFileName(), SCH_SHEET::GetFileNameSize(), SCH_SHEET::GetName(), SCH_SHEET::GetPins(), SCH_SHEET::GetPosition(), SCH_SHEET::GetSheetNameSize(), SCH_SHEET::GetSize(), EDA_ITEM::GetTimeStamp(), m_out, NULL, OUTPUTFORMATTER::Print(), PS_BIDI, PS_INPUT, PS_OUTPUT, PS_TRISTATE, PS_UNSPECIFIED, SHEET_BOTTOM_SIDE, SHEET_LEFT_SIDE, SHEET_RIGHT_SIDE, SHEET_TOP_SIDE, wxPoint::x, and wxPoint::y.

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

4396 {
4397  m_props = aProperties;
4398 
4399  cacheLib( aLibraryPath );
4400 
4401  m_cache->AddSymbol( aSymbol );
4402 
4403  if( !isBuffering( aProperties ) )
4404  m_cache->Save( writeDocFile( aProperties ) );
4405 }
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 2287 of file sch_legacy_plugin.cpp.

2288 {
2289  wxCHECK_RET( aText != NULL, "SCH_TEXT* is NULL" );
2290 
2291  const char* italics = "~";
2292  const char* textType = "Notes";
2293 
2294  if( aText->IsItalic() )
2295  italics = "Italic";
2296 
2297  wxString text = aText->GetText();
2298 
2299  SCH_LAYER_ID layer = aText->GetLayer();
2300 
2301  if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
2302  {
2303  if( layer == LAYER_NOTES )
2304  {
2305  // For compatibility reasons, the text must be saved in only one text line
2306  // so replace all EOLs with \\n
2307  text.Replace( wxT( "\n" ), wxT( "\\n" ) );
2308 
2309  // Here we should have no CR or LF character in line
2310  // This is not always the case if a multiline text was copied (using a copy/paste
2311  // function) from a text that uses E.O.L characters that differs from the current
2312  // EOL format. This is mainly the case under Linux using LF symbol when copying
2313  // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
2314  // (or LF left under MacOSX)
2315  for( unsigned ii = 0; ii < text.Len(); )
2316  {
2317  if( text[ii] == 0x0A || text[ii] == 0x0D )
2318  text.erase( ii, 1 );
2319  else
2320  ii++;
2321  }
2322  }
2323  else
2324  {
2325  textType = "Label";
2326  }
2327 
2328  // Local labels must have their spin style inverted for left and right
2329  int spinStyle = static_cast<int>( aText->GetLabelSpinStyle() );
2330 
2331  if( spinStyle == 0 )
2332  spinStyle = 2;
2333  else if( spinStyle == 2 )
2334  spinStyle = 0;
2335 
2336  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2337  Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
2338  spinStyle,
2339  Iu2Mils( aText->GetTextWidth() ),
2340  italics, Iu2Mils( aText->GetThickness() ), TO_UTF8( text ) );
2341  }
2342  else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2343  {
2344  textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2345 
2346  auto shapeLabelIt = sheetLabelNames.find( aText->GetShape() );
2347  wxCHECK_RET( shapeLabelIt != sheetLabelNames.end(), "Shape not found in names list" );
2348 
2349  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2350  Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
2351  static_cast<int>( aText->GetLabelSpinStyle() ),
2352  Iu2Mils( aText->GetTextWidth() ),
2353  shapeLabelIt->second,
2354  italics,
2355  Iu2Mils( aText->GetThickness() ), TO_UTF8( text ) );
2356  }
2357 }
int GetThickness() const
Return the pen width.
Definition: eda_text.h:148
bool IsItalic() const
Definition: eda_text.h:164
#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 NULL
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:238
SCH_LAYER_ID
Eeschema drawing layers.
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_text.h:315
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:212
int GetTextWidth() const
Definition: eda_text.h:226
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
const std::map< PINSHEETLABEL_SHAPE, const char * > sheetLabelNames
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
Return the string associated with the text object.
Definition: eda_text.h:123
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:243

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, NULL, OUTPUTFORMATTER::Print(), sheetLabelNames, TO_UTF8, wxPoint::x, and wxPoint::y.

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

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

References _.

◆ writeDocFile()

bool SCH_LEGACY_PLUGIN::writeDocFile ( const PROPERTIES aProperties)
private

Definition at line 4305 of file sch_legacy_plugin.cpp.

4306 {
4307  std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
4308 
4309  if( aProperties && aProperties->find( propName ) != aProperties->end() )
4310  return false;
4311 
4312  return true;
4313 }
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....

References PropNoDocFile.

Referenced by CreateSymbolLib(), 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 173 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 170 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 175 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 172 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 174 of file sch_legacy_plugin.h.

Referenced by cacheLib(), CreateSymbolLib(), 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 176 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 167 of file sch_legacy_plugin.h.

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

◆ PropBuffering

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

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

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

Definition at line 85 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

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

Definition at line 91 of file sch_legacy_plugin.h.

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


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