KiCad PCB EDA Suite
SCH_LEGACY_PLUGIN Class Reference

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

#include <sch_legacy_plugin.h>

Inheritance diagram for SCH_LEGACY_PLUGIN:
SCH_PLUGIN

Public Member Functions

 SCH_LEGACY_PLUGIN ()
 
virtual ~SCH_LEGACY_PLUGIN ()
 
const wxString GetName () const override
 Return a brief hard coded name for this SCH_PLUGIN. More...
 
const wxString GetFileExtension () const override
 Return the file extension for the SCH_PLUGIN. More...
 
const wxString GetLibraryFileExtension () const override
 Return the library file extension for the SCH_PLUGIN object. More...
 
void SetProgressReporter (PROGRESS_REPORTER *aReporter) override
 Set an optional progress reporter. More...
 
int GetModifyHash () const override
 Return the modification hash from the library cache. More...
 
SCH_SHEETLoad (const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr) override
 Load information from some input file format that this SCH_PLUGIN implementation knows about, into either a new SCH_SHEET or an existing one. More...
 
void LoadContent (LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
 
void Save (const wxString &aFileName, SCH_SHEET *aScreen, SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr) override
 Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file. More...
 
void Format (SCH_SHEET *aSheet)
 
void Format (SELECTION *aSelection, OUTPUTFORMATTER *aFormatter)
 
void EnumerateSymbolLib (wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath. More...
 
void EnumerateSymbolLib (std::vector< LIB_SYMBOL * > &aSymbolList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Populate a list of LIB_SYMBOL aliases contained within the library aLibraryPath. More...
 
LIB_SYMBOLLoadSymbol (const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=nullptr) override
 Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this SCH_PLUGIN knows about. More...
 
void SaveSymbol (const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const PROPERTIES *aProperties=nullptr) override
 Write aSymbol to an existing library located at aLibraryPath. More...
 
void DeleteSymbol (const wxString &aLibraryPath, const wxString &aSymbolName, const PROPERTIES *aProperties=nullptr) override
 Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath. More...
 
void CreateSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Create a new empty symbol library at aLibraryPath. More...
 
bool DeleteSymbolLib (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 Delete an existing symbol library and returns true if successful, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason. More...
 
void SaveLibrary (const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
 
bool CheckHeader (const wxString &aFileName) override
 Return true if the first line in aFileName begins with the expected header. More...
 
bool IsSymbolLibWritable (const wxString &aLibraryPath) override
 Return true if the library at aLibraryPath is writable. More...
 
const wxString & GetError () const override
 Return an error string to the caller. More...
 
virtual void SetReporter (REPORTER *aReporter)
 Set an optional reporter for warnings/errors. More...
 
virtual void SymbolLibOptions (PROPERTIES *aListToAppendTo) const
 Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 

Static Public Member Functions

static LIB_SYMBOLParsePart (LINE_READER &aReader, int majorVersion=0, int minorVersion=0)
 
static void FormatPart (LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter)
 

Static Public Attributes

static const char * PropBuffering = "buffering"
 The property used internally by the plugin to enable cache buffering which prevents the library file from being written every time the cache is changed. More...
 
static const char * PropNoDocFile = "no_doc_file"
 The property used internally by the plugin to disable writing the library documentation (.dcm) file when saving the library cache. More...
 

Protected Member Functions

void init (SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
 initialize PLUGIN like a constructor would. More...
 

Protected Attributes

int m_version
 Version of file being loaded. More...
 
wxString m_error
 For throwing exceptions or errors on partial schematic loads. More...
 
PROGRESS_REPORTERm_progressReporter
 optional; may be nullptr More...
 
LINE_READERm_lineReader
 for progress reporting More...
 
unsigned m_lastProgressLine
 
unsigned m_lineCount
 for progress reporting More...
 
wxString m_path
 Root project path for loading child sheets. More...
 
std::stack< wxString > m_currentPath
 Stack to maintain nested sheet paths. More...
 
SCH_SHEETm_rootSheet
 The root sheet of the schematic being loaded. More...
 
OUTPUTFORMATTERm_out
 The formatter for saving SCH_SCREEN objects. More...
 
SCH_LEGACY_PLUGIN_CACHEm_cache
 
SCHEMATICm_schematic
 

Private Member Functions

void checkpoint ()
 
void loadHierarchy (SCH_SHEET *aSheet)
 
void loadHeader (LINE_READER &aReader, SCH_SCREEN *aScreen)
 
void loadPageSettings (LINE_READER &aReader, SCH_SCREEN *aScreen)
 
void loadFile (const wxString &aFileName, SCH_SCREEN *aScreen)
 
SCH_SHEETloadSheet (LINE_READER &aReader)
 
SCH_BITMAPloadBitmap (LINE_READER &aReader)
 
SCH_JUNCTIONloadJunction (LINE_READER &aReader)
 
SCH_NO_CONNECTloadNoConnect (LINE_READER &aReader)
 
SCH_LINEloadWire (LINE_READER &aReader)
 
SCH_BUS_ENTRY_BASEloadBusEntry (LINE_READER &aReader)
 
SCH_TEXTloadText (LINE_READER &aReader)
 
SCH_SYMBOLloadSymbol (LINE_READER &aReader)
 
std::shared_ptr< BUS_ALIASloadBusAlias (LINE_READER &aReader, SCH_SCREEN *aScreen)
 
void saveSymbol (SCH_SYMBOL *aSymbol)
 
void saveField (SCH_FIELD *aField)
 
void saveBitmap (SCH_BITMAP *aBitmap)
 
void saveSheet (SCH_SHEET *aSheet)
 
void saveJunction (SCH_JUNCTION *aJunction)
 
void saveNoConnect (SCH_NO_CONNECT *aNoConnect)
 
void saveBusEntry (SCH_BUS_ENTRY_BASE *aBusEntry)
 
void saveLine (SCH_LINE *aLine)
 
void saveText (SCH_TEXT *aText)
 
void saveBusAlias (std::shared_ptr< BUS_ALIAS > aAlias)
 
void cacheLib (const wxString &aLibraryFileName, const PROPERTIES *aProperties)
 
bool writeDocFile (const PROPERTIES *aProperties)
 
bool isBuffering (const PROPERTIES *aProperties)
 

Detailed Description

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

The legacy parser and formatter attempt to be compatible with the legacy file format. The original parser was very forgiving in that it would parse only part of a keyword. So "$C", "$Co", and "$Com" could be used for "$Comp" and the old parser would allow this. This parser is not that forgiving and sticks to the legacy file format document.

As with all SCH_PLUGINs there is no UI dependencies i.e. windowing calls allowed.

Definition at line 63 of file sch_legacy_plugin.h.

Constructor & Destructor Documentation

◆ SCH_LEGACY_PLUGIN()

SCH_LEGACY_PLUGIN::SCH_LEGACY_PLUGIN ( )

Definition at line 577 of file sch_legacy_plugin.cpp.

577  :
578  m_progressReporter( nullptr ),
579  m_lineReader( nullptr ),
580  m_lastProgressLine( 0 ),
581  m_lineCount( 0 )
582 {
583  init( nullptr );
584 }
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.
LINE_READER * m_lineReader
for progress reporting
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
unsigned m_lineCount
for progress reporting

References init().

◆ ~SCH_LEGACY_PLUGIN()

SCH_LEGACY_PLUGIN::~SCH_LEGACY_PLUGIN ( )
virtual

Definition at line 587 of file sch_legacy_plugin.cpp.

588 {
589  delete m_cache;
590 }
SCH_LEGACY_PLUGIN_CACHE * m_cache

References m_cache.

Member Function Documentation

◆ cacheLib()

void SCH_LEGACY_PLUGIN::cacheLib ( const wxString &  aLibraryFileName,
const PROPERTIES aProperties 
)
private

Definition at line 4263 of file sch_legacy_plugin.cpp.

4264 {
4265  if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
4266  {
4267  // a spectacular episode in memory management:
4268  delete m_cache;
4269  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
4270 
4271  // Because m_cache is rebuilt, increment SYMBOL_LIBS::s_modify_generation
4272  // to modify the hash value that indicate symbol to symbol links
4273  // must be updated.
4275 
4276  if( !isBuffering( aProperties ) )
4277  m_cache->Load();
4278  }
4279 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
A cache assistant for the symbol library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_P...
bool isBuffering(const PROPERTIES *aProperties)
static void IncrementModifyGeneration()
bool IsFile(const wxString &aFullPathAndFileName) const

References SYMBOL_LIBS::IncrementModifyGeneration(), isBuffering(), SCH_LEGACY_PLUGIN_CACHE::IsFile(), SCH_LEGACY_PLUGIN_CACHE::IsFileChanged(), SCH_LEGACY_PLUGIN_CACHE::Load(), and m_cache.

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

◆ CheckHeader()

bool SCH_LEGACY_PLUGIN::CheckHeader ( const wxString &  aFileName)
overridevirtual

Return true if the first line in aFileName begins with the expected header.

Parameters
aFileNameis the name of the file to use as input

Reimplemented from SCH_PLUGIN.

Definition at line 4460 of file sch_legacy_plugin.cpp.

4461 {
4462  // Open file and check first line
4463  wxTextFile tempFile;
4464 
4465  tempFile.Open( aFileName );
4466  wxString firstline;
4467  // read the first line
4468  firstline = tempFile.GetFirstLine();
4469  tempFile.Close();
4470 
4471  return firstline.StartsWith( "EESchema" );
4472 }

◆ checkpoint()

void SCH_LEGACY_PLUGIN::checkpoint ( )
private

Definition at line 603 of file sch_legacy_plugin.cpp.

604 {
605  const unsigned PROGRESS_DELTA = 250;
606 
607  if( m_progressReporter )
608  {
609  unsigned curLine = m_lineReader->LineNumber();
610 
611  if( curLine > m_lastProgressLine + PROGRESS_DELTA )
612  {
613  m_progressReporter->SetCurrentProgress( ( (double) curLine )
614  / std::max( 1U, m_lineCount ) );
615 
617  THROW_IO_ERROR( ( "Open cancelled by user." ) );
618 
619  m_lastProgressLine = curLine;
620  }
621  }
622 }
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition: richio.h:135
LINE_READER * m_lineReader
for progress reporting
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
unsigned m_lineCount
for progress reporting
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).

References PROGRESS_REPORTER::KeepRefreshing(), LINE_READER::LineNumber(), m_lastProgressLine, m_lineCount, m_lineReader, m_progressReporter, PROGRESS_REPORTER::SetCurrentProgress(), and THROW_IO_ERROR.

Referenced by LoadContent(), and loadHeader().

◆ CreateSymbolLib()

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

Create a new empty symbol library at aLibraryPath.

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4396 of file sch_legacy_plugin.cpp.

4398 {
4399  if( wxFileExists( aLibraryPath ) )
4400  {
4401  THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' already exists." ),
4402  aLibraryPath.GetData() ) );
4403  }
4404 
4405  LOCALE_IO toggle;
4406 
4407  delete m_cache;
4408  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4409  m_cache->SetModified();
4410  m_cache->Save( writeDocFile( aProperties ) );
4411  m_cache->Load(); // update m_writable and m_mod_time
4412 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
SCH_LEGACY_PLUGIN_CACHE * m_cache
A cache assistant for the symbol library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_P...
#define _(s)
void SetModified(bool aModified=true)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
bool writeDocFile(const PROPERTIES *aProperties)

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

◆ DeleteSymbol()

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

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

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
aSymbolNameis the name of a LIB_SYMBOL associated with it's root LIB_SYMBOL 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 4382 of file sch_legacy_plugin.cpp.

4384 {
4385  LOCALE_IO toggle; // toggles on, then off, the C locale.
4386 
4387  cacheLib( aLibraryPath, aProperties );
4388 
4389  m_cache->DeleteSymbol( aSymbolName );
4390 
4391  if( !isBuffering( aProperties ) )
4392  m_cache->Save( writeDocFile( aProperties ) );
4393 }
void DeleteSymbol(const wxString &aName)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
SCH_LEGACY_PLUGIN_CACHE * m_cache
bool isBuffering(const PROPERTIES *aProperties)
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
bool writeDocFile(const PROPERTIES *aProperties)

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

◆ DeleteSymbolLib()

bool SCH_LEGACY_PLUGIN::DeleteSymbolLib ( const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4415 of file sch_legacy_plugin.cpp.

4417 {
4418  wxFileName fn = aLibraryPath;
4419 
4420  if( !fn.FileExists() )
4421  return false;
4422 
4423  // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
4424  // we don't want that. we want bare metal portability with no UI here.
4425  if( wxRemove( aLibraryPath ) )
4426  {
4427  THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' cannot be deleted." ),
4428  aLibraryPath.GetData() ) );
4429  }
4430 
4431  if( m_cache && m_cache->IsFile( aLibraryPath ) )
4432  {
4433  delete m_cache;
4434  m_cache = nullptr;
4435  }
4436 
4437  return true;
4438 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
bool IsFile(const wxString &aFullPathAndFileName) const
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

◆ EnumerateSymbolLib() [1/2]

void SCH_LEGACY_PLUGIN::EnumerateSymbolLib ( wxArrayString &  aSymbolNameList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

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

Parameters
aSymbolNameListis an array to populate with the LIB_SYMBOL names associated with the library.
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing one or more LIB_SYMBOL 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 4309 of file sch_legacy_plugin.cpp.

4312 {
4313  LOCALE_IO toggle; // toggles on, then off, the C locale.
4314 
4315  bool powerSymbolsOnly = ( aProperties &&
4316  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4317 
4318  cacheLib( aLibraryPath, aProperties );
4319 
4320  const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
4321 
4322  for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
4323  {
4324  if( !powerSymbolsOnly || it->second->IsPower() )
4325  aSymbolNameList.Add( it->first );
4326  }
4327 }
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
Symbol map used by symbol library object.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
SCH_LEGACY_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)
static const char * PropPowerSymsOnly

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

◆ EnumerateSymbolLib() [2/2]

void SCH_LEGACY_PLUGIN::EnumerateSymbolLib ( std::vector< LIB_SYMBOL * > &  aSymbolList,
const wxString &  aLibraryPath,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

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

Note
It is the responsibility of the caller to delete the returned object from the heap. Failure to do this will result in memory leaks.
Parameters
aSymbolListis an array to populate with the LIB_SYMBOL pointers associated with the library.
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing one or more LIB_SYMBOL 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 4330 of file sch_legacy_plugin.cpp.

4333 {
4334  LOCALE_IO toggle; // toggles on, then off, the C locale.
4335 
4336  bool powerSymbolsOnly = ( aProperties &&
4337  aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
4338 
4339  cacheLib( aLibraryPath, aProperties );
4340 
4341  const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
4342 
4343  for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
4344  {
4345  if( !powerSymbolsOnly || it->second->IsPower() )
4346  aSymbolList.push_back( it->second );
4347  }
4348 }
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
Symbol map used by symbol library object.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
SCH_LEGACY_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)
static const char * PropPowerSymsOnly

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

◆ Format() [1/2]

void SCH_LEGACY_PLUGIN::Format ( SCH_SHEET aSheet)

Definition at line 1901 of file sch_legacy_plugin.cpp.

1902 {
1903  wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." );
1904  wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." );
1905 
1906  SCH_SCREEN* screen = aSheet->GetScreen();
1907 
1908  wxCHECK( screen, /* void */ );
1909 
1910  // Write the header
1911  m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1912 
1913  // This section is not used, but written for file compatibility
1914  m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1915  m_out->Print( 0, "EELAYER END\n" );
1916 
1917  /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1918  * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1919  * simple hierarchy and flat hierarchy. Used also to search the root
1920  * sheet ( ScreenNumber = 1 ) within the files
1921  */
1922  const TITLE_BLOCK& tb = screen->GetTitleBlock();
1923  const PAGE_INFO& page = screen->GetPageSettings();
1924 
1925  m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1926  page.GetWidthMils(),
1927  page.GetHeightMils(),
1928  !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1929  m_out->Print( 0, "encoding utf-8\n" );
1930  m_out->Print( 0, "Sheet %d %d\n", screen->GetVirtualPageNumber(), screen->GetPageCount() );
1931  m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1932  m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1933  m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1934  m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1935  m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment( 0 ) ).c_str() );
1936  m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment( 1 ) ).c_str() );
1937  m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment( 2 ) ).c_str() );
1938  m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment( 3 ) ).c_str() );
1939  m_out->Print( 0, "Comment5 %s\n", EscapedUTF8( tb.GetComment( 4 ) ).c_str() );
1940  m_out->Print( 0, "Comment6 %s\n", EscapedUTF8( tb.GetComment( 5 ) ).c_str() );
1941  m_out->Print( 0, "Comment7 %s\n", EscapedUTF8( tb.GetComment( 6 ) ).c_str() );
1942  m_out->Print( 0, "Comment8 %s\n", EscapedUTF8( tb.GetComment( 7 ) ).c_str() );
1943  m_out->Print( 0, "Comment9 %s\n", EscapedUTF8( tb.GetComment( 8 ) ).c_str() );
1944  m_out->Print( 0, "$EndDescr\n" );
1945 
1946  for( const auto& alias : screen->GetBusAliases() )
1947  {
1948  saveBusAlias( alias );
1949  }
1950 
1951  // Enforce item ordering
1952  auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b ) { return *a < *b; };
1953  std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
1954 
1955  for( auto item : screen->Items() )
1956  save_map.insert( item );
1957 
1958 
1959  for( auto& item : save_map )
1960  {
1961  switch( item->Type() )
1962  {
1963  case SCH_SYMBOL_T:
1964  saveSymbol( static_cast<SCH_SYMBOL*>( item ) );
1965  break;
1966  case SCH_BITMAP_T:
1967  saveBitmap( static_cast<SCH_BITMAP*>( item ) );
1968  break;
1969  case SCH_SHEET_T:
1970  saveSheet( static_cast<SCH_SHEET*>( item ) );
1971  break;
1972  case SCH_JUNCTION_T:
1973  saveJunction( static_cast<SCH_JUNCTION*>( item ) );
1974  break;
1975  case SCH_NO_CONNECT_T:
1976  saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ) );
1977  break;
1978  case SCH_BUS_WIRE_ENTRY_T:
1979  case SCH_BUS_BUS_ENTRY_T:
1980  saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ) );
1981  break;
1982  case SCH_LINE_T:
1983  saveLine( static_cast<SCH_LINE*>( item ) );
1984  break;
1985  case SCH_TEXT_T:
1986  case SCH_LABEL_T:
1987  case SCH_GLOBAL_LABEL_T:
1988  case SCH_HIER_LABEL_T:
1989  saveText( static_cast<SCH_TEXT*>( item ) );
1990  break;
1991  default:
1992  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1993  }
1994  }
1995 
1996  m_out->Print( 0, "$EndSCHEMATC\n" );
1997 }
void saveLine(SCH_LINE *aLine)
const wxString & GetComment(int aIdx) const
Definition: title_block.h:107
int GetHeightMils() const
Definition: page_info.h:133
int GetVirtualPageNumber() const
Definition: base_screen.h:75
int GetPageCount() const
Definition: base_screen.h:72
void saveText(SCH_TEXT *aText)
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:150
const wxString & GetType() const
Definition: page_info.h:94
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
bool IsCustom() const
Definition: page_info.cpp:180
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:132
#define SCH_LAYER_ID_COUNT
Definition: layer_ids.h:365
void saveSheet(SCH_SHEET *aSheet)
void saveJunction(SCH_JUNCTION *aJunction)
#define SCHEMATIC_HEAD_STRING
Definition: general.h:36
void saveSymbol(SCH_SYMBOL *aSymbol)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
#define EESCHEMA_VERSION
Definition: general.h:35
const wxString & GetRevision() const
Definition: title_block.h:86
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
const wxString & GetCompany() const
Definition: title_block.h:96
void saveBitmap(SCH_BITMAP *aBitmap)
const wxString & GetDate() const
Definition: title_block.h:76
std::unordered_set< std::shared_ptr< BUS_ALIAS > > GetBusAliases() const
Return a list of bus aliases defined in this screen.
Definition: sch_screen.h:454
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
bool IsPortrait() const
Definition: page_info.h:117
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
const wxString & GetTitle() const
Definition: title_block.h:63
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:193
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
int GetWidthMils() const
Definition: page_info.h:130

References EESCHEMA_VERSION, EscapedUTF8(), SCH_SCREEN::GetBusAliases(), TITLE_BLOCK::GetComment(), TITLE_BLOCK::GetCompany(), TITLE_BLOCK::GetDate(), PAGE_INFO::GetHeightMils(), BASE_SCREEN::GetPageCount(), SCH_SCREEN::GetPageSettings(), TITLE_BLOCK::GetRevision(), SCH_SHEET::GetScreen(), TITLE_BLOCK::GetTitle(), SCH_SCREEN::GetTitleBlock(), PAGE_INFO::GetType(), BASE_SCREEN::GetVirtualPageNumber(), PAGE_INFO::GetWidthMils(), PAGE_INFO::IsCustom(), PAGE_INFO::IsPortrait(), SCH_SCREEN::Items(), m_out, m_schematic, OUTPUTFORMATTER::Print(), saveBitmap(), saveBusAlias(), saveBusEntry(), saveJunction(), saveLine(), saveNoConnect(), saveSheet(), saveSymbol(), saveText(), SCH_BITMAP_T, SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_JUNCTION_T, SCH_LABEL_T, SCH_LAYER_ID_COUNT, SCH_LINE_T, SCH_NO_CONNECT_T, SCH_SHEET_T, SCH_SYMBOL_T, SCH_TEXT_T, SCHEMATIC_HEAD_STRING, and TO_UTF8.

Referenced by Save().

◆ Format() [2/2]

void SCH_LEGACY_PLUGIN::Format ( SELECTION aSelection,
OUTPUTFORMATTER aFormatter 
)

Definition at line 2000 of file sch_legacy_plugin.cpp.

2001 {
2002  m_out = aFormatter;
2003 
2004  for( unsigned i = 0; i < aSelection->GetSize(); ++i )
2005  {
2006  SCH_ITEM* item = (SCH_ITEM*) aSelection->GetItem( i );
2007 
2008  switch( item->Type() )
2009  {
2010  case SCH_SYMBOL_T:
2011  saveSymbol( static_cast< SCH_SYMBOL* >( item ) );
2012  break;
2013  case SCH_BITMAP_T:
2014  saveBitmap( static_cast< SCH_BITMAP* >( item ) );
2015  break;
2016  case SCH_SHEET_T:
2017  saveSheet( static_cast< SCH_SHEET* >( item ) );
2018  break;
2019  case SCH_JUNCTION_T:
2020  saveJunction( static_cast< SCH_JUNCTION* >( item ) );
2021  break;
2022  case SCH_NO_CONNECT_T:
2023  saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
2024  break;
2025  case SCH_BUS_WIRE_ENTRY_T:
2026  case SCH_BUS_BUS_ENTRY_T:
2027  saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
2028  break;
2029  case SCH_LINE_T:
2030  saveLine( static_cast< SCH_LINE* >( item ) );
2031  break;
2032  case SCH_TEXT_T:
2033  case SCH_LABEL_T:
2034  case SCH_GLOBAL_LABEL_T:
2035  case SCH_HIER_LABEL_T:
2036  saveText( static_cast< SCH_TEXT* >( item ) );
2037  break;
2038  default:
2039  wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
2040  }
2041  }
2042 }
void saveLine(SCH_LINE *aLine)
void saveText(SCH_TEXT *aText)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
void saveSheet(SCH_SHEET *aSheet)
void saveJunction(SCH_JUNCTION *aJunction)
void saveSymbol(SCH_SYMBOL *aSymbol)
void saveBitmap(SCH_BITMAP *aBitmap)
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:87
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:52
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:193
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References SELECTION::GetItem(), SELECTION::GetSize(), m_out, saveBitmap(), saveBusEntry(), saveJunction(), saveLine(), saveNoConnect(), saveSheet(), saveSymbol(), saveText(), SCH_BITMAP_T, SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_JUNCTION_T, SCH_LABEL_T, SCH_LINE_T, SCH_NO_CONNECT_T, SCH_SHEET_T, SCH_SYMBOL_T, SCH_TEXT_T, and EDA_ITEM::Type().

◆ FormatPart()

void SCH_LEGACY_PLUGIN::FormatPart ( LIB_SYMBOL aSymbol,
OUTPUTFORMATTER aFormatter 
)
static

Definition at line 4489 of file sch_legacy_plugin.cpp.

4490 {
4491  SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( symbol, formatter );
4492 }
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_SYMBOL_MAP *aMap=nullptr)

References SCH_LEGACY_PLUGIN_CACHE::SaveSymbol().

◆ GetError()

const wxString& SCH_LEGACY_PLUGIN::GetError ( ) const
inlineoverridevirtual

Return an error string to the caller.

This is useful for schematic loaders that can load partial schematics where throwing an exception would be problematic such as the KiCad legacy plugin.

Returns
an unformatted string containing errors if any.

Reimplemented from SCH_PLUGIN.

Definition at line 141 of file sch_legacy_plugin.h.

141 { return m_error; }
wxString m_error
For throwing exceptions or errors on partial schematic loads.

References m_error.

◆ GetFileExtension()

const wxString SCH_LEGACY_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Return the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 75 of file sch_legacy_plugin.h.

76  {
77  return wxT( "sch" );
78  }

◆ GetLibraryFileExtension()

const wxString SCH_LEGACY_PLUGIN::GetLibraryFileExtension ( ) const
inlineoverridevirtual

Return the library file extension for the SCH_PLUGIN object.

Implements SCH_PLUGIN.

Definition at line 80 of file sch_legacy_plugin.h.

81  {
82  return wxT( "lib" );
83  }

◆ GetModifyHash()

int SCH_LEGACY_PLUGIN::GetModifyHash ( ) const
overridevirtual

Return the modification hash from the library cache.

Note
This is temporary until the new s-expr file format is implement. The new file format will embed symbols instead of referencing them from the library. This function can be removed when the new file format is implemented.
Returns
the modification hash of the library cache.

Implements SCH_PLUGIN.

Definition at line 4299 of file sch_legacy_plugin.cpp.

4300 {
4301  if( m_cache )
4303 
4304  // If the cache hasn't been loaded, it hasn't been modified.
4305  return 0;
4306 }
SCH_LEGACY_PLUGIN_CACHE * m_cache

References SCH_LEGACY_PLUGIN_CACHE::GetModifyHash(), and m_cache.

◆ GetName()

const wxString SCH_LEGACY_PLUGIN::GetName ( ) const
inlineoverridevirtual

Return a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 70 of file sch_legacy_plugin.h.

71  {
72  return wxT( "Eeschema-Legacy" );
73  }

◆ init()

void SCH_LEGACY_PLUGIN::init ( SCHEMATIC aSchematic,
const PROPERTIES aProperties = nullptr 
)
protected

initialize PLUGIN like a constructor would.

Definition at line 593 of file sch_legacy_plugin.cpp.

594 {
595  m_version = 0;
596  m_rootSheet = nullptr;
597  m_schematic = aSchematic;
598  m_cache = nullptr;
599  m_out = nullptr;
600 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
int m_version
Version of file being loaded.
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.

References m_cache, m_out, m_rootSheet, m_schematic, and m_version.

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

◆ isBuffering()

bool SCH_LEGACY_PLUGIN::isBuffering ( const PROPERTIES aProperties)
private

Definition at line 4293 of file sch_legacy_plugin.cpp.

4294 {
4295  return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
4296 }
bool Exists(const std::string &aProperty) const
Definition: properties.h:41
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...

References PROPERTIES::Exists(), and PropBuffering.

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

◆ IsSymbolLibWritable()

bool SCH_LEGACY_PLUGIN::IsSymbolLibWritable ( const wxString &  aLibraryPath)
overridevirtual

Return true if the library at aLibraryPath is writable.

(Often system libraries are read only because of where they are installed.)

Parameters
aLibraryPathis a locator for the "library", usually a directory, file, or URL containing several symbols.
Exceptions
IO_ERRORif no library at aLibraryPath exists.

Reimplemented from SCH_PLUGIN.

Definition at line 4475 of file sch_legacy_plugin.cpp.

4476 {
4477  // Writing legacy symbol libraries is deprecated.
4478  return false;
4479 }

◆ Load()

SCH_SHEET * SCH_LEGACY_PLUGIN::Load ( const wxString &  aFileName,
SCHEMATIC aSchematic,
SCH_SHEET aAppendToMe = nullptr,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

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

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

Parameters
aFileNameis the name of the file to use as input and may be foreign in nature or native in nature.
aKiwayis the KIWAY object used to access the symbol 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 625 of file sch_legacy_plugin.cpp.

627 {
628  wxASSERT( !aFileName || aSchematic != nullptr );
629 
630  LOCALE_IO toggle; // toggles on, then off, the C locale.
631  SCH_SHEET* sheet;
632 
633  wxFileName fn = aFileName;
634 
635  // Unfortunately child sheet file names the legacy schematic file format are not fully
636  // qualified and are always appended to the project path. The aFileName attribute must
637  // always be an absolute path so the project path can be used for load child sheet files.
638  wxASSERT( fn.IsAbsolute() );
639 
640  if( aAppendToMe )
641  {
642  wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
643  aFileName, aAppendToMe->GetFileName() );
644 
645  wxFileName normedFn = aAppendToMe->GetFileName();
646 
647  if( !normedFn.IsAbsolute() )
648  {
649  if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
650  m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
651  }
652 
653  if( m_path.IsEmpty() )
654  m_path = aSchematic->Prj().GetProjectPath();
655 
656  wxLogTrace( traceSchLegacyPlugin, "m_Normalized append path \"%s\".", m_path );
657  }
658  else
659  {
660  m_path = aSchematic->Prj().GetProjectPath();
661  }
662 
663  m_currentPath.push( m_path );
664  init( aSchematic, aProperties );
665 
666  if( aAppendToMe == nullptr )
667  {
668  // Clean up any allocated memory if an exception occurs loading the schematic.
669  std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
670  newSheet->SetFileName( aFileName );
671  m_rootSheet = newSheet.get();
672  loadHierarchy( newSheet.get() );
673 
674  // If we got here, the schematic loaded successfully.
675  sheet = newSheet.release();
676  m_rootSheet = nullptr; // Quiet Coverity warning.
677  }
678  else
679  {
680  wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
681  m_rootSheet = &aSchematic->Root();
682  sheet = aAppendToMe;
683  loadHierarchy( sheet );
684  }
685 
686  wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
687 
688  return sheet;
689 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:108
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:122
wxString m_path
Root project path for loading child sheets.
void loadHierarchy(SCH_SHEET *aSheet)
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:315
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
SCH_SHEET & Root() const
Definition: schematic.h:92
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.

References SCH_SHEET::GetFileName(), PROJECT::GetProjectPath(), init(), SCHEMATIC::IsValid(), loadHierarchy(), m_currentPath, m_path, m_rootSheet, SCHEMATIC::Prj(), SCHEMATIC::Root(), and traceSchLegacyPlugin.

◆ loadBitmap()

SCH_BITMAP * SCH_LEGACY_PLUGIN::loadBitmap ( LINE_READER aReader)
private

Definition at line 1135 of file sch_legacy_plugin.cpp.

1136 {
1137  std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
1138 
1139  const char* line = aReader.Line();
1140 
1141  wxCHECK( strCompare( "$Bitmap", line, &line ), nullptr );
1142 
1143  line = aReader.ReadLine();
1144 
1145  while( line != nullptr )
1146  {
1147  if( strCompare( "Pos", line, &line ) )
1148  {
1149  wxPoint position;
1150 
1151  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1152  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1153  bitmap->SetPosition( position );
1154  }
1155  else if( strCompare( "Scale", line, &line ) )
1156  {
1157  auto scalefactor = parseDouble( aReader, line, &line );
1158 
1159  // Prevent scalefactor values that cannot be displayed.
1160  // In the case of a bad value, we accept that the image might be mis-scaled
1161  // rather than removing the full image. Users can then edit the scale factor in
1162  // Eeschema to the appropriate value
1163  if( !std::isnormal( scalefactor ) )
1164  scalefactor = 1.0;
1165 
1166  bitmap->GetImage()->SetScale( scalefactor );
1167  }
1168  else if( strCompare( "Data", line, &line ) )
1169  {
1170  wxMemoryOutputStream stream;
1171 
1172  while( line )
1173  {
1174  if( !aReader.ReadLine() )
1175  SCH_PARSE_ERROR( _( "Unexpected end of file" ), aReader, line );
1176 
1177  line = aReader.Line();
1178 
1179  if( strCompare( "EndData", line ) )
1180  {
1181  // all the PNG date is read.
1182  // We expect here m_image and m_bitmap are void
1183  wxImage* image = new wxImage();
1184  wxMemoryInputStream istream( stream );
1185  image->LoadFile( istream, wxBITMAP_TYPE_PNG );
1186  bitmap->GetImage()->SetImage( image );
1187  bitmap->GetImage()->SetBitmap( new wxBitmap( *image ) );
1188  break;
1189  }
1190 
1191  // Read PNG data, stored in hexadecimal,
1192  // each byte = 2 hexadecimal digits and a space between 2 bytes
1193  // and put it in memory stream buffer
1194  int len = strlen( line );
1195 
1196  for( ; len > 0 && !isspace( *line ); len -= 3, line += 3 )
1197  {
1198  int value = 0;
1199 
1200  if( sscanf( line, "%X", &value ) == 1 )
1201  stream.PutC( (char) value );
1202  else
1203  THROW_IO_ERROR( "invalid PNG data" );
1204  }
1205  }
1206 
1207  if( line == nullptr )
1208  THROW_IO_ERROR( _( "unexpected end of file" ) );
1209  }
1210  else if( strCompare( "$EndBitmap", line ) )
1211  return bitmap.release();
1212 
1213  line = aReader.ReadLine();
1214  }
1215 
1216  THROW_IO_ERROR( _( "unexpected end of file" ) );
1217 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static double parseDouble(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parses an ASCII point string with possible leading whitespace into a double precision floating point ...
#define Mils2Iu(x)
#define _(s)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

Referenced by LoadContent().

◆ loadBusAlias()

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

Definition at line 1851 of file sch_legacy_plugin.cpp.

1853 {
1854  auto busAlias = std::make_shared<BUS_ALIAS>( aScreen );
1855  const char* line = aReader.Line();
1856 
1857  wxCHECK( strCompare( "BusAlias", line, &line ), nullptr );
1858 
1859  wxString buf;
1860  parseUnquotedString( buf, aReader, line, &line );
1861  busAlias->SetName( buf );
1862 
1863  while( *line != '\0' )
1864  {
1865  buf.clear();
1866  parseUnquotedString( buf, aReader, line, &line, true );
1867  if( buf.Len() > 0 )
1868  {
1869  busAlias->AddMember( buf );
1870  }
1871  }
1872 
1873  return busAlias;
1874 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.

References LINE_READER::Line(), parseUnquotedString(), and strCompare().

Referenced by LoadContent().

◆ loadBusEntry()

SCH_BUS_ENTRY_BASE * SCH_LEGACY_PLUGIN::loadBusEntry ( LINE_READER aReader)
private

Definition at line 1362 of file sch_legacy_plugin.cpp.

1363 {
1364  const char* line = aReader.Line();
1365 
1366  wxCHECK( strCompare( "Entry", line, &line ), nullptr );
1367 
1368  std::unique_ptr<SCH_BUS_ENTRY_BASE> busEntry;
1369 
1370  if( strCompare( "Wire", line, &line ) )
1371  {
1372  busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>();
1373 
1374  if( !strCompare( "Line", line, &line ) )
1375  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
1376  }
1377  else if( strCompare( "Bus", line, &line ) )
1378  {
1379  busEntry = std::make_unique<SCH_BUS_BUS_ENTRY>();
1380 
1381  if( !strCompare( "Bus", line, &line ) )
1382  SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
1383  }
1384  else
1385  SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
1386 
1387  line = aReader.ReadLine();
1388 
1389  wxPoint pos;
1390  wxSize size;
1391 
1392  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
1393  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
1394  size.x = Mils2Iu( parseInt( aReader, line, &line ) );
1395  size.y = Mils2Iu( parseInt( aReader, line, &line ) );
1396 
1397  size.x -= pos.x;
1398  size.y -= pos.y;
1399 
1400  busEntry->SetPosition( pos );
1401  busEntry->SetSize( size );
1402 
1403  return busEntry.release();
1404 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define Mils2Iu(x)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)

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

Referenced by LoadContent().

◆ LoadContent()

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

Definition at line 809 of file sch_legacy_plugin.cpp.

810 {
811  m_version = version;
812 
813  // We cannot safely load content without a set root level.
814  wxCHECK_RET( m_rootSheet,
815  "Cannot call SCH_LEGACY_PLUGIN::LoadContent() without setting root sheet." );
816 
817  while( aReader.ReadLine() )
818  {
819  checkpoint();
820 
821  char* line = aReader.Line();
822 
823  while( *line == ' ' )
824  line++;
825 
826  // Either an object will be loaded properly or the file load will fail and raise
827  // an exception.
828  if( strCompare( "$Descr", line ) )
829  loadPageSettings( aReader, aScreen );
830  else if( strCompare( "$Comp", line ) )
831  aScreen->Append( loadSymbol( aReader ) );
832  else if( strCompare( "$Sheet", line ) )
833  aScreen->Append( loadSheet( aReader ) );
834  else if( strCompare( "$Bitmap", line ) )
835  aScreen->Append( loadBitmap( aReader ) );
836  else if( strCompare( "Connection", line ) )
837  aScreen->Append( loadJunction( aReader ) );
838  else if( strCompare( "NoConn", line ) )
839  aScreen->Append( loadNoConnect( aReader ) );
840  else if( strCompare( "Wire", line ) )
841  aScreen->Append( loadWire( aReader ) );
842  else if( strCompare( "Entry", line ) )
843  aScreen->Append( loadBusEntry( aReader ) );
844  else if( strCompare( "Text", line ) )
845  aScreen->Append( loadText( aReader ) );
846  else if( strCompare( "BusAlias", line ) )
847  aScreen->AddBusAlias( loadBusAlias( aReader, aScreen ) );
848  else if( strCompare( "$EndSCHEMATC", line ) )
849  return;
850  else
851  SCH_PARSE_ERROR( "unrecognized token", aReader, line );
852  }
853 }
SCH_SHEET * loadSheet(LINE_READER &aReader)
SCH_JUNCTION * loadJunction(LINE_READER &aReader)
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
SCH_BUS_ENTRY_BASE * loadBusEntry(LINE_READER &aReader)
int m_version
Version of file being loaded.
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_BITMAP * loadBitmap(LINE_READER &aReader)
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Add a bus alias definition (and transfers ownership of the pointer).
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:144
SCH_NO_CONNECT * loadNoConnect(LINE_READER &aReader)
SCH_LINE * loadWire(LINE_READER &aReader)
SCH_TEXT * loadText(LINE_READER &aReader)
SCH_SYMBOL * loadSymbol(LINE_READER &aReader)
std::shared_ptr< BUS_ALIAS > loadBusAlias(LINE_READER &aReader, SCH_SCREEN *aScreen)

References SCH_SCREEN::AddBusAlias(), SCH_SCREEN::Append(), checkpoint(), LINE_READER::Line(), loadBitmap(), loadBusAlias(), loadBusEntry(), loadJunction(), loadNoConnect(), loadPageSettings(), loadSheet(), loadSymbol(), loadText(), loadWire(), m_rootSheet, m_version, LINE_READER::ReadLine(), SCH_PARSE_ERROR, and strCompare().

Referenced by loadFile().

◆ loadFile()

void SCH_LEGACY_PLUGIN::loadFile ( const wxString &  aFileName,
SCH_SCREEN aScreen 
)
private

Definition at line 770 of file sch_legacy_plugin.cpp.

771 {
772  FILE_LINE_READER reader( aFileName );
773 
774  if( m_progressReporter )
775  {
776  m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
777 
779  THROW_IO_ERROR( ( "Open cancelled by user." ) );
780 
781  m_lineReader = &reader;
782  m_lineCount = 0;
783 
784  while( reader.ReadLine() )
785  m_lineCount++;
786 
787  reader.Rewind();
788  }
789 
790  loadHeader( reader, aScreen );
791 
792  LoadContent( reader, aScreen, m_version );
793 
794  // Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
795  // so checking for its existance will fail so just exit here and take our chances. :(
796  if( m_version > 1 )
797  {
798  char* line = reader.Line();
799 
800  while( *line == ' ' )
801  line++;
802 
803  if( !strCompare( "$EndSCHEMATC", line ) )
804  THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
805  }
806 }
void LoadContent(LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
int m_version
Version of file being loaded.
A LINE_READER that reads from an open file.
Definition: richio.h:172
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
LINE_READER * m_lineReader
for progress reporting
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
unsigned m_lineCount
for progress reporting
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
void loadHeader(LINE_READER &aReader, SCH_SCREEN *aScreen)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, Format(), PROGRESS_REPORTER::KeepRefreshing(), LINE_READER::Line(), LoadContent(), loadHeader(), m_lineCount, m_lineReader, m_progressReporter, m_version, FILE_LINE_READER::ReadLine(), PROGRESS_REPORTER::Report(), FILE_LINE_READER::Rewind(), strCompare(), and THROW_IO_ERROR.

Referenced by loadHierarchy().

◆ loadHeader()

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

Definition at line 856 of file sch_legacy_plugin.cpp.

857 {
858  const char* line = aReader.ReadLine();
859 
860  if( !line || !strCompare( "Eeschema Schematic File Version", line, &line ) )
861  {
862  m_error.Printf( _( "'%s' does not appear to be an Eeschema file." ),
863  aScreen->GetFileName() );
865  }
866 
867  // get the file version here.
868  m_version = parseInt( aReader, line, &line );
869 
870  // The next lines are the lib list section, and are mainly comments, like:
871  // LIBS:power
872  // the lib list is not used, but is in schematic file just in case.
873  // It is usually not empty, but we accept empty list.
874  // If empty, there is a legacy section, not used
875  // EELAYER i j
876  // and the last line is
877  // EELAYER END
878  // Skip all lines until the end of header "EELAYER END" is found
879  while( aReader.ReadLine() )
880  {
881  checkpoint();
882 
883  line = aReader.Line();
884 
885  while( *line == ' ' )
886  line++;
887 
888  if( strCompare( "EELAYER END", line ) )
889  return;
890  }
891 
892  THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
893 }
const wxString & GetFileName() const
Definition: sch_screen.h:145
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
wxString m_error
For throwing exceptions or errors on partial schematic loads.
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
int m_version
Version of file being loaded.
#define _(s)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

Referenced by loadFile().

◆ loadHierarchy()

void SCH_LEGACY_PLUGIN::loadHierarchy ( SCH_SHEET aSheet)
private

Definition at line 694 of file sch_legacy_plugin.cpp.

695 {
696  SCH_SCREEN* screen = nullptr;
697 
698  if( !aSheet->GetScreen() )
699  {
700  // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
701  // stores the file name and extension. Add the project path to the file name and
702  // extension to compare when calling SCH_SHEET::SearchHierarchy().
703  wxFileName fileName = aSheet->GetFileName();
704  fileName.SetExt( "sch" );
705 
706  if( !fileName.IsAbsolute() )
707  fileName.MakeAbsolute( m_currentPath.top() );
708 
709  // Save the current path so that it gets restored when descending and ascending the
710  // sheet hierarchy which allows for sheet schematic files to be nested in folders
711  // relative to the last path a schematic was loaded from.
712  wxLogTrace( traceSchLegacyPlugin, "Saving path '%s'", m_currentPath.top() );
713  m_currentPath.push( fileName.GetPath() );
714  wxLogTrace( traceSchLegacyPlugin, "Current path '%s'", m_currentPath.top() );
715  wxLogTrace( traceSchLegacyPlugin, "Loading '%s'", fileName.GetFullPath() );
716 
717  m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
718 
719  if( screen )
720  {
721  aSheet->SetScreen( screen );
722  screen->SetParent( m_schematic );
723  // Do not need to load the sub-sheets - this has already been done.
724  }
725  else
726  {
727  aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
728  aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
729 
730  try
731  {
732  loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
733  }
734  catch( const IO_ERROR& ioe )
735  {
736  // If there is a problem loading the root sheet, there is no recovery.
737  if( aSheet == m_rootSheet )
738  throw( ioe );
739 
740  // For all subsheets, queue up the error message for the caller.
741  if( !m_error.IsEmpty() )
742  m_error += "\n";
743 
744  m_error += ioe.What();
745  }
746 
747  for( auto aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
748  {
749  wxCHECK2( aItem->Type() == SCH_SHEET_T, continue );
750  auto sheet = static_cast<SCH_SHEET*>( aItem );
751 
752  // Set the parent to aSheet. This effectively creates a method to find
753  // the root sheet from any sheet so a pointer to the root sheet does not
754  // need to be stored globally. Note: this is not the same as a hierarchy.
755  // Complex hierarchies can have multiple copies of a sheet. This only
756  // provides a simple tree to find the root sheet.
757  sheet->SetParent( aSheet );
758 
759  // Recursion starts here.
760  loadHierarchy( sheet );
761  }
762  }
763 
764  m_currentPath.pop();
765  wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
766  }
767 }
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:216
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:635
wxString m_error
For throwing exceptions or errors on partial schematic loads.
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:156
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
void loadFile(const wxString &aFileName, SCH_SCREEN *aScreen)
void loadHierarchy(SCH_SHEET *aSheet)
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:315
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:108
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.

References SCH_SHEET::GetFileName(), SCH_SHEET::GetScreen(), SCH_SCREEN::Items(), loadFile(), m_currentPath, m_error, m_rootSheet, m_schematic, EE_RTREE::OfType(), SCH_SHEET_T, SCH_SHEET::SearchHierarchy(), SCH_SCREEN::SetFileName(), EDA_ITEM::SetParent(), SCH_SHEET::SetScreen(), traceSchLegacyPlugin, and IO_ERROR::What().

Referenced by Load().

◆ loadJunction()

SCH_JUNCTION * SCH_LEGACY_PLUGIN::loadJunction ( LINE_READER aReader)
private

Definition at line 1220 of file sch_legacy_plugin.cpp.

1221 {
1222  std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
1223 
1224  const char* line = aReader.Line();
1225 
1226  wxCHECK( strCompare( "Connection", line, &line ), nullptr );
1227 
1228  wxString name;
1229 
1230  parseUnquotedString( name, aReader, line, &line );
1231 
1232  wxPoint position;
1233 
1234  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1235  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1236  junction->SetPosition( position );
1237 
1238  return junction.release();
1239 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
#define Mils2Iu(x)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
const char * name
Definition: DXF_plotter.cpp:56

References LINE_READER::Line(), Mils2Iu, name, parseInt(), parseUnquotedString(), and strCompare().

Referenced by LoadContent().

◆ loadNoConnect()

SCH_NO_CONNECT * SCH_LEGACY_PLUGIN::loadNoConnect ( LINE_READER aReader)
private

Definition at line 1242 of file sch_legacy_plugin.cpp.

1243 {
1244  std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>();
1245 
1246  const char* line = aReader.Line();
1247 
1248  wxCHECK( strCompare( "NoConn", line, &line ), nullptr );
1249 
1250  wxString name;
1251 
1252  parseUnquotedString( name, aReader, line, &line );
1253 
1254  wxPoint position;
1255 
1256  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1257  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1258  no_connect->SetPosition( position );
1259 
1260  return no_connect.release();
1261 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
#define Mils2Iu(x)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
const char * name
Definition: DXF_plotter.cpp:56

References LINE_READER::Line(), Mils2Iu, name, parseInt(), parseUnquotedString(), and strCompare().

Referenced by LoadContent().

◆ loadPageSettings()

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

Definition at line 896 of file sch_legacy_plugin.cpp.

897 {
898  wxASSERT( aScreen != nullptr );
899 
900  wxString buf;
901  const char* line = aReader.Line();
902 
903  PAGE_INFO pageInfo;
904  TITLE_BLOCK tb;
905 
906  wxCHECK_RET( strCompare( "$Descr", line, &line ), "Invalid sheet description" );
907 
908  parseUnquotedString( buf, aReader, line, &line );
909 
910  if( !pageInfo.SetType( buf ) )
911  SCH_PARSE_ERROR( "invalid page size", aReader, line );
912 
913  int pagew = parseInt( aReader, line, &line );
914  int pageh = parseInt( aReader, line, &line );
915 
916  if( buf == PAGE_INFO::Custom )
917  {
918  pageInfo.SetWidthMils( pagew );
919  pageInfo.SetHeightMils( pageh );
920  }
921  else
922  {
923  wxString orientation;
924 
925  // Non custom size, set portrait if its present. Can be empty string which defaults
926  // to landscape.
927  parseUnquotedString( orientation, aReader, line, &line, true );
928 
929  if( orientation == "portrait" )
930  pageInfo.SetPortrait( true );
931  }
932 
933  aScreen->SetPageSettings( pageInfo );
934 
935  while( line != nullptr )
936  {
937  buf.clear();
938 
939  if( !aReader.ReadLine() )
940  SCH_PARSE_ERROR( _( "unexpected end of file" ), aReader, line );
941 
942  line = aReader.Line();
943 
944  if( strCompare( "Sheet", line, &line ) )
945  {
946  aScreen->SetVirtualPageNumber( parseInt( aReader, line, &line ) );
947  aScreen->SetPageCount( parseInt( aReader, line, &line ) );
948  }
949  else if( strCompare( "Title", line, &line ) )
950  {
951  parseQuotedString( buf, aReader, line, &line, true );
952  tb.SetTitle( buf );
953  }
954  else if( strCompare( "Date", line, &line ) )
955  {
956  parseQuotedString( buf, aReader, line, &line, true );
957  tb.SetDate( buf );
958  }
959  else if( strCompare( "Rev", line, &line ) )
960  {
961  parseQuotedString( buf, aReader, line, &line, true );
962  tb.SetRevision( buf );
963  }
964  else if( strCompare( "Comp", line, &line ) )
965  {
966  parseQuotedString( buf, aReader, line, &line, true );
967  tb.SetCompany( buf );
968  }
969  else if( strCompare( "Comment1", line, &line ) )
970  {
971  parseQuotedString( buf, aReader, line, &line, true );
972  tb.SetComment( 0, buf );
973  }
974  else if( strCompare( "Comment2", line, &line ) )
975  {
976  parseQuotedString( buf, aReader, line, &line, true );
977  tb.SetComment( 1, buf );
978  }
979  else if( strCompare( "Comment3", line, &line ) )
980  {
981  parseQuotedString( buf, aReader, line, &line, true );
982  tb.SetComment( 2, buf );
983  }
984  else if( strCompare( "Comment4", line, &line ) )
985  {
986  parseQuotedString( buf, aReader, line, &line, true );
987  tb.SetComment( 3, buf );
988  }
989  else if( strCompare( "Comment5", line, &line ) )
990  {
991  parseQuotedString( buf, aReader, line, &line, true );
992  tb.SetComment( 4, buf );
993  }
994  else if( strCompare( "Comment6", line, &line ) )
995  {
996  parseQuotedString( buf, aReader, line, &line, true );
997  tb.SetComment( 5, buf );
998  }
999  else if( strCompare( "Comment7", line, &line ) )
1000  {
1001  parseQuotedString( buf, aReader, line, &line, true );
1002  tb.SetComment( 6, buf );
1003  }
1004  else if( strCompare( "Comment8", line, &line ) )
1005  {
1006  parseQuotedString( buf, aReader, line, &line, true );
1007  tb.SetComment( 7, buf );
1008  }
1009  else if( strCompare( "Comment9", line, &line ) )
1010  {
1011  parseQuotedString( buf, aReader, line, &line, true );
1012  tb.SetComment( 8, buf );
1013  }
1014  else if( strCompare( "$EndDescr", line ) )
1015  {
1016  aScreen->SetTitleBlock( tb );
1017  return;
1018  }
1019  }
1020 
1021  SCH_PARSE_ERROR( "missing 'EndDescr'", aReader, line );
1022 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
void SetVirtualPageNumber(int aPageNumber)
Definition: base_screen.h:76
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void SetRevision(const wxString &aRevision)
Definition: title_block.h:81
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
Definition: page_info.cpp:119
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
Definition: title_block.h:71
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:133
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:77
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
void SetComment(int aIdx, const wxString &aComment)
Definition: title_block.h:101
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
void SetCompany(const wxString &aCompany)
Definition: title_block.h:91
#define _(s)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:152
void SetTitle(const wxString &aTitle)
Definition: title_block.h:58
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:257
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:243
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
void SetPageCount(int aPageCount)
Definition: base_screen.cpp:63
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
Definition: page_info.cpp:186

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

Referenced by LoadContent().

◆ loadSheet()

SCH_SHEET * SCH_LEGACY_PLUGIN::loadSheet ( LINE_READER aReader)
private

Definition at line 1025 of file sch_legacy_plugin.cpp.

1026 {
1027  std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>();
1028 
1029  const char* line = aReader.ReadLine();
1030 
1031  while( line != nullptr )
1032  {
1033  if( strCompare( "S", line, &line ) ) // Sheet dimensions.
1034  {
1035  wxPoint position;
1036 
1037  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1038  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1039  sheet->SetPosition( position );
1040 
1041  wxSize size;
1042 
1043  size.SetWidth( Mils2Iu( parseInt( aReader, line, &line ) ) );
1044  size.SetHeight( Mils2Iu( parseInt( aReader, line, &line ) ) );
1045  sheet->SetSize( size );
1046  }
1047  else if( strCompare( "U", line, &line ) ) // Sheet UUID.
1048  {
1049  wxString text;
1050  parseUnquotedString( text, aReader, line );
1051 
1052  if( text != "00000000" )
1053  const_cast<KIID&>( sheet->m_Uuid ) = KIID( text );
1054  }
1055  else if( *line == 'F' ) // Sheet field.
1056  {
1057  line++;
1058 
1059  wxString text;
1060  int size;
1061  int fieldId = parseInt( aReader, line, &line );
1062 
1063  if( fieldId == 0 || fieldId == 1 ) // Sheet name and file name.
1064  {
1065  parseQuotedString( text, aReader, line, &line );
1066  size = Mils2Iu( parseInt( aReader, line, &line ) );
1067 
1068  SCH_FIELD& field = sheet->GetFields()[ fieldId ];
1069  field.SetText( text );
1070  field.SetTextSize( wxSize( size, size ) );
1071  }
1072  else // Sheet pin.
1073  {
1074  // Use a unique_ptr so that we clean up in the case of a throw
1075  std::unique_ptr<SCH_SHEET_PIN> sheetPin = std::make_unique<SCH_SHEET_PIN>( sheet.get() );
1076 
1077  sheetPin->SetNumber( fieldId );
1078 
1079  // Can be empty fields.
1080  parseQuotedString( text, aReader, line, &line, true );
1081 
1082  sheetPin->SetText( ConvertToNewOverbarNotation( text ) );
1083 
1084  if( line == nullptr )
1085  THROW_IO_ERROR( _( "unexpected end of line" ) );
1086 
1087  switch( parseChar( aReader, line, &line ) )
1088  {
1089  case 'I': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_INPUT ); break;
1090  case 'O': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_OUTPUT ); break;
1091  case 'B': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_BIDI ); break;
1092  case 'T': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_TRISTATE ); break;
1093  case 'U': sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_UNSPECIFIED ); break;
1094  default: SCH_PARSE_ERROR( "invalid sheet pin type", aReader, line );
1095  }
1096 
1097  switch( parseChar( aReader, line, &line ) )
1098  {
1099  case 'R': sheetPin->SetEdge( SHEET_SIDE::RIGHT ); break;
1100  case 'T': sheetPin->SetEdge( SHEET_SIDE::TOP ); break;
1101  case 'B': sheetPin->SetEdge( SHEET_SIDE::BOTTOM ); break;
1102  case 'L': sheetPin->SetEdge( SHEET_SIDE::LEFT ); break;
1103  default:
1104  SCH_PARSE_ERROR( "invalid sheet pin side", aReader, line );
1105  }
1106 
1107  wxPoint position;
1108 
1109  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1110  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1111  sheetPin->SetPosition( position );
1112 
1113  size = Mils2Iu( parseInt( aReader, line, &line ) );
1114 
1115  sheetPin->SetTextSize( wxSize( size, size ) );
1116 
1117  sheet->AddPin( sheetPin.release() );
1118  }
1119  }
1120  else if( strCompare( "$EndSheet", line ) )
1121  {
1122  sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
1123  return sheet.release();
1124  }
1125 
1126  line = aReader.ReadLine();
1127  }
1128 
1129  SCH_PARSE_ERROR( "missing '$EndSheet`", aReader, line );
1130 
1131  return nullptr; // Prevents compiler warning. Should never get here.
1132 }
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
#define Mils2Iu(x)
Definition: kiid.h:44
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:114
#define _(s)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

References _, BOTTOM, ConvertToNewOverbarNotation(), LEFT, Mils2Iu, parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), PS_BIDI, PS_INPUT, PS_OUTPUT, PS_TRISTATE, PS_UNSPECIFIED, LINE_READER::ReadLine(), RIGHT, SCH_PARSE_ERROR, EDA_TEXT::SetText(), EDA_TEXT::SetTextSize(), strCompare(), text, THROW_IO_ERROR, and TOP.

Referenced by LoadContent().

◆ LoadSymbol()

LIB_SYMBOL * SCH_LEGACY_PLUGIN::LoadSymbol ( const wxString &  aLibraryPath,
const wxString &  aPartName,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

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

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

Reimplemented from SCH_PLUGIN.

Definition at line 4351 of file sch_legacy_plugin.cpp.

4354 {
4355  LOCALE_IO toggle; // toggles on, then off, the C locale.
4356 
4357  cacheLib( aLibraryPath, aProperties );
4358 
4359  LIB_SYMBOL_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
4360 
4361  if( it == m_cache->m_symbols.end() )
4362  return nullptr;
4363 
4364  return it->second;
4365 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
SCH_LEGACY_PLUGIN_CACHE * m_cache
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)

References cacheLib(), m_cache, and SCH_LEGACY_PLUGIN_CACHE::m_symbols.

◆ loadSymbol()

SCH_SYMBOL * SCH_LEGACY_PLUGIN::loadSymbol ( LINE_READER aReader)
private

Definition at line 1535 of file sch_legacy_plugin.cpp.

1536 {
1537  const char* line = aReader.Line();
1538 
1539  wxCHECK( strCompare( "$Comp", line, &line ), nullptr );
1540 
1541  std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
1542 
1543  line = aReader.ReadLine();
1544 
1545  while( line != nullptr )
1546  {
1547  if( strCompare( "L", line, &line ) )
1548  {
1549  wxString libName;
1550  size_t pos = 2; // "X" plus ' ' space character.
1551  wxString utf8Line = wxString::FromUTF8( line );
1552  wxStringTokenizer tokens( utf8Line, " \r\n\t" );
1553 
1554  if( tokens.CountTokens() < 2 )
1555  THROW_PARSE_ERROR( "invalid symbol library definition", aReader.GetSource(),
1556  aReader.Line(), aReader.LineNumber(), pos );
1557 
1558  libName = tokens.GetNextToken();
1559  libName.Replace( "~", " " );
1560 
1561  LIB_ID libId;
1562 
1563  // Prior to schematic version 4, library IDs did not have a library nickname so
1564  // parsing the symbol name with LIB_ID::Parse() would break symbol library links
1565  // that contained '/' and ':' characters.
1566  if( m_version > 3 )
1567  libId.Parse( libName, true );
1568  else
1569  libId.SetLibItemName( libName );
1570 
1571  symbol->SetLibId( libId );
1572 
1573  wxString refDesignator = tokens.GetNextToken();
1574 
1575  refDesignator.Replace( "~", " " );
1576 
1577  wxString prefix = refDesignator;
1578 
1579  while( prefix.Length() )
1580  {
1581  if( ( prefix.Last() < '0' || prefix.Last() > '9') && prefix.Last() != '?' )
1582  break;
1583 
1584  prefix.RemoveLast();
1585  }
1586 
1587  // Avoid a prefix containing trailing/leading spaces
1588  prefix.Trim( true );
1589  prefix.Trim( false );
1590 
1591  if( prefix.IsEmpty() )
1592  symbol->SetPrefix( wxString( "U" ) );
1593  else
1594  symbol->SetPrefix( prefix );
1595  }
1596  else if( strCompare( "U", line, &line ) )
1597  {
1598  // This fixes a potentially buggy files caused by unit being set to zero which
1599  // causes netlist issues. See https://bugs.launchpad.net/kicad/+bug/1677282.
1600  int unit = parseInt( aReader, line, &line );
1601 
1602  if( unit == 0 )
1603  {
1604  unit = 1;
1605 
1606  // Set the file as modified so the user can be warned.
1607  if( m_rootSheet->GetScreen() )
1609  }
1610 
1611  symbol->SetUnit( unit );
1612 
1613  // Same can also happen with the convert parameter
1614  int convert = parseInt( aReader, line, &line );
1615 
1616  if( convert == 0 )
1617  {
1618  convert = 1;
1619 
1620  // Set the file as modified so the user can be warned.
1621  if( m_rootSheet->GetScreen() )
1623  }
1624 
1625  symbol->SetConvert( convert );
1626 
1627  wxString text;
1628  parseUnquotedString( text, aReader, line, &line );
1629 
1630  if( text != "00000000" )
1631  const_cast<KIID&>( symbol->m_Uuid ) = KIID( text );
1632  }
1633  else if( strCompare( "P", line, &line ) )
1634  {
1635  wxPoint pos;
1636 
1637  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
1638  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
1639  symbol->SetPosition( pos );
1640  }
1641  else if( strCompare( "AR", line, &line ) )
1642  {
1643  const char* strCompare = "Path=";
1644  int len = strlen( strCompare );
1645 
1646  if( strncasecmp( strCompare, line, len ) != 0 )
1647  SCH_PARSE_ERROR( "missing 'Path=' token", aReader, line );
1648 
1649  line += len;
1650  wxString pathStr, reference, unit;
1651 
1652  parseQuotedString( pathStr, aReader, line, &line );
1653 
1654  // Note: AR path excludes root sheet, but includes symbol. Normalize to
1655  // internal format by shifting everything down one and adding the root sheet.
1656  KIID_PATH path( pathStr );
1657 
1658  if( path.size() > 0 )
1659  {
1660  for( size_t i = path.size() - 1; i > 0; --i )
1661  path[i] = path[i-1];
1662 
1663  path[0] = m_rootSheet->m_Uuid;
1664  }
1665  else
1666  path.push_back( m_rootSheet->m_Uuid );
1667 
1668  strCompare = "Ref=";
1669  len = strlen( strCompare );
1670 
1671  if( strncasecmp( strCompare, line, len ) != 0 )
1672  SCH_PARSE_ERROR( "missing 'Ref=' token", aReader, line );
1673 
1674  line+= len;
1675  parseQuotedString( reference, aReader, line, &line );
1676 
1677  strCompare = "Part=";
1678  len = strlen( strCompare );
1679 
1680  if( strncasecmp( strCompare, line, len ) != 0 )
1681  SCH_PARSE_ERROR( "missing 'Part=' token", aReader, line );
1682 
1683  line+= len;
1684  parseQuotedString( unit, aReader, line, &line );
1685 
1686  long tmp;
1687 
1688  if( !unit.ToLong( &tmp, 10 ) )
1689  SCH_PARSE_ERROR( "expected integer value", aReader, line );
1690 
1691  if( tmp < 0 || tmp > MAX_UNIT_COUNT_PER_PACKAGE )
1692  SCH_PARSE_ERROR( "unit value out of range", aReader, line );
1693 
1694  symbol->AddHierarchicalReference( path, reference, (int)tmp );
1695  symbol->GetField( REFERENCE_FIELD )->SetText( reference );
1696 
1697  }
1698  else if( strCompare( "F", line, &line ) )
1699  {
1700  int index = parseInt( aReader, line, &line );
1701 
1702  wxString text, name;
1703 
1704  parseQuotedString( text, aReader, line, &line, true );
1705 
1706  char orientation = parseChar( aReader, line, &line );
1707  wxPoint pos;
1708  pos.x = Mils2Iu( parseInt( aReader, line, &line ) );
1709  pos.y = Mils2Iu( parseInt( aReader, line, &line ) );
1710  int size = Mils2Iu( parseInt( aReader, line, &line ) );
1711  int attributes = parseHex( aReader, line, &line );
1712 
1713  if( index >= symbol->GetFieldCount() )
1714  {
1715  // The first MANDATOR_FIELDS _must_ be constructed within the SCH_SYMBOL
1716  // constructor. This assert is simply here to guard against a change in that
1717  // constructor.
1718  wxASSERT( symbol->GetFieldCount() >= MANDATORY_FIELDS );
1719 
1720  // Ignore the _supplied_ fieldNdx. It is not important anymore if within the
1721  // user defined fields region (i.e. >= MANDATORY_FIELDS).
1722  // We freely renumber the index to fit the next available field slot.
1723  index = symbol->GetFieldCount(); // new has this index after insertion
1724 
1725  SCH_FIELD field( wxPoint( 0, 0 ), index, symbol.get(), name );
1726  symbol->AddField( field );
1727  }
1728 
1729  SCH_FIELD& field = symbol->GetFields()[index];
1730 
1731  // Prior to version 2 of the schematic file format, none of the following existed.
1732  if( m_version > 1 )
1733  {
1734  wxString textAttrs;
1735  char hjustify = parseChar( aReader, line, &line );
1736 
1737  parseUnquotedString( textAttrs, aReader, line, &line );
1738 
1739  // The name of the field is optional.
1740  parseQuotedString( name, aReader, line, &line, true );
1741 
1742  if( hjustify == 'L' )
1744  else if( hjustify == 'R' )
1746  else if( hjustify != 'C' )
1747  SCH_PARSE_ERROR( "symbol field text horizontal justification must be "
1748  "L, R, or C", aReader, line );
1749 
1750  // We are guaranteed to have a least one character here for older file formats
1751  // otherwise an exception would have been raised..
1752  if( textAttrs[0] == 'T' )
1754  else if( textAttrs[0] == 'B' )
1756  else if( textAttrs[0] != 'C' )
1757  SCH_PARSE_ERROR( "symbol field text vertical justification must be "
1758  "B, T, or C", aReader, line );
1759 
1760  // Newer file formats include the bold and italics text attribute.
1761  if( textAttrs.Length() > 1 )
1762  {
1763  if( textAttrs.Length() != 3 )
1764  SCH_PARSE_ERROR( _( "symbol field text attributes must be 3 characters wide" ),
1765  aReader, line );
1766 
1767  if( textAttrs[1] == 'I' )
1768  field.SetItalic( true );
1769  else if( textAttrs[1] != 'N' )
1770  SCH_PARSE_ERROR( "symbol field text italics indicator must be I or N",
1771  aReader, line );
1772 
1773  if( textAttrs[2] == 'B' )
1774  field.SetBold( true );
1775  else if( textAttrs[2] != 'N' )
1776  SCH_PARSE_ERROR( "symbol field text bold indicator must be B or N",
1777  aReader, line );
1778  }
1779  }
1780 
1781  field.SetText( text );
1782  field.SetTextPos( pos );
1783  field.SetVisible( !attributes );
1784  field.SetTextSize( wxSize( size, size ) );
1785 
1786  if( orientation == 'H' )
1787  field.SetTextAngle( TEXT_ANGLE_HORIZ );
1788  else if( orientation == 'V' )
1789  field.SetTextAngle( TEXT_ANGLE_VERT );
1790  else
1791  SCH_PARSE_ERROR( "symbol field orientation must be H or V", aReader, line );
1792 
1793  if( name.IsEmpty() )
1795 
1796  field.SetName( name );
1797  }
1798  else if( strCompare( "$EndComp", line ) )
1799  {
1800  // Ensure all flags (some are set by previous initializations) are reset:
1801  symbol->ClearFlags();
1802  return symbol.release();
1803  }
1804  else
1805  {
1806  // There are two lines that begin with a tab or spaces that includes a line with the
1807  // redundant position information and the transform matrix settings.
1808 
1809  // Parse the redundant position information just the same to check for formatting
1810  // errors.
1811  parseInt( aReader, line, &line ); // Always 1.
1812  parseInt( aReader, line, &line ); // The X coordinate.
1813  parseInt( aReader, line, &line ); // The Y coordinate.
1814 
1815  line = aReader.ReadLine();
1816 
1817  TRANSFORM transform;
1818 
1819  transform.x1 = parseInt( aReader, line, &line );
1820 
1821  if( transform.x1 < -1 || transform.x1 > 1 )
1822  SCH_PARSE_ERROR( "invalid symbol X1 transform value", aReader, line );
1823 
1824  transform.y1 = parseInt( aReader, line, &line );
1825 
1826  if( transform.y1 < -1 || transform.y1 > 1 )
1827  SCH_PARSE_ERROR( "invalid symbol Y1 transform value", aReader, line );
1828 
1829  transform.x2 = parseInt( aReader, line, &line );
1830 
1831  if( transform.x2 < -1 || transform.x2 > 1 )
1832  SCH_PARSE_ERROR( "invalid symbol X2 transform value", aReader, line );
1833 
1834  transform.y2 = parseInt( aReader, line, &line );
1835 
1836  if( transform.y2 < -1 || transform.y2 > 1 )
1837  SCH_PARSE_ERROR( "invalid symbol Y2 transform value", aReader, line );
1838 
1839  symbol->SetTransform( transform );
1840  }
1841 
1842  line = aReader.ReadLine();
1843  }
1844 
1845  SCH_PARSE_ERROR( "invalid symbol line", aReader, line );
1846 
1847  return nullptr; // Prevents compiler warning. Should never get here.
1848 }
Field Reference of part, i.e. "IC21".
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:50
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
int y2
Definition: transform.h:51
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
Definition: richio.h:109
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
void SetItalic(bool isItalic)
Definition: eda_text.h:179
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:246
int x2
Definition: transform.h:50
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
static uint32_t parseHex(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII hex integer string with possible leading whitespace into a long integer and updates th...
int x1
Definition: transform.h:48
#define MAX_UNIT_COUNT_PER_PACKAGE
The maximum number of units per package.
Definition: eeschema_id.h:44
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:237
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
#define Mils2Iu(x)
int m_version
Version of file being loaded.
int y1
Definition: transform.h:49
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:185
Definition: kiid.h:44
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:114
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition: richio.h:135
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:202
#define _(s)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:108
const KIID m_Uuid
Definition: eda_item.h:475
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:49
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
const char * name
Definition: DXF_plotter.cpp:56
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:201
static char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
void SetName(const wxString &aName)
Definition: sch_field.h:111
static void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
#define TEXT_ANGLE_VERT
Definition: eda_text.h:51
virtual void SetTextAngle(double aAngle)
Definition: eda_text.h:167
void SetBold(bool aBold)
Definition: eda_text.h:182

References _, convert, TEMPLATE_FIELDNAME::GetDefaultFieldName(), SCH_SHEET::GetScreen(), LINE_READER::GetSource(), GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_TOP, LINE_READER::Line(), LINE_READER::LineNumber(), m_rootSheet, EDA_ITEM::m_Uuid, m_version, MANDATORY_FIELDS, MAX_UNIT_COUNT_PER_PACKAGE, Mils2Iu, name, LIB_ID::Parse(), parseChar(), parseHex(), parseInt(), parseQuotedString(), parseUnquotedString(), path, LINE_READER::ReadLine(), REFERENCE_FIELD, SCH_PARSE_ERROR, EDA_TEXT::SetBold(), BASE_SCREEN::SetContentModified(), EDA_TEXT::SetHorizJustify(), EDA_TEXT::SetItalic(), LIB_ID::SetLibItemName(), SCH_FIELD::SetName(), EDA_TEXT::SetText(), EDA_TEXT::SetTextAngle(), EDA_TEXT::SetTextPos(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), strCompare(), text, TEXT_ANGLE_HORIZ, TEXT_ANGLE_VERT, THROW_PARSE_ERROR, TRANSFORM::x1, TRANSFORM::x2, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by LoadContent().

◆ loadText()

SCH_TEXT * SCH_LEGACY_PLUGIN::loadText ( LINE_READER aReader)
private

Definition at line 1418 of file sch_legacy_plugin.cpp.

1419 {
1420  const char* line = aReader.Line();
1421 
1422  wxCHECK( strCompare( "Text", line, &line ), nullptr );
1423 
1424  std::unique_ptr<SCH_TEXT> text;
1425 
1426  if( strCompare( "Notes", line, &line ) )
1427  text.reset( new SCH_TEXT );
1428  else if( strCompare( "Label", line, &line ) )
1429  text.reset( new SCH_LABEL );
1430  else if( strCompare( "HLabel", line, &line ) )
1431  text.reset( new SCH_HIERLABEL );
1432  else if( strCompare( "GLabel", line, &line ) )
1433  {
1434  // Prior to version 2, the SCH_GLOBALLABEL object did not exist.
1435  if( m_version == 1 )
1436  text = std::make_unique<SCH_HIERLABEL>();
1437  else
1438  text = std::make_unique<SCH_GLOBALLABEL>();
1439  }
1440  else
1441  SCH_PARSE_ERROR( "unknown Text type", aReader, line );
1442 
1443  // Parse the parameters common to all text objects.
1444  wxPoint position;
1445 
1446  position.x = Mils2Iu( parseInt( aReader, line, &line ) );
1447  position.y = Mils2Iu( parseInt( aReader, line, &line ) );
1448  text->SetPosition( position );
1449 
1450  int spinStyle = parseInt( aReader, line, &line );
1451 
1452  // Sadly we store the orientation of hierarchical and global labels using a different
1453  // int encoding than that for local labels:
1454  // Global Local
1455  // Left justified 0 2
1456  // Up 1 3
1457  // Right justified 2 0
1458  // Down 3 1
1459  // So we must flip it as the enum is setup with the "global" numbering
1460  if( text->Type() != SCH_GLOBAL_LABEL_T && text->Type() != SCH_HIER_LABEL_T )
1461  {
1462  if( spinStyle == 0 )
1463  spinStyle = 2;
1464  else if( spinStyle == 2 )
1465  spinStyle = 0;
1466  }
1467 
1468  text->SetLabelSpinStyle( (LABEL_SPIN_STYLE::SPIN) spinStyle );
1469 
1470  int size = Mils2Iu( parseInt( aReader, line, &line ) );
1471 
1472  text->SetTextSize( wxSize( size, size ) );
1473 
1474  // Parse the global and hierarchical label type.
1475  if( text->Type() == SCH_HIER_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
1476  {
1477  auto resultIt = std::find_if( sheetLabelNames.begin(), sheetLabelNames.end(),
1478  [ &line ]( const auto& it )
1479  {
1480  return strCompare( it.second, line, &line );
1481  } );
1482 
1483  if( resultIt != sheetLabelNames.end() )
1484  text->SetShape( resultIt->first );
1485  else
1486  SCH_PARSE_ERROR( "invalid label type", aReader, line );
1487  }
1488 
1489  int penWidth = 0;
1490 
1491  // The following tokens do not exist in version 1 schematic files,
1492  // and not always in version 2 for HLabels and GLabels
1493  if( m_version > 1 )
1494  {
1495  if( m_version > 2 || *line >= ' ' )
1496  {
1497  if( strCompare( "Italic", line, &line ) )
1498  text->SetItalic( true );
1499  else if( !strCompare( "~", line, &line ) )
1500  SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
1501  }
1502 
1503  // The penWidth token does not exist in older versions of the schematic file format
1504  // so calling parseInt will be made only if the EOL is not reached.
1505  if( *line >= ' ' )
1506  penWidth = parseInt( aReader, line, &line );
1507  }
1508 
1509  text->SetBold( penWidth != 0 );
1510  text->SetTextThickness( penWidth != 0 ? GetPenSizeForBold( size ) : 0 );
1511 
1512  // Read the text string for the text.
1513  char* tmp = aReader.ReadLine();
1514 
1515  tmp = strtok( tmp, "\r\n" );
1516  wxString val = FROM_UTF8( tmp );
1517 
1518  for( ; ; )
1519  {
1520  int i = val.find( wxT( "\\n" ) );
1521 
1522  if( i == wxNOT_FOUND )
1523  break;
1524 
1525  val.erase( i, 2 );
1526  val.insert( i, wxT( "\n" ) );
1527  }
1528 
1529  text->SetText( ConvertToNewOverbarNotation( val ) );
1530 
1531  return text.release();
1532 }
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:46
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
#define Mils2Iu(x)
int m_version
Version of file being loaded.
#define _(s)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
const std::map< PINSHEETLABEL_SHAPE, const char * > sheetLabelNames

References _, ConvertToNewOverbarNotation(), FROM_UTF8(), GetPenSizeForBold(), LINE_READER::Line(), m_version, Mils2Iu, parseInt(), LINE_READER::ReadLine(), SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_PARSE_ERROR, sheetLabelNames, strCompare(), and text.

Referenced by LoadContent().

◆ loadWire()

SCH_LINE * SCH_LEGACY_PLUGIN::loadWire ( LINE_READER aReader)
private

Definition at line 1264 of file sch_legacy_plugin.cpp.

1265 {
1266  std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
1267 
1268  const char* line = aReader.Line();
1269 
1270  wxCHECK( strCompare( "Wire", line, &line ), nullptr );
1271 
1272  if( strCompare( "Wire", line, &line ) )
1273  wire->SetLayer( LAYER_WIRE );
1274  else if( strCompare( "Bus", line, &line ) )
1275  wire->SetLayer( LAYER_BUS );
1276  else if( strCompare( "Notes", line, &line ) )
1277  wire->SetLayer( LAYER_NOTES );
1278  else
1279  SCH_PARSE_ERROR( "invalid line type", aReader, line );
1280 
1281  if( !strCompare( "Line", line, &line ) )
1282  SCH_PARSE_ERROR( "invalid wire definition", aReader, line );
1283 
1284  // Since Sept 15, 2017, a line style is alloved (width, style, color)
1285  // Only non default values are stored
1286  while( !is_eol( *line ) )
1287  {
1288  wxString buf;
1289 
1290  parseUnquotedString( buf, aReader, line, &line );
1291 
1292  if( buf == ")" )
1293  continue;
1294 
1295  else if( buf == T_WIDTH )
1296  {
1297  int size = Mils2Iu( parseInt( aReader, line, &line ) );
1298  wire->SetLineWidth( size );
1299  }
1300  else if( buf == T_STYLE )
1301  {
1302  parseUnquotedString( buf, aReader, line, &line );
1304  wire->SetLineStyle( style );
1305  }
1306  else // should be the color parameter.
1307  {
1308  // The color param is something like rgb(150, 40, 191)
1309  // and because there is no space between ( and 150
1310  // the first param is inside buf.
1311  // So break keyword and the first param into 2 separate strings.
1312  wxString prm, keyword;
1313  keyword = buf.BeforeLast( '(', &prm );
1314 
1315  if( ( keyword == T_COLOR ) || ( keyword == T_COLORA ) )
1316  {
1317  long color[4] = { 0 };
1318 
1319  int ii = 0;
1320 
1321  if( !prm.IsEmpty() )
1322  {
1323  prm.ToLong( &color[ii] );
1324  ii++;
1325  }
1326 
1327  int prm_count = ( keyword == T_COLORA ) ? 4 : 3;
1328  // fix opacity to 1.0 or 255, when not exists in file
1329  color[3] = 255;
1330 
1331  for(; ii < prm_count && !is_eol( *line ); ii++ )
1332  {
1333  color[ii] = parseInt( aReader, line, &line );
1334 
1335  // Skip the separator between values
1336  if( *line == ',' || *line == ' ')
1337  line++;
1338  }
1339 
1340  wire->SetLineColor( color[0]/255.0, color[1]/255.0, color[2]/255.0,color[3]/255.0 );
1341  }
1342  }
1343  }
1344 
1345  // Read the segment en points coordinates:
1346  line = aReader.ReadLine();
1347 
1348  wxPoint begin, end;
1349 
1350  begin.x = Mils2Iu( parseInt( aReader, line, &line ) );
1351  begin.y = Mils2Iu( parseInt( aReader, line, &line ) );
1352  end.x = Mils2Iu( parseInt( aReader, line, &line ) );
1353  end.y = Mils2Iu( parseInt( aReader, line, &line ) );
1354 
1355  wire->SetStartPoint( begin );
1356  wire->SetEndPoint( end );
1357 
1358  return wire.release();
1359 }
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
static bool strCompare(const char *aString, const char *aLine, const char **aOutput=nullptr)
Compare aString to the string starting at aLine and advances the character point to the end of String...
static void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken=nullptr, bool aCanBeEmpty=false)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
int color
Definition: DXF_plotter.cpp:57
#define Mils2Iu(x)
#define T_WIDTH
#define T_STYLE
static bool is_eol(char c)
static int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput=nullptr)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
#define T_COLOR
static PLOT_DASH_TYPE GetLineStyleByName(const wxString &aStyleName)
Definition: sch_line.cpp:95
PLOT_DASH_TYPE
Dashed line types.
Definition: plotter.h:104
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
#define SCH_PARSE_ERROR(text, reader, pos)
#define T_COLORA

References color, SCH_LINE::GetLineStyleByName(), is_eol(), LAYER_BUS, LAYER_NOTES, LAYER_WIRE, LINE_READER::Line(), Mils2Iu, parseInt(), parseUnquotedString(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, strCompare(), T_COLOR, T_COLORA, T_STYLE, and T_WIDTH.

Referenced by LoadContent().

◆ ParsePart()

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

Definition at line 4482 of file sch_legacy_plugin.cpp.

4484 {
4485  return SCH_LEGACY_PLUGIN_CACHE::LoadPart( reader, aMajorVersion, aMinorVersion );
4486 }
static LIB_SYMBOL * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_SYMBOL_MAP *aMap=nullptr)

References SCH_LEGACY_PLUGIN_CACHE::LoadPart().

◆ Save()

void SCH_LEGACY_PLUGIN::Save ( const wxString &  aFileName,
SCH_SHEET aSheet,
SCHEMATIC aSchematic,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

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

Parameters
aFileNameis the name of a file to save to on disk.
aSheetis the class SCH_SHEET in memory document tree from which to extract information when writing to aFileName. The caller continues to own the SCHEMATIC, and the plugin should refrain from modifying the SCHEMATIC if possible.
aSchematicis the SCHEMATIC object used to access any schematic-wide or project information needed to save the document.
aPropertiesis an associative array that can be used to tell the saver how to save the file, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL. Set the #PropSaveCurrentSheetOnly property to only save the current sheet. Otherwise, all hierarchical sheets are saved.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Reimplemented from SCH_PLUGIN.

Definition at line 1877 of file sch_legacy_plugin.cpp.

1879 {
1880  wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
1881  wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1882 
1883  LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
1884 
1885  init( aSchematic, aProperties );
1886 
1887  wxFileName fn = aFileName;
1888 
1889  // File names should be absolute. Don't assume everything relative to the project path
1890  // works properly.
1891  wxASSERT( fn.IsAbsolute() );
1892 
1893  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1894 
1895  m_out = &formatter; // no ownership
1896 
1897  Format( aSheet );
1898 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.
void Format(SCH_SHEET *aSheet)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
Used for text file output.
Definition: richio.h:456

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

◆ saveBitmap()

void SCH_LEGACY_PLUGIN::saveBitmap ( SCH_BITMAP aBitmap)
private

Definition at line 2187 of file sch_legacy_plugin.cpp.

2188 {
2189  wxCHECK_RET( aBitmap != nullptr, "SCH_BITMAP* is NULL" );
2190 
2191  const wxImage* image = aBitmap->GetImage()->GetImageData();
2192 
2193  wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
2194 
2195  m_out->Print( 0, "$Bitmap\n" );
2196  m_out->Print( 0, "Pos %-4d %-4d\n",
2197  Iu2Mils( aBitmap->GetPosition().x ),
2198  Iu2Mils( aBitmap->GetPosition().y ) );
2199  m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
2200  m_out->Print( 0, "Data\n" );
2201 
2202  wxMemoryOutputStream stream;
2203 
2204  image->SaveFile( stream, wxBITMAP_TYPE_PNG );
2205 
2206  // Write binary data in hexadecimal form (ASCII)
2207  wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
2208  char* begin = (char*) buffer->GetBufferStart();
2209 
2210  for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
2211  {
2212  if( ii >= 32 )
2213  {
2214  ii = 0;
2215 
2216  m_out->Print( 0, "\n" );
2217  }
2218 
2219  m_out->Print( 0, "%2.2X ", *begin & 0xFF );
2220  }
2221 
2222  m_out->Print( 0, "\nEndData\n" );
2223  m_out->Print( 0, "$EndBitmap\n" );
2224 }
double GetScale() const
Definition: bitmap_base.h:79
wxImage * GetImageData()
Definition: bitmap_base.h:70
wxPoint GetPosition() const override
Definition: sch_bitmap.h:136
BITMAP_BASE * GetImage() const
Definition: sch_bitmap.h:54
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426

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

Referenced by Format().

◆ saveBusAlias()

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

Definition at line 2440 of file sch_legacy_plugin.cpp.

2441 {
2442  wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" );
2443 
2444  wxString members = boost::algorithm::join( aAlias->Members(), " " );
2445 
2446  m_out->Print( 0, "BusAlias %s %s\n",
2447  TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
2448 }
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426

References m_out, OUTPUTFORMATTER::Print(), and TO_UTF8.

Referenced by Format().

◆ saveBusEntry()

void SCH_LEGACY_PLUGIN::saveBusEntry ( SCH_BUS_ENTRY_BASE aBusEntry)
private

Definition at line 2311 of file sch_legacy_plugin.cpp.

2312 {
2313  wxCHECK_RET( aBusEntry != nullptr, "SCH_BUS_ENTRY_BASE* is NULL" );
2314 
2315  if( aBusEntry->GetLayer() == LAYER_WIRE )
2316  m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
2317  Iu2Mils( aBusEntry->GetPosition().x ),
2318  Iu2Mils( aBusEntry->GetPosition().y ),
2319  Iu2Mils( aBusEntry->GetEnd().x ), Iu2Mils( aBusEntry->GetEnd().y ) );
2320  else
2321  m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
2322  Iu2Mils( aBusEntry->GetPosition().x ),
2323  Iu2Mils( aBusEntry->GetPosition().y ),
2324  Iu2Mils( aBusEntry->GetEnd().x ), Iu2Mils( aBusEntry->GetEnd().y ) );
2325 }
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:268
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
wxPoint GetEnd() const
wxPoint GetPosition() const override

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

Referenced by Format().

◆ saveField()

void SCH_LEGACY_PLUGIN::saveField ( SCH_FIELD aField)
private

Definition at line 2151 of file sch_legacy_plugin.cpp.

2152 {
2153  char hjustify = 'C';
2154 
2155  if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_LEFT )
2156  hjustify = 'L';
2157  else if( aField->GetHorizJustify() == GR_TEXT_HJUSTIFY_RIGHT )
2158  hjustify = 'R';
2159 
2160  char vjustify = 'C';
2161 
2162  if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_BOTTOM )
2163  vjustify = 'B';
2164  else if( aField->GetVertJustify() == GR_TEXT_VJUSTIFY_TOP )
2165  vjustify = 'T';
2166 
2167  m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
2168  aField->GetId(),
2169  EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
2170  aField->GetTextAngle() == TEXT_ANGLE_HORIZ ? 'H' : 'V',
2171  Iu2Mils( aField->GetLibPosition().x ),
2172  Iu2Mils( aField->GetLibPosition().y ),
2173  Iu2Mils( aField->GetTextWidth() ),
2174  !aField->IsVisible(),
2175  hjustify, vjustify,
2176  aField->IsItalic() ? 'I' : 'N',
2177  aField->IsBold() ? 'B' : 'N' );
2178 
2179  // Save field name, if the name is user definable
2180  if( aField->GetId() >= MANDATORY_FIELDS )
2181  m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
2182 
2183  m_out->Print( 0, "\n" );
2184 }
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: eda_text.h:50
bool IsBold() const
Definition: eda_text.h:183
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:199
double GetTextAngle() const
Definition: eda_text.h:174
int GetId() const
Definition: sch_field.h:113
bool IsItalic() const
Definition: eda_text.h:180
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:198
virtual bool IsVisible() const
Definition: eda_text.h:186
wxPoint GetLibPosition() const
Definition: sch_field.h:186
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
int GetTextWidth() const
Definition: eda_text.h:241
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
wxString GetName(bool aUseDefaultName=true) const
Return the field name.
Definition: sch_field.cpp:544
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133

References EscapedUTF8(), 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, MANDATORY_FIELDS, OUTPUTFORMATTER::Print(), and TEXT_ANGLE_HORIZ.

Referenced by saveSymbol().

◆ saveJunction()

void SCH_LEGACY_PLUGIN::saveJunction ( SCH_JUNCTION aJunction)
private

Definition at line 2291 of file sch_legacy_plugin.cpp.

2292 {
2293  wxCHECK_RET( aJunction != nullptr, "SCH_JUNCTION* is NULL" );
2294 
2295  m_out->Print( 0, "Connection ~ %-4d %-4d\n",
2296  Iu2Mils( aJunction->GetPosition().x ),
2297  Iu2Mils( aJunction->GetPosition().y ) );
2298 }
wxPoint GetPosition() const override
Definition: sch_junction.h:92
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426

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

Referenced by Format().

◆ SaveLibrary()

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

Reimplemented from SCH_PLUGIN.

Definition at line 4441 of file sch_legacy_plugin.cpp.

4442 {
4443  if( !m_cache )
4444  m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
4445 
4446  wxString oldFileName = m_cache->GetFileName();
4447 
4448  if( !m_cache->IsFile( aLibraryPath ) )
4449  {
4450  m_cache->SetFileName( aLibraryPath );
4451  }
4452 
4453  // This is a forced save.
4454  m_cache->SetModified();
4455  m_cache->Save( writeDocFile( aProperties ) );
4456  m_cache->SetFileName( oldFileName );
4457 }
SCH_LEGACY_PLUGIN_CACHE * m_cache
A cache assistant for the symbol library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_P...
void SetModified(bool aModified=true)
void SetFileName(const wxString &aFileName)
bool IsFile(const wxString &aFullPathAndFileName) const
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
bool writeDocFile(const PROPERTIES *aProperties)

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

◆ saveLine()

void SCH_LEGACY_PLUGIN::saveLine ( SCH_LINE aLine)
private

Definition at line 2328 of file sch_legacy_plugin.cpp.

2329 {
2330  wxCHECK_RET( aLine != nullptr, "SCH_LINE* is NULL" );
2331 
2332  const char* layer = "Notes";
2333  const char* width = "Line";
2334 
2335  if( aLine->GetLayer() == LAYER_WIRE )
2336  layer = "Wire";
2337  else if( aLine->GetLayer() == LAYER_BUS )
2338  layer = "Bus";
2339 
2340  m_out->Print( 0, "Wire %s %s", layer, width );
2341 
2342  // Write line style (width, type, color) only for non default values
2343  if( aLine->IsGraphicLine() )
2344  {
2345  if( aLine->GetLineSize() != 0 )
2346  m_out->Print( 0, " %s %d", T_WIDTH, Iu2Mils( aLine->GetLineSize() ) );
2347 
2348  if( aLine->GetLineStyle() != aLine->GetDefaultStyle() )
2349  m_out->Print( 0, " %s %s", T_STYLE,
2351 
2352  if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
2353  m_out->Print( 0, " %s",
2354  TO_UTF8( aLine->GetLineColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) ) );
2355  }
2356 
2357  m_out->Print( 0, "\n" );
2358 
2359  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
2360  Iu2Mils( aLine->GetStartPoint().x ), Iu2Mils( aLine->GetStartPoint().y ),
2361  Iu2Mils( aLine->GetEndPoint().x ), Iu2Mils( aLine->GetEndPoint().y ) );
2362 
2363  m_out->Print( 0, "\n");
2364 }
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:85
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:210
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:916
wxPoint GetStartPoint() const
Definition: sch_line.h:90
#define T_WIDTH
#define T_STYLE
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:224
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:248
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:268
int GetLineSize() const
Definition: sch_line.h:152
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
wxPoint GetEndPoint() const
Definition: sch_line.h:93

References SCH_LINE::GetDefaultStyle(), SCH_LINE::GetEndPoint(), SCH_ITEM::GetLayer(), SCH_LINE::GetLineColor(), SCH_LINE::GetLineSize(), SCH_LINE::GetLineStyle(), SCH_LINE::GetLineStyleName(), SCH_LINE::GetStartPoint(), SCH_LINE::IsGraphicLine(), LAYER_BUS, LAYER_WIRE, m_out, OUTPUTFORMATTER::Print(), T_STYLE, T_WIDTH, and TO_UTF8.

Referenced by Format().

◆ saveNoConnect()

void SCH_LEGACY_PLUGIN::saveNoConnect ( SCH_NO_CONNECT aNoConnect)
private

Definition at line 2301 of file sch_legacy_plugin.cpp.

2302 {
2303  wxCHECK_RET( aNoConnect != nullptr, "SCH_NOCONNECT* is NULL" );
2304 
2305  m_out->Print( 0, "NoConn ~ %-4d %-4d\n",
2306  Iu2Mils( aNoConnect->GetPosition().x ),
2307  Iu2Mils( aNoConnect->GetPosition().y ) );
2308 }
wxPoint GetPosition() const override
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426

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

Referenced by Format().

◆ saveSheet()

void SCH_LEGACY_PLUGIN::saveSheet ( SCH_SHEET aSheet)
private

Definition at line 2227 of file sch_legacy_plugin.cpp.

2228 {
2229  wxCHECK_RET( aSheet != nullptr, "SCH_SHEET* is NULL" );
2230 
2231  m_out->Print( 0, "$Sheet\n" );
2232  m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
2233  Iu2Mils( aSheet->GetPosition().x ),
2234  Iu2Mils( aSheet->GetPosition().y ),
2235  Iu2Mils( aSheet->GetSize().x ),
2236  Iu2Mils( aSheet->GetSize().y ) );
2237 
2238  m_out->Print( 0, "U %8.8X\n", aSheet->m_Uuid.AsLegacyTimestamp() );
2239 
2240  SCH_FIELD& sheetName = aSheet->GetFields()[SHEETNAME];
2241  SCH_FIELD& fileName = aSheet->GetFields()[SHEETFILENAME];
2242 
2243  if( !sheetName.GetText().IsEmpty() )
2244  m_out->Print( 0, "F0 %s %d\n",
2245  EscapedUTF8( sheetName.GetText() ).c_str(),
2246  Iu2Mils( sheetName.GetTextSize().x ) );
2247 
2248  if( !fileName.GetText().IsEmpty() )
2249  m_out->Print( 0, "F1 %s %d\n",
2250  EscapedUTF8( fileName.GetText() ).c_str(),
2251  Iu2Mils( fileName.GetTextSize().x ) );
2252 
2253  for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
2254  {
2255  int type, side;
2256 
2257  if( pin->GetText().IsEmpty() )
2258  break;
2259 
2260  switch( pin->GetEdge() )
2261  {
2262  default:
2263  case SHEET_SIDE::LEFT: side = 'L'; break;
2264  case SHEET_SIDE::RIGHT: side = 'R'; break;
2265  case SHEET_SIDE::TOP: side = 'T'; break;
2266  case SHEET_SIDE::BOTTOM: side = 'B'; break;
2267  }
2268 
2269  switch( pin->GetShape() )
2270  {
2271  default:
2272  case PINSHEETLABEL_SHAPE::PS_UNSPECIFIED: type = 'U'; break;
2273  case PINSHEETLABEL_SHAPE::PS_INPUT: type = 'I'; break;
2274  case PINSHEETLABEL_SHAPE::PS_OUTPUT: type = 'O'; break;
2275  case PINSHEETLABEL_SHAPE::PS_BIDI: type = 'B'; break;
2276  case PINSHEETLABEL_SHAPE::PS_TRISTATE: type = 'T'; break;
2277  }
2278 
2279  m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n",
2280  pin->GetNumber(),
2281  EscapedUTF8( pin->GetText() ).c_str(), // supplies wrapping quotes
2282  type, side, Iu2Mils( pin->GetPosition().x ),
2283  Iu2Mils( pin->GetPosition().y ),
2284  Iu2Mils( pin->GetTextWidth() ) );
2285  }
2286 
2287  m_out->Print( 0, "$EndSheet\n" );
2288 }
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:88
timestamp_t AsLegacyTimestamp() const
Definition: kiid.cpp:191
const wxSize & GetTextSize() const
Definition: eda_text.h:238
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
wxPoint GetPosition() const override
Definition: sch_sheet.h:380
const KIID m_Uuid
Definition: eda_item.h:475
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:184
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
wxSize GetSize() const
Definition: sch_sheet.h:105
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133

References KIID::AsLegacyTimestamp(), BOTTOM, EscapedUTF8(), SCH_SHEET::GetFields(), SCH_SHEET::GetPins(), SCH_SHEET::GetPosition(), SCH_SHEET::GetSize(), EDA_TEXT::GetText(), EDA_TEXT::GetTextSize(), LEFT, m_out, EDA_ITEM::m_Uuid, pin, OUTPUTFORMATTER::Print(), PS_BIDI, PS_INPUT, PS_OUTPUT, PS_TRISTATE, PS_UNSPECIFIED, RIGHT, SHEETFILENAME, SHEETNAME, and TOP.

Referenced by Format().

◆ SaveSymbol()

void SCH_LEGACY_PLUGIN::SaveSymbol ( const wxString &  aLibraryPath,
const LIB_SYMBOL aSymbol,
const PROPERTIES aProperties = nullptr 
)
overridevirtual

Write aSymbol to an existing library located at aLibraryPath.

If a LIB_SYMBOL by the same name already exists or there are any conflicting alias names, the new LIB_SYMBOL will silently overwrite any existing aliases and/or part because 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_SYMBOL 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 4368 of file sch_legacy_plugin.cpp.

4370 {
4371  LOCALE_IO toggle; // toggles on, then off, the C locale.
4372 
4373  cacheLib( aLibraryPath, aProperties );
4374 
4375  m_cache->AddSymbol( aSymbol );
4376 
4377  if( !isBuffering( aProperties ) )
4378  m_cache->Save( writeDocFile( aProperties ) );
4379 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:40
SCH_LEGACY_PLUGIN_CACHE * m_cache
void AddSymbol(const LIB_SYMBOL *aSymbol)
bool isBuffering(const PROPERTIES *aProperties)
void cacheLib(const wxString &aLibraryFileName, const PROPERTIES *aProperties)
void Save(bool aSaveDocFile=true)
Save the entire library to file m_libFileName;.
bool writeDocFile(const PROPERTIES *aProperties)

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

◆ saveSymbol()

void SCH_LEGACY_PLUGIN::saveSymbol ( SCH_SYMBOL aSymbol)
private

Definition at line 2045 of file sch_legacy_plugin.cpp.

2046 {
2047  std::string name1;
2048  std::string name2;
2049 
2050  static wxString delimiters( wxT( " " ) );
2051 
2052  // This is redundant with the AR entries below, but it makes the files backwards-compatible.
2053  if( aSymbol->GetInstanceReferences().size() > 0 )
2054  {
2055  const SYMBOL_INSTANCE_REFERENCE& instance = aSymbol->GetInstanceReferences()[0];
2056  name1 = toUTFTildaText( instance.m_Reference );
2057  }
2058  else
2059  {
2060  if( aSymbol->GetField( REFERENCE_FIELD )->GetText().IsEmpty() )
2061  name1 = toUTFTildaText( aSymbol->GetPrefix() );
2062  else
2063  name1 = toUTFTildaText( aSymbol->GetField( REFERENCE_FIELD )->GetText() );
2064  }
2065 
2066  wxString symbol_name = aSymbol->GetLibId().Format();
2067 
2068  if( symbol_name.size() )
2069  {
2070  name2 = toUTFTildaText( symbol_name );
2071  }
2072  else
2073  {
2074  name2 = "_NONAME_";
2075  }
2076 
2077  m_out->Print( 0, "$Comp\n" );
2078  m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
2079 
2080  // Generate unit number, conversion and timestamp
2081  m_out->Print( 0, "U %d %d %8.8X\n",
2082  aSymbol->GetUnit(),
2083  aSymbol->GetConvert(),
2084  aSymbol->m_Uuid.AsLegacyTimestamp() );
2085 
2086  // Save the position
2087  m_out->Print( 0, "P %d %d\n",
2088  Iu2Mils( aSymbol->GetPosition().x ),
2089  Iu2Mils( aSymbol->GetPosition().y ) );
2090 
2091  /* If this is a complex hierarchy; save hierarchical references.
2092  * but for simple hierarchies it is not necessary.
2093  * the reference inf is already saved
2094  * this is useful for old Eeschema version compatibility
2095  */
2096  if( aSymbol->GetInstanceReferences().size() > 1 )
2097  {
2098  for( const SYMBOL_INSTANCE_REFERENCE& instance : aSymbol->GetInstanceReferences() )
2099  {
2100  /*format:
2101  * AR Path="/140/2" Ref="C99" Part="1"
2102  * where 140 is the uid of the containing sheet and 2 is the timestamp of this symbol.
2103  * (timestamps are actually 8 hex chars)
2104  * Ref is the conventional symbol reference designator for this 'path'
2105  * Part is the conventional symbol unit selection for this 'path'
2106  */
2107  wxString path = "/";
2108 
2109  // Skip root sheet
2110  for( int i = 1; i < (int) instance.m_Path.size(); ++i )
2111  path += instance.m_Path[i].AsLegacyTimestampString() + "/";
2112 
2113  m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%d\" \n",
2114  TO_UTF8( path + aSymbol->m_Uuid.AsLegacyTimestampString() ),
2115  TO_UTF8( instance.m_Reference ),
2116  instance.m_Unit );
2117  }
2118  }
2119 
2120  // update the ugly field id, which I would like to see go away someday soon.
2121  for( int i = 0; i < aSymbol->GetFieldCount(); ++i )
2122  aSymbol->GetFields()[i].SetId( i );
2123 
2124  // Fixed fields:
2125  // Save mandatory fields even if they are blank,
2126  // because the visibility, size and orientation are set from library editor.
2127  for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
2128  saveField( &aSymbol->GetFields()[i] );
2129 
2130  // User defined fields:
2131  // The *policy* about which user defined fields are symbol of a symbol is now
2132  // only in the dialog editors. No policy should be enforced here, simply
2133  // save all the user defined fields, they are present because a dialog editor
2134  // thought they should be. If you disagree, go fix the dialog editors.
2135  for( int i = MANDATORY_FIELDS; i < aSymbol->GetFieldCount(); ++i )
2136  saveField( &aSymbol->GetFields()[i] );
2137 
2138  // Unit number, position, box ( old standard )
2139  m_out->Print( 0, "\t%-4d %-4d %-4d\n", aSymbol->GetUnit(),
2140  Iu2Mils( aSymbol->GetPosition().x ),
2141  Iu2Mils( aSymbol->GetPosition().y ) );
2142 
2143  TRANSFORM transform = aSymbol->GetTransform();
2144 
2145  m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
2146  transform.x1, transform.y1, transform.x2, transform.y2 );
2147  m_out->Print( 0, "$EndComp\n" );
2148 }
Field Reference of part, i.e. "IC21".
int y2
Definition: transform.h:51
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:675
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:711
int x2
Definition: transform.h:50
int x1
Definition: transform.h:48
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
Definition: sch_symbol.cpp:46
TRANSFORM & GetTransform()
Definition: sch_symbol.h:231
void saveField(SCH_FIELD *aField)
const std::vector< SYMBOL_INSTANCE_REFERENCE > & GetInstanceReferences()
Definition: sch_symbol.h:123
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
int y1
Definition: transform.h:49
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
timestamp_t AsLegacyTimestamp() const
Definition: kiid.cpp:191
int GetFieldCount() const
Return the number of fields in this symbol.
Definition: sch_symbol.h:421
A simple container for schematic symbol instance information.
UTF8 Format() const
Definition: lib_id.cpp:116
const KIID m_Uuid
Definition: eda_item.h:475
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
wxString AsLegacyTimestampString() const
Definition: kiid.cpp:224
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
wxString GetPrefix() const
Definition: sch_symbol.h:227
wxPoint GetPosition() const override
Definition: sch_symbol.h:641
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
int GetUnit() const
Definition: sch_symbol.h:195
int GetConvert() const
Definition: sch_symbol.h:223
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:147

References KIID::AsLegacyTimestamp(), KIID::AsLegacyTimestampString(), LIB_ID::Format(), SCH_SYMBOL::GetConvert(), SCH_SYMBOL::GetField(), SCH_SYMBOL::GetFieldCount(), SCH_SYMBOL::GetFields(), SCH_SYMBOL::GetInstanceReferences(), SCH_SYMBOL::GetLibId(), SCH_SYMBOL::GetPosition(), SCH_SYMBOL::GetPrefix(), EDA_TEXT::GetText(), SCH_SYMBOL::GetTransform(), SCH_SYMBOL::GetUnit(), m_out, SYMBOL_INSTANCE_REFERENCE::m_Reference, EDA_ITEM::m_Uuid, MANDATORY_FIELDS, path, OUTPUTFORMATTER::Print(), REFERENCE_FIELD, saveField(), TO_UTF8, toUTFTildaText(), TRANSFORM::x1, TRANSFORM::x2, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by Format().

◆ saveText()

void SCH_LEGACY_PLUGIN::saveText ( SCH_TEXT aText)
private

Definition at line 2367 of file sch_legacy_plugin.cpp.

2368 {
2369  wxCHECK_RET( aText != nullptr, "SCH_TEXT* is NULL" );
2370 
2371  const char* italics = "~";
2372  const char* textType = "Notes";
2373 
2374  if( aText->IsItalic() )
2375  italics = "Italic";
2376 
2377  wxString text = aText->GetText();
2378 
2379  SCH_LAYER_ID layer = aText->GetLayer();
2380 
2381  if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
2382  {
2383  if( layer == LAYER_NOTES )
2384  {
2385  // For compatibility reasons, the text must be saved in only one text line
2386  // so replace all EOLs with \\n
2387  text.Replace( wxT( "\n" ), wxT( "\\n" ) );
2388 
2389  // Here we should have no CR or LF character in line
2390  // This is not always the case if a multiline text was copied (using a copy/paste
2391  // function) from a text that uses E.O.L characters that differs from the current
2392  // EOL format. This is mainly the case under Linux using LF symbol when copying
2393  // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
2394  // (or LF left under MacOSX)
2395  for( unsigned ii = 0; ii < text.Len(); )
2396  {
2397  if( text[ii] == 0x0A || text[ii] == 0x0D )
2398  text.erase( ii, 1 );
2399  else
2400  ii++;
2401  }
2402  }
2403  else
2404  {
2405  textType = "Label";
2406  }
2407 
2408  // Local labels must have their spin style inverted for left and right
2409  int spinStyle = static_cast<int>( aText->GetLabelSpinStyle() );
2410 
2411  if( spinStyle == 0 )
2412  spinStyle = 2;
2413  else if( spinStyle == 2 )
2414  spinStyle = 0;
2415 
2416  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2417  Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
2418  spinStyle,
2419  Iu2Mils( aText->GetTextWidth() ),
2420  italics, Iu2Mils( aText->GetTextThickness() ), TO_UTF8( text ) );
2421  }
2422  else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2423  {
2424  textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2425 
2426  auto shapeLabelIt = sheetLabelNames.find( aText->GetShape() );
2427  wxCHECK_RET( shapeLabelIt != sheetLabelNames.end(), "Shape not found in names list" );
2428 
2429  m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2430  Iu2Mils( aText->GetPosition().x ), Iu2Mils( aText->GetPosition().y ),
2431  static_cast<int>( aText->GetLabelSpinStyle() ),
2432  Iu2Mils( aText->GetTextWidth() ),
2433  shapeLabelIt->second,
2434  italics,
2435  Iu2Mils( aText->GetTextThickness() ), TO_UTF8( text ) );
2436  }
2437 }
int GetTextThickness() const
Definition: eda_text.h:160
bool IsItalic() const
Definition: eda_text.h:180
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:323
LABEL_SPIN_STYLE GetLabelSpinStyle() const
Definition: sch_text.h:159
wxPoint GetPosition() const override
Definition: sch_text.h:239
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:268
int GetTextWidth() const
Definition: eda_text.h:241
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
const std::map< PINSHEETLABEL_SHAPE, const char * > sheetLabelNames
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:426
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:161

References SCH_TEXT::GetLabelSpinStyle(), SCH_ITEM::GetLayer(), SCH_TEXT::GetPosition(), SCH_TEXT::GetShape(), EDA_TEXT::GetText(), EDA_TEXT::GetTextThickness(), EDA_TEXT::GetTextWidth(), EDA_TEXT::IsItalic(), LAYER_GLOBLABEL, LAYER_HIERLABEL, LAYER_LOCLABEL, LAYER_NOTES, m_out, OUTPUTFORMATTER::Print(), sheetLabelNames, text, and TO_UTF8.

Referenced by Format().

◆ SetProgressReporter()

void SCH_LEGACY_PLUGIN::SetProgressReporter ( PROGRESS_REPORTER aReporter)
inlineoverridevirtual

Set an optional progress reporter.

Reimplemented from SCH_PLUGIN.

Definition at line 85 of file sch_legacy_plugin.h.

86  {
87  m_progressReporter = aReporter;
88  }
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr

References m_progressReporter.

◆ SetReporter()

virtual void SCH_PLUGIN::SetReporter ( REPORTER aReporter)
inlinevirtualinherited

Set an optional reporter for warnings/errors.

Reimplemented in SCH_EAGLE_PLUGIN, SCH_ALTIUM_PLUGIN, and CADSTAR_SCH_ARCHIVE_PLUGIN.

Definition at line 166 of file sch_io_mgr.h.

166 {}

◆ SymbolLibOptions()

void SCH_PLUGIN::SymbolLibOptions ( PROPERTIES aListToAppendTo) const
virtualinherited

Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.

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

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

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

Definition at line 133 of file sch_plugin.cpp.

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

References _.

◆ writeDocFile()

bool SCH_LEGACY_PLUGIN::writeDocFile ( const PROPERTIES aProperties)
private

Definition at line 4282 of file sch_legacy_plugin.cpp.

4283 {
4284  std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
4285 
4286  if( aProperties && aProperties->find( propName ) != aProperties->end() )
4287  return false;
4288 
4289  return true;
4290 }
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....

References PropNoDocFile.

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

Member Data Documentation

◆ m_cache

◆ m_currentPath

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

Stack to maintain nested sheet paths.

Definition at line 189 of file sch_legacy_plugin.h.

Referenced by Load(), and loadHierarchy().

◆ m_error

wxString SCH_LEGACY_PLUGIN::m_error
protected

For throwing exceptions or errors on partial schematic loads.

Definition at line 181 of file sch_legacy_plugin.h.

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

◆ m_lastProgressLine

unsigned SCH_LEGACY_PLUGIN::m_lastProgressLine
protected

Definition at line 185 of file sch_legacy_plugin.h.

Referenced by checkpoint().

◆ m_lineCount

unsigned SCH_LEGACY_PLUGIN::m_lineCount
protected

for progress reporting

Definition at line 186 of file sch_legacy_plugin.h.

Referenced by checkpoint(), and loadFile().

◆ m_lineReader

LINE_READER* SCH_LEGACY_PLUGIN::m_lineReader
protected

for progress reporting

Definition at line 184 of file sch_legacy_plugin.h.

Referenced by checkpoint(), and loadFile().

◆ m_out

OUTPUTFORMATTER* SCH_LEGACY_PLUGIN::m_out
protected

◆ m_path

wxString SCH_LEGACY_PLUGIN::m_path
protected

Root project path for loading child sheets.

Definition at line 188 of file sch_legacy_plugin.h.

Referenced by Load().

◆ m_progressReporter

PROGRESS_REPORTER* SCH_LEGACY_PLUGIN::m_progressReporter
protected

optional; may be nullptr

Definition at line 183 of file sch_legacy_plugin.h.

Referenced by checkpoint(), loadFile(), and SetProgressReporter().

◆ m_rootSheet

SCH_SHEET* SCH_LEGACY_PLUGIN::m_rootSheet
protected

The root sheet of the schematic being loaded.

Definition at line 190 of file sch_legacy_plugin.h.

Referenced by init(), Load(), LoadContent(), loadHierarchy(), and loadSymbol().

◆ m_schematic

SCHEMATIC* SCH_LEGACY_PLUGIN::m_schematic
protected

Definition at line 193 of file sch_legacy_plugin.h.

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

◆ m_version

int SCH_LEGACY_PLUGIN::m_version
protected

Version of file being loaded.

Definition at line 179 of file sch_legacy_plugin.h.

Referenced by init(), LoadContent(), loadFile(), loadHeader(), loadSymbol(), and loadText().

◆ PropBuffering

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

The property used internally by the plugin to enable cache buffering which prevents the library file from being written every time the cache is changed.

This is useful when writing the schematic cache library file or saving a library to a new file name.

Definition at line 95 of file sch_legacy_plugin.h.

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

◆ PropNoDocFile

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

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

Definition at line 101 of file sch_legacy_plugin.h.

Referenced by SYMBOL_LIB::IsCache(), SYMBOL_LIB::Save(), SYMBOL_LIB::SetCache(), and writeDocFile().


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