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

Constructor & Destructor Documentation

SCH_LEGACY_PLUGIN::SCH_LEGACY_PLUGIN ( )

Definition at line 562 of file sch_legacy_plugin.cpp.

References init().

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

Definition at line 568 of file sch_legacy_plugin.cpp.

References m_cache.

569 {
570  delete m_cache;
571 }
SCH_LEGACY_PLUGIN_CACHE * m_cache

Member Function Documentation

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

Definition at line 3980 of file sch_legacy_plugin.cpp.

References isBuffering(), SCH_LEGACY_PLUGIN_CACHE::IsFile(), SCH_LEGACY_PLUGIN_CACHE::IsFileChanged(), SCH_LEGACY_PLUGIN_CACHE::Load(), m_cache, m_props, and PART_LIBS::s_modify_generation.

Referenced by DeleteAlias(), DeleteSymbol(), EnumerateSymbolLib(), GetSymbolLibCount(), LoadSymbol(), and SaveSymbol().

3981 {
3982  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
3983  {
3984  // a spectacular episode in memory management:
3985  delete m_cache;
3986  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
3987 
3988  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
3989  // to modify the hash value that indicate component to symbol links
3990  // must be updated.
3992 
3993  if( !isBuffering( m_props ) )
3994  m_cache->Load();
3995  }
3996 }
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 4210 of file sch_legacy_plugin.cpp.

4211 {
4212  // Open file and check first line
4213  wxTextFile tempFile;
4214 
4215  tempFile.Open( aFileName );
4216  wxString firstline;
4217  // read the first line
4218  firstline = tempFile.GetFirstLine();
4219  tempFile.Close();
4220 
4221  return firstline.StartsWith( "EESchema" );
4222 }
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 4143 of file sch_legacy_plugin.cpp.

References Format(), SCH_LEGACY_PLUGIN_CACHE::Load(), m_cache, m_props, SCH_LEGACY_PLUGIN_CACHE::Save(), SCH_LEGACY_PLUGIN_CACHE::SetModified(), THROW_IO_ERROR, and writeDocFile().

4145 {
4146  if( wxFileExists( aLibraryPath ) )
4147  {
4149  _( "symbol library \"%s\" already exists, cannot create a new library" ),
4150  aLibraryPath.GetData() ) );
4151  }
4152 
4153  LOCALE_IO toggle;
4154 
4155  m_props = aProperties;
4156 
4157  delete m_cache;
4158  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4159  m_cache->SetModified();
4160  m_cache->Save( writeDocFile( aProperties ) );
4161  m_cache->Load(); // update m_writable and m_mod_time
4162 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
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 4115 of file sch_legacy_plugin.cpp.

References cacheLib(), SCH_LEGACY_PLUGIN_CACHE::DeleteAlias(), isBuffering(), m_cache, m_props, SCH_LEGACY_PLUGIN_CACHE::Save(), and writeDocFile().

4117 {
4118  m_props = aProperties;
4119 
4120  cacheLib( aLibraryPath );
4121 
4122  m_cache->DeleteAlias( aAliasName );
4123 
4124  if( !isBuffering( aProperties ) )
4125  m_cache->Save( writeDocFile( aProperties ) );
4126 }
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 4129 of file sch_legacy_plugin.cpp.

References cacheLib(), SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol(), isBuffering(), m_cache, m_props, SCH_LEGACY_PLUGIN_CACHE::Save(), and writeDocFile().

4131 {
4132  m_props = aProperties;
4133 
4134  cacheLib( aLibraryPath );
4135 
4136  m_cache->DeleteSymbol( aAliasName );
4137 
4138  if( !isBuffering( aProperties ) )
4139  m_cache->Save( writeDocFile( aProperties ) );
4140 }
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 4165 of file sch_legacy_plugin.cpp.

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

4167 {
4168  wxFileName fn = aLibraryPath;
4169 
4170  if( !fn.FileExists() )
4171  return false;
4172 
4173  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
4174  // we don't want that. we want bare metal portability with no UI here.
4175  if( wxRemove( aLibraryPath ) )
4176  {
4177  THROW_IO_ERROR( wxString::Format( _( "library \"%s\" cannot be deleted" ),
4178  aLibraryPath.GetData() ) );
4179  }
4180 
4181  if( m_cache && m_cache->IsFile( aLibraryPath ) )
4182  {
4183  delete m_cache;
4184  m_cache = 0;
4185  }
4186 
4187  return true;
4188 }
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 4039 of file sch_legacy_plugin.cpp.

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

4042 {
4043  LOCALE_IO toggle; // toggles on, then off, the C locale.
4044 
4045  m_props = aProperties;
4046 
4047  bool powerSymbolsOnly = ( aProperties &&
4048  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4049  cacheLib( aLibraryPath );
4050 
4051  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
4052 
4053  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
4054  {
4055  if( !powerSymbolsOnly || it->second->GetPart()->IsPower() )
4056  aAliasNameList.Add( it->first );
4057  }
4058 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
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 4061 of file sch_legacy_plugin.cpp.

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

4064 {
4065  LOCALE_IO toggle; // toggles on, then off, the C locale.
4066 
4067  m_props = aProperties;
4068 
4069  bool powerSymbolsOnly = ( aProperties &&
4070  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4071  cacheLib( aLibraryPath );
4072 
4073  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
4074 
4075  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
4076  {
4077  if( !powerSymbolsOnly || it->second->GetPart()->IsPower() )
4078  aAliasList.push_back( it->second );
4079  }
4080 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
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 1675 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(), m_kiway, BASE_SCREEN::m_NumberOfScreens, m_out, BASE_SCREEN::m_ScreenNumber, SCH_ITEM::Next(), OUTPUTFORMATTER::Print(), KIWAY::Prj(), saveBitmap(), saveBusEntry(), saveComponent(), saveJunction(), saveLine(), saveNoConnect(), saveSheet(), saveText(), SCH_BITMAP_T, SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T, SCH_COMPONENT_T, SCH_GLOBAL_LABEL_T, SCH_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.

Referenced by Save().

1676 {
1677  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN* object." );
1678  wxCHECK_RET( m_kiway != NULL, "NULL KIWAY* object." );
1679 
1680  // Write the header
1681  m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1682 
1683  // Write the project libraries.
1684  for( const PART_LIB& lib : *m_kiway->Prj().SchLibs() )
1685  m_out->Print( 0, "LIBS:%s\n", TO_UTF8( lib.GetName() ) );
1686 
1687  // This section is not used, but written for file compatibility
1688  m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1689  m_out->Print( 0, "EELAYER END\n" );
1690 
1691  /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1692  * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1693  * simple hierarchy and flat hierarchy. Used also to search the root
1694  * sheet ( ScreenNumber = 1 ) within the files
1695  */
1696  const TITLE_BLOCK& tb = aScreen->GetTitleBlock();
1697  const PAGE_INFO& page = aScreen->GetPageSettings();
1698 
1699  m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1700  page.GetWidthMils(),
1701  page.GetHeightMils(),
1702  !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1703  m_out->Print( 0, "encoding utf-8\n" );
1704  m_out->Print( 0, "Sheet %d %d\n", aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens );
1705  m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1706  m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1707  m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1708  m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1709  m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment1() ).c_str() );
1710  m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment2() ).c_str() );
1711  m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment3() ).c_str() );
1712  m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment4() ).c_str() );
1713  m_out->Print( 0, "$EndDescr\n" );
1714 
1715  for( SCH_ITEM* item = aScreen->GetDrawItems(); item; item = item->Next() )
1716  {
1717  switch( item->Type() )
1718  {
1719  case SCH_COMPONENT_T:
1720  saveComponent( dynamic_cast< SCH_COMPONENT* >( item ) );
1721  break;
1722  case SCH_BITMAP_T:
1723  saveBitmap( dynamic_cast< SCH_BITMAP* >( item ) );
1724  break;
1725  case SCH_SHEET_T:
1726  saveSheet( dynamic_cast< SCH_SHEET* >( item ) );
1727  break;
1728  case SCH_JUNCTION_T:
1729  saveJunction( dynamic_cast< SCH_JUNCTION* >( item ) );
1730  break;
1731  case SCH_NO_CONNECT_T:
1732  saveNoConnect( dynamic_cast< SCH_NO_CONNECT* >( item ) );
1733  break;
1734  case SCH_BUS_WIRE_ENTRY_T:
1735  case SCH_BUS_BUS_ENTRY_T:
1736  saveBusEntry( dynamic_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1737  break;
1738  case SCH_LINE_T:
1739  saveLine( dynamic_cast< SCH_LINE* >( item ) );
1740  break;
1741  case SCH_TEXT_T:
1742  case SCH_LABEL_T:
1743  case SCH_GLOBAL_LABEL_T:
1745  saveText( dynamic_cast< SCH_TEXT* >( item ) );
1746  break;
1747  default:
1748  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1749  }
1750  }
1751 
1752  m_out->Print( 0, "$EndSCHEMATC\n" );
1753 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
const wxString & GetCompany() const
void saveLine(SCH_LINE *aLine)
void saveText(SCH_TEXT *aText)
const wxString & GetComment4() const
const wxString & GetDate() const
#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.
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
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
const wxString & GetRevision() const
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
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
int GetWidthMils() const
void saveComponent(SCH_COMPONENT *aComponent)
const TITLE_BLOCK & GetTitleBlock() const
const wxString & GetComment2() const
SCH_ITEM * GetDrawItems() const
bool IsCustom() const
Function IsCustom returns true if the type is Custom.
const wxString & GetComment1() const
const PAGE_INFO & GetPageSettings() const
const wxString & GetType() const
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
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 128 of file sch_legacy_plugin.h.

References m_error.

128 { 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 71 of file sch_legacy_plugin.h.

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

References SCH_LEGACY_PLUGIN_CACHE::GetModifyHash(), and m_cache.

4017 {
4018  if( m_cache )
4019  return m_cache->GetModifyHash();
4020 
4021  // If the cache hasn't been loaded, it hasn't been modified.
4022  return 0;
4023 }
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 66 of file sch_legacy_plugin.h.

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

Reimplemented from SCH_PLUGIN.

Definition at line 4026 of file sch_legacy_plugin.cpp.

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

4028 {
4029  LOCALE_IO toggle;
4030 
4031  m_props = aProperties;
4032 
4033  cacheLib( aLibraryPath );
4034 
4035  return m_cache->m_aliases.size();
4036 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
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 574 of file sch_legacy_plugin.cpp.

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

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

575 {
576  m_version = 0;
577  m_rootSheet = NULL;
578  m_props = aProperties;
579  m_kiway = aKiway;
580  m_cache = NULL;
581  m_out = NULL;
582 }
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 4010 of file sch_legacy_plugin.cpp.

References PROPERTIES::Exists(), and PropBuffering.

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

4011 {
4012  return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
4013 }
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 4225 of file sch_legacy_plugin.cpp.

4226 {
4227  return wxFileName::IsFileWritable( aLibraryPath );
4228 }
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 585 of file sch_legacy_plugin.cpp.

References SCH_SHEET::GetRootSheet(), init(), loadHierarchy(), m_path, and m_rootSheet.

587 {
588  wxASSERT( !aFileName || aKiway != NULL );
589 
590  LOCALE_IO toggle; // toggles on, then off, the C locale.
591  SCH_SHEET* sheet;
592 
593  wxFileName fn = aFileName;
594 
595  // Unfortunately child sheet file names the legacy schematic file format are not fully
596  // qualified and are always appended to the project path. The aFileName attribute must
597  // always be an absolute path so the project path can be used for load child sheet files.
598  wxASSERT( fn.IsAbsolute() );
599 
600  m_path = fn.GetPath();
601 
602  init( aKiway, aProperties );
603 
604  if( aAppendToMe == NULL )
605  {
606  // Clean up any allocated memory if an exception occurs loading the schematic.
607  std::unique_ptr< SCH_SHEET > newSheet( new SCH_SHEET );
608  newSheet->SetFileName( aFileName );
609  m_rootSheet = newSheet.get();
610  loadHierarchy( newSheet.get() );
611 
612  // If we got here, the schematic loaded successfully.
613  sheet = newSheet.release();
614  }
615  else
616  {
617  m_rootSheet = aAppendToMe->GetRootSheet();
618  wxASSERT( m_rootSheet != NULL );
619  sheet = aAppendToMe;
620  loadHierarchy( sheet );
621  }
622 
623  return sheet;
624 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
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:135
wxString m_path
Root project path for loading child sheets.
void loadHierarchy(SCH_SHEET *aSheet)
void init(KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
initialize PLUGIN like a constructor would.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
SCH_BITMAP * SCH_LEGACY_PLUGIN::loadBitmap ( FILE_LINE_READER aReader)
private
Todo:
Make m_scale private and add accessors.

Definition at line 1022 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 loadFile().

1023 {
1024  std::unique_ptr< SCH_BITMAP > bitmap( new SCH_BITMAP );
1025 
1026  const char* line = aReader.Line();
1027 
1028  wxCHECK( strCompare( "$Bitmap", line, &line ), NULL );
1029 
1030  line = aReader.ReadLine();
1031 
1032  while( line != NULL )
1033  {
1034  if( strCompare( "Pos", line, &line ) )
1035  {
1036  wxPoint position;
1037 
1038  position.x = parseInt( aReader, line, &line );
1039  position.y = parseInt( aReader, line, &line );
1040  bitmap->SetPosition( position );
1041  }
1042  else if( strCompare( "Scale", line, &line ) )
1043  {
1045  bitmap->GetImage()->SetScale( parseDouble( aReader, line, &line ) );
1046  }
1047  else if( strCompare( "Data", line, &line ) )
1048  {
1049  wxMemoryOutputStream stream;
1050 
1051  while( line )
1052  {
1053  if( !aReader.ReadLine() )
1054  SCH_PARSE_ERROR( _( "Unexpected end of file" ), aReader, line );
1055 
1056  line = aReader.Line();
1057 
1058  if( strCompare( "EndData", line ) )
1059  {
1060  // all the PNG date is read.
1061  // We expect here m_image and m_bitmap are void
1062  wxImage* image = new wxImage();
1063  wxMemoryInputStream istream( stream );
1064  image->LoadFile( istream, wxBITMAP_TYPE_PNG );
1065  bitmap->GetImage()->SetImage( image );
1066  bitmap->GetImage()->SetBitmap( new wxBitmap( *image ) );
1067  break;
1068  }
1069 
1070  // Read PNG data, stored in hexadecimal,
1071  // each byte = 2 hexadecimal digits and a space between 2 bytes
1072  // and put it in memory stream buffer
1073  int len = strlen( line );
1074 
1075  for( ; len > 0 && !isspace( *line ); len -= 3, line += 3 )
1076  {
1077  int value = 0;
1078 
1079  if( sscanf( line, "%X", &value ) == 1 )
1080  stream.PutC( (char) value );
1081  else
1082  THROW_IO_ERROR( "invalid PNG data" );
1083  }
1084  }
1085 
1086  if( line == NULL )
1087  THROW_IO_ERROR( _( "unexpected end of file" ) );
1088  }
1089  else if( strCompare( "$EndBitmap", line ) )
1090  return bitmap.release();
1091 
1092  line = aReader.ReadLine();
1093  }
1094 
1095  THROW_IO_ERROR( _( "unexpected end of file" ) );
1096 }
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 1235 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 loadFile().

1236 {
1237  const char* line = aReader.Line();
1238 
1239  wxCHECK( strCompare( "Entry", line, &line ), NULL );
1240 
1241  std::unique_ptr< SCH_BUS_ENTRY_BASE > busEntry;
1242 
1243  if( strCompare( "Wire", line, &line ) )
1244  {
1245  busEntry.reset( new SCH_BUS_WIRE_ENTRY );
1246 
1247  if( !strCompare( "Line", line, &line ) )
1248  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
1249  }
1250  else if( strCompare( "Bus", line, &line ) )
1251  {
1252  busEntry.reset( new SCH_BUS_BUS_ENTRY );
1253 
1254  if( !strCompare( "Bus", line, &line ) )
1255  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
1256  }
1257  else
1258  SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
1259 
1260  line = aReader.ReadLine();
1261 
1262  wxPoint pos;
1263  wxSize size;
1264 
1265  pos.x = parseInt( aReader, line, &line );
1266  pos.y = parseInt( aReader, line, &line );
1267  size.x = parseInt( aReader, line, &line );
1268  size.y = parseInt( aReader, line, &line );
1269 
1270  size.x -= pos.x;
1271  size.y -= pos.y;
1272 
1273  busEntry->SetPosition( pos );
1274  busEntry->SetSize( size );
1275 
1276  return busEntry.release();
1277 }
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 1376 of file sch_legacy_plugin.cpp.

References TEMPLATE_FIELDNAME::GetDefaultFieldName(), SCH_SHEET::GetScreen(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, LINE_READER::Line(), m_rootSheet, m_version, 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(), BASE_SCREEN::SetModify(), strCompare(), TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, wxPoint::x, TRANSFORM::x1, TRANSFORM::x2, wxPoint::y, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by loadFile().

1377 {
1378  const char* line = aReader.Line();
1379 
1380  wxCHECK( strCompare( "$Comp", line, &line ), NULL );
1381 
1382  std::unique_ptr< SCH_COMPONENT > component( new SCH_COMPONENT() );
1383 
1384  line = aReader.ReadLine();
1385 
1386  while( line != NULL )
1387  {
1388  if( strCompare( "L", line, &line ) )
1389  {
1390  wxString libName;
1391 
1392  parseUnquotedString( libName, aReader, line, &line );
1393  libName.Replace( "~", " " );
1394 
1395  LIB_ID libId;
1396 
1397  // Prior to schematic version 4, library IDs did not have a library nickname so
1398  // parsing the symbol name with LIB_ID::Parse() would break symbol library links
1399  // that contained '/' and ':' characters.
1400  if( m_version > 3 )
1401  libId.Parse( libName );
1402  else
1403  libId.SetLibItemName( libName, false );
1404 
1405  component->SetLibId( libId );
1406 
1407  wxString refDesignator;
1408 
1409  parseUnquotedString( refDesignator, aReader, line, &line );
1410  refDesignator.Replace( "~", " " );
1411 
1412  wxString prefix = refDesignator;
1413 
1414  while( prefix.Length() )
1415  {
1416  if( ( prefix.Last() < '0' || prefix.Last() > '9') && prefix.Last() != '?' )
1417  break;
1418 
1419  prefix.RemoveLast();
1420  }
1421 
1422  // Avoid a prefix containing trailing/leading spaces
1423  prefix.Trim( true );
1424  prefix.Trim( false );
1425 
1426  if( prefix.IsEmpty() )
1427  component->SetPrefix( wxString( "U" ) );
1428  else
1429  component->SetPrefix( prefix );
1430  }
1431  else if( strCompare( "U", line, &line ) )
1432  {
1433  // This fixes a potentially buggy files caused by unit being set to zero which
1434  // causes netlist issues. See https://bugs.launchpad.net/kicad/+bug/1677282.
1435  int unit = parseInt( aReader, line, &line );
1436 
1437  if( unit == 0 )
1438  {
1439  unit = 1;
1440 
1441  // Set the file as modified so the user can be warned.
1442  if( m_rootSheet && m_rootSheet->GetScreen() )
1444  }
1445 
1446  component->SetUnit( unit );
1447  component->SetConvert( parseInt( aReader, line, &line ) );
1448  component->SetTimeStamp( parseHex( aReader, line, &line ) );
1449  }
1450  else if( strCompare( "P", line, &line ) )
1451  {
1452  wxPoint pos;
1453 
1454  pos.x = parseInt( aReader, line, &line );
1455  pos.y = parseInt( aReader, line, &line );
1456  component->SetPosition( pos );
1457  }
1458  else if( strCompare( "AR", line, &line ) )
1459  {
1460  const char* strCompare = "Path=";
1461  int len = strlen( strCompare );
1462 
1463  if( strncasecmp( strCompare, line, len ) != 0 )
1464  SCH_PARSE_ERROR( "missing 'Path=' token", aReader, line );
1465 
1466  line += len;
1467  wxString path, reference, unit;
1468 
1469  parseQuotedString( path, aReader, line, &line );
1470 
1471  strCompare = "Ref=";
1472  len = strlen( strCompare );
1473 
1474  if( strncasecmp( strCompare, line, len ) != 0 )
1475  SCH_PARSE_ERROR( "missing 'Ref=' token", aReader, line );
1476 
1477  line+= len;
1478  parseQuotedString( reference, aReader, line, &line );
1479 
1480  strCompare = "Part=";
1481  len = strlen( strCompare );
1482 
1483  if( strncasecmp( strCompare, line, len ) != 0 )
1484  SCH_PARSE_ERROR( "missing 'Part=' token", aReader, line );
1485 
1486  line+= len;
1487  parseQuotedString( unit, aReader, line, &line );
1488 
1489  long tmp;
1490 
1491  if( !unit.ToLong( &tmp, 10 ) )
1492  SCH_PARSE_ERROR( "expected integer value", aReader, line );
1493 
1494  if( tmp < 0 || tmp > MAX_UNIT_COUNT_PER_PACKAGE )
1495  SCH_PARSE_ERROR( "unit value out of range", aReader, line );
1496 
1497  component->AddHierarchicalReference( path, reference, (int)tmp );
1498  component->GetField( REFERENCE )->SetText( reference );
1499 
1500  }
1501  else if( strCompare( "F", line, &line ) )
1502  {
1503  int index = parseInt( aReader, line, &line );
1504 
1505  wxString text, name;
1506 
1507  parseQuotedString( text, aReader, line, &line, true );
1508 
1509  char orientation = parseChar( aReader, line, &line );
1510  wxPoint pos;
1511  pos.x = parseInt( aReader, line, &line );
1512  pos.y = parseInt( aReader, line, &line );
1513  int size = parseInt( aReader, line, &line );
1514  int attributes = parseHex( aReader, line, &line );
1515 
1516  if( index >= component->GetFieldCount() )
1517  {
1518  // The first MANDATOR_FIELDS _must_ be constructed within
1519  // the SCH_COMPONENT constructor. This assert is simply here
1520  // to guard against a change in that constructor.
1521  wxASSERT( component->GetFieldCount() >= MANDATORY_FIELDS );
1522 
1523  // Ignore the _supplied_ fieldNdx. It is not important anymore
1524  // if within the user defined fields region (i.e. >= MANDATORY_FIELDS).
1525  // We freely renumber the index to fit the next available field slot.
1526  index = component->GetFieldCount(); // new has this index after insertion
1527 
1528  SCH_FIELD field( wxPoint( 0, 0 ), -1, component.get(), name );
1529  component->AddField( field );
1530  }
1531 
1532  // Prior to version 2 of the schematic file format, none of the following existed.
1533  if( m_version > 1 )
1534  {
1535  wxString textAttrs;
1536  char hjustify = parseChar( aReader, line, &line );
1537 
1538  parseUnquotedString( textAttrs, aReader, line, &line );
1539 
1540  // The name of the field is optional.
1541  parseQuotedString( name, aReader, line, &line, true );
1542 
1543  if( hjustify == 'L' )
1544  component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
1545  else if( hjustify == 'R' )
1546  component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
1547  else if( hjustify != 'C' )
1548  SCH_PARSE_ERROR( "component field text horizontal justification must be "
1549  "L, R, or C", aReader, line );
1550 
1551  // We are guaranteed to have a least one character here for older file formats
1552  // otherwise an exception would have been raised..
1553  if( textAttrs[0] == 'T' )
1554  component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
1555  else if( textAttrs[0] == 'B' )
1556  component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
1557  else if( textAttrs[0] != 'C' )
1558  SCH_PARSE_ERROR( "component field text vertical justification must be "
1559  "B, T, or C", aReader, line );
1560 
1561  // Newer file formats include the bold and italics text attribute.
1562  if( textAttrs.Length() > 1 )
1563  {
1564  if( textAttrs.Length() != 3 )
1565  SCH_PARSE_ERROR( _( "component field text attributes must be 3 characters wide" ),
1566  aReader, line );
1567 
1568  if( textAttrs[1] == 'I' )
1569  component->GetField( index )->SetItalic( true );
1570  else if( textAttrs[1] != 'N' )
1571  SCH_PARSE_ERROR( "component field text italics indicator must be I or N",
1572  aReader, line );
1573 
1574  if( textAttrs[2] == 'B' )
1575  component->GetField( index )->SetBold( true );
1576  else if( textAttrs[2] != 'N' )
1577  SCH_PARSE_ERROR( "component field text bold indicator must be B or N",
1578  aReader, line );
1579  }
1580  }
1581 
1582  component->GetField( index )->SetText( text );
1583  component->GetField( index )->SetTextPos( pos );
1584  component->GetField( index )->SetVisible( !attributes );
1585  component->GetField( index )->SetTextSize( wxSize( size, size ) );
1586 
1587  if( orientation == 'H' )
1588  component->GetField( index )->SetTextAngle( TEXT_ANGLE_HORIZ );
1589  else if( orientation == 'V' )
1590  component->GetField( index )->SetTextAngle( TEXT_ANGLE_VERT );
1591  else
1592  SCH_PARSE_ERROR( "component field orientation must be H or V",
1593  aReader, line );
1594 
1595  if( name.IsEmpty() )
1597 
1598  component->GetField( index )->SetName( name );
1599  }
1600  else if( strCompare( "$EndComp", line ) )
1601  {
1602  // Ensure all flags (some are set by previous initializations) are reset:
1603  component->ClearFlags();
1604  return component.release();
1605  }
1606  else
1607  {
1608  // There are two lines that begin with a tab or spaces that includes a line with the
1609  // redundant position information and the transform matrix settings.
1610 
1611  // Parse the redundant position information just the same to check for formatting
1612  // errors.
1613  parseInt( aReader, line, &line ); // Always 1.
1614  parseInt( aReader, line, &line ); // The X coordinate.
1615  parseInt( aReader, line, &line ); // The Y coordinate.
1616 
1617  line = aReader.ReadLine();
1618 
1619  TRANSFORM transform;
1620 
1621  transform.x1 = parseInt( aReader, line, &line );
1622 
1623  if( transform.x1 < -1 || transform.x1 > 1 )
1624  SCH_PARSE_ERROR( "invalid component X1 transform value", aReader, line );
1625 
1626  transform.y1 = parseInt( aReader, line, &line );
1627 
1628  if( transform.y1 < -1 || transform.y1 > 1 )
1629  SCH_PARSE_ERROR( "invalid component Y1 transform value", aReader, line );
1630 
1631  transform.x2 = parseInt( aReader, line, &line );
1632 
1633  if( transform.x2 < -1 || transform.x2 > 1 )
1634  SCH_PARSE_ERROR( "invalid component X2 transform value", aReader, line );
1635 
1636  transform.y2 = parseInt( aReader, line, &line );
1637 
1638  if( transform.y2 < -1 || transform.y2 > 1 )
1639  SCH_PARSE_ERROR( "invalid component Y2 transform value", aReader, line );
1640 
1641  component->SetTransform( transform );
1642  }
1643 
1644  line = aReader.ReadLine();
1645  }
1646 
1647  SCH_PARSE_ERROR( "invalid component line", aReader, line );
1648 
1649  return NULL; // Prevents compiler warning. Should never get here.
1650 }
#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'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)
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...
const char * name
void SCH_LEGACY_PLUGIN::loadFile ( const wxString &  aFileName,
SCH_SCREEN aScreen 
)
private

Definition at line 699 of file sch_legacy_plugin.cpp.

References SCH_SCREEN::Append(), LINE_READER::Line(), loadBitmap(), loadBusEntry(), loadComponent(), loadHeader(), loadJunction(), loadNoConnect(), loadPageSettings(), loadSheet(), loadText(), loadWire(), m_version, FILE_LINE_READER::ReadLine(), strCompare(), and THROW_IO_ERROR.

Referenced by loadHierarchy().

700 {
701  FILE_LINE_READER reader( aFileName );
702 
703  loadHeader( reader, aScreen );
704 
705  while( reader.ReadLine() )
706  {
707  char* line = reader.Line();
708 
709  while( *line && *line == ' ' )
710  line++;
711 
712  // Either an object will be loaded properly or the file load will fail and raise
713  // an exception.
714  if( strCompare( "$Descr", line ) )
715  loadPageSettings( reader, aScreen );
716  else if( strCompare( "$Comp", line ) )
717  aScreen->Append( loadComponent( reader ) );
718  else if( strCompare( "$Sheet", line ) )
719  aScreen->Append( loadSheet( reader ) );
720  else if( strCompare( "$Bitmap", line ) )
721  aScreen->Append( loadBitmap( reader ) );
722  else if( strCompare( "Connection", line ) )
723  aScreen->Append( loadJunction( reader ) );
724  else if( strCompare( "NoConn", line ) )
725  aScreen->Append( loadNoConnect( reader ) );
726  else if( strCompare( "Wire", line ) )
727  aScreen->Append( loadWire( reader ) );
728  else if( strCompare( "Entry", line ) )
729  aScreen->Append( loadBusEntry( reader ) );
730  else if( strCompare( "Text", line ) )
731  aScreen->Append( loadText( reader ) );
732  else if( strCompare( "$EndSCHEMATC", line ) )
733  return;
734  }
735 
736  // Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
737  // so checking for it's existance will fail so just exit here and take our chances. :(
738  if( m_version > 1 )
739  THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
740 }
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)
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 743 of file sch_legacy_plugin.cpp.

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

Referenced by loadFile().

744 {
745  const char* line = aReader.ReadLine();
746 
747  if( !strCompare( "Eeschema Schematic File Version", line, &line ) )
748  {
749  m_error.Printf( _( "\"%s\" does not appear to be an Eeschema file" ),
750  GetChars( aScreen->GetFileName() ) );
752  }
753 
754  // get the file version here.
755  m_version = parseInt( aReader, line, &line );
756 
757  // The next lines are the lib list section, and are mainly comments, like:
758  // LIBS:power
759  // the lib list is not used, but is in schematic file just in case.
760  // It is usually not empty, but we accept empty list.
761  // If empty, there is a legacy section, not used
762  // EELAYER i j
763  // and the last line is
764  // EELAYER END
765  // Skip all lines until the end of header "EELAYER END" is found
766  while( aReader.ReadLine() )
767  {
768  line = aReader.Line();
769 
770  while( *line == ' ' )
771  line++;
772 
773  if( strCompare( "EELAYER END", line ) )
774  return;
775  }
776 
777  THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
778 }
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
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 629 of file sch_legacy_plugin.cpp.

References SCH_SCREEN::GetDrawItems(), SCH_SHEET::GetFileName(), SCH_SHEET::GetScreen(), loadFile(), m_error, m_kiway, m_path, m_rootSheet, SCH_SHEET_T, SCH_SHEET::SearchHierarchy(), SCH_SCREEN::SetFileName(), EDA_ITEM::SetParent(), SCH_SHEET::SetScreen(), and IO_ERROR::What().

Referenced by Load().

630 {
631  SCH_SCREEN* screen = NULL;
632 
633  if( !aSheet->GetScreen() )
634  {
635  // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
636  // stores the file name and extension. Add the project path to the file name and
637  // extension to compare when calling SCH_SHEET::SearchHierarchy().
638  wxFileName fileName = aSheet->GetFileName();
639 
640  if( !fileName.IsAbsolute() )
641  fileName.MakeAbsolute( m_path );
642 
643  m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
644 
645  if( screen )
646  {
647  aSheet->SetScreen( screen );
648 
649  // Do not need to load the sub-sheets - this has already been done.
650  }
651  else
652  {
653  aSheet->SetScreen( new SCH_SCREEN( m_kiway ) );
654  aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
655 
656  try
657  {
658  loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
659 
660  EDA_ITEM* item = aSheet->GetScreen()->GetDrawItems();
661 
662  while( item )
663  {
664  if( item->Type() == SCH_SHEET_T )
665  {
666  SCH_SHEET* sheet = (SCH_SHEET*) item;
667 
668  // Set the parent to aSheet. This effectively creates a method to find
669  // the root sheet from any sheet so a pointer to the root sheet does not
670  // need to be stored globally. Note: this is not the same as a hierarchy.
671  // Complex hierarchies can have multiple copies of a sheet. This only
672  // provides a simple tree to find the root sheet.
673  sheet->SetParent( aSheet );
674 
675  // Recursion starts here.
676  loadHierarchy( sheet );
677  }
678 
679  item = item->Next();
680  }
681  }
682  catch( const IO_ERROR& ioe )
683  {
684  // If there is a problem loading the root sheet, there is no recovery.
685  if( aSheet == m_rootSheet )
686  throw( ioe );
687 
688  // For all subsheets, queue up the error message for the caller.
689  if( !m_error.IsEmpty() )
690  m_error += "\n";
691 
692  m_error += ioe.What();
693  }
694  }
695  }
696 }
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:562
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:103
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)
wxString m_path
Root project path for loading child sheets.
void loadHierarchy(SCH_SHEET *aSheet)
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:240
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:645
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
SCH_ITEM * GetDrawItems() const
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:178
void SetFileName(const wxString &aFileName)
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:47
SCH_JUNCTION * SCH_LEGACY_PLUGIN::loadJunction ( FILE_LINE_READER aReader)
private

Definition at line 1099 of file sch_legacy_plugin.cpp.

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

Referenced by loadFile().

1100 {
1101  std::unique_ptr< SCH_JUNCTION > junction( new SCH_JUNCTION );
1102 
1103  const char* line = aReader.Line();
1104 
1105  wxCHECK( strCompare( "Connection", line, &line ), NULL );
1106 
1107  wxString name;
1108 
1109  parseUnquotedString( name, aReader, line, &line );
1110 
1111  wxPoint position;
1112 
1113  position.x = parseInt( aReader, line, &line );
1114  position.y = parseInt( aReader, line, &line );
1115  junction->SetPosition( position );
1116 
1117  return junction.release();
1118 }
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
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...
const char * name
SCH_NO_CONNECT * SCH_LEGACY_PLUGIN::loadNoConnect ( FILE_LINE_READER aReader)
private

Definition at line 1121 of file sch_legacy_plugin.cpp.

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

Referenced by loadFile().

1122 {
1123  std::unique_ptr< SCH_NO_CONNECT > no_connect( new SCH_NO_CONNECT );
1124 
1125  const char* line = aReader.Line();
1126 
1127  wxCHECK( strCompare( "NoConn", line, &line ), NULL );
1128 
1129  wxString name;
1130 
1131  parseUnquotedString( name, aReader, line, &line );
1132 
1133  wxPoint position;
1134 
1135  position.x = parseInt( aReader, line, &line );
1136  position.y = parseInt( aReader, line, &line );
1137  no_connect->SetPosition( position );
1138 
1139  return no_connect.release();
1140 }
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
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...
const char * name
void SCH_LEGACY_PLUGIN::loadPageSettings ( FILE_LINE_READER aReader,
SCH_SCREEN aScreen 
)
private

Definition at line 781 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 loadFile().

782 {
783  wxASSERT( aScreen != NULL );
784 
785  wxString buf;
786  const char* line = aReader.Line();
787 
788  PAGE_INFO pageInfo;
789  TITLE_BLOCK tb;
790 
791  wxCHECK_RET( strCompare( "$Descr", line, &line ), "Invalid sheet description" );
792 
793  parseUnquotedString( buf, aReader, line, &line );
794 
795  if( !pageInfo.SetType( buf ) )
796  SCH_PARSE_ERROR( "invalid page size", aReader, line );
797 
798  int pagew = parseInt( aReader, line, &line );
799  int pageh = parseInt( aReader, line, &line );
800 
801  if( buf == PAGE_INFO::Custom )
802  {
803  pageInfo.SetWidthMils( pagew );
804  pageInfo.SetHeightMils( pageh );
805  }
806  else
807  {
808  wxString orientation;
809 
810  // Non custom size, set portrait if its present. Can be empty string which defaults
811  // to landscape.
812  parseUnquotedString( orientation, aReader, line, &line, true );
813 
814  if( orientation == "portrait" )
815  pageInfo.SetPortrait( true );
816  }
817 
818  aScreen->SetPageSettings( pageInfo );
819 
820  while( line != NULL )
821  {
822  buf.clear();
823 
824  if( !aReader.ReadLine() )
825  SCH_PARSE_ERROR( _( "unexpected end of file" ), aReader, line );
826 
827  line = aReader.Line();
828 
829  if( strCompare( "Sheet", line, &line ) )
830  {
831  aScreen->m_ScreenNumber = parseInt( aReader, line, &line );
832  aScreen->m_NumberOfScreens = parseInt( aReader, line, &line );
833  }
834  else if( strCompare( "Title", line, &line ) )
835  {
836  parseQuotedString( buf, aReader, line, &line, true );
837  tb.SetTitle( buf );
838  }
839  else if( strCompare( "Date", line, &line ) )
840  {
841  parseQuotedString( buf, aReader, line, &line, true );
842  tb.SetDate( buf );
843  }
844  else if( strCompare( "Rev", line, &line ) )
845  {
846  parseQuotedString( buf, aReader, line, &line, true );
847  tb.SetRevision( buf );
848  }
849  else if( strCompare( "Comp", line, &line ) )
850  {
851  parseQuotedString( buf, aReader, line, &line, true );
852  tb.SetCompany( buf );
853  }
854  else if( strCompare( "Comment1", line, &line ) )
855  {
856  parseQuotedString( buf, aReader, line, &line, true );
857  tb.SetComment1( buf );
858  }
859  else if( strCompare( "Comment2", line, &line ) )
860  {
861  parseQuotedString( buf, aReader, line, &line, true );
862  tb.SetComment2( buf );
863  }
864  else if( strCompare( "Comment3", line, &line ) )
865  {
866  parseQuotedString( buf, aReader, line, &line, true );
867  tb.SetComment3( buf );
868  }
869  else if( strCompare( "Comment4", line, &line ) )
870  {
871  parseQuotedString( buf, aReader, line, &line, true );
872  tb.SetComment4( buf );
873  }
874  else if( strCompare( "$EndDescr", line ) )
875  {
876  aScreen->SetTitleBlock( tb );
877  return;
878  }
879  }
880 
881  SCH_PARSE_ERROR( "missing 'EndDescr'", aReader, line );
882 }
void SetComment1(const wxString &aComment)
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...
void SetRevision(const wxString &aRevision)
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...
void SetDate(const wxString &aDate)
Function SetDate sets the date field, and defaults to the current time and date.
void SetPageSettings(const PAGE_INFO &aPageSettings)
static const wxChar Custom[]
"User" defined page type
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
void SetComment4(const wxString &aComment)
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...
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)
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
void SetTitle(const wxString &aTitle)
void SetHeightMils(int aHeightInMils)
void SetComment2(const wxString &aComment)
#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)
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 SetComment3(const wxString &aComment)
void SetPortrait(bool aIsPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
SCH_SHEET * SCH_LEGACY_PLUGIN::loadSheet ( FILE_LINE_READER aReader)
private

Definition at line 885 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 loadFile().

886 {
887  std::unique_ptr< SCH_SHEET > sheet( new SCH_SHEET() );
888 
889  sheet->SetTimeStamp( GetNewTimeStamp() );
890 
891  const char* line = aReader.ReadLine();
892 
893  while( line != NULL )
894  {
895  if( strCompare( "S", line, &line ) ) // Sheet dimensions.
896  {
897  wxPoint position;
898 
899  position.x = parseInt( aReader, line, &line );
900  position.y = parseInt( aReader, line, &line );
901  sheet->SetPosition( position );
902 
903  wxSize size;
904 
905  size.SetWidth( parseInt( aReader, line, &line ) );
906  size.SetHeight( parseInt( aReader, line, &line ) );
907  sheet->SetSize( size );
908  }
909  else if( strCompare( "U", line, &line ) ) // Sheet time stamp.
910  {
911  sheet->SetTimeStamp( parseHex( aReader, line ) );
912  }
913  else if( *line == 'F' ) // Sheet field.
914  {
915  line++;
916 
917  wxString text;
918  int size;
919  int fieldId = parseInt( aReader, line, &line );
920 
921  if( fieldId == 0 || fieldId == 1 ) // Sheet name and file name.
922  {
923  parseQuotedString( text, aReader, line, &line );
924  size = parseInt( aReader, line, &line );
925 
926  if( fieldId == 0 )
927  {
928  sheet->SetName( text );
929  sheet->SetSheetNameSize( size );
930  }
931  else
932  {
933  sheet->SetFileName( text );
934  sheet->SetFileNameSize( size );
935  }
936  }
937  else // Sheet pin.
938  {
939  std::unique_ptr< SCH_SHEET_PIN > sheetPin( new SCH_SHEET_PIN( sheet.get() ) );
940 
941  sheetPin->SetNumber( fieldId );
942 
943  // Can be empty fields.
944  parseQuotedString( text, aReader, line, &line, true );
945 
946  sheetPin->SetText( text );
947 
948  if( line == NULL )
949  THROW_IO_ERROR( _( "unexpected end of line" ) );
950 
951  switch( parseChar( aReader, line, &line ) )
952  {
953  case 'I':
954  sheetPin->SetShape( NET_INPUT );
955  break;
956 
957  case 'O':
958  sheetPin->SetShape( NET_OUTPUT );
959  break;
960 
961  case 'B':
962  sheetPin->SetShape( NET_BIDI );
963  break;
964 
965  case 'T':
966  sheetPin->SetShape( NET_TRISTATE );
967  break;
968 
969  case 'U':
970  sheetPin->SetShape( NET_UNSPECIFIED );
971  break;
972  default:
973  SCH_PARSE_ERROR( "invalid sheet pin type", aReader, line );
974  }
975 
976  switch( parseChar( aReader, line, &line ) )
977  {
978  case 'R': /* pin on right side */
979  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_RIGHT_SIDE );
980  break;
981 
982  case 'T': /* pin on top side */
983  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_TOP_SIDE );
984  break;
985 
986  case 'B': /* pin on bottom side */
987  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_BOTTOM_SIDE );
988  break;
989 
990  case 'L': /* pin on left side */
991  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_LEFT_SIDE );
992  break;
993  default:
994  SCH_PARSE_ERROR( "invalid sheet pin side", aReader, line );
995  }
996 
997  wxPoint position;
998 
999  position.x = parseInt( aReader, line, &line );
1000  position.y = parseInt( aReader, line, &line );
1001  sheetPin->SetPosition( position );
1002 
1003  size = parseInt( aReader, line, &line );
1004 
1005  sheetPin->SetTextSize( wxSize( size, size ) );
1006 
1007  sheet->AddPin( sheetPin.release() );
1008  }
1009  }
1010  else if( strCompare( "$EndSheet", line ) )
1011  return sheet.release();
1012 
1013  line = aReader.ReadLine();
1014  }
1015 
1016  SCH_PARSE_ERROR( "missing '$EndSheet`", aReader, line );
1017 
1018  return NULL; // Prevents compiler warning. Should never get here.
1019 }
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:166
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 4083 of file sch_legacy_plugin.cpp.

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

4085 {
4086  LOCALE_IO toggle; // toggles on, then off, the C locale.
4087 
4088  m_props = aProperties;
4089 
4090  cacheLib( aLibraryPath );
4091 
4092  LIB_ALIAS_MAP::const_iterator it = m_cache->m_aliases.find( aAliasName );
4093 
4094  if( it == m_cache->m_aliases.end() )
4095  return NULL;
4096 
4097  return it->second;
4098 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
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 1280 of file sch_legacy_plugin.cpp.

References FROM_UTF8(), GetPenSizeForBold(), LINE_READER::Line(), m_version, 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 loadFile().

1281 {
1282  const char* line = aReader.Line();
1283 
1284  wxCHECK( strCompare( "Text", line, &line ), NULL );
1285 
1286  std::unique_ptr< SCH_TEXT> text;
1287 
1288  if( strCompare( "Notes", line, &line ) )
1289  text.reset( new SCH_TEXT );
1290  else if( strCompare( "Label", line, &line ) )
1291  text.reset( new SCH_LABEL );
1292  else if( strCompare( "HLabel", line, &line ) )
1293  text.reset( new SCH_HIERLABEL );
1294  else if( strCompare( "GLabel", line, &line ) )
1295  {
1296  // Prior to version 2, the SCH_GLOBALLABEL object did not exist.
1297  if( m_version == 1 )
1298  text.reset( new SCH_HIERLABEL );
1299  else
1300  text.reset( new SCH_GLOBALLABEL );
1301  }
1302  else
1303  SCH_PARSE_ERROR( "unknown Text type", aReader, line );
1304 
1305  // Parse the parameters common to all text objects.
1306  wxPoint position;
1307 
1308  position.x = parseInt( aReader, line, &line );
1309  position.y = parseInt( aReader, line, &line );
1310  text->SetPosition( position );
1311  text->SetLabelSpinStyle( parseInt( aReader, line, &line ) );
1312 
1313  int size = parseInt( aReader, line, &line );
1314 
1315  text->SetTextSize( wxSize( size, size ) );
1316 
1317  // Parse the global and hierarchical label type.
1318  if( text->Type() == SCH_HIERARCHICAL_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
1319  {
1320  if( strCompare( SheetLabelType[NET_INPUT], line, &line ) )
1321  text->SetShape( NET_INPUT );
1322  else if( strCompare( SheetLabelType[NET_OUTPUT], line, &line ) )
1323  text->SetShape( NET_OUTPUT );
1324  else if( strCompare( SheetLabelType[NET_BIDI], line, &line ) )
1325  text->SetShape( NET_BIDI );
1326  else if( strCompare( SheetLabelType[NET_TRISTATE], line, &line ) )
1327  text->SetShape( NET_TRISTATE );
1328  else if( strCompare( SheetLabelType[NET_UNSPECIFIED], line, &line ) )
1329  text->SetShape( NET_UNSPECIFIED );
1330  else
1331  SCH_PARSE_ERROR( "invalid label type", aReader, line );
1332  }
1333 
1334  int thickness = 0;
1335 
1336  // The following tokens do not exist in version 1 schematic files.
1337  if( m_version > 1 )
1338  {
1339  if( strCompare( "Italic", line, &line ) )
1340  text->SetItalic( true );
1341  else if( !strCompare( "~", line, &line ) )
1342  SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
1343 
1344  // The thickness token does not exist in older versions of the schematic file format
1345  // so calling parseInt will be made only if the EOL is not reached.
1346  if( *line >= ' ' )
1347  thickness = parseInt( aReader, line, &line );
1348  }
1349 
1350  text->SetBold( thickness != 0 );
1351  text->SetThickness( thickness != 0 ? GetPenSizeForBold( size ) : 0 );
1352 
1353  // Read the text string for the text.
1354  char* tmp = aReader.ReadLine();
1355 
1356  tmp = strtok( tmp, "\r\n" );
1357  wxString val = FROM_UTF8( tmp );
1358 
1359  for( ; ; )
1360  {
1361  int i = val.find( wxT( "\\n" ) );
1362 
1363  if( i == wxNOT_FOUND )
1364  break;
1365 
1366  val.erase( i, 2 );
1367  val.insert( i, wxT( "\n" ) );
1368  }
1369 
1370  text->SetText( val );
1371 
1372  return text.release();
1373 }
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
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:57
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
int GetPenSizeForBold(int aTextSize)
Function GetPensizeForBold.
Definition: drawtxt.cpp:49
#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...
SCH_LINE * SCH_LEGACY_PLUGIN::loadWire ( FILE_LINE_READER aReader)
private

Definition at line 1143 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 loadFile().

1144 {
1145  std::unique_ptr< SCH_LINE > wire( new SCH_LINE );
1146 
1147  const char* line = aReader.Line();
1148 
1149  wxCHECK( strCompare( "Wire", line, &line ), NULL );
1150 
1151  if( strCompare( "Wire", line, &line ) )
1152  wire->SetLayer( LAYER_WIRE );
1153  else if( strCompare( "Bus", line, &line ) )
1154  wire->SetLayer( LAYER_BUS );
1155  else if( strCompare( "Notes", line, &line ) )
1156  wire->SetLayer( LAYER_NOTES );
1157  else
1158  SCH_PARSE_ERROR( "invalid line type", aReader, line );
1159 
1160  if( !strCompare( "Line", line, &line ) )
1161  SCH_PARSE_ERROR( "invalid wire definition", aReader, line );
1162 
1163  // Since Sept 15, 2017, a line style is alloved (width, style, color)
1164  // Only non default values are stored
1165  while( !is_eol( *line ) )
1166  {
1167  wxString buf;
1168 
1169  parseUnquotedString( buf, aReader, line, &line );
1170 
1171  if( buf == ")" )
1172  continue;
1173 
1174  else if( buf == T_WIDTH )
1175  {
1176  int size = parseInt( aReader, line, &line );
1177  wire->SetLineWidth( size );
1178  }
1179  else if( buf == T_STYLE )
1180  {
1181  parseUnquotedString( buf, aReader, line, &line );
1182  int style = SCH_LINE::GetLineStyleInternalId( buf );
1183  wire->SetLineStyle( style );
1184  }
1185  else // should be the color parameter.
1186  {
1187  // The color param is something like rgb(150, 40, 191)
1188  // and because there is no space between ( and 150
1189  // the first param is inside buf.
1190  // So break keyword and the first param into 2 separate strings.
1191  wxString prm, keyword;
1192  keyword = buf.BeforeLast( '(', &prm );
1193 
1194  if( ( keyword == T_COLOR ) || ( keyword == T_COLORA ) )
1195  {
1196  long color[4] = { 0 };
1197 
1198  int ii = 0;
1199 
1200  if( !prm.IsEmpty() )
1201  {
1202  prm.ToLong( &color[ii] );
1203  ii++;
1204  }
1205 
1206  int prm_count = ( keyword == T_COLORA ) ? 4 : 3;
1207  // fix opacity to 1.0 or 255, when not exists in file
1208  color[3] = 255;
1209 
1210  for(; ii < prm_count && !is_eol( *line ); ii++ )
1211  color[ii] = parseInt( aReader, line, &line );
1212 
1213  wire->SetLineColor( color[0]/255.0, color[1]/255.0, color[2]/255.0,color[3]/255.0 );
1214  }
1215  }
1216  }
1217 
1218  // Read the segment en points coordinates:
1219  line = aReader.ReadLine();
1220 
1221  wxPoint begin, end;
1222 
1223  begin.x = parseInt( aReader, line, &line );
1224  begin.y = parseInt( aReader, line, &line );
1225  end.x = parseInt( aReader, line, &line );
1226  end.y = parseInt( aReader, line, &line );
1227 
1228  wire->SetStartPoint( begin );
1229  wire->SetEndPoint( end );
1230 
1231  return wire.release();
1232 }
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...
#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 1653 of file sch_legacy_plugin.cpp.

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

1655 {
1656  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN object." );
1657  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1658 
1659  init( aKiway, aProperties );
1660 
1661  wxFileName fn = aFileName;
1662 
1663  // File names should be absolute. Don't assume everything relative to the project path
1664  // works properly.
1665  wxASSERT( fn.IsAbsolute() );
1666 
1667  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1668 
1669  m_out = &formatter; // no ownership
1670 
1671  Format( aScreen );
1672 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
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 1893 of file sch_legacy_plugin.cpp.

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

Referenced by Format().

1894 {
1895  wxCHECK_RET( aBitmap != NULL, "SCH_BITMAP* is NULL" );
1896 
1897  wxImage* image = aBitmap->GetImage()->GetImageData();
1898 
1899  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
1900 
1901  m_out->Print( 0, "$Bitmap\n" );
1902  m_out->Print( 0, "Pos %-4d %-4d\n", aBitmap->GetPosition().x, aBitmap->GetPosition().y );
1903  m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
1904  m_out->Print( 0, "Data\n" );
1905 
1906  wxMemoryOutputStream stream;
1907 
1908  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1909 
1910  // Write binary data in hexadecimal form (ASCII)
1911  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1912  char* begin = (char*) buffer->GetBufferStart();
1913 
1914  for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
1915  {
1916  if( ii >= 32 )
1917  {
1918  ii = 0;
1919 
1920  m_out->Print( 0, "\n" );
1921  }
1922 
1923  m_out->Print( 0, "%2.2X ", *begin & 0xFF );
1924  }
1925 
1926  m_out->Print( 0, "\nEndData\n" );
1927  m_out->Print( 0, "$EndBitmap\n" );
1928 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxImage * GetImageData()
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_bitmap.h:133
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:65
double GetScale() const
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 2024 of file sch_legacy_plugin.cpp.

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

Referenced by Format().

2025 {
2026  wxCHECK_RET( aBusEntry != NULL, "SCH_BUS_ENTRY_BASE* is NULL" );
2027 
2028  if( aBusEntry->GetLayer() == LAYER_WIRE )
2029  m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
2030  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
2031  aBusEntry->m_End().x, aBusEntry->m_End().y );
2032  else
2033  m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
2034  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
2035  aBusEntry->m_End().x, aBusEntry->m_End().y );
2036 }
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 1756 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(), m_out, MANDATORY_FIELDS, OUTPUTFORMATTER::Print(), REFERENCE, saveField(), SCH_FIELD::SetId(), TO_UTF8, toUTFTildaText(), wxPoint::x, TRANSFORM::x1, TRANSFORM::x2, wxPoint::y, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by Format().

1757 {
1758  std::string name1;
1759  std::string name2;
1760  wxArrayString reference_fields;
1761 
1762  static wxString delimiters( wxT( " " ) );
1763 
1764  // This is redundant with the AR entries below, but it makes the files backwards-compatible.
1765  if( aComponent->GetPathsAndReferences().GetCount() > 0 )
1766  {
1767  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[0], delimiters );
1768  name1 = toUTFTildaText( reference_fields[1] );
1769  }
1770  else
1771  {
1772  if( aComponent->GetField( REFERENCE )->GetText().IsEmpty() )
1773  name1 = toUTFTildaText( aComponent->GetPrefix() );
1774  else
1775  name1 = toUTFTildaText( aComponent->GetField( REFERENCE )->GetText() );
1776  }
1777 
1778  wxString part_name = aComponent->GetLibId().Format();
1779 
1780  if( part_name.size() )
1781  {
1782  name2 = toUTFTildaText( part_name );
1783  }
1784  else
1785  {
1786  name2 = "_NONAME_";
1787  }
1788 
1789  m_out->Print( 0, "$Comp\n" );
1790  m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
1791 
1792  // Generate unit number, convert and time stamp
1793  m_out->Print( 0, "U %d %d %8.8lX\n", aComponent->GetUnit(), aComponent->GetConvert(),
1794  (unsigned long)aComponent->GetTimeStamp() );
1795 
1796  // Save the position
1797  m_out->Print( 0, "P %d %d\n", aComponent->GetPosition().x, aComponent->GetPosition().y );
1798 
1799  /* If this is a complex hierarchy; save hierarchical references.
1800  * but for simple hierarchies it is not necessary.
1801  * the reference inf is already saved
1802  * this is useful for old Eeschema version compatibility
1803  */
1804  if( aComponent->GetPathsAndReferences().GetCount() > 1 )
1805  {
1806  for( unsigned int ii = 0; ii < aComponent->GetPathsAndReferences().GetCount(); ii++ )
1807  {
1808  /*format:
1809  * AR Path="/140/2" Ref="C99" Part="1"
1810  * where 140 is the uid of the containing sheet
1811  * and 2 is the timestamp of this component.
1812  * (timestamps are actually 8 hex chars)
1813  * Ref is the conventional component reference for this 'path'
1814  * Part is the conventional component part selection for this 'path'
1815  */
1816  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[ii],
1817  delimiters );
1818 
1819  m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%s\" \n",
1820  TO_UTF8( reference_fields[0] ),
1821  TO_UTF8( reference_fields[1] ),
1822  TO_UTF8( reference_fields[2] ) );
1823  }
1824  }
1825 
1826  // update the ugly field index, which I would like to see go away someday soon.
1827  for( int i = 0; i < aComponent->GetFieldCount(); ++i )
1828  aComponent->GetField( i )->SetId( i );
1829 
1830  // Fixed fields:
1831  // Save mandatory fields even if they are blank,
1832  // because the visibility, size and orientation are set from libary editor.
1833  for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
1834  saveField( aComponent->GetField( i ) );
1835 
1836  // User defined fields:
1837  // The *policy* about which user defined fields are part of a symbol is now
1838  // only in the dialog editors. No policy should be enforced here, simply
1839  // save all the user defined fields, they are present because a dialog editor
1840  // thought they should be. If you disagree, go fix the dialog editors.
1841  for( int i = MANDATORY_FIELDS; i < aComponent->GetFieldCount(); ++i )
1842  saveField( aComponent->GetField( i ) );
1843 
1844  // Unit number, position, box ( old standard )
1845  m_out->Print( 0, "\t%-4d %-4d %-4d\n", aComponent->GetUnit(), aComponent->GetPosition().x,
1846  aComponent->GetPosition().y );
1847 
1848  TRANSFORM transform = aComponent->GetTransform();
1849 
1850  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
1851  transform.x1, transform.y1, transform.x2, transform.y2 );
1852  m_out->Print( 0, "$EndComp\n" );
1853 }
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.
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:231
void SCH_LEGACY_PLUGIN::saveField ( SCH_FIELD aField)
private

Definition at line 1856 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(), m_out, OUTPUTFORMATTER::Print(), TEXT_ANGLE_HORIZ, wxPoint::x, and wxPoint::y.

Referenced by saveComponent().

1857 {
1858  char hjustify = 'C';
1859 
1860  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
1861  hjustify = 'L';
1862  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
1863  hjustify = 'R';
1864 
1865  char vjustify = 'C';
1866 
1867  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
1868  vjustify = 'B';
1869  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
1870  vjustify = 'T';
1871 
1872  m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1873  aField->GetId(),
1874  EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
1875  aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
1876  aField->GetLibPosition().x, aField->GetLibPosition().y,
1877  aField->GetTextWidth(),
1878  !aField->IsVisible(),
1879  hjustify, vjustify,
1880  aField->IsItalic() ? 'I' : 'N',
1881  aField->IsBold() ? 'B' : 'N' );
1882 
1883  // Save field name, if the name is user definable
1884  if( aField->GetId() >= FIELD1 )
1885  {
1886  m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
1887  }
1888 
1889  m_out->Print( 0, "\n" );
1890 }
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:424
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 2006 of file sch_legacy_plugin.cpp.

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

Referenced by Format().

2007 {
2008  wxCHECK_RET( aJunction != NULL, "SCH_JUNCTION* is NULL" );
2009 
2010  m_out->Print( 0, "Connection ~ %-4d %-4d\n",
2011  aJunction->GetPosition().x, aJunction->GetPosition().y );
2012 }
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 4191 of file sch_legacy_plugin.cpp.

References SCH_LEGACY_PLUGIN_CACHE::GetFileName(), SCH_LEGACY_PLUGIN_CACHE::IsFile(), m_cache, SCH_LEGACY_PLUGIN_CACHE::Save(), SCH_LEGACY_PLUGIN_CACHE::SetFileName(), SCH_LEGACY_PLUGIN_CACHE::SetModified(), and writeDocFile().

4192 {
4193  if( !m_cache )
4194  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4195 
4196  wxString oldFileName = m_cache->GetFileName();
4197 
4198  if( !m_cache->IsFile( aLibraryPath ) )
4199  {
4200  m_cache->SetFileName( aLibraryPath );
4201  }
4202 
4203  // This is a forced save.
4204  m_cache->SetModified();
4205  m_cache->Save( writeDocFile( aProperties ) );
4206  m_cache->SetFileName( oldFileName );
4207 }
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 2039 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, m_out, OUTPUTFORMATTER::Print(), T_STYLE, T_WIDTH, TO_UTF8, wxPoint::x, and wxPoint::y.

Referenced by Format().

2040 {
2041  wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" );
2042 
2043  const char* layer = "Notes";
2044  const char* width = "Line";
2045 
2046  if( aLine->GetLayer() == LAYER_WIRE )
2047  layer = "Wire";
2048  else if( aLine->GetLayer() == LAYER_BUS )
2049  layer = "Bus";
2050 
2051  m_out->Print( 0, "Wire %s %s", layer, width );
2052 
2053  // Write line style (width, type, color) only for non default values
2054  if( aLine->GetLayer() == LAYER_NOTES )
2055  {
2056  if( aLine->GetPenSize() != aLine->GetDefaultWidth() )
2057  m_out->Print( 0, " %s %d", T_WIDTH, aLine->GetLineSize() );
2058 
2059  if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
2060  m_out->Print( 0, " %s %s", T_STYLE, SCH_LINE::GetLineStyleName( aLine->GetLineStyle() ) );
2061 
2062  if( aLine->GetLineColor() != aLine->GetDefaultColor() )
2063  m_out->Print( 0, " %s",
2064  TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
2065  }
2066 
2067  m_out->Print( 0, "\n" );
2068 
2069  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
2070  aLine->GetStartPoint().x, aLine->GetStartPoint().y,
2071  aLine->GetEndPoint().x, aLine->GetEndPoint().y );
2072 
2073  m_out->Print( 0, "\n");
2074 }
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 2015 of file sch_legacy_plugin.cpp.

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

Referenced by Format().

2016 {
2017  wxCHECK_RET( aNoConnect != NULL, "SCH_NOCONNECT* is NULL" );
2018 
2019  m_out->Print( 0, "NoConn ~ %-4d %-4d\n", aNoConnect->GetPosition().x,
2020  aNoConnect->GetPosition().y );
2021 }
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 1931 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(), m_out, NET_BIDI, NET_INPUT, NET_OUTPUT, NET_TRISTATE, NET_UNSPECIFIED, OUTPUTFORMATTER::Print(), 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 Format().

1932 {
1933  wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" );
1934 
1935  m_out->Print( 0, "$Sheet\n" );
1936  m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
1937  aSheet->GetPosition().x, aSheet->GetPosition().y,
1938  aSheet->GetSize().x, aSheet->GetSize().y );
1939 
1940  m_out->Print( 0, "U %8.8lX\n", (unsigned long) aSheet->GetTimeStamp() );
1941 
1942  if( !aSheet->GetName().IsEmpty() )
1943  m_out->Print( 0, "F0 %s %d\n", EscapedUTF8( aSheet->GetName() ).c_str(),
1944  aSheet->GetSheetNameSize() );
1945 
1946  if( !aSheet->GetFileName().IsEmpty() )
1947  m_out->Print( 0, "F1 %s %d\n", EscapedUTF8( aSheet->GetFileName() ).c_str(),
1948  aSheet->GetFileNameSize() );
1949 
1950  for( const SCH_SHEET_PIN& pin : aSheet->GetPins() )
1951  {
1952  int type, side;
1953 
1954  if( pin.GetText().IsEmpty() )
1955  break;
1956 
1957  switch( pin.GetEdge() )
1958  {
1959  default:
1961  side = 'L';
1962  break;
1963 
1965  side = 'R';
1966  break;
1967 
1969  side = 'T';
1970  break;
1971 
1973  side = 'B';
1974  break;
1975  }
1976 
1977  switch( pin.GetShape() )
1978  {
1979  case NET_INPUT:
1980  type = 'I'; break;
1981 
1982  case NET_OUTPUT:
1983  type = 'O'; break;
1984 
1985  case NET_BIDI:
1986  type = 'B'; break;
1987 
1988  case NET_TRISTATE:
1989  type = 'T'; break;
1990 
1991  default:
1992  case NET_UNSPECIFIED:
1993  type = 'U'; break;
1994  }
1995 
1996  m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n", pin.GetNumber(),
1997  EscapedUTF8( pin.GetText() ).c_str(), // supplies wrapping quotes
1998  type, side, pin.GetPosition().x, pin.GetPosition().y,
1999  pin.GetTextWidth() );
2000  }
2001 
2002  m_out->Print( 0, "$EndSheet\n" );
2003 }
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:645
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:231
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 4101 of file sch_legacy_plugin.cpp.

References SCH_LEGACY_PLUGIN_CACHE::AddSymbol(), cacheLib(), isBuffering(), m_cache, m_props, SCH_LEGACY_PLUGIN_CACHE::Save(), and writeDocFile().

4103 {
4104  m_props = aProperties;
4105 
4106  cacheLib( aLibraryPath );
4107 
4108  m_cache->AddSymbol( aSymbol );
4109 
4110  if( !isBuffering( aProperties ) )
4111  m_cache->Save( writeDocFile( aProperties ) );
4112 }
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 2077 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, m_out, OUTPUTFORMATTER::Print(), SheetLabelType, TO_UTF8, wxPoint::x, and wxPoint::y.

Referenced by Format().

2078 {
2079  wxCHECK_RET( aText != NULL, "SCH_TEXT* is NULL" );
2080 
2081  const char* italics = "~";
2082  const char* textType = "Notes";
2083 
2084  if( aText->IsItalic() )
2085  italics = "Italic";
2086 
2087  wxString text = aText->GetText();
2088 
2089  SCH_LAYER_ID layer = aText->GetLayer();
2090 
2091  if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
2092  {
2093  if( layer == LAYER_NOTES )
2094  {
2095  // For compatibility reasons, the text must be saved in only one text line
2096  // so replace all EOLs with \\n
2097  text.Replace( wxT( "\n" ), wxT( "\\n" ) );
2098 
2099  // Here we should have no CR or LF character in line
2100  // This is not always the case if a multiline text was copied (using a copy/paste
2101  // function) from a text that uses E.O.L characters that differs from the current
2102  // EOL format. This is mainly the case under Linux using LF symbol when copying
2103  // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
2104  // (or LF left under MacOSX)
2105  for( unsigned ii = 0; ii < text.Len(); )
2106  {
2107  if( text[ii] == 0x0A || text[ii] == 0x0D )
2108  text.erase( ii, 1 );
2109  else
2110  ii++;
2111  }
2112  }
2113  else
2114  {
2115  textType = "Label";
2116  }
2117 
2118  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2119  aText->GetPosition().x, aText->GetPosition().y,
2120  aText->GetLabelSpinStyle(),
2121  aText->GetTextWidth(),
2122  italics, aText->GetThickness(), TO_UTF8( text ) );
2123  }
2124  else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2125  {
2126  textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2127 
2128  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2129  aText->GetPosition().x, aText->GetPosition().y,
2130  aText->GetLabelSpinStyle(),
2131  aText->GetTextWidth(),
2132  SheetLabelType[aText->GetShape()],
2133  italics,
2134  aText->GetThickness(), TO_UTF8( text ) );
2135  }
2136 }
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:57
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 3999 of file sch_legacy_plugin.cpp.

References PropNoDocFile.

Referenced by CreateSymbolLib(), DeleteAlias(), DeleteSymbol(), SaveLibrary(), and SaveSymbol().

4000 {
4001  std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
4002 
4003  if( aProperties && aProperties->find( propName ) != aProperties->end() )
4004  return false;
4005 
4006  return true;
4007 }
static const char * PropNoDocFile
const char* PropBuffering

Member Data Documentation

wxString SCH_LEGACY_PLUGIN::m_error
protected

For throwing exceptions or errors on partial schematic loads.

Definition at line 162 of file sch_legacy_plugin.h.

Referenced by GetError(), loadHeader(), and loadHierarchy().

KIWAY* SCH_LEGACY_PLUGIN::m_kiway
protected

Required for path to legacy component libraries.

Definition at line 166 of file sch_legacy_plugin.h.

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

FILE_OUTPUTFORMATTER* SCH_LEGACY_PLUGIN::m_out
protected

The output formatter for saving SCH_SCREEN objects.

Definition at line 168 of file sch_legacy_plugin.h.

Referenced by Format(), init(), Save(), saveBitmap(), saveBusEntry(), saveComponent(), saveField(), saveJunction(), saveLine(), saveNoConnect(), saveSheet(), and saveText().

wxString SCH_LEGACY_PLUGIN::m_path
protected

Root project path for loading child sheets.

Definition at line 164 of file sch_legacy_plugin.h.

Referenced by Load(), and loadHierarchy().

const PROPERTIES* SCH_LEGACY_PLUGIN::m_props
protected

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

Definition at line 165 of file sch_legacy_plugin.h.

Referenced by cacheLib(), CreateSymbolLib(), DeleteAlias(), DeleteSymbol(), EnumerateSymbolLib(), GetSymbolLibCount(), init(), LoadSymbol(), and SaveSymbol().

SCH_SHEET* SCH_LEGACY_PLUGIN::m_rootSheet
protected

The root sheet of the schematic being loaded..

Definition at line 167 of file sch_legacy_plugin.h.

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

int SCH_LEGACY_PLUGIN::m_version
protected

Version of file being loaded.

Definition at line 159 of file sch_legacy_plugin.h.

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

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

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

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

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


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