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...
 
const wxString GetLibraryFileExtension () const override
 Return the library file extension for the SCH_PLUGIN object. More...
 
int GetModifyHash () const override
 Return the modification hash from the library cache. More...
 
SCH_SHEETLoad (const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr) override
 Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one. More...
 
void LoadContent (LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
 
void Save (const wxString &aFileName, SCH_SHEET *aScreen, SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr) override
 Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file. More...
 
void Format (SCH_SHEET *aSheet)
 
void Format (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 (SCHEMATIC *aSchematic, 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...
 
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
 
SCHEMATICm_schematic
 Passed to Load(), the schematic object being loaded. More...
 

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

568 {
569  init( NULL );
570 }
void init(SCHEMATIC *aSchematic, 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 573 of file sch_legacy_plugin.cpp.

574 {
575  delete m_cache;
576 }
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 4337 of file sch_legacy_plugin.cpp.

4338 {
4339  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
4340  {
4341  // a spectacular episode in memory management:
4342  delete m_cache;
4343  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
4344 
4345  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
4346  // to modify the hash value that indicate component to symbol links
4347  // must be updated.
4349 
4350  if( !isBuffering( m_props ) )
4351  m_cache->Load();
4352  }
4353 }
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 4540 of file sch_legacy_plugin.cpp.

4541 {
4542  // Open file and check first line
4543  wxTextFile tempFile;
4544 
4545  tempFile.Open( aFileName );
4546  wxString firstline;
4547  // read the first line
4548  firstline = tempFile.GetFirstLine();
4549  tempFile.Close();
4550 
4551  return firstline.StartsWith( "EESchema" );
4552 }

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

4475 {
4476  if( wxFileExists( aLibraryPath ) )
4477  {
4479  _( "symbol library \"%s\" already exists, cannot create a new library" ),
4480  aLibraryPath.GetData() ) );
4481  }
4482 
4483  LOCALE_IO toggle;
4484 
4485  m_props = aProperties;
4486 
4487  delete m_cache;
4488  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4489  m_cache->SetModified();
4490  m_cache->Save( writeDocFile( aProperties ) );
4491  m_cache->Load(); // update m_writable and m_mod_time
4492 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
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:33
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 4459 of file sch_legacy_plugin.cpp.

4461 {
4462  m_props = aProperties;
4463 
4464  cacheLib( aLibraryPath );
4465 
4466  m_cache->DeleteSymbol( aSymbolName );
4467 
4468  if( !isBuffering( aProperties ) )
4469  m_cache->Save( writeDocFile( aProperties ) );
4470 }
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 4495 of file sch_legacy_plugin.cpp.

4497 {
4498  wxFileName fn = aLibraryPath;
4499 
4500  if( !fn.FileExists() )
4501  return false;
4502 
4503  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
4504  // we don't want that. we want bare metal portability with no UI here.
4505  if( wxRemove( aLibraryPath ) )
4506  {
4507  THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
4508  aLibraryPath.GetData() ) );
4509  }
4510 
4511  if( m_cache && m_cache->IsFile( aLibraryPath ) )
4512  {
4513  delete m_cache;
4514  m_cache = 0;
4515  }
4516 
4517  return true;
4518 }
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:33

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

4386 {
4387  LOCALE_IO toggle; // toggles on, then off, the C locale.
4388 
4389  m_props = aProperties;
4390 
4391  bool powerSymbolsOnly = ( aProperties &&
4392  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4393  cacheLib( aLibraryPath );
4394 
4395  const LIB_PART_MAP& symbols = m_cache->m_symbols;
4396 
4397  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
4398  {
4399  if( !powerSymbolsOnly || it->second->IsPower() )
4400  aSymbolNameList.Add( it->first );
4401  }
4402 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
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 4405 of file sch_legacy_plugin.cpp.

4408 {
4409  LOCALE_IO toggle; // toggles on, then off, the C locale.
4410 
4411  m_props = aProperties;
4412 
4413  bool powerSymbolsOnly = ( aProperties &&
4414  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4415  cacheLib( aLibraryPath );
4416 
4417  const LIB_PART_MAP& symbols = m_cache->m_symbols;
4418 
4419  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
4420  {
4421  if( !powerSymbolsOnly || it->second->IsPower() )
4422  aSymbolList.push_back( it->second );
4423  }
4424 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
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_SHEET aSheet)

Definition at line 1845 of file sch_legacy_plugin.cpp.

1846 {
1847  wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET* object." );
1848  wxCHECK_RET( m_schematic != NULL, "NULL SCHEMATIC* object." );
1849 
1850  SCH_SCREEN* screen = aSheet->GetScreen();
1851 
1852  wxCHECK( screen, /* void */ );
1853 
1854  // Write the header
1855  m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1856 
1857  // This section is not used, but written for file compatibility
1858  m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1859  m_out->Print( 0, "EELAYER END\n" );
1860 
1861  /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1862  * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1863  * simple hierarchy and flat hierarchy. Used also to search the root
1864  * sheet ( ScreenNumber = 1 ) within the files
1865  */
1866  const TITLE_BLOCK& tb = screen->GetTitleBlock();
1867  const PAGE_INFO& page = screen->GetPageSettings();
1868 
1869  m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1870  page.GetWidthMils(),
1871  page.GetHeightMils(),
1872  !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1873  m_out->Print( 0, "encoding utf-8\n" );
1874  m_out->Print( 0, "Sheet %d %d\n", screen->m_ScreenNumber, screen->m_NumberOfScreens );
1875  m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1876  m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1877  m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1878  m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1879  m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment( 0 ) ).c_str() );
1880  m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment( 1 ) ).c_str() );
1881  m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment( 2 ) ).c_str() );
1882  m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment( 3 ) ).c_str() );
1883  m_out->Print( 0, "Comment5 %s\n", EscapedUTF8( tb.GetComment( 4 ) ).c_str() );
1884  m_out->Print( 0, "Comment6 %s\n", EscapedUTF8( tb.GetComment( 5 ) ).c_str() );
1885  m_out->Print( 0, "Comment7 %s\n", EscapedUTF8( tb.GetComment( 6 ) ).c_str() );
1886  m_out->Print( 0, "Comment8 %s\n", EscapedUTF8( tb.GetComment( 7 ) ).c_str() );
1887  m_out->Print( 0, "Comment9 %s\n", EscapedUTF8( tb.GetComment( 8 ) ).c_str() );
1888  m_out->Print( 0, "$EndDescr\n" );
1889 
1890  for( const auto& alias : screen->GetBusAliases() )
1891  {
1892  saveBusAlias( alias );
1893  }
1894 
1895  // Enforce item ordering
1896  auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b ) { return *a < *b; };
1897  std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
1898 
1899  for( auto item : screen->Items() )
1900  save_map.insert( item );
1901 
1902 
1903  for( auto& item : save_map )
1904  {
1905  switch( item->Type() )
1906  {
1907  case SCH_COMPONENT_T:
1908  saveComponent( static_cast<SCH_COMPONENT*>( item ) );
1909  break;
1910  case SCH_BITMAP_T:
1911  saveBitmap( static_cast<SCH_BITMAP*>( item ) );
1912  break;
1913  case SCH_SHEET_T:
1914  saveSheet( static_cast<SCH_SHEET*>( item ) );
1915  break;
1916  case SCH_JUNCTION_T:
1917  saveJunction( static_cast<SCH_JUNCTION*>( item ) );
1918  break;
1919  case SCH_NO_CONNECT_T:
1920  saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ) );
1921  break;
1922  case SCH_BUS_WIRE_ENTRY_T:
1923  case SCH_BUS_BUS_ENTRY_T:
1924  saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ) );
1925  break;
1926  case SCH_LINE_T:
1927  saveLine( static_cast<SCH_LINE*>( item ) );
1928  break;
1929  case SCH_TEXT_T:
1930  case SCH_LABEL_T:
1931  case SCH_GLOBAL_LABEL_T:
1932  case SCH_HIER_LABEL_T:
1933  saveText( static_cast<SCH_TEXT*>( item ) );
1934  break;
1935  default:
1936  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1937  }
1938  }
1939 
1940  m_out->Print( 0, "$EndSCHEMATC\n" );
1941 }
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
int m_ScreenNumber
Definition: base_screen.h:85
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:194
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
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
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:184
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:283
void saveJunction(SCH_JUNCTION *aJunction)
#define SCHEMATIC_HEAD_STRING
Definition: general.h:36
#define EESCHEMA_VERSION
Definition: general.h:35
#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:162
#define TO_UTF8(wxstring)
int m_NumberOfScreens
Definition: base_screen.h:86
const wxString & GetTitle() const
Definition: title_block.h:65
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:186
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:525
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(), SCH_SHEET::GetScreen(), TITLE_BLOCK::GetTitle(), SCH_SCREEN::GetTitleBlock(), PAGE_INFO::GetType(), PAGE_INFO::GetWidthMils(), PAGE_INFO::IsCustom(), PAGE_INFO::IsPortrait(), SCH_SCREEN::Items(), BASE_SCREEN::m_NumberOfScreens, m_out, m_schematic, 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 Save().

◆ Format() [2/2]

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

Definition at line 1944 of file sch_legacy_plugin.cpp.

1945 {
1946  m_out = aFormatter;
1947 
1948  for( unsigned i = 0; i < aSelection->GetSize(); ++i )
1949  {
1950  SCH_ITEM* item = (SCH_ITEM*) aSelection->GetItem( i );
1951 
1952  switch( item->Type() )
1953  {
1954  case SCH_COMPONENT_T:
1955  saveComponent( static_cast< SCH_COMPONENT* >( item ) );
1956  break;
1957  case SCH_BITMAP_T:
1958  saveBitmap( static_cast< SCH_BITMAP* >( item ) );
1959  break;
1960  case SCH_SHEET_T:
1961  saveSheet( static_cast< SCH_SHEET* >( item ) );
1962  break;
1963  case SCH_JUNCTION_T:
1964  saveJunction( static_cast< SCH_JUNCTION* >( item ) );
1965  break;
1966  case SCH_NO_CONNECT_T:
1967  saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
1968  break;
1969  case SCH_BUS_WIRE_ENTRY_T:
1970  case SCH_BUS_BUS_ENTRY_T:
1971  saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1972  break;
1973  case SCH_LINE_T:
1974  saveLine( static_cast< SCH_LINE* >( item ) );
1975  break;
1976  case SCH_TEXT_T:
1977  case SCH_LABEL_T:
1978  case SCH_GLOBAL_LABEL_T:
1979  case SCH_HIER_LABEL_T:
1980  saveText( static_cast< SCH_TEXT* >( item ) );
1981  break;
1982  default:
1983  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1984  }
1985  }
1986 }
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:105
void saveComponent(SCH_COMPONENT *aComponent)
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:100
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:186
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

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

4570 {
4571  SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( part, formatter );
4572 }
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_PART_MAP *aMap=nullptr)

References SCH_LEGACY_PLUGIN_CACHE::SaveSymbol().

Referenced by 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 136 of file sch_legacy_plugin.h.

136 { 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  }

◆ GetLibraryFileExtension()

const wxString SCH_LEGACY_PLUGIN::GetLibraryFileExtension ( ) const
inlineoverridevirtual

Return the library file extension for the SCH_PLUGIN object.

Implements SCH_PLUGIN.

Definition at line 80 of file sch_legacy_plugin.h.

81  {
82  return wxT( "lib" );
83  }

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

4374 {
4375  if( m_cache )
4376  return m_cache->GetModifyHash();
4377 
4378  // If the cache hasn't been loaded, it hasn't been modified.
4379  return 0;
4380 }
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 ( SCHEMATIC aSchematic,
const PROPERTIES aProperties = nullptr 
)
protected

initialize PLUGIN like a constructor would.

Definition at line 579 of file sch_legacy_plugin.cpp.

580 {
581  m_version = 0;
582  m_rootSheet = nullptr;
583  m_props = aProperties;
584  m_schematic = aSchematic;
585  m_cache = nullptr;
586  m_out = nullptr;
587 }
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
SCH_LEGACY_PLUGIN_CACHE * m_cache
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
int m_version
Version of file being loaded.
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.

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

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

◆ isBuffering()

bool SCH_LEGACY_PLUGIN::isBuffering ( const PROPERTIES aProperties)
private

Definition at line 4367 of file sch_legacy_plugin.cpp.

4368 {
4369  return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
4370 }
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 4555 of file sch_legacy_plugin.cpp.

4556 {
4557  // Writing legacy symbol libraries is deprecated.
4558  return false;
4559 }

◆ Load()

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

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 590 of file sch_legacy_plugin.cpp.

592 {
593  wxASSERT( !aFileName || aSchematic != NULL );
594 
595  LOCALE_IO toggle; // toggles on, then off, the C locale.
596  SCH_SHEET* sheet;
597 
598  wxFileName fn = aFileName;
599 
600  // Unfortunately child sheet file names the legacy schematic file format are not fully
601  // qualified and are always appended to the project path. The aFileName attribute must
602  // always be an absolute path so the project path can be used for load child sheet files.
603  wxASSERT( fn.IsAbsolute() );
604 
605  if( aAppendToMe )
606  {
607  wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
608  aFileName, aAppendToMe->GetFileName() );
609 
610  wxFileName normedFn = aAppendToMe->GetFileName();
611 
612  if( !normedFn.IsAbsolute() )
613  {
614  if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
615  m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
616  }
617 
618  if( m_path.IsEmpty() )
619  m_path = aSchematic->Prj().GetProjectPath();
620 
621  wxLogTrace( traceSchLegacyPlugin, "m_Normalized append path \"%s\".", m_path );
622  }
623  else
624  {
625  m_path = aSchematic->Prj().GetProjectPath();
626  }
627 
628  m_currentPath.push( m_path );
629  init( aSchematic, aProperties );
630 
631  if( aAppendToMe == NULL )
632  {
633  // Clean up any allocated memory if an exception occurs loading the schematic.
634  std::unique_ptr< SCH_SHEET > newSheet( new SCH_SHEET( aSchematic ) );
635  newSheet->SetFileName( aFileName );
636  m_rootSheet = newSheet.get();
637  loadHierarchy( newSheet.get() );
638 
639  // If we got here, the schematic loaded successfully.
640  sheet = newSheet.release();
641  m_rootSheet = nullptr; // Quiet Coverity warning.
642  }
643  else
644  {
645  wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
646  m_rootSheet = &aSchematic->Root();
647  sheet = aAppendToMe;
648  loadHierarchy( sheet );
649  }
650 
651  wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
652 
653  return sheet;
654 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:111
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:122
wxString m_path
Root project path for loading child sheets.
#define NULL
void loadHierarchy(SCH_SHEET *aSheet)
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:496
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
SCH_SHEET & Root() const
Definition: schematic.h:97
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:77
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.

References SCH_SHEET::GetFileName(), PROJECT::GetProjectPath(), init(), SCHEMATIC::IsValid(), loadHierarchy(), m_currentPath, m_path, m_rootSheet, NULL, SCHEMATIC::Prj(), SCHEMATIC::Root(), and traceSchLegacyPlugin.

◆ loadBitmap()

SCH_BITMAP * SCH_LEGACY_PLUGIN::loadBitmap ( LINE_READER aReader)
private

Definition at line 1080 of file sch_legacy_plugin.cpp.

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

1797 {
1798  auto busAlias = std::make_shared< BUS_ALIAS >( aScreen );
1799  const char* line = aReader.Line();
1800 
1801  wxCHECK( strCompare( "BusAlias", line, &line ), NULL );
1802 
1803  wxString buf;
1804  parseUnquotedString( buf, aReader, line, &line );
1805  busAlias->SetName( buf );
1806 
1807  while( *line != '\0' )
1808  {
1809  buf.clear();
1810  parseUnquotedString( buf, aReader, line, &line, true );
1811  if( buf.Len() > 0 )
1812  {
1813  busAlias->AddMember( buf );
1814  }
1815  }
1816 
1817  return busAlias;
1818 }
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 1307 of file sch_legacy_plugin.cpp.

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

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

759 {
760  m_version = version;
761 
762  // We cannot safely load content without a set root level.
763  wxCHECK_RET( m_rootSheet,
764  "Cannot call SCH_LEGACY_PLUGIN::LoadContent() without setting root sheet." );
765 
766  while( aReader.ReadLine() )
767  {
768  char* line = aReader.Line();
769 
770  while( *line == ' ' )
771  line++;
772 
773  // Either an object will be loaded properly or the file load will fail and raise
774  // an exception.
775  if( strCompare( "$Descr", line ) )
776  loadPageSettings( aReader, aScreen );
777  else if( strCompare( "$Comp", line ) )
778  aScreen->Append( loadComponent( aReader ) );
779  else if( strCompare( "$Sheet", line ) )
780  aScreen->Append( loadSheet( aReader ) );
781  else if( strCompare( "$Bitmap", line ) )
782  aScreen->Append( loadBitmap( aReader ) );
783  else if( strCompare( "Connection", line ) )
784  aScreen->Append( loadJunction( aReader ) );
785  else if( strCompare( "NoConn", line ) )
786  aScreen->Append( loadNoConnect( aReader ) );
787  else if( strCompare( "Wire", line ) )
788  aScreen->Append( loadWire( aReader ) );
789  else if( strCompare( "Entry", line ) )
790  aScreen->Append( loadBusEntry( aReader ) );
791  else if( strCompare( "Text", line ) )
792  aScreen->Append( loadText( aReader ) );
793  else if( strCompare( "BusAlias", line ) )
794  aScreen->AddBusAlias( loadBusAlias( aReader, aScreen ) );
795  else if( strCompare( "$EndSCHEMATC", line ) )
796  return;
797  else
798  SCH_PARSE_ERROR( "unrecognized token", aReader, line );
799  }
800 }
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_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
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)
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:133
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_rootSheet, m_version, LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by loadFile().

◆ loadFile()

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

Definition at line 735 of file sch_legacy_plugin.cpp.

736 {
737  FILE_LINE_READER reader( aFileName );
738 
739  loadHeader( reader, aScreen );
740 
741  LoadContent( reader, aScreen, m_version );
742 
743  // Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
744  // so checking for it's existance will fail so just exit here and take our chances. :(
745  if( m_version > 1 )
746  {
747  char* line = reader.Line();
748 
749  while( *line == ' ' )
750  line++;
751 
752  if( !strCompare( "$EndSCHEMATC", line ) )
753  THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
754  }
755 }
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 803 of file sch_legacy_plugin.cpp.

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

660 {
661  SCH_SCREEN* screen = NULL;
662 
663  if( !aSheet->GetScreen() )
664  {
665  // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
666  // stores the file name and extension. Add the project path to the file name and
667  // extension to compare when calling SCH_SHEET::SearchHierarchy().
668  wxFileName fileName = aSheet->GetFileName();
669  fileName.SetExt( "sch" );
670 
671  if( !fileName.IsAbsolute() )
672  fileName.MakeAbsolute( m_currentPath.top() );
673 
674  // Save the current path so that it gets restored when decending and ascending the
675  // sheet hierarchy which allows for sheet schematic files to be nested in folders
676  // relative to the last path a schematic was loaded from.
677  wxLogTrace( traceSchLegacyPlugin, "Saving path \"%s\"", m_currentPath.top() );
678  m_currentPath.push( fileName.GetPath() );
679  wxLogTrace( traceSchLegacyPlugin, "Current path \"%s\"", m_currentPath.top() );
680  wxLogTrace( traceSchLegacyPlugin, "Loading \"%s\"", fileName.GetFullPath() );
681 
682  m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
683 
684  if( screen )
685  {
686  aSheet->SetScreen( screen );
687  screen->SetParent( m_schematic );
688  // Do not need to load the sub-sheets - this has already been done.
689  }
690  else
691  {
692  aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
693  aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
694 
695  try
696  {
697  loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
698  }
699  catch( const IO_ERROR& ioe )
700  {
701  // If there is a problem loading the root sheet, there is no recovery.
702  if( aSheet == m_rootSheet )
703  throw( ioe );
704 
705  // For all subsheets, queue up the error message for the caller.
706  if( !m_error.IsEmpty() )
707  m_error += "\n";
708 
709  m_error += ioe.What();
710  }
711 
712  for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
713  {
714  wxCHECK2( aItem->Type() == SCH_SHEET_T, continue );
715  auto sheet = static_cast<SCH_SHEET*>( aItem );
716 
717  // Set the parent to aSheet. This effectively creates a method to find
718  // the root sheet from any sheet so a pointer to the root sheet does not
719  // need to be stored globally. Note: this is not the same as a hierarchy.
720  // Complex hierarchies can have multiple copies of a sheet. This only
721  // provides a simple tree to find the root sheet.
722  sheet->SetParent( aSheet );
723 
724  // Recursion starts here.
725  loadHierarchy( sheet );
726  }
727  }
728 
729  m_currentPath.pop();
730  wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
731  }
732 }
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:632
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:151
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:282
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:196
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() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:496
EE_RTREE & Items()
Definition: sch_screen.h:162
void SetFileName(const wxString &aFileName)
Definition: sch_screen.h:187
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_rootSheet, m_schematic, NULL, EE_RTREE::OfType(), SCH_SHEET_T, SCH_SHEET::SearchHierarchy(), SCH_SCREEN::SetFileName(), EDA_ITEM::SetParent(), SCH_SHEET::SetScreen(), traceSchLegacyPlugin, and IO_ERROR::What().

Referenced by Load().

◆ loadJunction()

SCH_JUNCTION * SCH_LEGACY_PLUGIN::loadJunction ( LINE_READER aReader)
private

Definition at line 1165 of file sch_legacy_plugin.cpp.

1166 {
1167  std::unique_ptr< SCH_JUNCTION > junction( new SCH_JUNCTION );
1168 
1169  const char* line = aReader.Line();
1170 
1171  wxCHECK( strCompare( "Connection", line, &line ), NULL );
1172 
1173  wxString name;
1174 
1175  parseUnquotedString( name, aReader, line, &line );
1176 
1177  wxPoint position;
1178 
1179  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1180  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1181  junction->SetPosition( position );
1182 
1183  return junction.release();
1184 }
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 1187 of file sch_legacy_plugin.cpp.

1188 {
1189  std::unique_ptr< SCH_NO_CONNECT > no_connect( new SCH_NO_CONNECT );
1190 
1191  const char* line = aReader.Line();
1192 
1193  wxCHECK( strCompare( "NoConn", line, &line ), NULL );
1194 
1195  wxString name;
1196 
1197  parseUnquotedString( name, aReader, line, &line );
1198 
1199  wxPoint position;
1200 
1201  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1202  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1203  no_connect->SetPosition( position );
1204 
1205  return no_connect.release();
1206 }
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 841 of file sch_legacy_plugin.cpp.

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

971 {
972  std::unique_ptr< SCH_SHEET > sheet( new SCH_SHEET() );
973 
974  const char* line = aReader.ReadLine();
975 
976  while( line != NULL )
977  {
978  if( strCompare( "S", line, &line ) ) // Sheet dimensions.
979  {
980  wxPoint position;
981 
982  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
983  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
984  sheet->SetPosition( position );
985 
986  wxSize size;
987 
988  size.SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
989  size.SetHeight( Mils2Iu( parseInt( aReader, line, &line ) ) );
990  sheet->SetSize( size );
991  }
992  else if( strCompare( "U", line, &line ) ) // Sheet UUID.
993  {
994  wxString text;
995  parseUnquotedString( text, aReader, line );
996 
997  if( text != "00000000" )
998  const_cast<KIID&>( sheet->m_Uuid ) = KIID( text );
999  }
1000  else if( *line == 'F' ) // Sheet field.
1001  {
1002  line++;
1003 
1004  wxString text;
1005  int size;
1006  int fieldId = parseInt( aReader, line, &line );
1007 
1008  if( fieldId == 0 || fieldId == 1 ) // Sheet name and file name.
1009  {
1010  parseQuotedString( text, aReader, line, &line );
1011  size = Mils2Iu( parseInt( aReader, line, &line ) );
1012 
1013  SCH_FIELD& field = sheet->GetFields()[ fieldId ];
1014  field.SetText( text );
1015  field.SetTextSize( wxSize( size, size ) );
1016  }
1017  else // Sheet pin.
1018  {
1019  // Use a unique_ptr so that we clean up in the case of a throw
1020  std::unique_ptr< SCH_SHEET_PIN > sheetPin( new SCH_SHEET_PIN( sheet.get() ) );
1021 
1022  sheetPin->SetNumber( fieldId );
1023 
1024  // Can be empty fields.
1025  parseQuotedString( text, aReader, line, &line, true );
1026 
1027  sheetPin->SetText( text );
1028 
1029  if( line == NULL )
1030  THROW_IO_ERROR( _( "unexpected end of line" ) );
1031 
1032  switch( parseChar( aReader, line, &line ) )
1033  {
1034  case 'I': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_INPUT ); break;
1035  case 'O': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_OUTPUT ); break;
1036  case 'B': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_BIDI ); break;
1037  case 'T': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_TRISTATE ); break;
1038  case 'U': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_UNSPECIFIED ); break;
1039  default: SCH_PARSE_ERROR( "invalid sheet pin type", aReader, line );
1040  }
1041 
1042  switch( parseChar( aReader, line, &line ) )
1043  {
1044  case 'R': sheetPin->SetEdge( SHEET_RIGHT_SIDE ); break;
1045  case 'T': sheetPin->SetEdge( SHEET_TOP_SIDE ); break;
1046  case 'B': sheetPin->SetEdge( SHEET_BOTTOM_SIDE ); break;
1047  case 'L': sheetPin->SetEdge( SHEET_LEFT_SIDE ); break;
1048  default:
1049  SCH_PARSE_ERROR( "invalid sheet pin side", aReader, line );
1050  }
1051 
1052  wxPoint position;
1053 
1054  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1055  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1056  sheetPin->SetPosition( position );
1057 
1058  size = Mils2Iu( parseInt( aReader, line, &line ) );
1059 
1060  sheetPin->SetTextSize( wxSize( size, size ) );
1061 
1062  sheet->AddPin( sheetPin.release() );
1063  }
1064  }
1065  else if( strCompare( "$EndSheet", line ) )
1066  {
1067  sheet->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
1068  return sheet.release();
1069  }
1070 
1071  line = aReader.ReadLine();
1072  }
1073 
1074  SCH_PARSE_ERROR( "missing '$EndSheet`", aReader, line );
1075 
1076  return NULL; // Prevents compiler warning. Should never get here.
1077 }
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
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 SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
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)
Definition: common.h:68
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:116
#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:84
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:216
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:33
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 _, Mils2Iu, NULL, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), PS_BIDI, PS_INPUT, PS_OUTPUT, PS_TRISTATE, PS_UNSPECIFIED, LINE_READER::ReadLine(), SCH_PARSE_ERROR, EDA_TEXT::SetText(), EDA_TEXT::SetTextSize(), 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 4427 of file sch_legacy_plugin.cpp.

4429 {
4430  LOCALE_IO toggle; // toggles on, then off, the C locale.
4431 
4432  m_props = aProperties;
4433 
4434  cacheLib( aLibraryPath );
4435 
4436  LIB_PART_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
4437 
4438  if( it == m_cache->m_symbols.end() )
4439  return nullptr;
4440 
4441  return it->second;
4442 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
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 1363 of file sch_legacy_plugin.cpp.

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

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

References color, SCH_LINE::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 4562 of file sch_legacy_plugin.cpp.

4564 {
4565  return SCH_LEGACY_PLUGIN_CACHE::LoadPart( reader, aMajorVersion, aMinorVersion );
4566 }
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().

◆ Save()

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 1821 of file sch_legacy_plugin.cpp.

1823 {
1824  wxCHECK_RET( aSheet != NULL, "NULL SCH_SHEET object." );
1825  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1826 
1827  LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
1828 
1829  init( aSchematic, aProperties );
1830 
1831  wxFileName fn = aFileName;
1832 
1833  // File names should be absolute. Don't assume everything relative to the project path
1834  // works properly.
1835  wxASSERT( fn.IsAbsolute() );
1836 
1837  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1838 
1839  m_out = &formatter; // no ownership
1840 
1841  Format( aSheet );
1842 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:216
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.
#define NULL
void Format(SCH_SHEET *aSheet)
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 2134 of file sch_legacy_plugin.cpp.

2135 {
2136  wxCHECK_RET( aBitmap != NULL, "SCH_BITMAP* is NULL" );
2137 
2138  const wxImage* image = aBitmap->GetImage()->GetImageData();
2139 
2140  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
2141 
2142  m_out->Print( 0, "$Bitmap\n" );
2143  m_out->Print( 0, "Pos %-4d %-4d\n",
2144  Iu2Mils( aBitmap->GetPosition().x ),
2145  Iu2Mils( aBitmap->GetPosition().y ) );
2146  m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
2147  m_out->Print( 0, "Data\n" );
2148 
2149  wxMemoryOutputStream stream;
2150 
2151  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
2152 
2153  // Write binary data in hexadecimal form (ASCII)
2154  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
2155  char* begin = (char*) buffer->GetBufferStart();
2156 
2157  for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
2158  {
2159  if( ii >= 32 )
2160  {
2161  ii = 0;
2162 
2163  m_out->Print( 0, "\n" );
2164  }
2165 
2166  m_out->Print( 0, "%2.2X ", *begin & 0xFF );
2167  }
2168 
2169  m_out->Print( 0, "\nEndData\n" );
2170  m_out->Print( 0, "$EndBitmap\n" );
2171 }
double GetScale() const
Definition: bitmap_base.h:92
wxImage * GetImageData()
Definition: bitmap_base.h:83
#define NULL
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:59
const wxPoint GetPosition() const override
Definition: sch_bitmap.h:140
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 2387 of file sch_legacy_plugin.cpp.

2388 {
2389  wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" );
2390 
2391  wxString members = boost::algorithm::join( aAlias->Members(), " " );
2392 
2393  m_out->Print( 0, "BusAlias %s %s\n",
2394  TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
2395 }
#define NULL
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
#define TO_UTF8(wxstring)
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 2258 of file sch_legacy_plugin.cpp.

2259 {
2260  wxCHECK_RET( aBusEntry != NULL, "SCH_BUS_ENTRY_BASE* is NULL" );
2261 
2262  if( aBusEntry->GetLayer() == LAYER_WIRE )
2263  m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
2264  Iu2Mils( aBusEntry->GetPosition().x ),
2265  Iu2Mils( aBusEntry->GetPosition().y ),
2266  Iu2Mils( aBusEntry->m_End().x ), Iu2Mils( aBusEntry->m_End().y ) );
2267  else
2268  m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
2269  Iu2Mils( aBusEntry->GetPosition().x ),
2270  Iu2Mils( aBusEntry->GetPosition().y ),
2271  Iu2Mils( aBusEntry->m_End().x ), Iu2Mils( aBusEntry->m_End().y ) );
2272 }
const wxPoint GetPosition() const override
#define NULL
wxPoint m_End() const
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:271
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_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 1989 of file sch_legacy_plugin.cpp.

1990 {
1991  std::string name1;
1992  std::string name2;
1993 
1994  static wxString delimiters( wxT( " " ) );
1995 
1996  // This is redundant with the AR entries below, but it makes the files backwards-compatible.
1997  if( aComponent->GetInstanceReferences().size() > 0 )
1998  {
1999  const COMPONENT_INSTANCE_REFERENCE& instance = aComponent->GetInstanceReferences()[0];
2000  name1 = toUTFTildaText( instance.m_Reference );
2001  }
2002  else
2003  {
2004  if( aComponent->GetField( REFERENCE )->GetText().IsEmpty() )
2005  name1 = toUTFTildaText( aComponent->GetPrefix() );
2006  else
2007  name1 = toUTFTildaText( aComponent->GetField( REFERENCE )->GetText() );
2008  }
2009 
2010  wxString part_name = aComponent->GetLibId().Format();
2011 
2012  if( part_name.size() )
2013  {
2014  name2 = toUTFTildaText( part_name );
2015  }
2016  else
2017  {
2018  name2 = "_NONAME_";
2019  }
2020 
2021  m_out->Print( 0, "$Comp\n" );
2022  m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
2023 
2024  // Generate unit number, conversion and timestamp
2025  m_out->Print( 0, "U %d %d %8.8X\n",
2026  aComponent->GetUnit(),
2027  aComponent->GetConvert(),
2028  aComponent->m_Uuid.AsLegacyTimestamp() );
2029 
2030  // Save the position
2031  m_out->Print( 0, "P %d %d\n",
2032  Iu2Mils( aComponent->GetPosition().x ),
2033  Iu2Mils( aComponent->GetPosition().y ) );
2034 
2035  /* If this is a complex hierarchy; save hierarchical references.
2036  * but for simple hierarchies it is not necessary.
2037  * the reference inf is already saved
2038  * this is useful for old Eeschema version compatibility
2039  */
2040  if( aComponent->GetInstanceReferences().size() > 1 )
2041  {
2042  for( const COMPONENT_INSTANCE_REFERENCE& instance : aComponent->GetInstanceReferences() )
2043  {
2044  /*format:
2045  * AR Path="/140/2" Ref="C99" Part="1"
2046  * where 140 is the uid of the containing sheet
2047  * and 2 is the timestamp of this component.
2048  * (timestamps are actually 8 hex chars)
2049  * Ref is the conventional component reference for this 'path'
2050  * Part is the conventional component part selection for this 'path'
2051  */
2052  wxString path = "/";
2053 
2054  // Skip root sheet
2055  for( int i = 1; i < (int) instance.m_Path.size(); ++i )
2056  path += instance.m_Path[i].AsLegacyTimestampString() + "/";
2057 
2058  m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%d\" \n",
2059  TO_UTF8( path + aComponent->m_Uuid.AsLegacyTimestampString() ),
2060  TO_UTF8( instance.m_Reference ),
2061  instance.m_Unit );
2062  }
2063  }
2064 
2065  // update the ugly field index, which I would like to see go away someday soon.
2066  for( int i = 0; i < aComponent->GetFieldCount(); ++i )
2067  aComponent->GetField( i )->SetId( i );
2068 
2069  // Fixed fields:
2070  // Save mandatory fields even if they are blank,
2071  // because the visibility, size and orientation are set from library editor.
2072  for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
2073  saveField( aComponent->GetField( i ) );
2074 
2075  // User defined fields:
2076  // The *policy* about which user defined fields are part of a symbol is now
2077  // only in the dialog editors. No policy should be enforced here, simply
2078  // save all the user defined fields, they are present because a dialog editor
2079  // thought they should be. If you disagree, go fix the dialog editors.
2080  for( int i = MANDATORY_FIELDS; i < aComponent->GetFieldCount(); ++i )
2081  saveField( aComponent->GetField( i ) );
2082 
2083  // Unit number, position, box ( old standard )
2084  m_out->Print( 0, "\t%-4d %-4d %-4d\n", aComponent->GetUnit(),
2085  Iu2Mils( aComponent->GetPosition().x ),
2086  Iu2Mils( aComponent->GetPosition().y ) );
2087 
2088  TRANSFORM transform = aComponent->GetTransform();
2089 
2090  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
2091  transform.x1, transform.y1, transform.x2, transform.y2 );
2092  m_out->Print( 0, "$EndComp\n" );
2093 }
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".
void saveField(SCH_FIELD *aField)
int y1
Definition: transform.h:49
int GetUnit() const
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
timestamp_t AsLegacyTimestamp() const
Definition: common.cpp:138
TRANSFORM & GetTransform() const
A simple container for schematic symbol instance infromation.
const wxPoint GetPosition() const override
const std::vector< COMPONENT_INSTANCE_REFERENCE > & GetInstanceReferences()
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
int GetFieldCount() const
Return the number of fields in this symbol.
UTF8 Format() const
Definition: lib_id.cpp:237
const KIID m_Uuid
Definition: base_struct.h:162
SCH_FIELD * GetField(int aFieldNdx)
Returns a field in this symbol.
wxString AsLegacyTimestampString() const
Definition: common.cpp:171
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
#define TO_UTF8(wxstring)
int GetConvert() const
void SetId(int aId)
Definition: sch_field.cpp:76
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:126

References KIID::AsLegacyTimestamp(), KIID::AsLegacyTimestampString(), LIB_ID::Format(), SCH_COMPONENT::GetConvert(), SCH_COMPONENT::GetField(), SCH_COMPONENT::GetFieldCount(), SCH_COMPONENT::GetInstanceReferences(), SCH_COMPONENT::GetLibId(), SCH_COMPONENT::GetPosition(), SCH_COMPONENT::GetPrefix(), EDA_TEXT::GetText(), SCH_COMPONENT::GetTransform(), SCH_COMPONENT::GetUnit(), m_out, COMPONENT_INSTANCE_REFERENCE::m_Reference, EDA_ITEM::m_Uuid, 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 2096 of file sch_legacy_plugin.cpp.

2097 {
2098  char hjustify = 'C';
2099 
2100  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
2101  hjustify = 'L';
2102  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
2103  hjustify = 'R';
2104 
2105  char vjustify = 'C';
2106 
2107  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
2108  vjustify = 'B';
2109  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
2110  vjustify = 'T';
2111 
2112  m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
2113  aField->GetId(),
2114  EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
2115  aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
2116  Iu2Mils( aField->GetLibPosition().x ),
2117  Iu2Mils( aField->GetLibPosition().y ),
2118  Iu2Mils( aField->GetTextWidth() ),
2119  !aField->IsVisible(),
2120  hjustify, vjustify,
2121  aField->IsItalic() ? 'I' : 'N',
2122  aField->IsBold() ? 'B' : 'N' );
2123 
2124  // Save field name, if the name is user definable
2125  if( aField->GetId() >= FIELD1 )
2126  {
2127  m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
2128  }
2129 
2130  m_out->Print( 0, "\n" );
2131 }
#define TEXT_ANGLE_HORIZ
bool IsBold() const
Definition: eda_text.h:182
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
bool IsVisible() const
Definition: eda_text.h:185
double GetTextAngle() const
Definition: eda_text.h:173
int GetId() const
Definition: sch_field.h:114
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:283
bool IsItalic() const
Definition: eda_text.h:179
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
wxPoint GetLibPosition() const
Definition: sch_field.h:188
int GetTextWidth() const
Definition: eda_text.h:241
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:420
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:126

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

2239 {
2240  wxCHECK_RET( aJunction != NULL, "SCH_JUNCTION* is NULL" );
2241 
2242  m_out->Print( 0, "Connection ~ %-4d %-4d\n",
2243  Iu2Mils( aJunction->GetPosition().x ),
2244  Iu2Mils( aJunction->GetPosition().y ) );
2245 }
#define NULL
const wxPoint GetPosition() const override
Definition: sch_junction.h:97
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 4521 of file sch_legacy_plugin.cpp.

4522 {
4523  if( !m_cache )
4524  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4525 
4526  wxString oldFileName = m_cache->GetFileName();
4527 
4528  if( !m_cache->IsFile( aLibraryPath ) )
4529  {
4530  m_cache->SetFileName( aLibraryPath );
4531  }
4532 
4533  // This is a forced save.
4534  m_cache->SetModified();
4535  m_cache->Save( writeDocFile( aProperties ) );
4536  m_cache->SetFileName( oldFileName );
4537 }
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 2275 of file sch_legacy_plugin.cpp.

2276 {
2277  wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" );
2278 
2279  const char* layer = "Notes";
2280  const char* width = "Line";
2281 
2282  if( aLine->GetLayer() == LAYER_WIRE )
2283  layer = "Wire";
2284  else if( aLine->GetLayer() == LAYER_BUS )
2285  layer = "Bus";
2286 
2287  m_out->Print( 0, "Wire %s %s", layer, width );
2288 
2289  // Write line style (width, type, color) only for non default values
2290  if( aLine->IsGraphicLine() )
2291  {
2292  if( aLine->GetLineSize() != 0 )
2293  m_out->Print( 0, " %s %d", T_WIDTH, Iu2Mils( aLine->GetLineSize() ) );
2294 
2295  if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
2296  m_out->Print( 0, " %s %s", T_STYLE,
2298 
2299  if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
2300  m_out->Print( 0, " %s",
2301  TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
2302  }
2303 
2304  m_out->Print( 0, "\n" );
2305 
2306  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
2307  Iu2Mils( aLine->GetStartPoint().x ), Iu2Mils( aLine->GetStartPoint().y ),
2308  Iu2Mils( aLine->GetEndPoint().x ), Iu2Mils( aLine->GetEndPoint().y ) );
2309 
2310  m_out->Print( 0, "\n");
2311 }
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:102
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:227
bool IsGraphicLine() const
Returns if the line is a graphic (non electrical line)
Definition: sch_line.cpp:798
wxPoint GetStartPoint() const
Definition: sch_line.h:94
#define T_WIDTH
#define T_STYLE
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:233
#define NULL
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:257
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:271
int GetLineSize() const
Definition: sch_line.h:136
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
#define TO_UTF8(wxstring)
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:97

References SCH_LINE::GetDefaultStyle(), SCH_LINE::GetEndPoint(), SCH_ITEM::GetLayer(), SCH_LINE::GetLineColor(), SCH_LINE::GetLineSize(), SCH_LINE::GetLineStyle(), SCH_LINE::GetLineStyleName(), 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 2248 of file sch_legacy_plugin.cpp.

2249 {
2250  wxCHECK_RET( aNoConnect != NULL, "SCH_NOCONNECT* is NULL" );
2251 
2252  m_out->Print( 0, "NoConn ~ %-4d %-4d\n",
2253  Iu2Mils( aNoConnect->GetPosition().x ),
2254  Iu2Mils( aNoConnect->GetPosition().y ) );
2255 }
#define NULL
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
const wxPoint GetPosition() const override
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 2174 of file sch_legacy_plugin.cpp.

2175 {
2176  wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" );
2177 
2178  m_out->Print( 0, "$Sheet\n" );
2179  m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
2180  Iu2Mils( aSheet->GetPosition().x ),
2181  Iu2Mils( aSheet->GetPosition().y ),
2182  Iu2Mils( aSheet->GetSize().x ),
2183  Iu2Mils( aSheet->GetSize().y ) );
2184 
2185  m_out->Print( 0, "U %8.8X\n", aSheet->m_Uuid.AsLegacyTimestamp() );
2186 
2187  SCH_FIELD& sheetName = aSheet->GetFields()[SHEETNAME];
2188  SCH_FIELD& fileName = aSheet->GetFields()[SHEETFILENAME];
2189 
2190  if( !sheetName.GetText().IsEmpty() )
2191  m_out->Print( 0, "F0 %s %d\n",
2192  EscapedUTF8( sheetName.GetText() ).c_str(),
2193  Iu2Mils( sheetName.GetTextSize().x ) );
2194 
2195  if( !fileName.GetText().IsEmpty() )
2196  m_out->Print( 0, "F1 %s %d\n",
2197  EscapedUTF8( fileName.GetText() ).c_str(),
2198  Iu2Mils( fileName.GetTextSize().x ) );
2199 
2200  for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
2201  {
2202  int type, side;
2203 
2204  if( pin->GetText().IsEmpty() )
2205  break;
2206 
2207  switch( pin->GetEdge() )
2208  {
2209  default:
2210  case SHEET_LEFT_SIDE: side = 'L'; break;
2211  case SHEET_RIGHT_SIDE: side = 'R'; break;
2212  case SHEET_TOP_SIDE: side = 'T'; break;
2213  case SHEET_BOTTOM_SIDE: side = 'B'; break;
2214  }
2215 
2216  switch( pin->GetShape() )
2217  {
2218  default:
2219  case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED: type = 'U'; break;
2220  case PINSHEETLABEL_SHAPE::PS_INPUT: type = 'I'; break;
2221  case PINSHEETLABEL_SHAPE::PS_OUTPUT: type = 'O'; break;
2222  case PINSHEETLABEL_SHAPE::PS_BIDI: type = 'B'; break;
2223  case PINSHEETLABEL_SHAPE::PS_TRISTATE: type = 'T'; break;
2224  }
2225 
2226  m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n",
2227  pin->GetNumber(),
2228  EscapedUTF8( pin->GetText() ).c_str(), // supplies wrapping quotes
2229  type, side, Iu2Mils( pin->GetPosition().x ),
2230  Iu2Mils( pin->GetPosition().y ),
2231  Iu2Mils( pin->GetTextWidth() ) );
2232  }
2233 
2234  m_out->Print( 0, "$EndSheet\n" );
2235 }
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
std::string EscapedUTF8(wxString aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:283
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:268
#define NULL
timestamp_t AsLegacyTimestamp() const
Definition: common.cpp:138
const wxSize & GetTextSize() const
Definition: eda_text.h:238
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
const KIID m_Uuid
Definition: base_struct.h:162
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:362
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
const wxPoint GetPosition() const override
Definition: sch_sheet.h:570
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:126
wxSize GetSize()
Definition: sch_sheet.h:284

References KIID::AsLegacyTimestamp(), EscapedUTF8(), SCH_SHEET::GetFields(), SCH_SHEET::GetPins(), SCH_SHEET::GetPosition(), SCH_SHEET::GetSize(), EDA_TEXT::GetText(), EDA_TEXT::GetTextSize(), m_out, EDA_ITEM::m_Uuid, 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, SHEETFILENAME, SHEETNAME, 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 4445 of file sch_legacy_plugin.cpp.

4447 {
4448  m_props = aProperties;
4449 
4450  cacheLib( aLibraryPath );
4451 
4452  m_cache->AddSymbol( aSymbol );
4453 
4454  if( !isBuffering( aProperties ) )
4455  m_cache->Save( writeDocFile( aProperties ) );
4456 }
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 2314 of file sch_legacy_plugin.cpp.

2315 {
2316  wxCHECK_RET( aText != NULL, "SCH_TEXT* is NULL" );
2317 
2318  const char* italics = "~";
2319  const char* textType = "Notes";
2320 
2321  if( aText->IsItalic() )
2322  italics = "Italic";
2323 
2324  wxString text = aText->GetText();
2325 
2326  SCH_LAYER_ID layer = aText->GetLayer();
2327 
2328  if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
2329  {
2330  if( layer == LAYER_NOTES )
2331  {
2332  // For compatibility reasons, the text must be saved in only one text line
2333  // so replace all EOLs with \\n
2334  text.Replace( wxT( "\n" ), wxT( "\\n" ) );
2335 
2336  // Here we should have no CR or LF character in line
2337  // This is not always the case if a multiline text was copied (using a copy/paste
2338  // function) from a text that uses E.O.L characters that differs from the current
2339  // EOL format. This is mainly the case under Linux using LF symbol when copying
2340  // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
2341  // (or LF left under MacOSX)
2342  for( unsigned ii = 0; ii < text.Len(); )
2343  {
2344  if( text[ii] == 0x0A || text[ii] == 0x0D )
2345  text.erase( ii, 1 );
2346  else
2347  ii++;
2348  }
2349  }
2350  else
2351  {
2352  textType = "Label";
2353  }
2354 
2355  // Local labels must have their spin style inverted for left and right
2356  int spinStyle = static_cast<int>( aText->GetLabelSpinStyle() );
2357 
2358  if( spinStyle == 0 )
2359  spinStyle = 2;
2360  else if( spinStyle == 2 )
2361  spinStyle = 0;
2362 
2363  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2364  Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
2365  spinStyle,
2366  Iu2Mils( aText->GetTextWidth() ),
2367  italics, Iu2Mils( aText->GetTextThickness() ), TO_UTF8( text ) );
2368  }
2369  else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2370  {
2371  textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2372 
2373  auto shapeLabelIt = sheetLabelNames.find( aText->GetShape() );
2374  wxCHECK_RET( shapeLabelIt != sheetLabelNames.end(), "Shape not found in names list" );
2375 
2376  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2377  Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
2378  static_cast<int>( aText->GetLabelSpinStyle() ),
2379  Iu2Mils( aText->GetTextWidth() ),
2380  shapeLabelIt->second,
2381  italics,
2382  Iu2Mils( aText->GetTextThickness() ), TO_UTF8( text ) );
2383  }
2384 }
int GetTextThickness() const
Definition: eda_text.h:158
bool IsItalic() const
Definition: eda_text.h:179
#define NULL
const wxPoint GetPosition() const override
Definition: sch_text.h:313
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:232
SCH_LAYER_ID
Eeschema drawing layers.
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:271
int GetTextWidth() const
Definition: eda_text.h:241
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
const std::map< PINSHEETLABEL_SHAPE, const char * > sheetLabelNames
#define TO_UTF8(wxstring)
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:126
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:237

References SCH_TEXT::GetLabelSpinStyle(), SCH_ITEM::GetLayer(), SCH_TEXT::GetPosition(), SCH_TEXT::GetShape(), EDA_TEXT::GetText(), EDA_TEXT::GetTextThickness(), EDA_TEXT::GetTextWidth(), 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:33

References _.

◆ writeDocFile()

bool SCH_LEGACY_PLUGIN::writeDocFile ( const PROPERTIES aProperties)
private

Definition at line 4356 of file sch_legacy_plugin.cpp.

4357 {
4358  std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
4359 
4360  if( aProperties && aProperties->find( propName ) != aProperties->end() )
4361  return false;
4362 
4363  return true;
4364 }
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 178 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 175 of file sch_legacy_plugin.h.

Referenced by GetError(), loadHeader(), 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 177 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 179 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 180 of file sch_legacy_plugin.h.

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

◆ m_schematic

SCHEMATIC* SCH_LEGACY_PLUGIN::m_schematic
protected

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

Definition at line 183 of file sch_legacy_plugin.h.

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

◆ m_version

int SCH_LEGACY_PLUGIN::m_version
protected

Version of file being loaded.

Definition at line 172 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 90 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 96 of file sch_legacy_plugin.h.

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


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