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

569 {
570  init( NULL );
571 }
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 574 of file sch_legacy_plugin.cpp.

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

4301 {
4302  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
4303  {
4304  // a spectacular episode in memory management:
4305  delete m_cache;
4306  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
4307 
4308  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
4309  // to modify the hash value that indicate component to symbol links
4310  // must be updated.
4312 
4313  if( !isBuffering( m_props ) )
4314  m_cache->Load();
4315  }
4316 }
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 4503 of file sch_legacy_plugin.cpp.

4504 {
4505  // Open file and check first line
4506  wxTextFile tempFile;
4507 
4508  tempFile.Open( aFileName );
4509  wxString firstline;
4510  // read the first line
4511  firstline = tempFile.GetFirstLine();
4512  tempFile.Close();
4513 
4514  return firstline.StartsWith( "EESchema" );
4515 }

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

4438 {
4439  if( wxFileExists( aLibraryPath ) )
4440  {
4442  _( "symbol library \"%s\" already exists, cannot create a new library" ),
4443  aLibraryPath.GetData() ) );
4444  }
4445 
4446  LOCALE_IO toggle;
4447 
4448  m_props = aProperties;
4449 
4450  delete m_cache;
4451  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4452  m_cache->SetModified();
4453  m_cache->Save( writeDocFile( aProperties ) );
4454  m_cache->Load(); // update m_writable and m_mod_time
4455 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
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 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:201
#define _(s)
Definition: 3d_actions.cpp:33
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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 4422 of file sch_legacy_plugin.cpp.

4424 {
4425  m_props = aProperties;
4426 
4427  cacheLib( aLibraryPath );
4428 
4429  m_cache->DeleteSymbol( aSymbolName );
4430 
4431  if( !isBuffering( aProperties ) )
4432  m_cache->Save( writeDocFile( aProperties ) );
4433 }
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 4458 of file sch_legacy_plugin.cpp.

4460 {
4461  wxFileName fn = aLibraryPath;
4462 
4463  if( !fn.FileExists() )
4464  return false;
4465 
4466  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
4467  // we don't want that. we want bare metal portability with no UI here.
4468  if( wxRemove( aLibraryPath ) )
4469  {
4470  THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
4471  aLibraryPath.GetData() ) );
4472  }
4473 
4474  if( m_cache && m_cache->IsFile( aLibraryPath ) )
4475  {
4476  delete m_cache;
4477  m_cache = 0;
4478  }
4479 
4480  return true;
4481 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
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:201
#define _(s)
Definition: 3d_actions.cpp:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

4349 {
4350  LOCALE_IO toggle; // toggles on, then off, the C locale.
4351 
4352  m_props = aProperties;
4353 
4354  bool powerSymbolsOnly = ( aProperties &&
4355  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4356  cacheLib( aLibraryPath );
4357 
4358  const LIB_PART_MAP& symbols = m_cache->m_symbols;
4359 
4360  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
4361  {
4362  if( !powerSymbolsOnly || it->second->IsPower() )
4363  aSymbolNameList.Add( it->first );
4364  }
4365 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
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 4368 of file sch_legacy_plugin.cpp.

4371 {
4372  LOCALE_IO toggle; // toggles on, then off, the C locale.
4373 
4374  m_props = aProperties;
4375 
4376  bool powerSymbolsOnly = ( aProperties &&
4377  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4378  cacheLib( aLibraryPath );
4379 
4380  const LIB_PART_MAP& symbols = m_cache->m_symbols;
4381 
4382  for( LIB_PART_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
4383  {
4384  if( !powerSymbolsOnly || it->second->IsPower() )
4385  aSymbolList.push_back( it->second );
4386  }
4387 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
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 1846 of file sch_legacy_plugin.cpp.

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

References EESCHEMA_VERSION, EscapedUTF8(), SCH_SCREEN::GetBusAliases(), TITLE_BLOCK::GetComment(), TITLE_BLOCK::GetCompany(), TITLE_BLOCK::GetDate(), PAGE_INFO::GetHeightMils(), BASE_SCREEN::GetPageCount(), SCH_SCREEN::GetPageSettings(), TITLE_BLOCK::GetRevision(), SCH_SHEET::GetScreen(), TITLE_BLOCK::GetTitle(), SCH_SCREEN::GetTitleBlock(), PAGE_INFO::GetType(), BASE_SCREEN::GetVirtualPageNumber(), PAGE_INFO::GetWidthMils(), PAGE_INFO::IsCustom(), PAGE_INFO::IsPortrait(), SCH_SCREEN::Items(), m_out, m_schematic, 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 1945 of file sch_legacy_plugin.cpp.

1946 {
1947  m_out = aFormatter;
1948 
1949  for( unsigned i = 0; i < aSelection->GetSize(); ++i )
1950  {
1951  SCH_ITEM* item = (SCH_ITEM*) aSelection->GetItem( i );
1952 
1953  switch( item->Type() )
1954  {
1955  case SCH_COMPONENT_T:
1956  saveComponent( static_cast< SCH_COMPONENT* >( item ) );
1957  break;
1958  case SCH_BITMAP_T:
1959  saveBitmap( static_cast< SCH_BITMAP* >( item ) );
1960  break;
1961  case SCH_SHEET_T:
1962  saveSheet( static_cast< SCH_SHEET* >( item ) );
1963  break;
1964  case SCH_JUNCTION_T:
1965  saveJunction( static_cast< SCH_JUNCTION* >( item ) );
1966  break;
1967  case SCH_NO_CONNECT_T:
1968  saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
1969  break;
1970  case SCH_BUS_WIRE_ENTRY_T:
1971  case SCH_BUS_BUS_ENTRY_T:
1972  saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1973  break;
1974  case SCH_LINE_T:
1975  saveLine( static_cast< SCH_LINE* >( item ) );
1976  break;
1977  case SCH_TEXT_T:
1978  case SCH_LABEL_T:
1979  case SCH_GLOBAL_LABEL_T:
1980  case SCH_HIER_LABEL_T:
1981  saveText( static_cast< SCH_TEXT* >( item ) );
1982  break;
1983  default:
1984  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1985  }
1986  }
1987 }
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:194
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182

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

4533 {
4534  SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( part, formatter );
4535 }
static void SaveSymbol(LIB_PART *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_PART_MAP *aMap=nullptr)

References SCH_LEGACY_PLUGIN_CACHE::SaveSymbol().

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

4337 {
4338  if( m_cache )
4339  return m_cache->GetModifyHash();
4340 
4341  // If the cache hasn't been loaded, it hasn't been modified.
4342  return 0;
4343 }
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 580 of file sch_legacy_plugin.cpp.

581 {
582  m_version = 0;
583  m_rootSheet = nullptr;
584  m_props = aProperties;
585  m_schematic = aSchematic;
586  m_cache = nullptr;
587  m_out = nullptr;
588 }
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 4330 of file sch_legacy_plugin.cpp.

4331 {
4332  return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
4333 }
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 4518 of file sch_legacy_plugin.cpp.

4519 {
4520  // Writing legacy symbol libraries is deprecated.
4521  return false;
4522 }

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

593 {
594  wxASSERT( !aFileName || aSchematic != NULL );
595 
596  LOCALE_IO toggle; // toggles on, then off, the C locale.
597  SCH_SHEET* sheet;
598 
599  wxFileName fn = aFileName;
600 
601  // Unfortunately child sheet file names the legacy schematic file format are not fully
602  // qualified and are always appended to the project path. The aFileName attribute must
603  // always be an absolute path so the project path can be used for load child sheet files.
604  wxASSERT( fn.IsAbsolute() );
605 
606  if( aAppendToMe )
607  {
608  wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
609  aFileName, aAppendToMe->GetFileName() );
610 
611  wxFileName normedFn = aAppendToMe->GetFileName();
612 
613  if( !normedFn.IsAbsolute() )
614  {
615  if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
616  m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
617  }
618 
619  if( m_path.IsEmpty() )
620  m_path = aSchematic->Prj().GetProjectPath();
621 
622  wxLogTrace( traceSchLegacyPlugin, "m_Normalized append path \"%s\".", m_path );
623  }
624  else
625  {
626  m_path = aSchematic->Prj().GetProjectPath();
627  }
628 
629  m_currentPath.push( m_path );
630  init( aSchematic, aProperties );
631 
632  if( aAppendToMe == NULL )
633  {
634  // Clean up any allocated memory if an exception occurs loading the schematic.
635  std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
636  newSheet->SetFileName( aFileName );
637  m_rootSheet = newSheet.get();
638  loadHierarchy( newSheet.get() );
639 
640  // If we got here, the schematic loaded successfully.
641  sheet = newSheet.release();
642  m_rootSheet = nullptr; // Quiet Coverity warning.
643  }
644  else
645  {
646  wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
647  m_rootSheet = &aSchematic->Root();
648  sheet = aAppendToMe;
649  loadHierarchy( sheet );
650  }
651 
652  wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
653 
654  return sheet;
655 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
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:110
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:121
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:501
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
SCH_SHEET & Root() const
Definition: schematic.h:96
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:79
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 1081 of file sch_legacy_plugin.cpp.

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

References _, LINE_READER::Line(), Mils2Iu, NULL, parseDouble(), parseInt(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, strCompare(), and THROW_IO_ERROR.

Referenced by LoadContent().

◆ loadBusAlias()

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

Definition at line 1796 of file sch_legacy_plugin.cpp.

1798 {
1799  auto busAlias = std::make_shared<BUS_ALIAS>( aScreen );
1800  const char* line = aReader.Line();
1801 
1802  wxCHECK( strCompare( "BusAlias", line, &line ), NULL );
1803 
1804  wxString buf;
1805  parseUnquotedString( buf, aReader, line, &line );
1806  busAlias->SetName( buf );
1807 
1808  while( *line != '\0' )
1809  {
1810  buf.clear();
1811  parseUnquotedString( buf, aReader, line, &line, true );
1812  if( buf.Len() > 0 )
1813  {
1814  busAlias->AddMember( buf );
1815  }
1816  }
1817 
1818  return busAlias;
1819 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:140
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 1308 of file sch_legacy_plugin.cpp.

1309 {
1310  const char* line = aReader.Line();
1311 
1312  wxCHECK( strCompare( "Entry", line, &line ), NULL );
1313 
1314  std::unique_ptr<SCH_BUS_ENTRY_BASE> busEntry;
1315 
1316  if( strCompare( "Wire", line, &line ) )
1317  {
1318  busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>();
1319 
1320  if( !strCompare( "Line", line, &line ) )
1321  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
1322  }
1323  else if( strCompare( "Bus", line, &line ) )
1324  {
1325  busEntry = std::make_unique<SCH_BUS_BUS_ENTRY>();
1326 
1327  if( !strCompare( "Bus", line, &line ) )
1328  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
1329  }
1330  else
1331  SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
1332 
1333  line = aReader.ReadLine();
1334 
1335  wxPoint pos;
1336  wxSize size;
1337 
1338  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
1339  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
1340  size.x = Mils2Iu( parseInt( aReader, line, &line ) );
1341  size.y = Mils2Iu( parseInt( aReader, line, &line ) );
1342 
1343  size.x -= pos.x;
1344  size.y -= pos.y;
1345 
1346  busEntry->SetPosition( pos );
1347  busEntry->SetSize( size );
1348 
1349  return busEntry.release();
1350 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:140
#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...

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

Referenced by LoadContent().

◆ loadComponent()

SCH_COMPONENT * SCH_LEGACY_PLUGIN::loadComponent ( LINE_READER aReader)
private

Definition at line 1481 of file sch_legacy_plugin.cpp.

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

Referenced by LoadContent().

◆ LoadContent()

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

Definition at line 759 of file sch_legacy_plugin.cpp.

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

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

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

805 {
806  const char* line = aReader.ReadLine();
807 
808  if( !line || !strCompare( "Eeschema Schematic File Version", line, &line ) )
809  {
810  m_error.Printf(
811  _( "\"%s\" does not appear to be an Eeschema file" ), aScreen->GetFileName() );
813  }
814 
815  // get the file version here.
816  m_version = parseInt( aReader, line, &line );
817 
818  // The next lines are the lib list section, and are mainly comments, like:
819  // LIBS:power
820  // the lib list is not used, but is in schematic file just in case.
821  // It is usually not empty, but we accept empty list.
822  // If empty, there is a legacy section, not used
823  // EELAYER i j
824  // and the last line is
825  // EELAYER END
826  // Skip all lines until the end of header "EELAYER END" is found
827  while( aReader.ReadLine() )
828  {
829  line = aReader.Line();
830 
831  while( *line == ' ' )
832  line++;
833 
834  if( strCompare( "EELAYER END", line ) )
835  return;
836  }
837 
838  THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
839 }
const wxString & GetFileName() const
Definition: sch_screen.h:186
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:140
wxString m_error
For throwing exceptions or errors on partial schematic loads.
int m_version
Version of file being loaded.
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter.
#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...
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, 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 660 of file sch_legacy_plugin.cpp.

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

1167 {
1168  std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
1169 
1170  const char* line = aReader.Line();
1171 
1172  wxCHECK( strCompare( "Connection", line, &line ), NULL );
1173 
1174  wxString name;
1175 
1176  parseUnquotedString( name, aReader, line, &line );
1177 
1178  wxPoint position;
1179 
1180  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1181  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1182  junction->SetPosition( position );
1183 
1184  return junction.release();
1185 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:140
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:59
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(), and strCompare().

Referenced by LoadContent().

◆ loadNoConnect()

SCH_NO_CONNECT * SCH_LEGACY_PLUGIN::loadNoConnect ( LINE_READER aReader)
private

Definition at line 1188 of file sch_legacy_plugin.cpp.

1189 {
1190  std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>();
1191 
1192  const char* line = aReader.Line();
1193 
1194  wxCHECK( strCompare( "NoConn", line, &line ), NULL );
1195 
1196  wxString name;
1197 
1198  parseUnquotedString( name, aReader, line, &line );
1199 
1200  wxPoint position;
1201 
1202  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1203  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1204  no_connect->SetPosition( position );
1205 
1206  return no_connect.release();
1207 }
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:140
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:59
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(), and strCompare().

Referenced by LoadContent().

◆ loadPageSettings()

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

Definition at line 842 of file sch_legacy_plugin.cpp.

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

References _, PAGE_INFO::Custom, LINE_READER::Line(), NULL, parseInt(), parseQuotedString(), parseUnquotedString(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, TITLE_BLOCK::SetComment(), TITLE_BLOCK::SetCompany(), TITLE_BLOCK::SetDate(), PAGE_INFO::SetHeightMils(), BASE_SCREEN::SetPageCount(), SCH_SCREEN::SetPageSettings(), PAGE_INFO::SetPortrait(), TITLE_BLOCK::SetRevision(), TITLE_BLOCK::SetTitle(), SCH_SCREEN::SetTitleBlock(), PAGE_INFO::SetType(), BASE_SCREEN::SetVirtualPageNumber(), PAGE_INFO::SetWidthMils(), and strCompare().

Referenced by LoadContent().

◆ loadSheet()

SCH_SHEET * SCH_LEGACY_PLUGIN::loadSheet ( LINE_READER aReader)
private

Definition at line 971 of file sch_legacy_plugin.cpp.

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

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(), and THROW_IO_ERROR.

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

4392 {
4393  LOCALE_IO toggle; // toggles on, then off, the C locale.
4394 
4395  m_props = aProperties;
4396 
4397  cacheLib( aLibraryPath );
4398 
4399  LIB_PART_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
4400 
4401  if( it == m_cache->m_symbols.end() )
4402  return nullptr;
4403 
4404  return it->second;
4405 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
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 1364 of file sch_legacy_plugin.cpp.

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

Referenced by LoadContent().

◆ loadWire()

SCH_LINE * SCH_LEGACY_PLUGIN::loadWire ( LINE_READER aReader)
private

Definition at line 1210 of file sch_legacy_plugin.cpp.

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

Referenced by LoadContent().

◆ ParsePart()

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

Definition at line 4525 of file sch_legacy_plugin.cpp.

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

References SCH_LEGACY_PLUGIN_CACHE::LoadPart().

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

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

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

◆ saveBitmap()

void SCH_LEGACY_PLUGIN::saveBitmap ( SCH_BITMAP aBitmap)
private

Definition at line 2135 of file sch_legacy_plugin.cpp.

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

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

Referenced by Format().

◆ saveBusAlias()

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

Definition at line 2388 of file sch_legacy_plugin.cpp.

2389 {
2390  wxCHECK_RET( aAlias != NULL, "BUS_ALIAS* is NULL" );
2391 
2392  wxString members = boost::algorithm::join( aAlias->Members(), " " );
2393 
2394  m_out->Print( 0, "BusAlias %s %s\n",
2395  TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
2396 }
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
#define NULL
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

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

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

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

Referenced by Format().

◆ saveComponent()

void SCH_LEGACY_PLUGIN::saveComponent ( SCH_COMPONENT aComponent)
private

Definition at line 1990 of file sch_legacy_plugin.cpp.

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

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(), TRANSFORM::x1, TRANSFORM::x2, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by Format().

◆ saveField()

void SCH_LEGACY_PLUGIN::saveField ( SCH_FIELD aField)
private

Definition at line 2097 of file sch_legacy_plugin.cpp.

2098 {
2099  char hjustify = 'C';
2100 
2101  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
2102  hjustify = 'L';
2103  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
2104  hjustify = 'R';
2105 
2106  char vjustify = 'C';
2107 
2108  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
2109  vjustify = 'B';
2110  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
2111  vjustify = 'T';
2112 
2113  m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
2114  aField->GetId(),
2115  EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
2116  aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
2117  Iu2Mils( aField->GetLibPosition().x ),
2118  Iu2Mils( aField->GetLibPosition().y ),
2119  Iu2Mils( aField->GetTextWidth() ),
2120  !aField->IsVisible(),
2121  hjustify, vjustify,
2122  aField->IsItalic() ? 'I' : 'N',
2123  aField->IsBold() ? 'B' : 'N' );
2124 
2125  // Save field name, if the name is user definable
2126  if( aField->GetId() >= FIELD1 )
2127  {
2128  m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
2129  }
2130 
2131  m_out->Print( 0, "\n" );
2132 }
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:50
bool IsBold() const
Definition: eda_text.h:189
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:206
bool IsVisible() const
Definition: eda_text.h:192
double GetTextAngle() const
Definition: eda_text.h:180
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:304
bool IsItalic() const
Definition: eda_text.h:186
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:205
wxPoint GetLibPosition() const
Definition: sch_field.h:188
int GetTextWidth() const
Definition: eda_text.h:248
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:440
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133

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

Referenced by saveComponent().

◆ saveJunction()

void SCH_LEGACY_PLUGIN::saveJunction ( SCH_JUNCTION aJunction)
private

Definition at line 2239 of file sch_legacy_plugin.cpp.

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

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

Referenced by Format().

◆ SaveLibrary()

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

Reimplemented from SCH_PLUGIN.

Definition at line 4484 of file sch_legacy_plugin.cpp.

4485 {
4486  if( !m_cache )
4487  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4488 
4489  wxString oldFileName = m_cache->GetFileName();
4490 
4491  if( !m_cache->IsFile( aLibraryPath ) )
4492  {
4493  m_cache->SetFileName( aLibraryPath );
4494  }
4495 
4496  // This is a forced save.
4497  m_cache->SetModified();
4498  m_cache->Save( writeDocFile( aProperties ) );
4499  m_cache->SetFileName( oldFileName );
4500 }
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 2276 of file sch_legacy_plugin.cpp.

2277 {
2278  wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" );
2279 
2280  const char* layer = "Notes";
2281  const char* width = "Line";
2282 
2283  if( aLine->GetLayer() == LAYER_WIRE )
2284  layer = "Wire";
2285  else if( aLine->GetLayer() == LAYER_BUS )
2286  layer = "Bus";
2287 
2288  m_out->Print( 0, "Wire %s %s", layer, width );
2289 
2290  // Write line style (width, type, color) only for non default values
2291  if( aLine->IsGraphicLine() )
2292  {
2293  if( aLine->GetLineSize() != 0 )
2294  m_out->Print( 0, " %s %d", T_WIDTH, Iu2Mils( aLine->GetLineSize() ) );
2295 
2296  if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
2297  m_out->Print( 0, " %s %s", T_STYLE,
2299 
2300  if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
2301  m_out->Print( 0, " %s",
2302  TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
2303  }
2304 
2305  m_out->Print( 0, "\n" );
2306 
2307  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
2308  Iu2Mils( aLine->GetStartPoint().x ), Iu2Mils( aLine->GetStartPoint().y ),
2309  Iu2Mils( aLine->GetEndPoint().x ), Iu2Mils( aLine->GetEndPoint().y ) );
2310 
2311  m_out->Print( 0, "\n");
2312 }
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:83
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:208
bool IsGraphicLine() const
Returns if the line is a graphic (non electrical line)
Definition: sch_line.cpp:851
wxPoint GetStartPoint() const
Definition: sch_line.h:94
#define T_WIDTH
#define T_STYLE
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:95
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:222
#define NULL
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:246
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:279
int GetLineSize() const
Definition: sch_line.h:156
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:408
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, and TO_UTF8.

Referenced by Format().

◆ saveNoConnect()

void SCH_LEGACY_PLUGIN::saveNoConnect ( SCH_NO_CONNECT aNoConnect)
private

Definition at line 2249 of file sch_legacy_plugin.cpp.

2250 {
2251  wxCHECK_RET( aNoConnect != NULL, "SCH_NOCONNECT* is NULL" );
2252 
2253  m_out->Print( 0, "NoConn ~ %-4d %-4d\n",
2254  Iu2Mils( aNoConnect->GetPosition().x ),
2255  Iu2Mils( aNoConnect->GetPosition().y ) );
2256 }
wxPoint GetPosition() const override
#define NULL
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

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

Referenced by Format().

◆ saveSheet()

void SCH_LEGACY_PLUGIN::saveSheet ( SCH_SHEET aSheet)
private

Definition at line 2175 of file sch_legacy_plugin.cpp.

2176 {
2177  wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" );
2178 
2179  m_out->Print( 0, "$Sheet\n" );
2180  m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
2181  Iu2Mils( aSheet->GetPosition().x ),
2182  Iu2Mils( aSheet->GetPosition().y ),
2183  Iu2Mils( aSheet->GetSize().x ),
2184  Iu2Mils( aSheet->GetSize().y ) );
2185 
2186  m_out->Print( 0, "U %8.8X\n", aSheet->m_Uuid.AsLegacyTimestamp() );
2187 
2188  SCH_FIELD& sheetName = aSheet->GetFields()[SHEETNAME];
2189  SCH_FIELD& fileName = aSheet->GetFields()[SHEETFILENAME];
2190 
2191  if( !sheetName.GetText().IsEmpty() )
2192  m_out->Print( 0, "F0 %s %d\n",
2193  EscapedUTF8( sheetName.GetText() ).c_str(),
2194  Iu2Mils( sheetName.GetTextSize().x ) );
2195 
2196  if( !fileName.GetText().IsEmpty() )
2197  m_out->Print( 0, "F1 %s %d\n",
2198  EscapedUTF8( fileName.GetText() ).c_str(),
2199  Iu2Mils( fileName.GetTextSize().x ) );
2200 
2201  for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
2202  {
2203  int type, side;
2204 
2205  if( pin->GetText().IsEmpty() )
2206  break;
2207 
2208  switch( pin->GetEdge() )
2209  {
2210  default:
2211  case SHEET_LEFT_SIDE: side = 'L'; break;
2212  case SHEET_RIGHT_SIDE: side = 'R'; break;
2213  case SHEET_TOP_SIDE: side = 'T'; break;
2214  case SHEET_BOTTOM_SIDE: side = 'B'; break;
2215  }
2216 
2217  switch( pin->GetShape() )
2218  {
2219  default:
2220  case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED: type = 'U'; break;
2221  case PINSHEETLABEL_SHAPE::PS_INPUT: type = 'I'; break;
2222  case PINSHEETLABEL_SHAPE::PS_OUTPUT: type = 'O'; break;
2223  case PINSHEETLABEL_SHAPE::PS_BIDI: type = 'B'; break;
2224  case PINSHEETLABEL_SHAPE::PS_TRISTATE: type = 'T'; break;
2225  }
2226 
2227  m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n",
2228  pin->GetNumber(),
2229  EscapedUTF8( pin->GetText() ).c_str(), // supplies wrapping quotes
2230  type, side, Iu2Mils( pin->GetPosition().x ),
2231  Iu2Mils( pin->GetPosition().y ),
2232  Iu2Mils( pin->GetTextWidth() ) );
2233  }
2234 
2235  m_out->Print( 0, "$EndSheet\n" );
2236 }
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:304
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:273
#define NULL
timestamp_t AsLegacyTimestamp() const
Definition: kiid.cpp:147
const wxSize & GetTextSize() const
Definition: eda_text.h:245
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:85
wxPoint GetPosition() const override
Definition: sch_sheet.h:572
const KIID m_Uuid
Definition: eda_item.h:151
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:367
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:408
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
wxSize GetSize()
Definition: sch_sheet.h:289

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, and SHEETNAME.

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

4410 {
4411  m_props = aProperties;
4412 
4413  cacheLib( aLibraryPath );
4414 
4415  m_cache->AddSymbol( aSymbol );
4416 
4417  if( !isBuffering( aProperties ) )
4418  m_cache->Save( writeDocFile( aProperties ) );
4419 }
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 2315 of file sch_legacy_plugin.cpp.

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

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, and TO_UTF8.

Referenced by Format().

◆ SymbolLibOptions()

void SCH_PLUGIN::SymbolLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.

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

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

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

Definition at line 133 of file sch_plugin.cpp.

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

4320 {
4321  std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
4322 
4323  if( aProperties && aProperties->find( propName ) != aProperties->end() )
4324  return false;
4325 
4326  return true;
4327 }
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: