KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN Class Reference

Class SCH_LEGACY_PLUGIN. 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
 
virtual bool IsSymbolLibWritable (const wxString &aLibraryPath)
 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

Class SCH_LEGACY_PLUGIN.

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

Constructor & Destructor Documentation

SCH_LEGACY_PLUGIN::SCH_LEGACY_PLUGIN ( )

Definition at line 549 of file sch_legacy_plugin.cpp.

References init().

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

Definition at line 555 of file sch_legacy_plugin.cpp.

References m_cache.

556 {
557  delete m_cache;
558 }
SCH_LEGACY_PLUGIN_CACHE * m_cache

Member Function Documentation

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

Definition at line 3382 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, and m_props.

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

3383 {
3384  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
3385  {
3386  // a spectacular episode in memory management:
3387  delete m_cache;
3388  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
3389 
3390  if( !isBuffering( m_props ) )
3391  m_cache->Load();
3392  }
3393 }
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.
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 3530 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().

3532 {
3533  if( wxFileExists( aLibraryPath ) )
3534  {
3536  _( "symbol library '%s' already exists, cannot create a new library" ),
3537  aLibraryPath.GetData() ) );
3538  }
3539 
3540  LOCALE_IO toggle;
3541 
3542  m_props = aProperties;
3543 
3544  delete m_cache;
3545  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
3546  m_cache->SetModified();
3547  m_cache->Save( writeDocFile( aProperties ) );
3548  m_cache->Load(); // update m_writable and m_mod_time
3549 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
SCH_LEGACY_PLUGIN_CACHE * m_cache
Class SCH_LEGACY_PLUGIN_CACHE is a cache assistant for the part library portion of the SCH_PLUGIN API...
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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;.
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 3502 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().

3504 {
3505  m_props = aProperties;
3506 
3507  cacheLib( aLibraryPath );
3508 
3509  m_cache->DeleteAlias( aAliasName );
3510 
3511  if( !isBuffering( aProperties ) )
3512  m_cache->Save( writeDocFile( aProperties ) );
3513 }
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 3516 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().

3518 {
3519  m_props = aProperties;
3520 
3521  cacheLib( aLibraryPath );
3522 
3523  m_cache->DeleteSymbol( aAliasName );
3524 
3525  if( !isBuffering( aProperties ) )
3526  m_cache->Save( writeDocFile( aProperties ) );
3527 }
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 3552 of file sch_legacy_plugin.cpp.

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

3554 {
3555  wxFileName fn = aLibraryPath;
3556 
3557  if( !fn.FileExists() )
3558  return false;
3559 
3560  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
3561  // we don't want that. we want bare metal portability with no UI here.
3562  if( wxRemove( aLibraryPath ) )
3563  {
3564  THROW_IO_ERROR( wxString::Format( _( "library '%s' cannot be deleted" ),
3565  aLibraryPath.GetData() ) );
3566  }
3567 
3568  if( m_cache && m_cache->IsFile( aLibraryPath ) )
3569  {
3570  delete m_cache;
3571  m_cache = 0;
3572  }
3573 
3574  return true;
3575 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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
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 3436 of file sch_legacy_plugin.cpp.

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

3439 {
3440  LOCALE_IO toggle; // toggles on, then off, the C locale.
3441 
3442  m_props = aProperties;
3443 
3444  cacheLib( aLibraryPath );
3445 
3446  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
3447 
3448  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
3449  aAliasNameList.Add( it->first );
3450 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
SCH_LEGACY_PLUGIN_CACHE * m_cache
std::map< wxString, LIB_ALIAS *, AliasMapSort > LIB_ALIAS_MAP
Alias map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
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 3453 of file sch_legacy_plugin.cpp.

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

3456 {
3457  LOCALE_IO toggle; // toggles on, then off, the C locale.
3458 
3459  m_props = aProperties;
3460 
3461  cacheLib( aLibraryPath );
3462 
3463  const LIB_ALIAS_MAP& aliases = m_cache->m_aliases;
3464 
3465  for( LIB_ALIAS_MAP::const_iterator it = aliases.begin(); it != aliases.end(); ++it )
3466  aAliasList.push_back( it->second );
3467 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
SCH_LEGACY_PLUGIN_CACHE * m_cache
std::map< wxString, LIB_ALIAS *, AliasMapSort > LIB_ALIAS_MAP
Alias map used by part library object.
void cacheLib(const wxString &aLibraryFileName)
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 1582 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().

1583 {
1584  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN* object." );
1585  wxCHECK_RET( m_kiway != NULL, "NULL KIWAY* object." );
1586 
1587  // Write the header
1588  m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1589 
1590  // Write the project libraries.
1591  for( const PART_LIB& lib : *m_kiway->Prj().SchLibs() )
1592  m_out->Print( 0, "LIBS:%s\n", TO_UTF8( lib.GetName() ) );
1593 
1594  // This section is not used, but written for file compatibility
1595  m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1596  m_out->Print( 0, "EELAYER END\n" );
1597 
1598  /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1599  * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1600  * simple hierarchy and flat hierarchy. Used also to search the root
1601  * sheet ( ScreenNumber = 1 ) within the files
1602  */
1603  const TITLE_BLOCK& tb = aScreen->GetTitleBlock();
1604  const PAGE_INFO& page = aScreen->GetPageSettings();
1605 
1606  m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1607  page.GetWidthMils(),
1608  page.GetHeightMils(),
1609  !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1610  m_out->Print( 0, "encoding utf-8\n" );
1611  m_out->Print( 0, "Sheet %d %d\n", aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens );
1612  m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1613  m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1614  m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1615  m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1616  m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment1() ).c_str() );
1617  m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment2() ).c_str() );
1618  m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment3() ).c_str() );
1619  m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment4() ).c_str() );
1620  m_out->Print( 0, "$EndDescr\n" );
1621 
1622  for( SCH_ITEM* item = aScreen->GetDrawItems(); item; item = item->Next() )
1623  {
1624  switch( item->Type() )
1625  {
1626  case SCH_COMPONENT_T:
1627  saveComponent( dynamic_cast< SCH_COMPONENT* >( item ) );
1628  break;
1629  case SCH_BITMAP_T:
1630  saveBitmap( dynamic_cast< SCH_BITMAP* >( item ) );
1631  break;
1632  case SCH_SHEET_T:
1633  saveSheet( dynamic_cast< SCH_SHEET* >( item ) );
1634  break;
1635  case SCH_JUNCTION_T:
1636  saveJunction( dynamic_cast< SCH_JUNCTION* >( item ) );
1637  break;
1638  case SCH_NO_CONNECT_T:
1639  saveNoConnect( dynamic_cast< SCH_NO_CONNECT* >( item ) );
1640  break;
1641  case SCH_BUS_WIRE_ENTRY_T:
1642  case SCH_BUS_BUS_ENTRY_T:
1643  saveBusEntry( dynamic_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1644  break;
1645  case SCH_LINE_T:
1646  saveLine( dynamic_cast< SCH_LINE* >( item ) );
1647  break;
1648  case SCH_TEXT_T:
1649  case SCH_LABEL_T:
1650  case SCH_GLOBAL_LABEL_T:
1652  saveText( dynamic_cast< SCH_TEXT* >( item ) );
1653  break;
1654  default:
1655  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1656  }
1657  }
1658 
1659  m_out->Print( 0, "$EndSCHEMATC\n" );
1660 }
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
Function GetDrawItems().
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:408
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 73 of file sch_legacy_plugin.h.

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

References SCH_LEGACY_PLUGIN_CACHE::GetModifyHash(), and m_cache.

3414 {
3415  if( m_cache )
3416  return m_cache->GetModifyHash();
3417 
3418  // If the cache hasn't been loaded, it hasn't been modified.
3419  return 0;
3420 }
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 68 of file sch_legacy_plugin.h.

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

Reimplemented from SCH_PLUGIN.

Definition at line 3423 of file sch_legacy_plugin.cpp.

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

3425 {
3426  LOCALE_IO toggle;
3427 
3428  m_props = aProperties;
3429 
3430  cacheLib( aLibraryPath );
3431 
3432  return m_cache->m_aliases.size();
3433 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
SCH_LEGACY_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.
void SCH_LEGACY_PLUGIN::init ( KIWAY aKiway,
const PROPERTIES aProperties = NULL 
)
protected

initialize PLUGIN like a constructor would.

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

562 {
563  m_version = 0;
564  m_rootSheet = NULL;
565  m_props = aProperties;
566  m_kiway = aKiway;
567  m_cache = NULL;
568  m_out = NULL;
569 }
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 3407 of file sch_legacy_plugin.cpp.

References PROPERTIES::Exists(), and PropBuffering.

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

3408 {
3409  return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
3410 }
bool Exists(const std::string &aProperty) const
Definition: properties.h:44
static const char * PropBuffering
const char* PropBuffering
bool SCH_PLUGIN::IsSymbolLibWritable ( const wxString &  aLibraryPath)
virtualinherited

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.

Definition at line 149 of file sch_plugin.cpp.

References not_implemented().

Referenced by SYMBOL_LIB_TABLE::IsSymbolLibWritable().

150 {
151  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
152  not_implemented( this, __FUNCTION__ );
153  return false;
154 }
static void not_implemented(SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented...
Definition: sch_plugin.cpp:36
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 572 of file sch_legacy_plugin.cpp.

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

574 {
575  wxASSERT( !aFileName || aKiway != NULL );
576 
577  LOCALE_IO toggle; // toggles on, then off, the C locale.
578  SCH_SHEET* sheet;
579 
580  wxFileName fn = aFileName;
581 
582  // Unfortunately child sheet file names the legacy schematic file format are not fully
583  // qualified and are always appended to the project path. The aFileName attribute must
584  // always be an absolute path so the project path can be used for load child sheet files.
585  wxASSERT( fn.IsAbsolute() );
586 
587  m_path = fn.GetPath();
588 
589  init( aKiway, aProperties );
590 
591  if( aAppendToMe == NULL )
592  {
593  // Clean up any allocated memory if an exception occurs loading the schematic.
594  std::unique_ptr< SCH_SHEET > newSheet( new SCH_SHEET );
595  newSheet->SetFileName( aFileName );
596  m_rootSheet = newSheet.get();
597  loadHierarchy( newSheet.get() );
598 
599  // If we got here, the schematic loaded successfully.
600  sheet = newSheet.release();
601  }
602  else
603  {
604  m_rootSheet = aAppendToMe->GetRootSheet();
605  wxASSERT( m_rootSheet != NULL );
606  sheet = aAppendToMe;
607  loadHierarchy( sheet );
608  }
609 
610  return sheet;
611 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
SCH_SHEET * GetRootSheet()
Function GetRootSheet.
Definition: sch_sheet.cpp:137
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.
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
SCH_BITMAP * SCH_LEGACY_PLUGIN::loadBitmap ( FILE_LINE_READER aReader)
private
Todo:
Make m_scale private and add accessors.

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

994 {
995  std::unique_ptr< SCH_BITMAP > bitmap( new SCH_BITMAP );
996 
997  const char* line = aReader.Line();
998 
999  wxCHECK( strCompare( "$Bitmap", line, &line ), NULL );
1000 
1001  line = aReader.ReadLine();
1002 
1003  while( line != NULL )
1004  {
1005  if( strCompare( "Pos", line, &line ) )
1006  {
1007  wxPoint position;
1008 
1009  position.x = parseInt( aReader, line, &line );
1010  position.y = parseInt( aReader, line, &line );
1011  bitmap->SetPosition( position );
1012  }
1013  else if( strCompare( "Scale", line, &line ) )
1014  {
1016  bitmap->GetImage()->SetScale( parseDouble( aReader, line, &line ) );
1017  }
1018  else if( strCompare( "Data", line, &line ) )
1019  {
1020  wxMemoryOutputStream stream;
1021 
1022  while( line )
1023  {
1024  if( !aReader.ReadLine() )
1025  SCH_PARSE_ERROR( _( "Unexpected end of file" ), aReader, line );
1026 
1027  line = aReader.Line();
1028 
1029  if( strCompare( "EndData", line ) )
1030  {
1031  // all the PNG date is read.
1032  // We expect here m_image and m_bitmap are void
1033  wxImage* image = new wxImage();
1034  wxMemoryInputStream istream( stream );
1035  image->LoadFile( istream, wxBITMAP_TYPE_PNG );
1036  bitmap->GetImage()->SetImage( image );
1037  bitmap->GetImage()->SetBitmap( new wxBitmap( *image ) );
1038  break;
1039  }
1040 
1041  // Read PNG data, stored in hexadecimal,
1042  // each byte = 2 hexadecimal digits and a space between 2 bytes
1043  // and put it in memory stream buffer
1044  int len = strlen( line );
1045 
1046  for( ; len > 0 && !isspace( *line ); len -= 3, line += 3 )
1047  {
1048  int value = 0;
1049 
1050  if( sscanf( line, "%X", &value ) == 1 )
1051  stream.PutC( (char) value );
1052  else
1053  THROW_IO_ERROR( "invalid PNG data" );
1054  }
1055  }
1056 
1057  if( line == NULL )
1058  THROW_IO_ERROR( _( "unexpected end of file" ) );
1059  }
1060  else if( strCompare( "$EndBitmap", line ) )
1061  return bitmap.release();
1062 
1063  line = aReader.ReadLine();
1064  }
1065 
1066  THROW_IO_ERROR( _( "unexpected end of file" ) );
1067 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
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
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
#define SCH_PARSE_ERROR(text, reader, pos)
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
SCH_BUS_ENTRY_BASE * SCH_LEGACY_PLUGIN::loadBusEntry ( FILE_LINE_READER aReader)
private

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

1151 {
1152  const char* line = aReader.Line();
1153 
1154  wxCHECK( strCompare( "Entry", line, &line ), NULL );
1155 
1156  std::unique_ptr< SCH_BUS_ENTRY_BASE > busEntry;
1157 
1158  if( strCompare( "Wire", line, &line ) )
1159  {
1160  busEntry.reset( new SCH_BUS_WIRE_ENTRY );
1161 
1162  if( !strCompare( "Line", line, &line ) )
1163  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
1164  }
1165  else if( strCompare( "Bus", line, &line ) )
1166  {
1167  busEntry.reset( new SCH_BUS_BUS_ENTRY );
1168 
1169  if( !strCompare( "Bus", line, &line ) )
1170  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
1171  }
1172  else
1173  SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
1174 
1175  line = aReader.ReadLine();
1176 
1177  wxPoint pos;
1178  wxSize size;
1179 
1180  pos.x = parseInt( aReader, line, &line );
1181  pos.y = parseInt( aReader, line, &line );
1182  size.x = parseInt( aReader, line, &line );
1183  size.y = parseInt( aReader, line, &line );
1184 
1185  size.x -= pos.x;
1186  size.y -= pos.y;
1187 
1188  busEntry->SetPosition( pos );
1189  busEntry->SetSize( size );
1190 
1191  return busEntry.release();
1192 }
Class SCH_BUS_WIRE_ENTRY.
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
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 SCH_BUS_WIRE_ENTRY.
SCH_COMPONENT * SCH_LEGACY_PLUGIN::loadComponent ( FILE_LINE_READER aReader)
private

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

1292 {
1293  const char* line = aReader.Line();
1294 
1295  wxCHECK( strCompare( "$Comp", line, &line ), NULL );
1296 
1297  std::unique_ptr< SCH_COMPONENT > component( new SCH_COMPONENT() );
1298 
1299  line = aReader.ReadLine();
1300 
1301  while( line != NULL )
1302  {
1303  if( strCompare( "L", line, &line ) )
1304  {
1305  wxString libName;
1306 
1307  parseUnquotedString( libName, aReader, line, &line );
1308  libName.Replace( "~", " " );
1309 
1310  LIB_ID libId( wxEmptyString, libName );
1311 
1312  component->SetLibId( libId );
1313 
1314  wxString refDesignator;
1315 
1316  parseUnquotedString( refDesignator, aReader, line, &line );
1317  refDesignator.Replace( "~", " " );
1318 
1319  wxString prefix = refDesignator;
1320 
1321  while( prefix.Length() )
1322  {
1323  if( ( prefix.Last() < '0' || prefix.Last() > '9') && prefix.Last() != '?' )
1324  break;
1325 
1326  prefix.RemoveLast();
1327  }
1328 
1329  // Avoid a prefix containing trailing/leading spaces
1330  prefix.Trim( true );
1331  prefix.Trim( false );
1332 
1333  if( prefix.IsEmpty() )
1334  component->SetPrefix( wxString( "U" ) );
1335  else
1336  component->SetPrefix( prefix );
1337  }
1338  else if( strCompare( "U", line, &line ) )
1339  {
1340  // This fixes a potentially buggy files caused by unit being set to zero which
1341  // causes netlist issues. See https://bugs.launchpad.net/kicad/+bug/1677282.
1342  int unit = parseInt( aReader, line, &line );
1343 
1344  if( unit == 0 )
1345  {
1346  unit = 1;
1347 
1348  // Set the file as modified so the user can be warned.
1349  if( m_rootSheet && m_rootSheet->GetScreen() )
1351  }
1352 
1353  component->SetUnit( unit );
1354  component->SetConvert( parseInt( aReader, line, &line ) );
1355  component->SetTimeStamp( parseHex( aReader, line, &line ) );
1356  }
1357  else if( strCompare( "P", line, &line ) )
1358  {
1359  wxPoint pos;
1360 
1361  pos.x = parseInt( aReader, line, &line );
1362  pos.y = parseInt( aReader, line, &line );
1363  component->SetPosition( pos );
1364  }
1365  else if( strCompare( "AR", line, &line ) )
1366  {
1367  const char* strCompare = "Path=";
1368  int len = strlen( strCompare );
1369 
1370  if( strncasecmp( strCompare, line, len ) != 0 )
1371  SCH_PARSE_ERROR( "missing 'Path=' token", aReader, line );
1372 
1373  line += len;
1374  wxString path, reference, unit;
1375 
1376  parseQuotedString( path, aReader, line, &line );
1377 
1378  strCompare = "Ref=";
1379  len = strlen( strCompare );
1380 
1381  if( strncasecmp( strCompare, line, len ) != 0 )
1382  SCH_PARSE_ERROR( "missing 'Ref=' token", aReader, line );
1383 
1384  line+= len;
1385  parseQuotedString( reference, aReader, line, &line );
1386 
1387  strCompare = "Part=";
1388  len = strlen( strCompare );
1389 
1390  if( strncasecmp( strCompare, line, len ) != 0 )
1391  SCH_PARSE_ERROR( "missing 'Part=' token", aReader, line );
1392 
1393  line+= len;
1394  parseQuotedString( unit, aReader, line, &line );
1395 
1396  long tmp;
1397 
1398  if( !unit.ToLong( &tmp, 10 ) )
1399  SCH_PARSE_ERROR( "expected integer value", aReader, line );
1400 
1401  if( tmp < 0 || tmp > MAX_UNIT_COUNT_PER_PACKAGE )
1402  SCH_PARSE_ERROR( "unit value out of range", aReader, line );
1403 
1404  component->AddHierarchicalReference( path, reference, (int)tmp );
1405  component->GetField( REFERENCE )->SetText( reference );
1406 
1407  }
1408  else if( strCompare( "F", line, &line ) )
1409  {
1410  int index = parseInt( aReader, line, &line );
1411 
1412  wxString text, name;
1413 
1414  parseQuotedString( text, aReader, line, &line, true );
1415 
1416  char orientation = parseChar( aReader, line, &line );
1417  wxPoint pos;
1418  pos.x = parseInt( aReader, line, &line );
1419  pos.y = parseInt( aReader, line, &line );
1420  int size = parseInt( aReader, line, &line );
1421  int attributes = parseHex( aReader, line, &line );
1422 
1423  if( index >= component->GetFieldCount() )
1424  {
1425  // The first MANDATOR_FIELDS _must_ be constructed within
1426  // the SCH_COMPONENT constructor. This assert is simply here
1427  // to guard against a change in that constructor.
1428  wxASSERT( component->GetFieldCount() >= MANDATORY_FIELDS );
1429 
1430  // Ignore the _supplied_ fieldNdx. It is not important anymore
1431  // if within the user defined fields region (i.e. >= MANDATORY_FIELDS).
1432  // We freely renumber the index to fit the next available field slot.
1433  index = component->GetFieldCount(); // new has this index after insertion
1434 
1435  SCH_FIELD field( wxPoint( 0, 0 ), -1, component.get(), name );
1436  component->AddField( field );
1437  }
1438 
1439  // Prior to version 2 of the schematic file format, none of the following existed.
1440  if( m_version > 1 )
1441  {
1442  wxString textAttrs;
1443  char hjustify = parseChar( aReader, line, &line );
1444 
1445  parseUnquotedString( textAttrs, aReader, line, &line );
1446 
1447  // The name of the field is optional.
1448  parseQuotedString( name, aReader, line, &line, true );
1449 
1450  if( hjustify == 'L' )
1451  component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
1452  else if( hjustify == 'R' )
1453  component->GetField( index )->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
1454  else if( hjustify != 'C' )
1455  SCH_PARSE_ERROR( _( "component field text horizontal justification must be "
1456  "L, R, or C" ), aReader, line );
1457 
1458  // We are guaranteed to have a least one character here for older file formats
1459  // otherwise an exception would have been raised..
1460  if( textAttrs[0] == 'T' )
1461  component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
1462  else if( textAttrs[0] == 'B' )
1463  component->GetField( index )->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
1464  else if( textAttrs[0] != 'C' )
1465  SCH_PARSE_ERROR( _( "component field text vertical justification must be "
1466  "B, T, or C" ), aReader, line );
1467 
1468  // Newer file formats include the bold and italics text attribute.
1469  if( textAttrs.Length() > 1 )
1470  {
1471  if( textAttrs.Length() != 3 )
1472  SCH_PARSE_ERROR( _( "component field text attributes must be 3 characters wide" ),
1473  aReader, line );
1474 
1475  if( textAttrs[1] == 'I' )
1476  component->GetField( index )->SetItalic( true );
1477  else if( textAttrs[1] != 'N' )
1478  SCH_PARSE_ERROR( _( "component field text italics indicator must be I or N" ),
1479  aReader, line );
1480 
1481  if( textAttrs[2] == 'B' )
1482  component->GetField( index )->SetBold( true );
1483  else if( textAttrs[2] != 'N' )
1484  SCH_PARSE_ERROR( _( "component field text bold indicator must be B or N" ),
1485  aReader, line );
1486  }
1487  }
1488 
1489  component->GetField( index )->SetText( text );
1490  component->GetField( index )->SetTextPos( pos );
1491  component->GetField( index )->SetVisible( !attributes );
1492  component->GetField( index )->SetTextSize( wxSize( size, size ) );
1493 
1494  if( orientation == 'H' )
1495  component->GetField( index )->SetTextAngle( TEXT_ANGLE_HORIZ );
1496  else if( orientation == 'V' )
1497  component->GetField( index )->SetTextAngle( TEXT_ANGLE_VERT );
1498  else
1499  SCH_PARSE_ERROR( _( "component field orientation must be H or V" ),
1500  aReader, line );
1501 
1502  if( name.IsEmpty() )
1504 
1505  component->GetField( index )->SetName( name );
1506  }
1507  else if( strCompare( "$EndComp", line ) )
1508  {
1509  // Ensure all flags (some are set by previous initializations) are reset:
1510  component->ClearFlags();
1511  return component.release();
1512  }
1513  else
1514  {
1515  // There are two lines that begin with a tab or spaces that includes a line with the
1516  // redundant position information and the transform matrix settings.
1517 
1518  // Parse the redundant position information just the same to check for formatting
1519  // errors.
1520  parseInt( aReader, line, &line ); // Always 1.
1521  parseInt( aReader, line, &line ); // The X coordinate.
1522  parseInt( aReader, line, &line ); // The Y coordinate.
1523 
1524  line = aReader.ReadLine();
1525 
1526  TRANSFORM transform;
1527 
1528  transform.x1 = parseInt( aReader, line, &line );
1529 
1530  if( transform.x1 < -1 || transform.x1 > 1 )
1531  SCH_PARSE_ERROR( _( "invalid component X1 transform value" ), aReader, line );
1532 
1533  transform.y1 = parseInt( aReader, line, &line );
1534 
1535  if( transform.y1 < -1 || transform.y1 > 1 )
1536  SCH_PARSE_ERROR( _( "invalid component Y1 transform value" ), aReader, line );
1537 
1538  transform.x2 = parseInt( aReader, line, &line );
1539 
1540  if( transform.x2 < -1 || transform.x2 > 1 )
1541  SCH_PARSE_ERROR( _( "invalid component X2 transform value" ), aReader, line );
1542 
1543  transform.y2 = parseInt( aReader, line, &line );
1544 
1545  if( transform.y2 < -1 || transform.y2 > 1 )
1546  SCH_PARSE_ERROR( _( "invalid component Y2 transform value" ), aReader, line );
1547 
1548  component->SetTransform( transform );
1549  }
1550 
1551  line = aReader.ReadLine();
1552  }
1553 
1554  SCH_PARSE_ERROR( "invalid component line", aReader, line );
1555 
1556  return NULL; // Prevents compiler warning. Should never get here.
1557 }
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
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...
#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:286
#define TEXT_ANGLE_VERT
Definition: common.h:92
Field Reference of part, i.e. "IC21".
int m_version
Version of file being loaded.
int y1
Definition: transform.h:49
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
static void parseUnquotedString(wxString &aString, FILE_LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=NULL, bool aCanBeEmpty=false)
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 670 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().

671 {
672  FILE_LINE_READER reader( aFileName );
673 
674  loadHeader( reader, aScreen );
675 
676  while( reader.ReadLine() )
677  {
678  char* line = reader.Line();
679 
680  while( *line && *line == ' ' )
681  line++;
682 
683  // Either an object will be loaded properly or the file load will fail and raise
684  // an exception.
685  if( strCompare( "$Descr", line ) )
686  loadPageSettings( reader, aScreen );
687  else if( strCompare( "$Comp", line ) )
688  aScreen->Append( loadComponent( reader ) );
689  else if( strCompare( "$Sheet", line ) )
690  aScreen->Append( loadSheet( reader ) );
691  else if( strCompare( "$Bitmap", line ) )
692  aScreen->Append( loadBitmap( reader ) );
693  else if( strCompare( "Connection", line ) )
694  aScreen->Append( loadJunction( reader ) );
695  else if( strCompare( "NoConn", line ) )
696  aScreen->Append( loadNoConnect( reader ) );
697  else if( strCompare( "Wire", line ) )
698  aScreen->Append( loadWire( reader ) );
699  else if( strCompare( "Entry", line ) )
700  aScreen->Append( loadBusEntry( reader ) );
701  else if( strCompare( "Text", line ) )
702  aScreen->Append( loadText( reader ) );
703  else if( strCompare( "$EndSCHEMATC", line ) )
704  return;
705  }
706 
707  // Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
708  // so checking for it's existance will fail so just exit here and take our chances. :(
709  if( m_version > 1 )
710  THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
711 }
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)
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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)
void SCH_LEGACY_PLUGIN::loadHeader ( FILE_LINE_READER aReader,
SCH_SCREEN aScreen 
)
private

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

715 {
716  const char* line = aReader.ReadLine();
717 
718  if( !strCompare( "Eeschema Schematic File Version", line, &line ) )
719  {
720  m_error.Printf( _( "'%s' does not appear to be an Eeschema file" ),
721  GetChars( aScreen->GetFileName() ) );
723  }
724 
725  // get the file version here.
726  m_version = parseInt( aReader, line, &line );
727 
728  // The next lines are the lib list section, and are mainly comments, like:
729  // LIBS:power
730  // the lib list is not used, but is in schematic file just in case.
731  // It is usually not empty, but we accept empty list.
732  // If empty, there is a legacy section, not used
733  // EELAYER i j
734  // and the last line is
735  // EELAYER END
736  // Skip all lines until the end of header "EELAYER END" is found
737  while( aReader.ReadLine() )
738  {
739  line = aReader.Line();
740 
741  while( *line == ' ' )
742  line++;
743 
744  if( strCompare( "EELAYER END", line ) )
745  return;
746  }
747 
748  THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
749 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
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
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
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.
void SCH_LEGACY_PLUGIN::loadHierarchy ( SCH_SHEET aSheet)
private

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

617 {
618  SCH_SCREEN* screen = NULL;
619 
620  if( !aSheet->GetScreen() )
621  {
622  // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
623  // stores the file name and extension. Add the project path to the file name and
624  // extension to compare when calling SCH_SHEET::SearchHierarchy().
625  wxFileName fileName = aSheet->GetFileName();
626 
627  if( !fileName.IsAbsolute() )
628  fileName.MakeAbsolute( m_path );
629 
630  m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
631 
632  if( screen )
633  {
634  aSheet->SetScreen( screen );
635 
636  // Do not need to load the sub-sheets - this has already been done.
637  }
638  else
639  {
640  aSheet->SetScreen( new SCH_SCREEN( m_kiway ) );
641  aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
642  loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
643 
644  EDA_ITEM* item = aSheet->GetScreen()->GetDrawItems();
645 
646  while( item )
647  {
648  if( item->Type() == SCH_SHEET_T )
649  {
650  SCH_SHEET* sheet = (SCH_SHEET*) item;
651 
652  // Set the parent to aSheet. This effectively creates a method to find
653  // the root sheet from any sheet so a pointer to the root sheet does not
654  // need to be stored globally. Note: this is not the same as a hierarchy.
655  // Complex hierarchies can have multiple copies of a sheet. This only
656  // provides a simple tree to find the root sheet.
657  sheet->SetParent( aSheet );
658 
659  // Recursion starts here.
660  loadHierarchy( sheet );
661  }
662 
663  item = item->Next();
664  }
665  }
666  }
667 }
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Function SearchHierarchy search the existing hierarchy for an instance of screen "FileName".
Definition: sch_sheet.cpp:713
void SetScreen(SCH_SCREEN *aScreen)
Function SetScreen sets the screen associated with this sheet to aScreen.
Definition: sch_sheet.cpp:105
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:286
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:213
wxString GetFileName(void) const
Function GetFileName return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:849
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
SCH_ITEM * GetDrawItems() const
Function GetDrawItems().
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
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 1070 of file sch_legacy_plugin.cpp.

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

Referenced by loadFile().

1071 {
1072  std::unique_ptr< SCH_JUNCTION > junction( new SCH_JUNCTION );
1073 
1074  const char* line = aReader.Line();
1075 
1076  wxCHECK( strCompare( "Connection", line, &line ), NULL );
1077 
1078  wxString name;
1079 
1080  parseUnquotedString( name, aReader, line, &line );
1081 
1082  wxPoint position;
1083 
1084  position.x = parseInt( aReader, line, &line );
1085  position.y = parseInt( aReader, line, &line );
1086  junction->SetPosition( position );
1087 
1088  return junction.release();
1089 }
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 1092 of file sch_legacy_plugin.cpp.

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

Referenced by loadFile().

1093 {
1094  std::unique_ptr< SCH_NO_CONNECT > no_connect( new SCH_NO_CONNECT );
1095 
1096  const char* line = aReader.Line();
1097 
1098  wxCHECK( strCompare( "NoConn", line, &line ), NULL );
1099 
1100  wxString name;
1101 
1102  parseUnquotedString( name, aReader, line, &line );
1103 
1104  wxPoint position;
1105 
1106  position.x = parseInt( aReader, line, &line );
1107  position.y = parseInt( aReader, line, &line );
1108  no_connect->SetPosition( position );
1109 
1110  return no_connect.release();
1111 }
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 752 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().

753 {
754  wxASSERT( aScreen != NULL );
755 
756  wxString buf;
757  const char* line = aReader.Line();
758 
759  PAGE_INFO pageInfo;
760  TITLE_BLOCK tb;
761 
762  wxCHECK_RET( strCompare( "$Descr", line, &line ), "Invalid sheet description" );
763 
764  parseUnquotedString( buf, aReader, line, &line );
765 
766  if( !pageInfo.SetType( buf ) )
767  SCH_PARSE_ERROR( _( "invalid page size" ), aReader, line );
768 
769  int pagew = parseInt( aReader, line, &line );
770  int pageh = parseInt( aReader, line, &line );
771 
772  if( buf == PAGE_INFO::Custom )
773  {
774  pageInfo.SetWidthMils( pagew );
775  pageInfo.SetHeightMils( pageh );
776  }
777  else
778  {
779  wxString orientation;
780 
781  // Non custom size, set portrait if its present. Can be empty string which defaults
782  // to landscape.
783  parseUnquotedString( orientation, aReader, line, &line, true );
784 
785  if( orientation == "portrait" )
786  pageInfo.SetPortrait( true );
787  }
788 
789  aScreen->SetPageSettings( pageInfo );
790 
791  while( line != NULL )
792  {
793  buf.clear();
794 
795  if( !aReader.ReadLine() )
796  SCH_PARSE_ERROR( _( "unexpected end of file" ), aReader, line );
797 
798  line = aReader.Line();
799 
800  if( strCompare( "Sheet", line, &line ) )
801  {
802  aScreen->m_ScreenNumber = parseInt( aReader, line, &line );
803  aScreen->m_NumberOfScreens = parseInt( aReader, line, &line );
804  }
805  else if( strCompare( "Title", line, &line ) )
806  {
807  parseQuotedString( buf, aReader, line, &line, true );
808  tb.SetTitle( buf );
809  }
810  else if( strCompare( "Date", line, &line ) )
811  {
812  parseQuotedString( buf, aReader, line, &line, true );
813  tb.SetDate( buf );
814  }
815  else if( strCompare( "Rev", line, &line ) )
816  {
817  parseQuotedString( buf, aReader, line, &line, true );
818  tb.SetRevision( buf );
819  }
820  else if( strCompare( "Comp", line, &line ) )
821  {
822  parseQuotedString( buf, aReader, line, &line, true );
823  tb.SetCompany( buf );
824  }
825  else if( strCompare( "Comment1", line, &line ) )
826  {
827  parseQuotedString( buf, aReader, line, &line, true );
828  tb.SetComment1( buf );
829  }
830  else if( strCompare( "Comment2", line, &line ) )
831  {
832  parseQuotedString( buf, aReader, line, &line, true );
833  tb.SetComment2( buf );
834  }
835  else if( strCompare( "Comment3", line, &line ) )
836  {
837  parseQuotedString( buf, aReader, line, &line, true );
838  tb.SetComment3( buf );
839  }
840  else if( strCompare( "Comment4", line, &line ) )
841  {
842  parseQuotedString( buf, aReader, line, &line, true );
843  tb.SetComment4( buf );
844  }
845  else if( strCompare( "$EndDescr", line ) )
846  {
847  aScreen->SetTitleBlock( tb );
848  return;
849  }
850  }
851 
852  SCH_PARSE_ERROR( _( "missing 'EndDescr'" ), aReader, line );
853 }
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:196
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 856 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().

857 {
858  std::unique_ptr< SCH_SHEET > sheet( new SCH_SHEET() );
859 
860  sheet->SetTimeStamp( GetNewTimeStamp() );
861 
862  const char* line = aReader.ReadLine();
863 
864  while( line != NULL )
865  {
866  if( strCompare( "S", line, &line ) ) // Sheet dimensions.
867  {
868  wxPoint position;
869 
870  position.x = parseInt( aReader, line, &line );
871  position.y = parseInt( aReader, line, &line );
872  sheet->SetPosition( position );
873 
874  wxSize size;
875 
876  size.SetWidth( parseInt( aReader, line, &line ) );
877  size.SetHeight( parseInt( aReader, line, &line ) );
878  sheet->SetSize( size );
879  }
880  else if( strCompare( "U", line, &line ) ) // Sheet time stamp.
881  {
882  sheet->SetTimeStamp( parseHex( aReader, line ) );
883  }
884  else if( *line == 'F' ) // Sheet field.
885  {
886  line++;
887 
888  wxString text;
889  int size;
890  int fieldId = parseInt( aReader, line, &line );
891 
892  if( fieldId == 0 || fieldId == 1 ) // Sheet name and file name.
893  {
894  parseQuotedString( text, aReader, line, &line );
895  size = parseInt( aReader, line, &line );
896 
897  if( fieldId == 0 )
898  {
899  sheet->SetName( text );
900  sheet->SetSheetNameSize( size );
901  }
902  else
903  {
904  sheet->SetFileName( text );
905  sheet->SetFileNameSize( size );
906  }
907  }
908  else // Sheet pin.
909  {
910  std::unique_ptr< SCH_SHEET_PIN > sheetPin( new SCH_SHEET_PIN( sheet.get() ) );
911 
912  sheetPin->SetNumber( fieldId );
913 
914  // Can be empty fields.
915  parseQuotedString( text, aReader, line, &line, true );
916 
917  sheetPin->SetText( text );
918 
919  if( line == NULL )
920  THROW_IO_ERROR( _( "unexpected end of line" ) );
921 
922  switch( parseChar( aReader, line, &line ) )
923  {
924  case 'I':
925  sheetPin->SetShape( NET_INPUT );
926  break;
927 
928  case 'O':
929  sheetPin->SetShape( NET_OUTPUT );
930  break;
931 
932  case 'B':
933  sheetPin->SetShape( NET_BIDI );
934  break;
935 
936  case 'T':
937  sheetPin->SetShape( NET_TRISTATE );
938  break;
939 
940  case 'U':
941  sheetPin->SetShape( NET_UNSPECIFIED );
942  break;
943  default:
944  SCH_PARSE_ERROR( _( "invalid sheet pin type" ), aReader, line );
945  }
946 
947  switch( parseChar( aReader, line, &line ) )
948  {
949  case 'R': /* pin on right side */
950  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_RIGHT_SIDE );
951  break;
952 
953  case 'T': /* pin on top side */
954  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_TOP_SIDE );
955  break;
956 
957  case 'B': /* pin on bottom side */
958  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_BOTTOM_SIDE );
959  break;
960 
961  case 'L': /* pin on left side */
962  sheetPin->SetEdge( SCH_SHEET_PIN::SHEET_LEFT_SIDE );
963  break;
964  default:
965  SCH_PARSE_ERROR( _( "invalid sheet pin side" ), aReader, line );
966  }
967 
968  wxPoint position;
969 
970  position.x = parseInt( aReader, line, &line );
971  position.y = parseInt( aReader, line, &line );
972  sheetPin->SetPosition( position );
973 
974  size = parseInt( aReader, line, &line );
975 
976  sheetPin->SetTextSize( wxSize( size, size ) );
977 
978  sheet->AddPin( sheetPin.release() );
979  }
980  }
981  else if( strCompare( "$EndSheet", line ) )
982  return sheet.release();
983 
984  line = aReader.ReadLine();
985  }
986 
987  SCH_PARSE_ERROR( _( "missing '$EndSheet`" ), aReader, line );
988 
989  return NULL; // Prevents compiler warning. Should never get here.
990 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
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.
Class SCH_SHEET_PIN defines a sheet pin (label) used in sheets to create hierarchical schematics...
Definition: sch_sheet.h:62
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
#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.
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 3470 of file sch_legacy_plugin.cpp.

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

3472 {
3473  LOCALE_IO toggle; // toggles on, then off, the C locale.
3474 
3475  m_props = aProperties;
3476 
3477  cacheLib( aLibraryPath );
3478 
3479  LIB_ALIAS_MAP::const_iterator it = m_cache->m_aliases.find( aAliasName );
3480 
3481  if( it == m_cache->m_aliases.end() )
3482  return NULL;
3483 
3484  return it->second;
3485 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
SCH_LEGACY_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be NULL.
SCH_TEXT * SCH_LEGACY_PLUGIN::loadText ( FILE_LINE_READER aReader)
private

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

1196 {
1197  const char* line = aReader.Line();
1198 
1199  wxCHECK( strCompare( "Text", line, &line ), NULL );
1200 
1201  std::unique_ptr< SCH_TEXT> text;
1202 
1203  if( strCompare( "Notes", line, &line ) )
1204  text.reset( new SCH_TEXT );
1205  else if( strCompare( "Label", line, &line ) )
1206  text.reset( new SCH_LABEL );
1207  else if( strCompare( "HLabel", line, &line ) )
1208  text.reset( new SCH_HIERLABEL );
1209  else if( strCompare( "GLabel", line, &line ) )
1210  {
1211  // Prior to version 2, the SCH_GLOBALLABEL object did not exist.
1212  if( m_version == 1 )
1213  text.reset( new SCH_HIERLABEL );
1214  else
1215  text.reset( new SCH_GLOBALLABEL );
1216  }
1217  else
1218  SCH_PARSE_ERROR( "unknown Text type", aReader, line );
1219 
1220  // Parse the parameters common to all text objects.
1221  wxPoint position;
1222 
1223  position.x = parseInt( aReader, line, &line );
1224  position.y = parseInt( aReader, line, &line );
1225  text->SetPosition( position );
1226  text->SetLabelSpinStyle( parseInt( aReader, line, &line ) );
1227 
1228  int size = parseInt( aReader, line, &line );
1229 
1230  text->SetTextSize( wxSize( size, size ) );
1231 
1232  // Parse the global and hierarchical label type.
1233  if( text->Type() == SCH_HIERARCHICAL_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
1234  {
1235  if( strCompare( SheetLabelType[NET_INPUT], line, &line ) )
1236  text->SetShape( NET_INPUT );
1237  else if( strCompare( SheetLabelType[NET_OUTPUT], line, &line ) )
1238  text->SetShape( NET_OUTPUT );
1239  else if( strCompare( SheetLabelType[NET_BIDI], line, &line ) )
1240  text->SetShape( NET_BIDI );
1241  else if( strCompare( SheetLabelType[NET_TRISTATE], line, &line ) )
1242  text->SetShape( NET_TRISTATE );
1243  else if( strCompare( SheetLabelType[NET_UNSPECIFIED], line, &line ) )
1244  text->SetShape( NET_UNSPECIFIED );
1245  else
1246  SCH_PARSE_ERROR( _( "invalid label type" ), aReader, line );
1247  }
1248 
1249  int thickness = 0;
1250 
1251  // The following tokens do not exist in version 1 schematic files.
1252  if( m_version > 1 )
1253  {
1254  if( strCompare( "Italic", line, &line ) )
1255  text->SetItalic( true );
1256  else if( !strCompare( "~", line, &line ) )
1257  SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
1258 
1259  // The thickness token does not exist in older versions of the schematic file format
1260  // so calling parseInt will be made only if the EOL is not reached.
1261  if( *line >= ' ' )
1262  thickness = parseInt( aReader, line, &line );
1263  }
1264 
1265  text->SetBold( thickness != 0 );
1266  text->SetThickness( thickness != 0 ? GetPenSizeForBold( size ) : 0 );
1267 
1268  // Read the text string for the text.
1269  char* tmp = aReader.ReadLine();
1270 
1271  tmp = strtok( tmp, "\r\n" );
1272  wxString val = FROM_UTF8( tmp );
1273 
1274  for( ; ; )
1275  {
1276  int i = val.find( wxT( "\\n" ) );
1277 
1278  if( i == wxNOT_FOUND )
1279  break;
1280 
1281  val.erase( i, 2 );
1282  val.insert( i, wxT( "\n" ) );
1283  }
1284 
1285  text->SetText( val );
1286 
1287  return text.release();
1288 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
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 1114 of file sch_legacy_plugin.cpp.

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

Referenced by loadFile().

1115 {
1116  std::unique_ptr< SCH_LINE > wire( new SCH_LINE );
1117 
1118  const char* line = aReader.Line();
1119 
1120  wxCHECK( strCompare( "Wire", line, &line ), NULL );
1121 
1122  if( strCompare( "Wire", line, &line ) )
1123  wire->SetLayer( LAYER_WIRE );
1124  else if( strCompare( "Bus", line, &line ) )
1125  wire->SetLayer( LAYER_BUS );
1126  else if( strCompare( "Notes", line, &line ) )
1127  wire->SetLayer( LAYER_NOTES );
1128  else
1129  SCH_PARSE_ERROR( "invalid line type", aReader, line );
1130 
1131  if( !strCompare( "Line", line, &line ) )
1132  SCH_PARSE_ERROR( "invalid wire definition", aReader, line );
1133 
1134  line = aReader.ReadLine();
1135 
1136  wxPoint begin, end;
1137 
1138  begin.x = parseInt( aReader, line, &line );
1139  begin.y = parseInt( aReader, line, &line );
1140  end.x = parseInt( aReader, line, &line );
1141  end.y = parseInt( aReader, line, &line );
1142 
1143  wire->SetStartPoint( begin );
1144  wire->SetEndPoint( end );
1145 
1146  return wire.release();
1147 }
char * ReadLine() override
Function ReadLine reads a line of text into the buffer and increments the line number counter...
Definition: richio.cpp:196
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)
Class SCH_LINE is a segment description base class to describe items which have 2 end points (track...
Definition: sch_line.h:42
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=NULL)
Function strCompare.
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 1560 of file sch_legacy_plugin.cpp.

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

1562 {
1563  wxCHECK_RET( aScreen != NULL, "NULL SCH_SCREEN object." );
1564  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1565 
1566  init( aKiway, aProperties );
1567 
1568  wxFileName fn = aFileName;
1569 
1570  // File names should be absolute. Don't assume everything relative to the project path
1571  // works properly.
1572  wxASSERT( fn.IsAbsolute() );
1573 
1574  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1575 
1576  m_out = &formatter; // no ownership
1577 
1578  Format( aScreen );
1579 }
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 1800 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().

1801 {
1802  wxCHECK_RET( aBitmap != NULL, "SCH_BITMAP* is NULL" );
1803 
1804  wxImage* image = aBitmap->GetImage()->GetImageData();
1805 
1806  wxCHECK_RET( image != NULL, "wxImage* is NULL" );
1807 
1808  m_out->Print( 0, "$Bitmap\n" );
1809  m_out->Print( 0, "Pos %-4d %-4d\n", aBitmap->GetPosition().x, aBitmap->GetPosition().y );
1810  m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
1811  m_out->Print( 0, "Data\n" );
1812 
1813  wxMemoryOutputStream stream;
1814 
1815  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1816 
1817  // Write binary data in hexadecimal form (ASCII)
1818  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1819  char* begin = (char*) buffer->GetBufferStart();
1820 
1821  for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
1822  {
1823  if( ii >= 32 )
1824  {
1825  ii = 0;
1826 
1827  m_out->Print( 0, "\n" );
1828  }
1829 
1830  m_out->Print( 0, "%2.2X ", *begin & 0xFF );
1831  }
1832 
1833  m_out->Print( 0, "\nEndData\n" );
1834  m_out->Print( 0, "$EndBitmap\n" );
1835 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxImage * GetImageData()
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_bitmap.h:135
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:61
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:408
void SCH_LEGACY_PLUGIN::saveBusEntry ( SCH_BUS_ENTRY_BASE aBusEntry)
private

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

1932 {
1933  wxCHECK_RET( aBusEntry != NULL, "SCH_BUS_ENTRY_BASE* is NULL" );
1934 
1935  if( aBusEntry->GetLayer() == LAYER_WIRE )
1936  m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
1937  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
1938  aBusEntry->m_End().x, aBusEntry->m_End().y );
1939  else
1940  m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
1941  aBusEntry->GetPosition().x, aBusEntry->GetPosition().y,
1942  aBusEntry->m_End().x, aBusEntry->m_End().y );
1943 }
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:408
wxPoint GetPosition() const override
Function GetPosition.
void SCH_LEGACY_PLUGIN::saveComponent ( SCH_COMPONENT aComponent)
private

Definition at line 1663 of file sch_legacy_plugin.cpp.

References FROM_UTF8(), SCH_COMPONENT::GetConvert(), SCH_COMPONENT::GetField(), SCH_COMPONENT::GetFieldCount(), SCH_COMPONENT::GetLibId(), LIB_ID::GetLibItemName(), 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().

1664 {
1665  std::string name1;
1666  std::string name2;
1667  wxArrayString reference_fields;
1668 
1669  static wxString delimiters( wxT( " " ) );
1670 
1671  // This is redundant with the AR entries below, but it makes the files backwards-compatible.
1672  if( aComponent->GetPathsAndReferences().GetCount() > 0 )
1673  {
1674  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[0], delimiters );
1675  name1 = toUTFTildaText( reference_fields[1] );
1676  }
1677  else
1678  {
1679  if( aComponent->GetField( REFERENCE )->GetText().IsEmpty() )
1680  name1 = toUTFTildaText( aComponent->GetPrefix() );
1681  else
1682  name1 = toUTFTildaText( aComponent->GetField( REFERENCE )->GetText() );
1683  }
1684 
1685  wxString part_name = FROM_UTF8( aComponent->GetLibId().GetLibItemName() );
1686 
1687  if( part_name.size() )
1688  {
1689  name2 = toUTFTildaText( part_name );
1690  }
1691  else
1692  {
1693  name2 = "_NONAME_";
1694  }
1695 
1696  m_out->Print( 0, "$Comp\n" );
1697  m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
1698 
1699  // Generate unit number, convert and time stamp
1700  m_out->Print( 0, "U %d %d %8.8lX\n", aComponent->GetUnit(), aComponent->GetConvert(),
1701  (unsigned long)aComponent->GetTimeStamp() );
1702 
1703  // Save the position
1704  m_out->Print( 0, "P %d %d\n", aComponent->GetPosition().x, aComponent->GetPosition().y );
1705 
1706  /* If this is a complex hierarchy; save hierarchical references.
1707  * but for simple hierarchies it is not necessary.
1708  * the reference inf is already saved
1709  * this is useful for old Eeschema version compatibility
1710  */
1711  if( aComponent->GetPathsAndReferences().GetCount() > 1 )
1712  {
1713  for( unsigned int ii = 0; ii < aComponent->GetPathsAndReferences().GetCount(); ii++ )
1714  {
1715  /*format:
1716  * AR Path="/140/2" Ref="C99" Part="1"
1717  * where 140 is the uid of the containing sheet
1718  * and 2 is the timestamp of this component.
1719  * (timestamps are actually 8 hex chars)
1720  * Ref is the conventional component reference for this 'path'
1721  * Part is the conventional component part selection for this 'path'
1722  */
1723  reference_fields = wxStringTokenize( aComponent->GetPathsAndReferences()[ii],
1724  delimiters );
1725 
1726  m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%s\" \n",
1727  TO_UTF8( reference_fields[0] ),
1728  TO_UTF8( reference_fields[1] ),
1729  TO_UTF8( reference_fields[2] ) );
1730  }
1731  }
1732 
1733  // update the ugly field index, which I would like to see go away someday soon.
1734  for( int i = 0; i < aComponent->GetFieldCount(); ++i )
1735  aComponent->GetField( i )->SetId( i );
1736 
1737  // Fixed fields:
1738  // Save mandatory fields even if they are blank,
1739  // because the visibility, size and orientation are set from libary editor.
1740  for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
1741  saveField( aComponent->GetField( i ) );
1742 
1743  // User defined fields:
1744  // The *policy* about which user defined fields are part of a symbol is now
1745  // only in the dialog editors. No policy should be enforced here, simply
1746  // save all the user defined fields, they are present because a dialog editor
1747  // thought they should be. If you disagree, go fix the dialog editors.
1748  for( int i = MANDATORY_FIELDS; i < aComponent->GetFieldCount(); ++i )
1749  saveField( aComponent->GetField( i ) );
1750 
1751  // Unit number, position, box ( old standard )
1752  m_out->Print( 0, "\t%-4d %-4d %-4d\n", aComponent->GetUnit(), aComponent->GetPosition().x,
1753  aComponent->GetPosition().y );
1754 
1755  TRANSFORM transform = aComponent->GetTransform();
1756 
1757  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
1758  transform.x1, transform.y1, transform.x2, transform.y2 );
1759  m_out->Print( 0, "$EndComp\n" );
1760 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
TRANSFORM & GetTransform() const
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
int 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
Function GetField returns a field.
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
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:204
int GetFieldCount() const
Function GetFieldCount returns the number of fields in this component.
wxPoint GetPosition() const override
Function GetPosition.
const LIB_ID & GetLibId() const
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:408
void SCH_LEGACY_PLUGIN::saveField ( SCH_FIELD aField)
private

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

1764 {
1765  char hjustify = 'C';
1766 
1767  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
1768  hjustify = 'L';
1769  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
1770  hjustify = 'R';
1771 
1772  char vjustify = 'C';
1773 
1774  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
1775  vjustify = 'B';
1776  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
1777  vjustify = 'T';
1778 
1779  m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1780  aField->GetId(),
1781  EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
1782  aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
1783  aField->GetLibPosition().x, aField->GetLibPosition().y,
1784  aField->GetTextWidth(),
1785  !aField->IsVisible(),
1786  hjustify, vjustify,
1787  aField->IsItalic() ? 'I' : 'N',
1788  aField->IsBold() ? 'B' : 'N' );
1789 
1790  // Save field name, if the name is user definable
1791  if( aField->GetId() >= FIELD1 )
1792  {
1793  m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
1794  }
1795 
1796  m_out->Print( 0, "\n" );
1797 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:473
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:189
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:408
void SCH_LEGACY_PLUGIN::saveJunction ( SCH_JUNCTION aJunction)
private

Definition at line 1913 of file sch_legacy_plugin.cpp.

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

Referenced by Format().

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

Reimplemented from SCH_PLUGIN.

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

3579 {
3580  if( !m_cache )
3581  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
3582 
3583  wxString oldFileName = m_cache->GetFileName();
3584 
3585  if( !m_cache->IsFile( aLibraryPath ) )
3586  {
3587  m_cache->SetFileName( aLibraryPath );
3588  }
3589 
3590  // This is a forced save.
3591  m_cache->SetModified();
3592  m_cache->Save( writeDocFile( aProperties ) );
3593  m_cache->SetFileName( oldFileName );
3594 }
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 1946 of file sch_legacy_plugin.cpp.

References SCH_LINE::GetEndPoint(), SCH_ITEM::GetLayer(), SCH_LINE::GetStartPoint(), LAYER_BUS, LAYER_WIRE, m_out, OUTPUTFORMATTER::Print(), wxPoint::x, and wxPoint::y.

Referenced by Format().

1947 {
1948  wxCHECK_RET( aLine != NULL, "SCH_LINE* is NULL" );
1949 
1950  const char* layer = "Notes";
1951  const char* width = "Line";
1952 
1953  if( aLine->GetLayer() == LAYER_WIRE )
1954  layer = "Wire";
1955  else if( aLine->GetLayer() == LAYER_BUS )
1956  layer = "Bus";
1957 
1958  m_out->Print( 0, "Wire %s %s\n", layer, width );
1959  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n", aLine->GetStartPoint().x, aLine->GetStartPoint().y,
1960  aLine->GetEndPoint().x, aLine->GetEndPoint().y );
1961 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
wxPoint GetEndPoint() const
Definition: sch_line.h:75
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
wxPoint GetStartPoint() const
Definition: sch_line.h:71
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void SCH_LEGACY_PLUGIN::saveNoConnect ( SCH_NO_CONNECT aNoConnect)
private

Definition at line 1922 of file sch_legacy_plugin.cpp.

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

Referenced by Format().

1923 {
1924  wxCHECK_RET( aNoConnect != NULL, "SCH_NOCONNECT* is NULL" );
1925 
1926  m_out->Print( 0, "NoConn ~ %-4d %-4d\n", aNoConnect->GetPosition().x,
1927  aNoConnect->GetPosition().y );
1928 }
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:408
void SCH_LEGACY_PLUGIN::saveSheet ( SCH_SHEET aSheet)
private

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

1839 {
1840  wxCHECK_RET( aSheet != NULL, "SCH_SHEET* is NULL" );
1841 
1842  m_out->Print( 0, "$Sheet\n" );
1843  m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
1844  aSheet->GetPosition().x, aSheet->GetPosition().y,
1845  aSheet->GetSize().x, aSheet->GetSize().y );
1846 
1847  m_out->Print( 0, "U %8.8lX\n", (unsigned long) aSheet->GetTimeStamp() );
1848 
1849  if( !aSheet->GetName().IsEmpty() )
1850  m_out->Print( 0, "F0 %s %d\n", EscapedUTF8( aSheet->GetName() ).c_str(),
1851  aSheet->GetSheetNameSize() );
1852 
1853  if( !aSheet->GetFileName().IsEmpty() )
1854  m_out->Print( 0, "F1 %s %d\n", EscapedUTF8( aSheet->GetFileName() ).c_str(),
1855  aSheet->GetFileNameSize() );
1856 
1857  for( const SCH_SHEET_PIN& pin : aSheet->GetPins() )
1858  {
1859  int type, side;
1860 
1861  if( pin.GetText().IsEmpty() )
1862  break;
1863 
1864  switch( pin.GetEdge() )
1865  {
1866  default:
1868  side = 'L';
1869  break;
1870 
1872  side = 'R';
1873  break;
1874 
1876  side = 'T';
1877  break;
1878 
1880  side = 'B';
1881  break;
1882  }
1883 
1884  switch( pin.GetShape() )
1885  {
1886  case NET_INPUT:
1887  type = 'I'; break;
1888 
1889  case NET_OUTPUT:
1890  type = 'O'; break;
1891 
1892  case NET_BIDI:
1893  type = 'B'; break;
1894 
1895  case NET_TRISTATE:
1896  type = 'T'; break;
1897 
1898  default:
1899  case NET_UNSPECIFIED:
1900  type = 'U'; break;
1901  }
1902 
1903  m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n", pin.GetNumber(),
1904  EscapedUTF8( pin.GetText() ).c_str(), // supplies wrapping quotes
1905  type, side, pin.GetPosition().x, pin.GetPosition().y,
1906  pin.GetTextWidth() );
1907  }
1908 
1909  m_out->Print( 0, "$EndSheet\n" );
1910 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
SCH_SHEET_PINS & GetPins()
Definition: sch_sheet.h:348
int GetSheetNameSize() const
Definition: sch_sheet.h:278
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:282
Class SCH_SHEET_PIN defines a sheet pin (label) used in sheets to create hierarchical schematics...
Definition: sch_sheet.h:62
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_sheet.h:582
wxString GetFileName(void) const
Function GetFileName return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:849
time_t GetTimeStamp() const
Definition: base_struct.h:204
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
wxString GetName() const
Definition: sch_sheet.h:274
wxSize GetSize()
Definition: sch_sheet.h:288
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 3488 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().

3490 {
3491  m_props = aProperties;
3492 
3493  cacheLib( aLibraryPath );
3494 
3495  m_cache->AddSymbol( aSymbol );
3496 
3497  if( !isBuffering( aProperties ) )
3498  m_cache->Save( writeDocFile( aProperties ) );
3499 }
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 1964 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().

1965 {
1966  wxCHECK_RET( aText != NULL, "SCH_TEXT* is NULL" );
1967 
1968  const char* italics = "~";
1969  const char* textType = "Notes";
1970 
1971  if( aText->IsItalic() )
1972  italics = "Italic";
1973 
1974  wxString text = aText->GetText();
1975 
1976  SCH_LAYER_ID layer = aText->GetLayer();
1977 
1978  if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
1979  {
1980  if( layer == LAYER_NOTES )
1981  {
1982  // For compatibility reasons, the text must be saved in only one text line
1983  // so replace all EOLs with \\n
1984  text.Replace( wxT( "\n" ), wxT( "\\n" ) );
1985 
1986  // Here we should have no CR or LF character in line
1987  // This is not always the case if a multiline text was copied (using a copy/paste
1988  // function) from a text that uses E.O.L characters that differs from the current
1989  // EOL format. This is mainly the case under Linux using LF symbol when copying
1990  // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
1991  // (or LF left under MacOSX)
1992  for( unsigned ii = 0; ii < text.Len(); )
1993  {
1994  if( text[ii] == 0x0A || text[ii] == 0x0D )
1995  text.erase( ii, 1 );
1996  else
1997  ii++;
1998  }
1999  }
2000  else
2001  {
2002  textType = "Label";
2003  }
2004 
2005  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2006  aText->GetPosition().x, aText->GetPosition().y,
2007  aText->GetLabelSpinStyle(),
2008  aText->GetTextWidth(),
2009  italics, aText->GetThickness(), TO_UTF8( text ) );
2010  }
2011  else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2012  {
2013  textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2014 
2015  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2016  aText->GetPosition().x, aText->GetPosition().y,
2017  aText->GetLabelSpinStyle(),
2018  aText->GetTextWidth(),
2019  SheetLabelType[aText->GetShape()],
2020  italics,
2021  aText->GetThickness(), TO_UTF8( text ) );
2022  }
2023 }
FILE_OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:121
bool IsItalic() const
Definition: eda_text.h:170
int GetTextWidth() const
Definition: eda_text.h:218
int GetLabelSpinStyle() const
Definition: sch_text.h:119
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:200
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
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 157 of file sch_plugin.cpp.

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

Definition at line 3396 of file sch_legacy_plugin.cpp.

References PropNoDocFile.

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

3397 {
3398  std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
3399 
3400  if( aProperties && aProperties->find( propName ) != aProperties->end() )
3401  return false;
3402 
3403  return true;
3404 }
static const char * PropNoDocFile
const char* PropBuffering

Member Data Documentation

wxString SCH_LEGACY_PLUGIN::m_error
protected

For throwing exceptions.

Definition at line 157 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 160 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 162 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 158 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 159 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 161 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 156 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 85 of file sch_legacy_plugin.h.

Referenced by PART_LIB::EnableBuffering(), isBuffering(), and PART_LIB::IsBuffering().

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 93 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: