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
 Function CheckHeader returns 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...
 
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. 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 561 of file sch_legacy_plugin.cpp.

References init().

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

Definition at line 567 of file sch_legacy_plugin.cpp.

References m_cache.

568 {
569  delete m_cache;
570 }
SCH_LEGACY_PLUGIN_CACHE * m_cache

Member Function Documentation

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

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

3478 {
3479  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
3480  {
3481  // a spectacular episode in memory management:
3482  delete m_cache;
3483  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
3484 
3485  // Because m_cache is rebuilt, increment PART_LIBS::s_modify_generation
3486  // to modify the hash value that indicate component to symbol links
3487  // must be updated.
3489 
3490  if( !isBuffering( m_props ) )
3491  m_cache->Load();
3492  }
3493 }
static int s_modify_generation
helper for GetModifyHash()
SCH_LEGACY_PLUGIN_CACHE * m_cache
Class SCH_LEGACY_PLUGIN_CACHE is a cache assistant for the part library portion of the SCH_PLUGIN API...
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

Function CheckHeader returns 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 3707 of file sch_legacy_plugin.cpp.

3708 {
3709  // Open file and check first line
3710  wxTextFile tempFile;
3711 
3712  tempFile.Open( aFileName );
3713  wxString firstline;
3714  // read the first line
3715  firstline = tempFile.GetFirstLine();
3716  tempFile.Close();
3717 
3718  return firstline.StartsWith( "EESchema" );
3719 }
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 3640 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().

3642 {
3643  if( wxFileExists( aLibraryPath ) )
3644  {
3646  _( "symbol library '%s' already exists, cannot create a new library" ),
3647  aLibraryPath.GetData() ) );
3648  }
3649 
3650  LOCALE_IO toggle;
3651 
3652  m_props = aProperties;
3653 
3654  delete m_cache;
3655  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
3656  m_cache->SetModified();
3657  m_cache->Save( writeDocFile( aProperties ) );
3658  m_cache->Load(); // update m_writable and m_mod_time
3659 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:165
SCH_LEGACY_PLUGIN_CACHE * m_cache
Class SCH_LEGACY_PLUGIN_CACHE is a cache assistant for the part library portion of the SCH_PLUGIN API...
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 3612 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().

3614 {
3615  m_props = aProperties;
3616 
3617  cacheLib( aLibraryPath );
3618 
3619  m_cache->DeleteAlias( aAliasName );
3620 
3621  if( !isBuffering( aProperties ) )
3622  m_cache->Save( writeDocFile( aProperties ) );
3623 }
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 3626 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().

3628 {
3629  m_props = aProperties;
3630 
3631  cacheLib( aLibraryPath );
3632 
3633  m_cache->DeleteSymbol( aAliasName );
3634 
3635  if( !isBuffering( aProperties ) )
3636  m_cache->Save( writeDocFile( aProperties ) );
3637 }
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 3662 of file sch_legacy_plugin.cpp.

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

3664 {
3665  wxFileName fn = aLibraryPath;
3666 
3667  if( !fn.FileExists() )
3668  return false;
3669 
3670  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
3671  // we don't want that. we want bare metal portability with no UI here.
3672  if( wxRemove( aLibraryPath ) )
3673  {
3674  THROW_IO_ERROR( wxString::Format( _( "library '%s' cannot be deleted" ),
3675  aLibraryPath.GetData() ) );
3676  }
3677 
3678  if( m_cache && m_cache->IsFile( aLibraryPath ) )
3679  {
3680  delete m_cache;
3681  m_cache = 0;
3682  }
3683 
3684  return true;
3685 }
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 3536 of file sch_legacy_plugin.cpp.

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

3539 {
3540  LOCALE_IO toggle; // toggles on, then off, the C locale.
3541 
3542  m_props = aProperties;
3543 
3544  bool powerSymbolsOnly = ( aProperties &&
3545  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
3546  cacheLib( aLibraryPath );
3547 
3548  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
3549 
3550  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
3551  {
3552  if( !powerSymbolsOnly || it->second->GetPart()->IsPower() )
3553  aAliasNameList.Add( it->first );
3554  }
3555 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:165
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 3558 of file sch_legacy_plugin.cpp.

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

3561 {
3562  LOCALE_IO toggle; // toggles on, then off, the C locale.
3563 
3564  m_props = aProperties;
3565 
3566  bool powerSymbolsOnly = ( aProperties &&
3567  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
3568  cacheLib( aLibraryPath );
3569 
3570  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
3571 
3572  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
3573  {
3574  if( !powerSymbolsOnly || it->second->GetPart()->IsPower() )
3575  aAliasList.push_back( it->second );
3576  }
3577 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:165
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 1652 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().

1653 {
1654  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN* object." );
1655  wxCHECK_RET( m_kiway != NULL, "NULL KIWAY* object." );
1656 
1657  // Write the header
1658  m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1659 
1660  // Write the project libraries.
1661  for( const PART_LIB& lib : *m_kiway->Prj().SchLibs() )
1662  m_out->Print( 0, "LIBS:%s\n", TO_UTF8( lib.GetName() ) );
1663 
1664  // This section is not used, but written for file compatibility
1665  m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1666  m_out->Print( 0, "EELAYER END\n" );
1667 
1668  /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1669  * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1670  * simple hierarchy and flat hierarchy. Used also to search the root
1671  * sheet ( ScreenNumber = 1 ) within the files
1672  */
1673  const TITLE_BLOCK& tb = aScreen->GetTitleBlock();
1674  const PAGE_INFO& page = aScreen->GetPageSettings();
1675 
1676  m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1677  page.GetWidthMils(),
1678  page.GetHeightMils(),
1679  !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1680  m_out->Print( 0, "encoding utf-8\n" );
1681  m_out->Print( 0, "Sheet %d %d\n", aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens );
1682  m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1683  m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1684  m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1685  m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1686  m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment1() ).c_str() );
1687  m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment2() ).c_str() );
1688  m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment3() ).c_str() );
1689  m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment4() ).c_str() );
1690  m_out->Print( 0, "$EndDescr\n" );
1691 
1692  for( SCH_ITEM* item = aScreen->GetDrawItems(); item; item = item->Next() )
1693  {
1694  switch( item->Type() )
1695  {
1696  case SCH_COMPONENT_T:
1697  saveComponent( dynamic_cast< SCH_COMPONENT* >( item ) );
1698  break;
1699  case SCH_BITMAP_T:
1700  saveBitmap( dynamic_cast< SCH_BITMAP* >( item ) );
1701  break;
1702  case SCH_SHEET_T:
1703  saveSheet( dynamic_cast< SCH_SHEET* >( item ) );
1704  break;
1705  case SCH_JUNCTION_T:
1706  saveJunction( dynamic_cast< SCH_JUNCTION* >( item ) );
1707  break;
1708  case SCH_NO_CONNECT_T:
1709  saveNoConnect( dynamic_cast< SCH_NO_CONNECT* >( item ) );
1710  break;
1711  case SCH_BUS_WIRE_ENTRY_T:
1712  case SCH_BUS_BUS_ENTRY_T:
1713  saveBusEntry( dynamic_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1714  break;
1715  case SCH_LINE_T:
1716  saveLine( dynamic_cast< SCH_LINE* >( item ) );
1717  break;
1718  case SCH_TEXT_T:
1719  case SCH_LABEL_T:
1720  case SCH_GLOBAL_LABEL_T:
1722  saveText( dynamic_cast< SCH_TEXT* >( item ) );
1723  break;
1724  default:
1725  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1726  }
1727  }
1728 
1729  m_out->Print( 0, "$EndSCHEMATC\n" );
1730 }
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:144
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
Class PART_LIB is used to load, save, search, and otherwise manipulate part 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::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 3513 of file sch_legacy_plugin.cpp.

References SCH_LEGACY_PLUGIN_CACHE::GetModifyHash(), and m_cache.

3514 {
3515  if( m_cache )
3516  return m_cache->GetModifyHash();
3517 
3518  // If the cache hasn't been loaded, it hasn't been modified.
3519  return 0;
3520 }
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 3523 of file sch_legacy_plugin.cpp.

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

3525 {
3526  LOCALE_IO toggle;
3527 
3528  m_props = aProperties;
3529 
3530  cacheLib( aLibraryPath );
3531 
3532  return m_cache->m_aliases.size();
3533 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:165
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 573 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().

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

References PROPERTIES::Exists(), and PropBuffering.

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

3508 {
3509  return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
3510 }
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 3722 of file sch_legacy_plugin.cpp.

3723 {
3724  return wxFileName::IsFileWritable( aLibraryPath );
3725 }
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 584 of file sch_legacy_plugin.cpp.

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

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

1006 {
1007  std::unique_ptr< SCH_BITMAP > bitmap( new SCH_BITMAP );
1008 
1009  const char* line = aReader.Line();
1010 
1011  wxCHECK( strCompare( "$Bitmap", line, &line ), NULL );
1012 
1013  line = aReader.ReadLine();
1014 
1015  while( line != NULL )
1016  {
1017  if( strCompare( "Pos", line, &line ) )
1018  {
1019  wxPoint position;
1020 
1021  position.x = parseInt( aReader, line, &line );
1022  position.y = parseInt( aReader, line, &line );
1023  bitmap->SetPosition( position );
1024  }
1025  else if( strCompare( "Scale", line, &line ) )
1026  {
1028  bitmap->GetImage()->SetScale( parseDouble( aReader, line, &line ) );
1029  }
1030  else if( strCompare( "Data", line, &line ) )
1031  {
1032  wxMemoryOutputStream stream;
1033 
1034  while( line )
1035  {
1036  if( !aReader.ReadLine() )
1037  SCH_PARSE_ERROR( _( "Unexpected end of file" ), aReader, line );
1038 
1039  line = aReader.Line();
1040 
1041  if( strCompare( "EndData", line ) )
1042  {
1043  // all the PNG date is read.
1044  // We expect here m_image and m_bitmap are void
1045  wxImage* image = new wxImage();
1046  wxMemoryInputStream istream( stream );
1047  image->LoadFile( istream, wxBITMAP_TYPE_PNG );
1048  bitmap->GetImage()->SetImage( image );
1049  bitmap->GetImage()->SetBitmap( new wxBitmap( *image ) );
1050  break;
1051  }
1052 
1053  // Read PNG data, stored in hexadecimal,
1054  // each byte = 2 hexadecimal digits and a space between 2 bytes
1055  // and put it in memory stream buffer
1056  int len = strlen( line );
1057 
1058  for( ; len > 0 && !isspace( *line ); len -= 3, line += 3 )
1059  {
1060  int value = 0;
1061 
1062  if( sscanf( line, "%X", &value ) == 1 )
1063  stream.PutC( (char) value );
1064  else
1065  THROW_IO_ERROR( "invalid PNG data" );
1066  }
1067  }
1068 
1069  if( line == NULL )
1070  THROW_IO_ERROR( _( "unexpected end of file" ) );
1071  }
1072  else if( strCompare( "$EndBitmap", line ) )
1073  return bitmap.release();
1074 
1075  line = aReader.ReadLine();
1076  }
1077 
1078  THROW_IO_ERROR( _( "unexpected end of file" ) );
1079 }
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)
Function parseInt.
static double parseDouble(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseDouble.
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)
Function strCompare.
#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 1218 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().

1219 {
1220  const char* line = aReader.Line();
1221 
1222  wxCHECK( strCompare( "Entry", line, &line ), NULL );
1223 
1224  std::unique_ptr< SCH_BUS_ENTRY_BASE > busEntry;
1225 
1226  if( strCompare( "Wire", line, &line ) )
1227  {
1228  busEntry.reset( new SCH_BUS_WIRE_ENTRY );
1229 
1230  if( !strCompare( "Line", line, &line ) )
1231  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
1232  }
1233  else if( strCompare( "Bus", line, &line ) )
1234  {
1235  busEntry.reset( new SCH_BUS_BUS_ENTRY );
1236 
1237  if( !strCompare( "Bus", line, &line ) )
1238  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
1239  }
1240  else
1241  SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
1242 
1243  line = aReader.ReadLine();
1244 
1245  wxPoint pos;
1246  wxSize size;
1247 
1248  pos.x = parseInt( aReader, line, &line );
1249  pos.y = parseInt( aReader, line, &line );
1250  size.x = parseInt( aReader, line, &line );
1251  size.y = parseInt( aReader, line, &line );
1252 
1253  size.x -= pos.x;
1254  size.y -= pos.y;
1255 
1256  busEntry->SetPosition( pos );
1257  busEntry->SetSize( size );
1258 
1259  return busEntry.release();
1260 }
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)
Function parseInt.
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)
Function strCompare.
Class for a wire to bus entry.
SCH_COMPONENT * SCH_LEGACY_PLUGIN::loadComponent ( FILE_LINE_READER aReader)
private

Definition at line 1359 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, 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().

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

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

683 {
684  FILE_LINE_READER reader( aFileName );
685 
686  loadHeader( reader, aScreen );
687 
688  while( reader.ReadLine() )
689  {
690  char* line = reader.Line();
691 
692  while( *line && *line == ' ' )
693  line++;
694 
695  // Either an object will be loaded properly or the file load will fail and raise
696  // an exception.
697  if( strCompare( "$Descr", line ) )
698  loadPageSettings( reader, aScreen );
699  else if( strCompare( "$Comp", line ) )
700  aScreen->Append( loadComponent( reader ) );
701  else if( strCompare( "$Sheet", line ) )
702  aScreen->Append( loadSheet( reader ) );
703  else if( strCompare( "$Bitmap", line ) )
704  aScreen->Append( loadBitmap( reader ) );
705  else if( strCompare( "Connection", line ) )
706  aScreen->Append( loadJunction( reader ) );
707  else if( strCompare( "NoConn", line ) )
708  aScreen->Append( loadNoConnect( reader ) );
709  else if( strCompare( "Wire", line ) )
710  aScreen->Append( loadWire( reader ) );
711  else if( strCompare( "Entry", line ) )
712  aScreen->Append( loadBusEntry( reader ) );
713  else if( strCompare( "Text", line ) )
714  aScreen->Append( loadText( reader ) );
715  else if( strCompare( "$EndSCHEMATC", line ) )
716  return;
717  }
718 
719  // Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
720  // so checking for it's existance will fail so just exit here and take our chances. :(
721  if( m_version > 1 )
722  THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
723 }
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)
Function strCompare.
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 726 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().

727 {
728  const char* line = aReader.ReadLine();
729 
730  if( !strCompare( "Eeschema Schematic File Version", line, &line ) )
731  {
732  m_error.Printf( _( "'%s' does not appear to be an Eeschema file" ),
733  GetChars( aScreen->GetFileName() ) );
735  }
736 
737  // get the file version here.
738  m_version = parseInt( aReader, line, &line );
739 
740  // The next lines are the lib list section, and are mainly comments, like:
741  // LIBS:power
742  // the lib list is not used, but is in schematic file just in case.
743  // It is usually not empty, but we accept empty list.
744  // If empty, there is a legacy section, not used
745  // EELAYER i j
746  // and the last line is
747  // EELAYER END
748  // Skip all lines until the end of header "EELAYER END" is found
749  while( aReader.ReadLine() )
750  {
751  line = aReader.Line();
752 
753  while( *line == ' ' )
754  line++;
755 
756  if( strCompare( "EELAYER END", line ) )
757  return;
758  }
759 
760  THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
761 }
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.
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
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)
Function strCompare.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void SCH_LEGACY_PLUGIN::loadHierarchy ( SCH_SHEET aSheet)
private

Definition at line 628 of file sch_legacy_plugin.cpp.

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

Referenced by Load().

629 {
630  SCH_SCREEN* screen = NULL;
631 
632  if( !aSheet->GetScreen() )
633  {
634  // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
635  // stores the file name and extension. Add the project path to the file name and
636  // extension to compare when calling SCH_SHEET::SearchHierarchy().
637  wxFileName fileName = aSheet->GetFileName();
638 
639  if( !fileName.IsAbsolute() )
640  fileName.MakeAbsolute( m_path );
641 
642  m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
643 
644  if( screen )
645  {
646  aSheet->SetScreen( screen );
647 
648  // Do not need to load the sub-sheets - this has already been done.
649  }
650  else
651  {
652  aSheet->SetScreen( new SCH_SCREEN( m_kiway ) );
653  aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
654  loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
655 
656  EDA_ITEM* item = aSheet->GetScreen()->GetDrawItems();
657 
658  while( item )
659  {
660  if( item->Type() == SCH_SHEET_T )
661  {
662  SCH_SHEET* sheet = (SCH_SHEET*) item;
663 
664  // Set the parent to aSheet. This effectively creates a method to find
665  // the root sheet from any sheet so a pointer to the root sheet does not
666  // need to be stored globally. Note: this is not the same as a hierarchy.
667  // Complex hierarchies can have multiple copies of a sheet. This only
668  // provides a simple tree to find the root sheet.
669  sheet->SetParent( aSheet );
670 
671  // Recursion starts here.
672  loadHierarchy( sheet );
673  }
674 
675  item = item->Next();
676  }
677  }
678  }
679 }
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
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:227
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
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
void SetFileName(const wxString &aFileName)
KIWAY * m_kiway
Required for path to legacy component libraries.
SCH_JUNCTION * SCH_LEGACY_PLUGIN::loadJunction ( FILE_LINE_READER aReader)
private

Definition at line 1082 of file sch_legacy_plugin.cpp.

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

Referenced by loadFile().

1083 {
1084  std::unique_ptr< SCH_JUNCTION > junction( new SCH_JUNCTION );
1085 
1086  const char* line = aReader.Line();
1087 
1088  wxCHECK( strCompare( "Connection", line, &line ), NULL );
1089 
1090  wxString name;
1091 
1092  parseUnquotedString( name, aReader, line, &line );
1093 
1094  wxPoint position;
1095 
1096  position.x = parseInt( aReader, line, &line );
1097  position.y = parseInt( aReader, line, &line );
1098  junction->SetPosition( position );
1099 
1100  return junction.release();
1101 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseUnquotedString.
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)
Function strCompare.
const char * name
SCH_NO_CONNECT * SCH_LEGACY_PLUGIN::loadNoConnect ( FILE_LINE_READER aReader)
private

Definition at line 1104 of file sch_legacy_plugin.cpp.

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

Referenced by loadFile().

1105 {
1106  std::unique_ptr< SCH_NO_CONNECT > no_connect( new SCH_NO_CONNECT );
1107 
1108  const char* line = aReader.Line();
1109 
1110  wxCHECK( strCompare( "NoConn", line, &line ), NULL );
1111 
1112  wxString name;
1113 
1114  parseUnquotedString( name, aReader, line, &line );
1115 
1116  wxPoint position;
1117 
1118  position.x = parseInt( aReader, line, &line );
1119  position.y = parseInt( aReader, line, &line );
1120  no_connect->SetPosition( position );
1121 
1122  return no_connect.release();
1123 }
static int parseInt(FILE_LINE_READER &aReader, const char *aLine, const char **aOutput=NULL)
Function parseInt.
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
Function parseUnquotedString.
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)
Function strCompare.
const char * name
void SCH_LEGACY_PLUGIN::loadPageSettings ( FILE_LINE_READER aReader,
SCH_SCREEN aScreen 
)
private

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

765 {
766  wxASSERT( aScreen != NULL );
767 
768  wxString buf;
769  const char* line = aReader.Line();
770 
771  PAGE_INFO pageInfo;
772  TITLE_BLOCK tb;
773 
774  wxCHECK_RET( strCompare( "$Descr", line, &line ), "Invalid sheet description" );
775 
776  parseUnquotedString( buf, aReader, line, &line );
777 
778  if( !pageInfo.SetType( buf ) )
779  SCH_PARSE_ERROR( "invalid page size", aReader, line );
780 
781  int pagew = parseInt( aReader, line, &line );
782  int pageh = parseInt( aReader, line, &line );
783 
784  if( buf == PAGE_INFO::Custom )
785  {
786  pageInfo.SetWidthMils( pagew );
787  pageInfo.SetHeightMils( pageh );
788  }
789  else
790  {
791  wxString orientation;
792 
793  // Non custom size, set portrait if its present. Can be empty string which defaults
794  // to landscape.
795  parseUnquotedString( orientation, aReader, line, &line, true );
796 
797  if( orientation == "portrait" )
798  pageInfo.SetPortrait( true );
799  }
800 
801  aScreen->SetPageSettings( pageInfo );
802 
803  while( line != NULL )
804  {
805  buf.clear();
806 
807  if( !aReader.ReadLine() )
808  SCH_PARSE_ERROR( _( "unexpected end of file" ), aReader, line );
809 
810  line = aReader.Line();
811 
812  if( strCompare( "Sheet", line, &line ) )
813  {
814  aScreen->m_ScreenNumber = parseInt( aReader, line, &line );
815  aScreen->m_NumberOfScreens = parseInt( aReader, line, &line );
816  }
817  else if( strCompare( "Title", line, &line ) )
818  {
819  parseQuotedString( buf, aReader, line, &line, true );
820  tb.SetTitle( buf );
821  }
822  else if( strCompare( "Date", line, &line ) )
823  {
824  parseQuotedString( buf, aReader, line, &line, true );
825  tb.SetDate( buf );
826  }
827  else if( strCompare( "Rev", line, &line ) )
828  {
829  parseQuotedString( buf, aReader, line, &line, true );
830  tb.SetRevision( buf );
831  }
832  else if( strCompare( "Comp", line, &line ) )
833  {
834  parseQuotedString( buf, aReader, line, &line, true );
835  tb.SetCompany( buf );
836  }
837  else if( strCompare( "Comment1", line, &line ) )
838  {
839  parseQuotedString( buf, aReader, line, &line, true );
840  tb.SetComment1( buf );
841  }
842  else if( strCompare( "Comment2", line, &line ) )
843  {
844  parseQuotedString( buf, aReader, line, &line, true );
845  tb.SetComment2( buf );
846  }
847  else if( strCompare( "Comment3", line, &line ) )
848  {
849  parseQuotedString( buf, aReader, line, &line, true );
850  tb.SetComment3( buf );
851  }
852  else if( strCompare( "Comment4", line, &line ) )
853  {
854  parseQuotedString( buf, aReader, line, &line, true );
855  tb.SetComment4( buf );
856  }
857  else if( strCompare( "$EndDescr", line ) )
858  {
859  aScreen->SetTitleBlock( tb );
860  return;
861  }
862  }
863 
864  SCH_PARSE_ERROR( "missing 'EndDescr'", aReader, line );
865 }
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)
Function parseInt.
void SetRevision(const wxString &aRevision)
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)
Function parseUnquotedString.
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)
bool SetType(const wxString &aStandardPageDescriptionName, bool IsPortrait=false)
Function SetType sets the name of the page type and also the sizes and margins commonly associated wi...
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
void SetTitle(const wxString &aTitle)
void SetPortrait(bool isPortrait)
Function SetPortrait will rotate the paper page 90 degrees.
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)
Function parseQuotedString.
void SetWidthMils(int aWidthInMils)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
void SetComment3(const wxString &aComment)
SCH_SHEET * SCH_LEGACY_PLUGIN::loadSheet ( FILE_LINE_READER aReader)
private

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

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

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

3582 {
3583  LOCALE_IO toggle; // toggles on, then off, the C locale.
3584 
3585  m_props = aProperties;
3586 
3587  cacheLib( aLibraryPath );
3588 
3589  LIB_ALIAS_MAP::const_iterator it = m_cache->m_aliases.find( aAliasName );
3590 
3591  if( it == m_cache->m_aliases.end() )
3592  return NULL;
3593 
3594  return it->second;
3595 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:165
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 1263 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().

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

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

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

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

1632 {
1633  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN object." );
1634  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1635 
1636  init( aKiway, aProperties );
1637 
1638  wxFileName fn = aFileName;
1639 
1640  // File names should be absolute. Don't assume everything relative to the project path
1641  // works properly.
1642  wxASSERT( fn.IsAbsolute() );
1643 
1644  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1645 
1646  m_out = &formatter; // no ownership
1647 
1648  Format( aScreen );
1649 }
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 1870 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().

1871 {
1872  wxCHECK_RET( aBitmap != NULL, "SCH_BITMAP* is NULL" );
1873 
1874  wxImage* image = aBitmap->GetImage()->GetImageData();
1875 
1876  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
1877 
1878  m_out->Print( 0, "$Bitmap\n" );
1879  m_out->Print( 0, "Pos %-4d %-4d\n", aBitmap->GetPosition().x, aBitmap->GetPosition().y );
1880  m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
1881  m_out->Print( 0, "Data\n" );
1882 
1883  wxMemoryOutputStream stream;
1884 
1885  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1886 
1887  // Write binary data in hexadecimal form (ASCII)
1888  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1889  char* begin = (char*) buffer->GetBufferStart();
1890 
1891  for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
1892  {
1893  if( ii >= 32 )
1894  {
1895  ii = 0;
1896 
1897  m_out->Print( 0, "\n" );
1898  }
1899 
1900  m_out->Print( 0, "%2.2X ", *begin & 0xFF );
1901  }
1902 
1903  m_out->Print( 0, "\nEndData\n" );
1904  m_out->Print( 0, "$EndBitmap\n" );
1905 }
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 2001 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().

2002 {
2003  wxCHECK_RET( aBusEntry != NULL, "SCH_BUS_ENTRY_BASE* is NULL" );
2004 
2005  if( aBusEntry->GetLayer() == LAYER_WIRE )
2006  m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
2007  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
2008  aBusEntry->m_End().x, aBusEntry->m_End().y );
2009  else
2010  m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
2011  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
2012  aBusEntry->m_End().x, aBusEntry->m_End().y );
2013 }
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 1733 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().

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

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

1834 {
1835  char hjustify = 'C';
1836 
1837  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
1838  hjustify = 'L';
1839  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
1840  hjustify = 'R';
1841 
1842  char vjustify = 'C';
1843 
1844  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
1845  vjustify = 'B';
1846  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
1847  vjustify = 'T';
1848 
1849  m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1850  aField->GetId(),
1851  EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
1852  aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
1853  aField->GetLibPosition().x, aField->GetLibPosition().y,
1854  aField->GetTextWidth(),
1855  !aField->IsVisible(),
1856  hjustify, vjustify,
1857  aField->IsItalic() ? 'I' : 'N',
1858  aField->IsBold() ? 'B' : 'N' );
1859 
1860  // Save field name, if the name is user definable
1861  if( aField->GetId() >= FIELD1 )
1862  {
1863  m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
1864  }
1865 
1866  m_out->Print( 0, "\n" );
1867 }
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:90
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:425
bool IsItalic() const
Definition: eda_text.h:170
int GetId() const
Definition: sch_field.h:87
int GetTextWidth() const
Definition: eda_text.h:218
wxPoint GetLibPosition() const
Definition: sch_field.h:187
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:190
bool IsBold() const
Definition: eda_text.h:173
double GetTextAngle() const
Definition: eda_text.h:164
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:130
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:191
bool IsVisible() const
Definition: eda_text.h:176
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 1983 of file sch_legacy_plugin.cpp.

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

Referenced by Format().

1984 {
1985  wxCHECK_RET( aJunction != NULL, "SCH_JUNCTION* is NULL" );
1986 
1987  m_out->Print( 0, "Connection ~ %-4d %-4d\n",
1988  aJunction->GetPosition().x, aJunction->GetPosition().y );
1989 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_junction.h:88
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 3688 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().

3689 {
3690  if( !m_cache )
3691  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
3692 
3693  wxString oldFileName = m_cache->GetFileName();
3694 
3695  if( !m_cache->IsFile( aLibraryPath ) )
3696  {
3697  m_cache->SetFileName( aLibraryPath );
3698  }
3699 
3700  // This is a forced save.
3701  m_cache->SetModified();
3702  m_cache->Save( writeDocFile( aProperties ) );
3703  m_cache->SetFileName( oldFileName );
3704 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
Class SCH_LEGACY_PLUGIN_CACHE is a cache assistant for the part library portion of the SCH_PLUGIN API...
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 2016 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().

2017 {
2018  wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" );
2019 
2020  const char* layer = "Notes";
2021  const char* width = "Line";
2022 
2023  if( aLine->GetLayer() == LAYER_WIRE )
2024  layer = "Wire";
2025  else if( aLine->GetLayer() == LAYER_BUS )
2026  layer = "Bus";
2027 
2028  m_out->Print( 0, "Wire %s %s", layer, width );
2029 
2030  // Write line style (width, type, color) only for non default values
2031  if( aLine->GetLayer() == LAYER_NOTES )
2032  {
2033  if( aLine->GetPenSize() != aLine->GetDefaultWidth() )
2034  m_out->Print( 0, " %s %d", T_WIDTH, aLine->GetLineSize() );
2035 
2036  if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
2037  m_out->Print( 0, " %s %s", T_STYLE, SCH_LINE::GetLineStyleName( aLine->GetLineStyle() ) );
2038 
2039  if( aLine->GetLineColor() != aLine->GetDefaultColor() )
2040  m_out->Print( 0, " %s",
2041  TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
2042  }
2043 
2044  m_out->Print( 0, "\n" );
2045 
2046  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
2047  aLine->GetStartPoint().x, aLine->GetStartPoint().y,
2048  aLine->GetEndPoint().x, aLine->GetEndPoint().y );
2049 
2050  m_out->Print( 0, "\n");
2051 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
COLOR4D GetLineColor() const
Definition: sch_line.cpp:234
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:204
int GetLineStyle() const
Definition: sch_line.cpp:260
int GetDefaultWidth() const
Definition: sch_line.cpp:269
int GetLineSize() const
Definition: sch_line.h:110
static const char * GetLineStyleName(int aStyle)
Definition: sch_line.cpp:103
int GetDefaultStyle() const
Definition: sch_line.cpp:242
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:287
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 1992 of file sch_legacy_plugin.cpp.

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

Referenced by Format().

1993 {
1994  wxCHECK_RET( aNoConnect != NULL, "SCH_NOCONNECT* is NULL" );
1995 
1996  m_out->Print( 0, "NoConn ~ %-4d %-4d\n", aNoConnect->GetPosition().x,
1997  aNoConnect->GetPosition().y );
1998 }
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 1908 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().

1909 {
1910  wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" );
1911 
1912  m_out->Print( 0, "$Sheet\n" );
1913  m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
1914  aSheet->GetPosition().x, aSheet->GetPosition().y,
1915  aSheet->GetSize().x, aSheet->GetSize().y );
1916 
1917  m_out->Print( 0, "U %8.8lX\n", (unsigned long) aSheet->GetTimeStamp() );
1918 
1919  if( !aSheet->GetName().IsEmpty() )
1920  m_out->Print( 0, "F0 %s %d\n", EscapedUTF8( aSheet->GetName() ).c_str(),
1921  aSheet->GetSheetNameSize() );
1922 
1923  if( !aSheet->GetFileName().IsEmpty() )
1924  m_out->Print( 0, "F1 %s %d\n", EscapedUTF8( aSheet->GetFileName() ).c_str(),
1925  aSheet->GetFileNameSize() );
1926 
1927  for( const SCH_SHEET_PIN& pin : aSheet->GetPins() )
1928  {
1929  int type, side;
1930 
1931  if( pin.GetText().IsEmpty() )
1932  break;
1933 
1934  switch( pin.GetEdge() )
1935  {
1936  default:
1938  side = 'L';
1939  break;
1940 
1942  side = 'R';
1943  break;
1944 
1946  side = 'T';
1947  break;
1948 
1950  side = 'B';
1951  break;
1952  }
1953 
1954  switch( pin.GetShape() )
1955  {
1956  case NET_INPUT:
1957  type = 'I'; break;
1958 
1959  case NET_OUTPUT:
1960  type = 'O'; break;
1961 
1962  case NET_BIDI:
1963  type = 'B'; break;
1964 
1965  case NET_TRISTATE:
1966  type = 'T'; break;
1967 
1968  default:
1969  case NET_UNSPECIFIED:
1970  type = 'U'; break;
1971  }
1972 
1973  m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n", pin.GetNumber(),
1974  EscapedUTF8( pin.GetText() ).c_str(), // supplies wrapping quotes
1975  type, side, pin.GetPosition().x, pin.GetPosition().y,
1976  pin.GetTextWidth() );
1977  }
1978 
1979  m_out->Print( 0, "$EndSheet\n" );
1980 }
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:540
wxString GetFileName(void) const
Return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:645
time_t GetTimeStamp() const
Definition: base_struct.h:218
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
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 3598 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().

3600 {
3601  m_props = aProperties;
3602 
3603  cacheLib( aLibraryPath );
3604 
3605  m_cache->AddSymbol( aSymbol );
3606 
3607  if( !isBuffering( aProperties ) )
3608  m_cache->Save( writeDocFile( aProperties ) );
3609 }
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 2054 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().

2055 {
2056  wxCHECK_RET( aText != NULL, "SCH_TEXT* is NULL" );
2057 
2058  const char* italics = "~";
2059  const char* textType = "Notes";
2060 
2061  if( aText->IsItalic() )
2062  italics = "Italic";
2063 
2064  wxString text = aText->GetText();
2065 
2066  SCH_LAYER_ID layer = aText->GetLayer();
2067 
2068  if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
2069  {
2070  if( layer == LAYER_NOTES )
2071  {
2072  // For compatibility reasons, the text must be saved in only one text line
2073  // so replace all EOLs with \\n
2074  text.Replace( wxT( "\n" ), wxT( "\\n" ) );
2075 
2076  // Here we should have no CR or LF character in line
2077  // This is not always the case if a multiline text was copied (using a copy/paste
2078  // function) from a text that uses E.O.L characters that differs from the current
2079  // EOL format. This is mainly the case under Linux using LF symbol when copying
2080  // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
2081  // (or LF left under MacOSX)
2082  for( unsigned ii = 0; ii < text.Len(); )
2083  {
2084  if( text[ii] == 0x0A || text[ii] == 0x0D )
2085  text.erase( ii, 1 );
2086  else
2087  ii++;
2088  }
2089  }
2090  else
2091  {
2092  textType = "Label";
2093  }
2094 
2095  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2096  aText->GetPosition().x, aText->GetPosition().y,
2097  aText->GetLabelSpinStyle(),
2098  aText->GetTextWidth(),
2099  italics, aText->GetThickness(), TO_UTF8( text ) );
2100  }
2101  else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2102  {
2103  textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2104 
2105  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2106  aText->GetPosition().x, aText->GetPosition().y,
2107  aText->GetLabelSpinStyle(),
2108  aText->GetTextWidth(),
2109  SheetLabelType[aText->GetShape()],
2110  italics,
2111  aText->GetThickness(), TO_UTF8( text ) );
2112  }
2113 }
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:170
int GetTextWidth() const
Definition: eda_text.h:218
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:154
#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:130
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 3496 of file sch_legacy_plugin.cpp.

References PropNoDocFile.

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

3497 {
3498  std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
3499 
3500  if( aProperties && aProperties->find( propName ) != aProperties->end() )
3501  return false;
3502 
3503  return true;
3504 }
static const char * PropNoDocFile
const char* PropBuffering

Member Data Documentation

wxString SCH_LEGACY_PLUGIN::m_error
protected

For throwing exceptions.

Definition at line 158 of file sch_legacy_plugin.h.

Referenced by loadHeader().

KIWAY* SCH_LEGACY_PLUGIN::m_kiway
protected

Required for path to legacy component libraries.

Definition at line 161 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 163 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 159 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 160 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 162 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 157 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(), and SYMBOL_LIB_TABLE_RESCUER::OpenRescueLibrary().

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(), PART_LIB::SetCache(), and writeDocFile().


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