KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN Class Reference

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

#include <sch_legacy_plugin.h>

Inheritance diagram for SCH_LEGACY_PLUGIN:
SCH_PLUGIN

Public Member Functions

 SCH_LEGACY_PLUGIN ()
 
virtual ~SCH_LEGACY_PLUGIN ()
 
const wxString GetName () const override
 Returns a brief hard coded name for this SCH_PLUGIN. More...
 
const wxString GetFileExtension () const override
 Returns the file extension for the SCH_PLUGIN. More...
 
int GetModifyHash () const override
 Return the modification hash from the library cache. More...
 
SCH_SHEETLoad (const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL) override
 Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one. More...
 
void Save (const wxString &aFileName, SCH_SCREEN *aScreen, KIWAY *aKiway, const PROPERTIES *aProperties=NULL) override
 Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file. More...
 
void Format (SCH_SCREEN *aScreen)
 
size_t GetSymbolLibCount (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 
void EnumerateSymbolLib (wxArrayString &aAliasNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Populate a list of LIB_PART alias names contained within the library aLibraryPath. More...
 
void EnumerateSymbolLib (std::vector< LIB_ALIAS * > &aAliasList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Populate a list of LIB_PART aliases contained within the library aLibraryPath. More...
 
LIB_ALIASLoadSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL) override
 Load a LIB_ALIAS object having aAliasName from the aLibraryPath containing a library format that this SCH_PLUGIN knows about. More...
 
void SaveSymbol (const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=NULL) override
 Write aSymbol to an existing library located at aLibraryPath. More...
 
void DeleteAlias (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL) override
 Delete aAliasName from the library at aLibraryPath. More...
 
void DeleteSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL) override
 Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath. More...
 
void CreateSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Create a new empty symbol library at aLibraryPath. More...
 
bool DeleteSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 Delete an existing symbol library and returns true if successful, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 
void SaveLibrary (const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL) override
 
bool CheckHeader (const wxString &aFileName) override
 Return true if the first line in aFileName begins with the expected header. More...
 
bool IsSymbolLibWritable (const wxString &aLibraryPath) override
 Return true if the library at aLibraryPath is writable. More...
 
const wxString & GetError () const override
 Return an error string to the caller. More...
 
virtual void SymbolLibOptions (PROPERTIES *aListToAppendTo) const
 Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Static Public Attributes

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

Protected Member Functions

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

Protected Attributes

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

Private Member Functions

void loadHierarchy (SCH_SHEET *aSheet)
 
void loadHeader (FILE_LINE_READER &aReader, SCH_SCREEN *aScreen)
 
void loadPageSettings (FILE_LINE_READER &aReader, SCH_SCREEN *aScreen)
 
void loadFile (const wxString &aFileName, SCH_SCREEN *aScreen)
 
SCH_SHEETloadSheet (FILE_LINE_READER &aReader)
 
SCH_BITMAPloadBitmap (FILE_LINE_READER &aReader)
 
SCH_JUNCTIONloadJunction (FILE_LINE_READER &aReader)
 
SCH_NO_CONNECTloadNoConnect (FILE_LINE_READER &aReader)
 
SCH_LINEloadWire (FILE_LINE_READER &aReader)
 
SCH_BUS_ENTRY_BASEloadBusEntry (FILE_LINE_READER &aReader)
 
SCH_TEXTloadText (FILE_LINE_READER &aReader)
 
SCH_COMPONENTloadComponent (FILE_LINE_READER &aReader)
 
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 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 60 of file sch_legacy_plugin.h.

Constructor & Destructor Documentation

SCH_LEGACY_PLUGIN::SCH_LEGACY_PLUGIN ( )

Definition at line 557 of file sch_legacy_plugin.cpp.

558 {
559  init( NULL );
560 }
void init(KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
initialize PLUGIN like a constructor would.
SCH_LEGACY_PLUGIN::~SCH_LEGACY_PLUGIN ( )
virtual

Definition at line 563 of file sch_legacy_plugin.cpp.

564 {
565  delete m_cache;
566 }
SCH_LEGACY_PLUGIN_CACHE * m_cache

Member Function Documentation

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

Definition at line 4045 of file sch_legacy_plugin.cpp.

References PART_LIBS::s_modify_generation, and SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN_CACHE().

Referenced by GetError().

4046 {
4047  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
4048  {
4049  // a spectacular episode in memory management:
4050  delete m_cache;
4051  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
4052 
4053  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
4054  // to modify the hash value that indicate component to symbol links
4055  // must be updated.
4057 
4058  if( !isBuffering( m_props ) )
4059  m_cache->Load();
4060  }
4061 }
static int s_modify_generation
helper for GetModifyHash()
SCH_LEGACY_PLUGIN_CACHE * m_cache
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLU...
bool isBuffering(const PROPERTIES *aProperties)
bool IsFile(const wxString &aFullPathAndFileName) const
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.
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 4275 of file sch_legacy_plugin.cpp.

4276 {
4277  // Open file and check first line
4278  wxTextFile tempFile;
4279 
4280  tempFile.Open( aFileName );
4281  wxString firstline;
4282  // read the first line
4283  firstline = tempFile.GetFirstLine();
4284  tempFile.Close();
4285 
4286  return firstline.StartsWith( "EESchema" );
4287 }
void SCH_LEGACY_PLUGIN::CreateSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Create a new empty symbol library at aLibraryPath.

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4208 of file sch_legacy_plugin.cpp.

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

4210 {
4211  if( wxFileExists( aLibraryPath ) )
4212  {
4214  _( "symbol library \"%s\" already exists, cannot create a new library" ),
4215  aLibraryPath.GetData() ) );
4216  }
4217 
4218  LOCALE_IO toggle;
4219 
4220  m_props = aProperties;
4221 
4222  delete m_cache;
4223  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4224  m_cache->SetModified();
4225  m_cache->Save( writeDocFile( aProperties ) );
4226  m_cache->Load(); // update m_writable and m_mod_time
4227 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
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:205
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 NULL.
void SCH_LEGACY_PLUGIN::DeleteAlias ( const wxString &  aLibraryPath,
const wxString &  aAliasName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Delete aAliasName from the library at aLibraryPath.

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4180 of file sch_legacy_plugin.cpp.

4182 {
4183  m_props = aProperties;
4184 
4185  cacheLib( aLibraryPath );
4186 
4187  m_cache->DeleteAlias( aAliasName );
4188 
4189  if( !isBuffering( aProperties ) )
4190  m_cache->Save( writeDocFile( aProperties ) );
4191 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
bool isBuffering(const PROPERTIES *aProperties)
void DeleteAlias(const wxString &aAliasName)
void cacheLib(const wxString &aLibraryFileName)
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
bool writeDocFile(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.
void SCH_LEGACY_PLUGIN::DeleteSymbol ( const wxString &  aLibraryPath,
const wxString &  aAliasName,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4194 of file sch_legacy_plugin.cpp.

4196 {
4197  m_props = aProperties;
4198 
4199  cacheLib( aLibraryPath );
4200 
4201  m_cache->DeleteSymbol( aAliasName );
4202 
4203  if( !isBuffering( aProperties ) )
4204  m_cache->Save( writeDocFile( aProperties ) );
4205 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
bool isBuffering(const PROPERTIES *aProperties)
void cacheLib(const wxString &aLibraryFileName)
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
void DeleteSymbol(const wxString &aAliasName)
bool writeDocFile(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.
bool SCH_LEGACY_PLUGIN::DeleteSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4230 of file sch_legacy_plugin.cpp.

References Format(), and THROW_IO_ERROR.

4232 {
4233  wxFileName fn = aLibraryPath;
4234 
4235  if( !fn.FileExists() )
4236  return false;
4237 
4238  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
4239  // we don't want that. we want bare metal portability with no UI here.
4240  if( wxRemove( aLibraryPath ) )
4241  {
4242  THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
4243  aLibraryPath.GetData() ) );
4244  }
4245 
4246  if( m_cache && m_cache->IsFile( aLibraryPath ) )
4247  {
4248  delete m_cache;
4249  m_cache = 0;
4250  }
4251 
4252  return true;
4253 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool IsFile(const wxString &aFullPathAndFileName) const
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SCH_LEGACY_PLUGIN::EnumerateSymbolLib ( wxArrayString &  aAliasNameList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4104 of file sch_legacy_plugin.cpp.

References SYMBOL_LIB_TABLE::PropPowerSymsOnly.

4107 {
4108  LOCALE_IO toggle; // toggles on, then off, the C locale.
4109 
4110  m_props = aProperties;
4111 
4112  bool powerSymbolsOnly = ( aProperties &&
4113  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4114  cacheLib( aLibraryPath );
4115 
4116  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
4117 
4118  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
4119  {
4120  if( !powerSymbolsOnly || it->second->GetPart()->IsPower() )
4121  aAliasNameList.Add( it->first );
4122  }
4123 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
SCH_LEGACY_PLUGIN_CACHE * m_cache
std::map< wxString, LIB_ALIAS *, AliasMapSort > LIB_ALIAS_MAP
Alias map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
static const char * PropPowerSymsOnly
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.
void SCH_LEGACY_PLUGIN::EnumerateSymbolLib ( std::vector< LIB_ALIAS * > &  aAliasList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4126 of file sch_legacy_plugin.cpp.

References SYMBOL_LIB_TABLE::PropPowerSymsOnly.

4129 {
4130  LOCALE_IO toggle; // toggles on, then off, the C locale.
4131 
4132  m_props = aProperties;
4133 
4134  bool powerSymbolsOnly = ( aProperties &&
4135  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4136  cacheLib( aLibraryPath );
4137 
4138  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
4139 
4140  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
4141  {
4142  if( !powerSymbolsOnly || it->second->GetPart()->IsPower() )
4143  aAliasList.push_back( it->second );
4144  }
4145 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
SCH_LEGACY_PLUGIN_CACHE * m_cache
std::map< wxString, LIB_ALIAS *, AliasMapSort > LIB_ALIAS_MAP
Alias map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
static const char * PropPowerSymsOnly
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.
void SCH_LEGACY_PLUGIN::Format ( SCH_SCREEN aScreen)

Definition at line 1707 of file sch_legacy_plugin.cpp.

References EESCHEMA_VERSION, EscapedUTF8(), TITLE_BLOCK::GetComment1(), TITLE_BLOCK::GetComment2(), TITLE_BLOCK::GetComment3(), TITLE_BLOCK::GetComment4(), TITLE_BLOCK::GetCompany(), TITLE_BLOCK::GetDate(), SCH_SCREEN::GetDrawItems(), PAGE_INFO::GetHeightMils(), SCH_SCREEN::GetPageSettings(), TITLE_BLOCK::GetRevision(), TITLE_BLOCK::GetTitle(), SCH_SCREEN::GetTitleBlock(), PAGE_INFO::GetType(), PAGE_INFO::GetWidthMils(), PAGE_INFO::IsCustom(), PAGE_INFO::IsPortrait(), BASE_SCREEN::m_NumberOfScreens, BASE_SCREEN::m_ScreenNumber, SCH_ITEM::Next(), SCH_LEGACY_PLUGIN_CACHE::saveText(), SCH_BITMAP_T, SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T, SCH_COMPONENT_T, SCH_GLOBAL_LABEL_T, SCH_HIERARCHICAL_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.

1708 {
1709  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN* object." );
1710  wxCHECK_RET( m_kiway != NULL, "NULL KIWAY* object." );
1711 
1712  // Write the header
1713  m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1714 
1715  // Write the project libraries.
1716  for( const PART_LIB& lib : *m_kiway->Prj().SchLibs() )
1717  m_out->Print( 0, "LIBS:%s\n", TO_UTF8( lib.GetName() ) );
1718 
1719  // This section is not used, but written for file compatibility
1720  m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1721  m_out->Print( 0, "EELAYER END\n" );
1722 
1723  /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1724  * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1725  * simple hierarchy and flat hierarchy. Used also to search the root
1726  * sheet ( ScreenNumber = 1 ) within the files
1727  */
1728  const TITLE_BLOCK& tb = aScreen->GetTitleBlock();
1729  const PAGE_INFO& page = aScreen->GetPageSettings();
1730 
1731  m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1732  page.GetWidthMils(),
1733  page.GetHeightMils(),
1734  !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1735  m_out->Print( 0, "encoding utf-8\n" );
1736  m_out->Print( 0, "Sheet %d %d\n", aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens );
1737  m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1738  m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1739  m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1740  m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1741  m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment1() ).c_str() );
1742  m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment2() ).c_str() );
1743  m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment3() ).c_str() );
1744  m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment4() ).c_str() );
1745  m_out->Print( 0, "$EndDescr\n" );
1746 
1747  for( SCH_ITEM* item = aScreen->GetDrawItems(); item; item = item->Next() )
1748  {
1749  switch( item->Type() )
1750  {
1751  case SCH_COMPONENT_T:
1752  saveComponent( static_cast< SCH_COMPONENT* >( item ) );
1753  break;
1754  case SCH_BITMAP_T:
1755  saveBitmap( static_cast< SCH_BITMAP* >( item ) );
1756  break;
1757  case SCH_SHEET_T:
1758  saveSheet( static_cast< SCH_SHEET* >( item ) );
1759  break;
1760  case SCH_JUNCTION_T:
1761  saveJunction( static_cast< SCH_JUNCTION* >( item ) );
1762  break;
1763  case SCH_NO_CONNECT_T:
1764  saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
1765  break;
1766  case SCH_BUS_WIRE_ENTRY_T:
1767  case SCH_BUS_BUS_ENTRY_T:
1768  saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1769  break;
1770  case SCH_LINE_T:
1771  saveLine( static_cast< SCH_LINE* >( item ) );
1772  break;
1773  case SCH_TEXT_T:
1774  case SCH_LABEL_T:
1775  case SCH_GLOBAL_LABEL_T:
1777  saveText( static_cast< SCH_TEXT* >( item ) );
1778  break;
1779  default:
1780  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1781  }
1782  }
1783 
1784  m_out->Print( 0, "$EndSCHEMATC\n" );
1785 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
int m_ScreenNumber
Definition: base_screen.h:216
const wxString & GetCompany() const
Definition: title_block.h:98
void saveLine(SCH_LINE *aLine)
void saveText(SCH_TEXT *aText)
const wxString & GetComment4() const
Definition: title_block.h:123
const wxString & GetDate() const
Definition: title_block.h:78
#define SCH_LAYER_ID_COUNT
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:39
SCH_ITEM * Next() const
void saveSheet(SCH_SHEET *aSheet)
void saveJunction(SCH_JUNCTION *aJunction)
#define SCHEMATIC_HEAD_STRING
Definition: general.h:41
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
const wxString & GetTitle() const
Definition: title_block.h:64
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:137
#define EESCHEMA_VERSION
Definition: general.h:40
bool IsPortrait() const
Definition: page_info.h:116
const wxString & GetRevision() const
Definition: title_block.h:88
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:49
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:142
void saveBitmap(SCH_BITMAP *aBitmap)
const wxString & GetComment3() const
Definition: title_block.h:122
int GetWidthMils() const
Definition: page_info.h:132
void saveComponent(SCH_COMPONENT *aComponent)
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:125
const wxString & GetComment2() const
Definition: title_block.h:121
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:138
bool IsCustom() const
Function IsCustom returns true if the type is Custom.
Definition: page_info.cpp:176
const wxString & GetComment1() const
Definition: title_block.h:120
int m_NumberOfScreens
Definition: base_screen.h:217
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:115
const wxString & GetType() const
Definition: page_info.h:92
KIWAY * m_kiway
Required for path to legacy component libraries.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
Object used to load, save, search, and otherwise manipulate symbol library files. ...
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
int GetHeightMils() const
Definition: page_info.h:135
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 129 of file sch_legacy_plugin.h.

References cacheLib(), isBuffering(), loadBitmap(), loadBusEntry(), loadComponent(), loadFile(), loadHeader(), loadHierarchy(), loadJunction(), loadNoConnect(), loadPageSettings(), loadSheet(), loadText(), loadWire(), m_error, saveBitmap(), saveBusEntry(), saveComponent(), saveField(), saveJunction(), saveLine(), saveNoConnect(), saveSheet(), saveText(), and writeDocFile().

129 { return m_error; }
wxString m_error
For throwing exceptions or errors on partial schematic loads.
const wxString SCH_LEGACY_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Returns the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 72 of file sch_legacy_plugin.h.

73  {
74  return wxT( "sch" );
75  }
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 4081 of file sch_legacy_plugin.cpp.

4082 {
4083  if( m_cache )
4084  return m_cache->GetModifyHash();
4085 
4086  // If the cache hasn't been loaded, it hasn't been modified.
4087  return 0;
4088 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
const wxString SCH_LEGACY_PLUGIN::GetName ( ) const
inlineoverridevirtual

Returns a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 67 of file sch_legacy_plugin.h.

68  {
69  return wxT( "Eeschema-Legacy" );
70  }
size_t SCH_LEGACY_PLUGIN::GetSymbolLibCount ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Reimplemented from SCH_PLUGIN.

Definition at line 4091 of file sch_legacy_plugin.cpp.

4093 {
4094  LOCALE_IO toggle;
4095 
4096  m_props = aProperties;
4097 
4098  cacheLib( aLibraryPath );
4099 
4100  return m_cache->m_aliases.size();
4101 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
SCH_LEGACY_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.
void SCH_LEGACY_PLUGIN::init ( KIWAY aKiway,
const PROPERTIES aProperties = NULL 
)
protected

initialize PLUGIN like a constructor would.

Definition at line 569 of file sch_legacy_plugin.cpp.

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

Definition at line 4075 of file sch_legacy_plugin.cpp.

References PROPERTIES::Exists(), and PropBuffering.

Referenced by GetError().

4076 {
4077  return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
4078 }
bool Exists(const std::string &aProperty) const
Definition: properties.h:44
static const char * PropBuffering
const char* PropBuffering
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 4290 of file sch_legacy_plugin.cpp.

References PropBuffering, and PropNoDocFile.

4291 {
4292  return wxFileName::IsFileWritable( aLibraryPath );
4293 }
SCH_SHEET * SCH_LEGACY_PLUGIN::Load ( const wxString &  aFileName,
KIWAY aKiway,
SCH_SHEET aAppendToMe = NULL,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 580 of file sch_legacy_plugin.cpp.

References SCH_SHEET::GetFileName(), PROJECT::GetProjectPath(), SCH_SHEET::GetRootSheet(), KIWAY::Prj(), and traceSchLegacyPlugin.

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

Definition at line 1052 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

1053 {
1054  std::unique_ptr< SCH_BITMAP > bitmap( new SCH_BITMAP );
1055 
1056  const char* line = aReader.Line();
1057 
1058  wxCHECK( strCompare( "$Bitmap", line, &line ), NULL );
1059 
1060  line = aReader.ReadLine();
1061 
1062  while( line != NULL )
1063  {
1064  if( strCompare( "Pos", line, &line ) )
1065  {
1066  wxPoint position;
1067 
1068  position.x = parseInt( aReader, line, &line );
1069  position.y = parseInt( aReader, line, &line );
1070  bitmap->SetPosition( position );
1071  }
1072  else if( strCompare( "Scale", line, &line ) )
1073  {
1075  bitmap->GetImage()->SetScale( parseDouble( aReader, line, &line ) );
1076  }
1077  else if( strCompare( "Data", line, &line ) )
1078  {
1079  wxMemoryOutputStream stream;
1080 
1081  while( line )
1082  {
1083  if( !aReader.ReadLine() )
1084  SCH_PARSE_ERROR( _( "Unexpected end of file" ), aReader, line );
1085 
1086  line = aReader.Line();
1087 
1088  if( strCompare( "EndData", line ) )
1089  {
1090  // all the PNG date is read.
1091  // We expect here m_image and m_bitmap are void
1092  wxImage* image = new wxImage();
1093  wxMemoryInputStream istream( stream );
1094  image->LoadFile( istream, wxBITMAP_TYPE_PNG );
1095  bitmap->GetImage()->SetImage( image );
1096  bitmap->GetImage()->SetBitmap( new wxBitmap( *image ) );
1097  break;
1098  }
1099 
1100  // Read PNG data, stored in hexadecimal,
1101  // each byte = 2 hexadecimal digits and a space between 2 bytes
1102  // and put it in memory stream buffer
1103  int len = strlen( line );
1104 
1105  for( ; len > 0 && !isspace( *line ); len -= 3, line += 3 )
1106  {
1107  int value = 0;
1108 
1109  if( sscanf( line, "%X", &value ) == 1 )
1110  stream.PutC( (char) value );
1111  else
1112  THROW_IO_ERROR( "invalid PNG data" );
1113  }
1114  }
1115 
1116  if( line == NULL )
1117  THROW_IO_ERROR( _( "unexpected end of file" ) );
1118  }
1119  else if( strCompare( "$EndBitmap", line ) )
1120  return bitmap.release();
1121 
1122  line = aReader.ReadLine();
1123  }
1124 
1125  THROW_IO_ERROR( _( "unexpected end of file" ) );
1126 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
static int parseInt(FILE_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 double parseDouble(FILE_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 ...
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
SCH_BUS_ENTRY_BASE * SCH_LEGACY_PLUGIN::loadBusEntry ( FILE_LINE_READER aReader)
private

Definition at line 1265 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

1266 {
1267  const char* line = aReader.Line();
1268 
1269  wxCHECK( strCompare( "Entry", line, &line ), NULL );
1270 
1271  std::unique_ptr< SCH_BUS_ENTRY_BASE > busEntry;
1272 
1273  if( strCompare( "Wire", line, &line ) )
1274  {
1275  busEntry.reset( new SCH_BUS_WIRE_ENTRY );
1276 
1277  if( !strCompare( "Line", line, &line ) )
1278  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
1279  }
1280  else if( strCompare( "Bus", line, &line ) )
1281  {
1282  busEntry.reset( new SCH_BUS_BUS_ENTRY );
1283 
1284  if( !strCompare( "Bus", line, &line ) )
1285  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
1286  }
1287  else
1288  SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
1289 
1290  line = aReader.ReadLine();
1291 
1292  wxPoint pos;
1293  wxSize size;
1294 
1295  pos.x = parseInt( aReader, line, &line );
1296  pos.y = parseInt( aReader, line, &line );
1297  size.x = parseInt( aReader, line, &line );
1298  size.y = parseInt( aReader, line, &line );
1299 
1300  size.x -= pos.x;
1301  size.y -= pos.y;
1302 
1303  busEntry->SetPosition( pos );
1304  busEntry->SetSize( size );
1305 
1306  return busEntry.release();
1307 }
Class for a bus to bus entry.
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
static int parseInt(FILE_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...
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
Class for a wire to bus entry.
SCH_COMPONENT * SCH_LEGACY_PLUGIN::loadComponent ( FILE_LINE_READER aReader)
private

Definition at line 1406 of file sch_legacy_plugin.cpp.

References TEMPLATE_FIELDNAME::GetDefaultFieldName(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, LINE_READER::Line(), MANDATORY_FIELDS, MAX_UNIT_COUNT_PER_PACKAGE, name, LIB_ID::Parse(), parseChar(), parseHex(), parseInt(), parseQuotedString(), parseUnquotedString(), FILE_LINE_READER::ReadLine(), REFERENCE, SCH_PARSE_ERROR, LIB_ID::SetLibItemName(), strCompare(), TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, wxPoint::x, TRANSFORM::x1, TRANSFORM::x2, wxPoint::y, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by GetError().

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

Definition at line 729 of file sch_legacy_plugin.cpp.

References SCH_SCREEN::Append(), LINE_READER::Line(), SCH_LEGACY_PLUGIN_CACHE::loadHeader(), SCH_LEGACY_PLUGIN_CACHE::loadText(), FILE_LINE_READER::ReadLine(), strCompare(), and THROW_IO_ERROR.

Referenced by GetError().

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

Definition at line 773 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

774 {
775  const char* line = aReader.ReadLine();
776 
777  if( !line || !strCompare( "Eeschema Schematic File Version", line, &line ) )
778  {
779  m_error.Printf( _( "\"%s\" does not appear to be an Eeschema file" ),
780  GetChars( aScreen->GetFileName() ) );
782  }
783 
784  // get the file version here.
785  m_version = parseInt( aReader, line, &line );
786 
787  // The next lines are the lib list section, and are mainly comments, like:
788  // LIBS:power
789  // the lib list is not used, but is in schematic file just in case.
790  // It is usually not empty, but we accept empty list.
791  // If empty, there is a legacy section, not used
792  // EELAYER i j
793  // and the last line is
794  // EELAYER END
795  // Skip all lines until the end of header "EELAYER END" is found
796  while( aReader.ReadLine() )
797  {
798  line = aReader.Line();
799 
800  while( *line == ' ' )
801  line++;
802 
803  if( strCompare( "EELAYER END", line ) )
804  return;
805  }
806 
807  THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
808 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
wxString m_error
For throwing exceptions or errors on partial schematic loads.
static int parseInt(FILE_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 wxString & GetFileName() const
Definition: sch_screen.h:120
int m_version
Version of file being loaded.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
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
void SCH_LEGACY_PLUGIN::loadHierarchy ( SCH_SHEET aSheet)
private

Definition at line 648 of file sch_legacy_plugin.cpp.

References SCH_SCREEN::GetDrawItems(), SCH_SHEET::GetFileName(), SCH_SHEET::GetScreen(), SCH_SHEET_T, SCH_SCREEN::SetFileName(), EDA_ITEM::SetParent(), SCH_SHEET::SetScreen(), traceSchLegacyPlugin, and IO_ERROR::What().

Referenced by GetError().

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

Definition at line 1129 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

1130 {
1131  std::unique_ptr< SCH_JUNCTION > junction( new SCH_JUNCTION );
1132 
1133  const char* line = aReader.Line();
1134 
1135  wxCHECK( strCompare( "Connection", line, &line ), NULL );
1136 
1137  wxString name;
1138 
1139  parseUnquotedString( name, aReader, line, &line );
1140 
1141  wxPoint position;
1142 
1143  position.x = parseInt( aReader, line, &line );
1144  position.y = parseInt( aReader, line, &line );
1145  junction->SetPosition( position );
1146 
1147  return junction.release();
1148 }
static int parseInt(FILE_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 void parseUnquotedString(wxString &aString, FILE_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.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
const char * name
Definition: DXF_plotter.cpp:61
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
SCH_NO_CONNECT * SCH_LEGACY_PLUGIN::loadNoConnect ( FILE_LINE_READER aReader)
private

Definition at line 1151 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

1152 {
1153  std::unique_ptr< SCH_NO_CONNECT > no_connect( new SCH_NO_CONNECT );
1154 
1155  const char* line = aReader.Line();
1156 
1157  wxCHECK( strCompare( "NoConn", line, &line ), NULL );
1158 
1159  wxString name;
1160 
1161  parseUnquotedString( name, aReader, line, &line );
1162 
1163  wxPoint position;
1164 
1165  position.x = parseInt( aReader, line, &line );
1166  position.y = parseInt( aReader, line, &line );
1167  no_connect->SetPosition( position );
1168 
1169  return no_connect.release();
1170 }
static int parseInt(FILE_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 void parseUnquotedString(wxString &aString, FILE_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.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
const char * name
Definition: DXF_plotter.cpp:61
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SCH_LEGACY_PLUGIN::loadPageSettings ( FILE_LINE_READER aReader,
SCH_SCREEN aScreen 
)
private

Definition at line 811 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

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

Definition at line 915 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

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

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

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4148 of file sch_legacy_plugin.cpp.

4150 {
4151  LOCALE_IO toggle; // toggles on, then off, the C locale.
4152 
4153  m_props = aProperties;
4154 
4155  cacheLib( aLibraryPath );
4156 
4157  LIB_ALIAS_MAP::const_iterator it = m_cache->m_aliases.find( aAliasName );
4158 
4159  if( it == m_cache->m_aliases.end() )
4160  return NULL;
4161 
4162  return it->second;
4163 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
SCH_LEGACY_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.
SCH_TEXT * SCH_LEGACY_PLUGIN::loadText ( FILE_LINE_READER aReader)
private

Definition at line 1310 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

1311 {
1312  const char* line = aReader.Line();
1313 
1314  wxCHECK( strCompare( "Text", line, &line ), NULL );
1315 
1316  std::unique_ptr< SCH_TEXT> text;
1317 
1318  if( strCompare( "Notes", line, &line ) )
1319  text.reset( new SCH_TEXT );
1320  else if( strCompare( "Label", line, &line ) )
1321  text.reset( new SCH_LABEL );
1322  else if( strCompare( "HLabel", line, &line ) )
1323  text.reset( new SCH_HIERLABEL );
1324  else if( strCompare( "GLabel", line, &line ) )
1325  {
1326  // Prior to version 2, the SCH_GLOBALLABEL object did not exist.
1327  if( m_version == 1 )
1328  text.reset( new SCH_HIERLABEL );
1329  else
1330  text.reset( new SCH_GLOBALLABEL );
1331  }
1332  else
1333  SCH_PARSE_ERROR( "unknown Text type", aReader, line );
1334 
1335  // Parse the parameters common to all text objects.
1336  wxPoint position;
1337 
1338  position.x = parseInt( aReader, line, &line );
1339  position.y = parseInt( aReader, line, &line );
1340  text->SetPosition( position );
1341  text->SetLabelSpinStyle( parseInt( aReader, line, &line ) );
1342 
1343  int size = parseInt( aReader, line, &line );
1344 
1345  text->SetTextSize( wxSize( size, size ) );
1346 
1347  // Parse the global and hierarchical label type.
1348  if( text->Type() == SCH_HIERARCHICAL_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
1349  {
1350  if( strCompare( SheetLabelType[NET_INPUT], line, &line ) )
1351  text->SetShape( NET_INPUT );
1352  else if( strCompare( SheetLabelType[NET_OUTPUT], line, &line ) )
1353  text->SetShape( NET_OUTPUT );
1354  else if( strCompare( SheetLabelType[NET_BIDI], line, &line ) )
1355  text->SetShape( NET_BIDI );
1356  else if( strCompare( SheetLabelType[NET_TRISTATE], line, &line ) )
1357  text->SetShape( NET_TRISTATE );
1358  else if( strCompare( SheetLabelType[NET_UNSPECIFIED], line, &line ) )
1359  text->SetShape( NET_UNSPECIFIED );
1360  else
1361  SCH_PARSE_ERROR( "invalid label type", aReader, line );
1362  }
1363 
1364  int thickness = 0;
1365 
1366  // The following tokens do not exist in version 1 schematic files.
1367  if( m_version > 1 )
1368  {
1369  if( strCompare( "Italic", line, &line ) )
1370  text->SetItalic( true );
1371  else if( !strCompare( "~", line, &line ) )
1372  SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
1373 
1374  // The thickness token does not exist in older versions of the schematic file format
1375  // so calling parseInt will be made only if the EOL is not reached.
1376  if( *line >= ' ' )
1377  thickness = parseInt( aReader, line, &line );
1378  }
1379 
1380  text->SetBold( thickness != 0 );
1381  text->SetThickness( thickness != 0 ? GetPenSizeForBold( size ) : 0 );
1382 
1383  // Read the text string for the text.
1384  char* tmp = aReader.ReadLine();
1385 
1386  tmp = strtok( tmp, "\r\n" );
1387  wxString val = FROM_UTF8( tmp );
1388 
1389  for( ; ; )
1390  {
1391  int i = val.find( wxT( "\\n" ) );
1392 
1393  if( i == wxNOT_FOUND )
1394  break;
1395 
1396  val.erase( i, 2 );
1397  val.insert( i, wxT( "\n" ) );
1398  }
1399 
1400  text->SetText( val );
1401 
1402  return text.release();
1403 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
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:53
int GetPenSizeForBold(int aTextSize)
Function GetPensizeForBold.
static int parseInt(FILE_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 * SheetLabelType[]
Definition: sch_text.cpp:58
int m_version
Version of file being loaded.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
#define SCH_PARSE_ERROR(text, reader, pos)
size_t i
Definition: json11.cpp:597
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
SCH_LINE * SCH_LEGACY_PLUGIN::loadWire ( FILE_LINE_READER aReader)
private

Definition at line 1173 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

1174 {
1175  std::unique_ptr< SCH_LINE > wire( new SCH_LINE );
1176 
1177  const char* line = aReader.Line();
1178 
1179  wxCHECK( strCompare( "Wire", line, &line ), NULL );
1180 
1181  if( strCompare( "Wire", line, &line ) )
1182  wire->SetLayer( LAYER_WIRE );
1183  else if( strCompare( "Bus", line, &line ) )
1184  wire->SetLayer( LAYER_BUS );
1185  else if( strCompare( "Notes", line, &line ) )
1186  wire->SetLayer( LAYER_NOTES );
1187  else
1188  SCH_PARSE_ERROR( "invalid line type", aReader, line );
1189 
1190  if( !strCompare( "Line", line, &line ) )
1191  SCH_PARSE_ERROR( "invalid wire definition", aReader, line );
1192 
1193  // Since Sept 15, 2017, a line style is alloved (width, style, color)
1194  // Only non default values are stored
1195  while( !is_eol( *line ) )
1196  {
1197  wxString buf;
1198 
1199  parseUnquotedString( buf, aReader, line, &line );
1200 
1201  if( buf == ")" )
1202  continue;
1203 
1204  else if( buf == T_WIDTH )
1205  {
1206  int size = parseInt( aReader, line, &line );
1207  wire->SetLineWidth( size );
1208  }
1209  else if( buf == T_STYLE )
1210  {
1211  parseUnquotedString( buf, aReader, line, &line );
1212  int style = SCH_LINE::GetLineStyleInternalId( buf );
1213  wire->SetLineStyle( style );
1214  }
1215  else // should be the color parameter.
1216  {
1217  // The color param is something like rgb(150, 40, 191)
1218  // and because there is no space between ( and 150
1219  // the first param is inside buf.
1220  // So break keyword and the first param into 2 separate strings.
1221  wxString prm, keyword;
1222  keyword = buf.BeforeLast( '(', &prm );
1223 
1224  if( ( keyword == T_COLOR ) || ( keyword == T_COLORA ) )
1225  {
1226  long color[4] = { 0 };
1227 
1228  int ii = 0;
1229 
1230  if( !prm.IsEmpty() )
1231  {
1232  prm.ToLong( &color[ii] );
1233  ii++;
1234  }
1235 
1236  int prm_count = ( keyword == T_COLORA ) ? 4 : 3;
1237  // fix opacity to 1.0 or 255, when not exists in file
1238  color[3] = 255;
1239 
1240  for(; ii < prm_count && !is_eol( *line ); ii++ )
1241  color[ii] = parseInt( aReader, line, &line );
1242 
1243  wire->SetLineColor( color[0]/255.0, color[1]/255.0, color[2]/255.0,color[3]/255.0 );
1244  }
1245  }
1246  }
1247 
1248  // Read the segment en points coordinates:
1249  line = aReader.ReadLine();
1250 
1251  wxPoint begin, end;
1252 
1253  begin.x = parseInt( aReader, line, &line );
1254  begin.y = parseInt( aReader, line, &line );
1255  end.x = parseInt( aReader, line, &line );
1256  end.y = parseInt( aReader, line, &line );
1257 
1258  wire->SetStartPoint( begin );
1259  wire->SetEndPoint( end );
1260 
1261  return wire.release();
1262 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:194
static int parseInt(FILE_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 color
Definition: DXF_plotter.cpp:62
#define T_WIDTH
#define T_STYLE
static void parseUnquotedString(wxString &aString, FILE_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.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
static bool is_eol(char c)
#define T_COLOR
static int GetLineStyleInternalId(const wxString &aStyleName)
Definition: sch_line.cpp:138
#define SCH_PARSE_ERROR(text, reader, pos)
Segment description base class to describe items which have 2 end points (track, wire, draw line ...)
Definition: sch_line.h:41
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define T_COLORA
void SCH_LEGACY_PLUGIN::Save ( const wxString &  aFileName,
SCH_SCREEN aSchematic,
KIWAY aKiway,
const PROPERTIES aProperties = NULL 
)
overridevirtual

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

Parameters
aFileNameis the name of a file to save to on disk.
aSchematicis the class SCH_SCREEN in memory document tree from which to extract information when writing to aFileName. The caller continues to own the SCHEMATIC, and the plugin should refrain from modifying the SCHEMATIC if possible.
aKiwayis the KIWAY object used to access the component libraries loaded by the project.
aPropertiesis an associative array that can be used to tell the saver how to save the file, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented from SCH_PLUGIN.

Definition at line 1683 of file sch_legacy_plugin.cpp.

References Format().

1685 {
1686  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN object." );
1687  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1688 
1689  LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
1690 
1691  init( aKiway, aProperties );
1692 
1693  wxFileName fn = aFileName;
1694 
1695  // File names should be absolute. Don't assume everything relative to the project path
1696  // works properly.
1697  wxASSERT( fn.IsAbsolute() );
1698 
1699  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1700 
1701  m_out = &formatter; // no ownership
1702 
1703  Format( aScreen );
1704 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown...
Definition: common.h:167
void Format(SCH_SCREEN *aScreen)
void init(KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
initialize PLUGIN like a constructor would.
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
void SCH_LEGACY_PLUGIN::saveBitmap ( SCH_BITMAP aBitmap)
private

Definition at line 1925 of file sch_legacy_plugin.cpp.

References SCH_BITMAP::GetImage(), BITMAP_BASE::GetImageData(), SCH_BITMAP::GetPosition(), BITMAP_BASE::GetScale(), wxPoint::x, and wxPoint::y.

Referenced by GetError().

1926 {
1927  wxCHECK_RET( aBitmap != NULL, "SCH_BITMAP* is NULL" );
1928 
1929  wxImage* image = aBitmap->GetImage()->GetImageData();
1930 
1931  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
1932 
1933  m_out->Print( 0, "$Bitmap\n" );
1934  m_out->Print( 0, "Pos %-4d %-4d\n", aBitmap->GetPosition().x, aBitmap->GetPosition().y );
1935  m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
1936  m_out->Print( 0, "Data\n" );
1937 
1938  wxMemoryOutputStream stream;
1939 
1940  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1941 
1942  // Write binary data in hexadecimal form (ASCII)
1943  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1944  char* begin = (char*) buffer->GetBufferStart();
1945 
1946  for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
1947  {
1948  if( ii >= 32 )
1949  {
1950  ii = 0;
1951 
1952  m_out->Print( 0, "\n" );
1953  }
1954 
1955  m_out->Print( 0, "%2.2X ", *begin & 0xFF );
1956  }
1957 
1958  m_out->Print( 0, "\nEndData\n" );
1959  m_out->Print( 0, "$EndBitmap\n" );
1960 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxImage * GetImageData()
Definition: bitmap_base.h:75
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_bitmap.h:133
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:65
double GetScale() const
Definition: bitmap_base.h:82
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void SCH_LEGACY_PLUGIN::saveBusEntry ( SCH_BUS_ENTRY_BASE aBusEntry)
private

Definition at line 2056 of file sch_legacy_plugin.cpp.

References SCH_ITEM::GetLayer(), SCH_BUS_ENTRY_BASE::GetPosition(), LAYER_WIRE, SCH_BUS_ENTRY_BASE::m_End(), wxPoint::x, and wxPoint::y.

Referenced by GetError().

2057 {
2058  wxCHECK_RET( aBusEntry != NULL, "SCH_BUS_ENTRY_BASE* is NULL" );
2059 
2060  if( aBusEntry->GetLayer() == LAYER_WIRE )
2061  m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
2062  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
2063  aBusEntry->m_End().x, aBusEntry->m_End().y );
2064  else
2065  m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
2066  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
2067  aBusEntry->m_End().x, aBusEntry->m_End().y );
2068 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
wxPoint m_End() const
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxPoint GetPosition() const override
Function GetPosition.
void SCH_LEGACY_PLUGIN::saveComponent ( SCH_COMPONENT aComponent)
private

Definition at line 1788 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

1789 {
1790  std::string name1;
1791  std::string name2;
1792  wxArrayString reference_fields;
1793 
1794  static wxString delimiters( wxT( " " ) );
1795 
1796  // This is redundant with the AR entries below, but it makes the files backwards-compatible.
1797  if( aComponent->GetPathsAndReferences().GetCount() > 0 )
1798  {
1799  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[0], delimiters );
1800  name1 = toUTFTildaText( reference_fields[1] );
1801  }
1802  else
1803  {
1804  if( aComponent->GetField( REFERENCE )->GetText().IsEmpty() )
1805  name1 = toUTFTildaText( aComponent->GetPrefix() );
1806  else
1807  name1 = toUTFTildaText( aComponent->GetField( REFERENCE )->GetText() );
1808  }
1809 
1810  wxString part_name = aComponent->GetLibId().Format();
1811 
1812  if( part_name.size() )
1813  {
1814  name2 = toUTFTildaText( part_name );
1815  }
1816  else
1817  {
1818  name2 = "_NONAME_";
1819  }
1820 
1821  m_out->Print( 0, "$Comp\n" );
1822  m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
1823 
1824  // Generate unit number, convert and time stamp
1825  m_out->Print( 0, "U %d %d %8.8lX\n", aComponent->GetUnit(), aComponent->GetConvert(),
1826  (unsigned long)aComponent->GetTimeStamp() );
1827 
1828  // Save the position
1829  m_out->Print( 0, "P %d %d\n", aComponent->GetPosition().x, aComponent->GetPosition().y );
1830 
1831  /* If this is a complex hierarchy; save hierarchical references.
1832  * but for simple hierarchies it is not necessary.
1833  * the reference inf is already saved
1834  * this is useful for old Eeschema version compatibility
1835  */
1836  if( aComponent->GetPathsAndReferences().GetCount() > 1 )
1837  {
1838  for( unsigned int ii = 0; ii < aComponent->GetPathsAndReferences().GetCount(); ii++ )
1839  {
1840  /*format:
1841  * AR Path="/140/2" Ref="C99" Part="1"
1842  * where 140 is the uid of the containing sheet
1843  * and 2 is the timestamp of this component.
1844  * (timestamps are actually 8 hex chars)
1845  * Ref is the conventional component reference for this 'path'
1846  * Part is the conventional component part selection for this 'path'
1847  */
1848  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[ii],
1849  delimiters );
1850 
1851  m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%s\" \n",
1852  TO_UTF8( reference_fields[0] ),
1853  TO_UTF8( reference_fields[1] ),
1854  TO_UTF8( reference_fields[2] ) );
1855  }
1856  }
1857 
1858  // update the ugly field index, which I would like to see go away someday soon.
1859  for( int i = 0; i < aComponent->GetFieldCount(); ++i )
1860  aComponent->GetField( i )->SetId( i );
1861 
1862  // Fixed fields:
1863  // Save mandatory fields even if they are blank,
1864  // because the visibility, size and orientation are set from libary editor.
1865  for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
1866  saveField( aComponent->GetField( i ) );
1867 
1868  // User defined fields:
1869  // The *policy* about which user defined fields are part of a symbol is now
1870  // only in the dialog editors. No policy should be enforced here, simply
1871  // save all the user defined fields, they are present because a dialog editor
1872  // thought they should be. If you disagree, go fix the dialog editors.
1873  for( int i = MANDATORY_FIELDS; i < aComponent->GetFieldCount(); ++i )
1874  saveField( aComponent->GetField( i ) );
1875 
1876  // Unit number, position, box ( old standard )
1877  m_out->Print( 0, "\t%-4d %-4d %-4d\n", aComponent->GetUnit(), aComponent->GetPosition().x,
1878  aComponent->GetPosition().y );
1879 
1880  TRANSFORM transform = aComponent->GetTransform();
1881 
1882  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
1883  transform.x1, transform.y1, transform.x2, transform.y2 );
1884  m_out->Print( 0, "$EndComp\n" );
1885 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
TRANSFORM & GetTransform() const
int y2
Definition: transform.h:51
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
wxString GetPrefix() const
int x2
Definition: transform.h:50
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:47
int GetConvert() const
int y1
Definition: transform.h:49
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
const wxArrayString & GetPathsAndReferences() const
std::string toUTFTildaText(const wxString &txt)
Function toUTFTildaText convert a wxString to UTF8 and replace any control characters with a ~...
int GetUnit() const
int GetFieldCount() const
Return the number of fields in this symbol.
size_t i
Definition: json11.cpp:597
wxPoint GetPosition() const override
Function GetPosition.
const LIB_ID & GetLibId() const
UTF8 Format() const
Definition: lib_id.cpp:263
void SetId(int aId)
Definition: sch_field.h:89
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
void SCH_LEGACY_PLUGIN::saveField ( SCH_FIELD aField)
private

Definition at line 1888 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

1889 {
1890  char hjustify = 'C';
1891 
1892  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
1893  hjustify = 'L';
1894  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
1895  hjustify = 'R';
1896 
1897  char vjustify = 'C';
1898 
1899  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
1900  vjustify = 'B';
1901  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
1902  vjustify = 'T';
1903 
1904  m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1905  aField->GetId(),
1906  EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
1907  aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
1908  aField->GetLibPosition().x, aField->GetLibPosition().y,
1909  aField->GetTextWidth(),
1910  !aField->IsVisible(),
1911  hjustify, vjustify,
1912  aField->IsItalic() ? 'I' : 'N',
1913  aField->IsBold() ? 'B' : 'N' );
1914 
1915  // Save field name, if the name is user definable
1916  if( aField->GetId() >= FIELD1 )
1917  {
1918  m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
1919  }
1920 
1921  m_out->Print( 0, "\n" );
1922 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:438
bool IsItalic() const
Definition: eda_text.h:168
int GetId() const
Definition: sch_field.h:87
int GetTextWidth() const
Definition: eda_text.h:216
wxPoint GetLibPosition() const
Definition: sch_field.h:187
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:188
bool IsBold() const
Definition: eda_text.h:171
double GetTextAngle() const
Definition: eda_text.h:162
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:137
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:189
bool IsVisible() const
Definition: eda_text.h:174
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void SCH_LEGACY_PLUGIN::saveJunction ( SCH_JUNCTION aJunction)
private

Definition at line 2038 of file sch_legacy_plugin.cpp.

References SCH_JUNCTION::GetPosition(), wxPoint::x, and wxPoint::y.

Referenced by GetError().

2039 {
2040  wxCHECK_RET( aJunction != NULL, "SCH_JUNCTION* is NULL" );
2041 
2042  m_out->Print( 0, "Connection ~ %-4d %-4d\n",
2043  aJunction->GetPosition().x, aJunction->GetPosition().y );
2044 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_junction.h:94
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void SCH_LEGACY_PLUGIN::SaveLibrary ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Reimplemented from SCH_PLUGIN.

Definition at line 4256 of file sch_legacy_plugin.cpp.

References SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN_CACHE().

4257 {
4258  if( !m_cache )
4259  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4260 
4261  wxString oldFileName = m_cache->GetFileName();
4262 
4263  if( !m_cache->IsFile( aLibraryPath ) )
4264  {
4265  m_cache->SetFileName( aLibraryPath );
4266  }
4267 
4268  // This is a forced save.
4269  m_cache->SetModified();
4270  m_cache->Save( writeDocFile( aProperties ) );
4271  m_cache->SetFileName( oldFileName );
4272 }
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...
wxString GetFileName() const
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)
void SCH_LEGACY_PLUGIN::saveLine ( SCH_LINE aLine)
private

Definition at line 2071 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

2072 {
2073  wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" );
2074 
2075  const char* layer = "Notes";
2076  const char* width = "Line";
2077 
2078  if( aLine->GetLayer() == LAYER_WIRE )
2079  layer = "Wire";
2080  else if( aLine->GetLayer() == LAYER_BUS )
2081  layer = "Bus";
2082 
2083  m_out->Print( 0, "Wire %s %s", layer, width );
2084 
2085  // Write line style (width, type, color) only for non default values
2086  if( aLine->GetLayer() == LAYER_NOTES )
2087  {
2088  if( aLine->GetPenSize() != aLine->GetDefaultWidth() )
2089  m_out->Print( 0, " %s %d", T_WIDTH, aLine->GetLineSize() );
2090 
2091  if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
2092  m_out->Print( 0, " %s %s", T_STYLE, SCH_LINE::GetLineStyleName( aLine->GetLineStyle() ) );
2093 
2094  if( aLine->GetLineColor() != aLine->GetDefaultColor() )
2095  m_out->Print( 0, " %s",
2096  TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
2097  }
2098 
2099  m_out->Print( 0, "\n" );
2100 
2101  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
2102  aLine->GetStartPoint().x, aLine->GetStartPoint().y,
2103  aLine->GetEndPoint().x, aLine->GetEndPoint().y );
2104 
2105  m_out->Print( 0, "\n");
2106 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
COLOR4D GetLineColor() const
Definition: sch_line.cpp:241
wxPoint GetEndPoint() const
Definition: sch_line.h:80
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
#define T_WIDTH
#define T_STYLE
wxPoint GetStartPoint() const
Definition: sch_line.h:76
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
COLOR4D GetDefaultColor() const
Definition: sch_line.cpp:211
int GetLineStyle() const
Definition: sch_line.cpp:267
int GetDefaultWidth() const
Definition: sch_line.cpp:276
int GetLineSize() const
Definition: sch_line.h:110
static const char * GetLineStyleName(int aStyle)
Definition: sch_line.cpp:110
int GetDefaultStyle() const
Definition: sch_line.cpp:249
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:294
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void SCH_LEGACY_PLUGIN::saveNoConnect ( SCH_NO_CONNECT aNoConnect)
private

Definition at line 2047 of file sch_legacy_plugin.cpp.

References SCH_NO_CONNECT::GetPosition(), wxPoint::x, and wxPoint::y.

Referenced by GetError().

2048 {
2049  wxCHECK_RET( aNoConnect != NULL, "SCH_NOCONNECT* is NULL" );
2050 
2051  m_out->Print( 0, "NoConn ~ %-4d %-4d\n", aNoConnect->GetPosition().x,
2052  aNoConnect->GetPosition().y );
2053 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxPoint GetPosition() const override
Function GetPosition.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void SCH_LEGACY_PLUGIN::saveSheet ( SCH_SHEET aSheet)
private

Definition at line 1963 of file sch_legacy_plugin.cpp.

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

Referenced by GetError().

1964 {
1965  wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" );
1966 
1967  m_out->Print( 0, "$Sheet\n" );
1968  m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
1969  aSheet->GetPosition().x, aSheet->GetPosition().y,
1970  aSheet->GetSize().x, aSheet->GetSize().y );
1971 
1972  m_out->Print( 0, "U %8.8lX\n", (unsigned long) aSheet->GetTimeStamp() );
1973 
1974  if( !aSheet->GetName().IsEmpty() )
1975  m_out->Print( 0, "F0 %s %d\n", EscapedUTF8( aSheet->GetName() ).c_str(),
1976  aSheet->GetSheetNameSize() );
1977 
1978  if( !aSheet->GetFileName().IsEmpty() )
1979  m_out->Print( 0, "F1 %s %d\n", EscapedUTF8( aSheet->GetFileName() ).c_str(),
1980  aSheet->GetFileNameSize() );
1981 
1982  for( const SCH_SHEET_PIN& pin : aSheet->GetPins() )
1983  {
1984  int type, side;
1985 
1986  if( pin.GetText().IsEmpty() )
1987  break;
1988 
1989  switch( pin.GetEdge() )
1990  {
1991  default:
1993  side = 'L';
1994  break;
1995 
1997  side = 'R';
1998  break;
1999 
2001  side = 'T';
2002  break;
2003 
2005  side = 'B';
2006  break;
2007  }
2008 
2009  switch( pin.GetShape() )
2010  {
2011  case NET_INPUT:
2012  type = 'I'; break;
2013 
2014  case NET_OUTPUT:
2015  type = 'O'; break;
2016 
2017  case NET_BIDI:
2018  type = 'B'; break;
2019 
2020  case NET_TRISTATE:
2021  type = 'T'; break;
2022 
2023  default:
2024  case NET_UNSPECIFIED:
2025  type = 'U'; break;
2026  }
2027 
2028  m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n", pin.GetNumber(),
2029  EscapedUTF8( pin.GetText() ).c_str(), // supplies wrapping quotes
2030  type, side, pin.GetPosition().x, pin.GetPosition().y,
2031  pin.GetTextWidth() );
2032  }
2033 
2034  m_out->Print( 0, "$EndSheet\n" );
2035 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
SCH_SHEET_PINS & GetPins()
Definition: sch_sheet.h:334
int GetSheetNameSize() const
Definition: sch_sheet.h:271
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:137
int GetFileNameSize() const
Definition: sch_sheet.h:275
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:61
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:547
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:646
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
wxString GetName() const
Definition: sch_sheet.h:267
wxSize GetSize()
Definition: sch_sheet.h:281
timestamp_t GetTimeStamp() const
Definition: base_struct.h:215
void SCH_LEGACY_PLUGIN::SaveSymbol ( const wxString &  aLibraryPath,
const LIB_PART aSymbol,
const PROPERTIES aProperties = NULL 
)
overridevirtual

Write aSymbol to an existing library located at aLibraryPath.

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4166 of file sch_legacy_plugin.cpp.

4168 {
4169  m_props = aProperties;
4170 
4171  cacheLib( aLibraryPath );
4172 
4173  m_cache->AddSymbol( aSymbol );
4174 
4175  if( !isBuffering( aProperties ) )
4176  m_cache->Save( writeDocFile( aProperties ) );
4177 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
bool isBuffering(const PROPERTIES *aProperties)
void cacheLib(const wxString &aLibraryFileName)
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
void AddSymbol(const LIB_PART *aPart)
bool writeDocFile(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.
void SCH_LEGACY_PLUGIN::saveText ( SCH_TEXT aText)
private

Definition at line 2109 of file sch_legacy_plugin.cpp.

References SCH_TEXT::GetLabelSpinStyle(), SCH_ITEM::GetLayer(), SCH_TEXT::GetPosition(), SCH_TEXT::GetShape(), EDA_TEXT::GetText(), EDA_TEXT::GetTextWidth(), EDA_TEXT::GetThickness(), EDA_TEXT::IsItalic(), LAYER_GLOBLABEL, LAYER_HIERLABEL, LAYER_LOCLABEL, LAYER_NOTES, SCH_LEGACY_PLUGIN_CACHE::m_modHash, SheetLabelType, TO_UTF8, wxPoint::x, and wxPoint::y.

Referenced by GetError().

2110 {
2111  wxCHECK_RET( aText != NULL, "SCH_TEXT* is NULL" );
2112 
2113  const char* italics = "~";
2114  const char* textType = "Notes";
2115 
2116  if( aText->IsItalic() )
2117  italics = "Italic";
2118 
2119  wxString text = aText->GetText();
2120 
2121  SCH_LAYER_ID layer = aText->GetLayer();
2122 
2123  if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
2124  {
2125  if( layer == LAYER_NOTES )
2126  {
2127  // For compatibility reasons, the text must be saved in only one text line
2128  // so replace all EOLs with \\n
2129  text.Replace( wxT( "\n" ), wxT( "\\n" ) );
2130 
2131  // Here we should have no CR or LF character in line
2132  // This is not always the case if a multiline text was copied (using a copy/paste
2133  // function) from a text that uses E.O.L characters that differs from the current
2134  // EOL format. This is mainly the case under Linux using LF symbol when copying
2135  // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
2136  // (or LF left under MacOSX)
2137  for( unsigned ii = 0; ii < text.Len(); )
2138  {
2139  if( text[ii] == 0x0A || text[ii] == 0x0D )
2140  text.erase( ii, 1 );
2141  else
2142  ii++;
2143  }
2144  }
2145  else
2146  {
2147  textType = "Label";
2148  }
2149 
2150  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2151  aText->GetPosition().x, aText->GetPosition().y,
2152  aText->GetLabelSpinStyle(),
2153  aText->GetTextWidth(),
2154  italics, aText->GetThickness(), TO_UTF8( text ) );
2155  }
2156  else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2157  {
2158  textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2159 
2160  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2161  aText->GetPosition().x, aText->GetPosition().y,
2162  aText->GetLabelSpinStyle(),
2163  aText->GetTextWidth(),
2164  SheetLabelType[aText->GetShape()],
2165  italics,
2166  aText->GetThickness(), TO_UTF8( text ) );
2167  }
2168 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:118
bool IsItalic() const
Definition: eda_text.h:168
int GetTextWidth() const
Definition: eda_text.h:216
int GetLabelSpinStyle() const
Definition: sch_text.h:116
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
const char * SheetLabelType[]
Definition: sch_text.cpp:58
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:152
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
SCH_LAYER_ID
Eeschema drawing layers.
virtual wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_text.h:192
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void SCH_PLUGIN::SymbolLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.

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

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

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

Definition at line 149 of file sch_plugin.cpp.

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

Definition at line 4064 of file sch_legacy_plugin.cpp.

References PropNoDocFile.

Referenced by GetError().

4065 {
4066  std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
4067 
4068  if( aProperties && aProperties->find( propName ) != aProperties->end() )
4069  return false;
4070 
4071  return true;
4072 }
static const char * PropNoDocFile
const char* PropBuffering

Member Data Documentation

SCH_LEGACY_PLUGIN_CACHE* SCH_LEGACY_PLUGIN::m_cache
protected

Definition at line 171 of file sch_legacy_plugin.h.

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

Stack to maintain nested sheet paths.

Definition at line 166 of file sch_legacy_plugin.h.

wxString SCH_LEGACY_PLUGIN::m_error
protected

For throwing exceptions or errors on partial schematic loads.

Definition at line 163 of file sch_legacy_plugin.h.

Referenced by GetError().

KIWAY* SCH_LEGACY_PLUGIN::m_kiway
protected

Required for path to legacy component libraries.

Definition at line 168 of file sch_legacy_plugin.h.

FILE_OUTPUTFORMATTER* SCH_LEGACY_PLUGIN::m_out
protected

The output formatter for saving SCH_SCREEN objects.

Definition at line 170 of file sch_legacy_plugin.h.

wxString SCH_LEGACY_PLUGIN::m_path
protected

Root project path for loading child sheets.

Definition at line 165 of file sch_legacy_plugin.h.

const PROPERTIES* SCH_LEGACY_PLUGIN::m_props
protected

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

Definition at line 167 of file sch_legacy_plugin.h.

SCH_SHEET* SCH_LEGACY_PLUGIN::m_rootSheet
protected

The root sheet of the schematic being loaded..

Definition at line 169 of file sch_legacy_plugin.h.

int SCH_LEGACY_PLUGIN::m_version
protected

Version of file being loaded.

Definition at line 160 of file sch_legacy_plugin.h.

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

const char* PropBuffering

is a property used internally by the plugin to enable cache buffering which prevents the library file from being written every time the cache is changed. This is useful when writing the schematic cache library file or saving a library to a new file name.

Definition at line 84 of file sch_legacy_plugin.h.

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

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

const char* PropBuffering

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

Definition at line 92 of file sch_legacy_plugin.h.

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


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