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 STRING_UTF8_MAP *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 STRING_UTF8_MAP *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 STRING_UTF8_MAP *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 STRING_UTF8_MAP *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 STRING_UTF8_MAP *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 STRING_UTF8_MAP *aProperties=nullptr) override
 Write aSymbol to an existing library located at aLibraryPath. More...
 
void DeleteSymbol (const wxString &aLibraryPath, const wxString &aSymbolName, const STRING_UTF8_MAP *aProperties=nullptr) override
 Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath. More...
 
void CreateSymbolLib (const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
 Create a new empty symbol library at aLibraryPath. More...
 
bool DeleteSymbolLib (const wxString &aLibraryPath, const STRING_UTF8_MAP *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 STRING_UTF8_MAP *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 (STRING_UTF8_MAP *aListToAppendTo) const
 Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions. More...
 
virtual bool SupportsSubLibraries () const
 
virtual void GetSubLibraryNames (std::vector< wxString > &aNames)
 Retrieves a list of sub-libraries in this library. More...
 
virtual void GetAvailableSymbolFields (std::vector< wxString > &aNames)
 Retrieves a list of (custom) field names that are present on symbols in this library. More...
 
virtual void GetDefaultSymbolFields (std::vector< wxString > &aNames)
 Retrieves a list of (custom) field names that should be shown by default for this library in the symbol chooser. More...
 
virtual void SetLibTable (SYMBOL_LIB_TABLE *aTable)
 Some library plugins need to have access to their parent library table. 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 STRING_UTF8_MAP *aProperties=nullptr)
 initialize PLUGIN like a constructor would. More...
 

Protected Attributes

int m_version
 Version of file being loaded. More...
 
bool m_appending
 
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...
 
SCH_SHEETm_currentSheet
 The sheet currently 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 STRING_UTF8_MAP *aProperties)
 
bool writeDocFile (const STRING_UTF8_MAP *aProperties)
 
bool isBuffering (const STRING_UTF8_MAP *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 74 of file sch_legacy_plugin.cpp.

74 :
75 m_appending( false ),
76 m_progressReporter( nullptr ),
77 m_lineReader( nullptr ),
79 m_lineCount( 0 )
80{
81 init( nullptr );
82}
void init(SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
initialize PLUGIN like a constructor would.
unsigned m_lineCount
for progress reporting
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
LINE_READER * m_lineReader
for progress reporting

References init().

◆ ~SCH_LEGACY_PLUGIN()

SCH_LEGACY_PLUGIN::~SCH_LEGACY_PLUGIN ( )
virtual

Definition at line 85 of file sch_legacy_plugin.cpp.

86{
87 delete m_cache;
88}
SCH_LEGACY_PLUGIN_CACHE * m_cache

References m_cache.

Member Function Documentation

◆ cacheLib()

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

Definition at line 2038 of file sch_legacy_plugin.cpp.

2039{
2040 if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
2041 {
2042 // a spectacular episode in memory management:
2043 delete m_cache;
2044 m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
2045
2046 if( !isBuffering( aProperties ) )
2047 m_cache->Load();
2048 }
2049}
A cache assistant for KiCad legacy symbol libraries.
bool isBuffering(const STRING_UTF8_MAP *aProperties)
bool IsFile(const wxString &aFullPathAndFileName) const

References isBuffering(), SCH_LIB_PLUGIN_CACHE::IsFile(), SCH_LIB_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 2230 of file sch_legacy_plugin.cpp.

2231{
2232 // Open file and check first line
2233 wxTextFile tempFile;
2234
2235 tempFile.Open( aFileName );
2236 wxString firstline;
2237 // read the first line
2238 firstline = tempFile.GetFirstLine();
2239 tempFile.Close();
2240
2241 return firstline.StartsWith( "EESchema" );
2242}

◆ checkpoint()

void SCH_LEGACY_PLUGIN::checkpoint ( )
private

Definition at line 102 of file sch_legacy_plugin.cpp.

103{
104 const unsigned PROGRESS_DELTA = 250;
105
107 {
108 unsigned curLine = m_lineReader->LineNumber();
109
110 if( curLine > m_lastProgressLine + PROGRESS_DELTA )
111 {
112 m_progressReporter->SetCurrentProgress( ( (double) curLine )
113 / std::max( 1U, m_lineCount ) );
114
116 THROW_IO_ERROR( ( "Open cancelled by user." ) );
117
118 m_lastProgressLine = curLine;
119 }
120 }
121}
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition: richio.h:135
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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 STRING_UTF8_MAP 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 2166 of file sch_legacy_plugin.cpp.

2168{
2169 if( wxFileExists( aLibraryPath ) )
2170 {
2171 THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' already exists." ),
2172 aLibraryPath.GetData() ) );
2173 }
2174
2175 LOCALE_IO toggle;
2176
2177 delete m_cache;
2178 m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
2180 m_cache->Save( writeDocFile( aProperties ) );
2181 m_cache->Load(); // update m_writable and m_mod_time
2182}
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
void Save(const std::optional< bool > &aOpt) override
Save the entire library to file m_libFileName;.
bool writeDocFile(const STRING_UTF8_MAP *aProperties)
void SetModified(bool aModified=true)
#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

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

◆ DeleteSymbol()

void SCH_LEGACY_PLUGIN::DeleteSymbol ( const wxString &  aLibraryPath,
const wxString &  aSymbolName,
const STRING_UTF8_MAP 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 2152 of file sch_legacy_plugin.cpp.

2154{
2155 LOCALE_IO toggle; // toggles on, then off, the C locale.
2156
2157 cacheLib( aLibraryPath, aProperties );
2158
2159 m_cache->DeleteSymbol( aSymbolName );
2160
2161 if( !isBuffering( aProperties ) )
2162 m_cache->Save( writeDocFile( aProperties ) );
2163}
void DeleteSymbol(const wxString &aName) override
void cacheLib(const wxString &aLibraryFileName, const STRING_UTF8_MAP *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 STRING_UTF8_MAP 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 2185 of file sch_legacy_plugin.cpp.

2187{
2188 wxFileName fn = aLibraryPath;
2189
2190 if( !fn.FileExists() )
2191 return false;
2192
2193 // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2194 // we don't want that. we want bare metal portability with no UI here.
2195 if( wxRemove( aLibraryPath ) )
2196 {
2197 THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' cannot be deleted." ),
2198 aLibraryPath.GetData() ) );
2199 }
2200
2201 if( m_cache && m_cache->IsFile( aLibraryPath ) )
2202 {
2203 delete m_cache;
2204 m_cache = nullptr;
2205 }
2206
2207 return true;
2208}

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

◆ EnumerateSymbolLib() [1/2]

void SCH_LEGACY_PLUGIN::EnumerateSymbolLib ( std::vector< LIB_SYMBOL * > &  aSymbolList,
const wxString &  aLibraryPath,
const STRING_UTF8_MAP 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 2100 of file sch_legacy_plugin.cpp.

2103{
2104 LOCALE_IO toggle; // toggles on, then off, the C locale.
2105
2106 bool powerSymbolsOnly = ( aProperties &&
2107 aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2108
2109 cacheLib( aLibraryPath, aProperties );
2110
2111 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
2112
2113 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2114 {
2115 if( !powerSymbolsOnly || it->second->IsPower() )
2116 aSymbolList.push_back( it->second );
2117 }
2118}
static const char * PropPowerSymsOnly
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP

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

◆ EnumerateSymbolLib() [2/2]

void SCH_LEGACY_PLUGIN::EnumerateSymbolLib ( wxArrayString &  aSymbolNameList,
const wxString &  aLibraryPath,
const STRING_UTF8_MAP 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 2079 of file sch_legacy_plugin.cpp.

2082{
2083 LOCALE_IO toggle; // toggles on, then off, the C locale.
2084
2085 bool powerSymbolsOnly = ( aProperties &&
2086 aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2087
2088 cacheLib( aLibraryPath, aProperties );
2089
2090 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
2091
2092 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2093 {
2094 if( !powerSymbolsOnly || it->second->IsPower() )
2095 aSymbolNameList.Add( it->first );
2096 }
2097}

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

◆ Format() [1/2]

void SCH_LEGACY_PLUGIN::Format ( SCH_SHEET aSheet)

Definition at line 1475 of file sch_legacy_plugin.cpp.

1476{
1477 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." );
1478 wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." );
1479
1480 SCH_SCREEN* screen = aSheet->GetScreen();
1481
1482 wxCHECK( screen, /* void */ );
1483
1484 // Write the header
1485 m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1486
1487 // This section is not used, but written for file compatibility
1488 m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1489 m_out->Print( 0, "EELAYER END\n" );
1490
1491 /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1492 * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1493 * simple hierarchy and flat hierarchy. Used also to search the root
1494 * sheet ( ScreenNumber = 1 ) within the files
1495 */
1496 const TITLE_BLOCK& tb = screen->GetTitleBlock();
1497 const PAGE_INFO& page = screen->GetPageSettings();
1498
1499 m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1500 page.GetWidthMils(),
1501 page.GetHeightMils(),
1502 !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1503 m_out->Print( 0, "encoding utf-8\n" );
1504 m_out->Print( 0, "Sheet %d %d\n", screen->GetVirtualPageNumber(), screen->GetPageCount() );
1505 m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1506 m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1507 m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1508 m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1509 m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment( 0 ) ).c_str() );
1510 m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment( 1 ) ).c_str() );
1511 m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment( 2 ) ).c_str() );
1512 m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment( 3 ) ).c_str() );
1513 m_out->Print( 0, "Comment5 %s\n", EscapedUTF8( tb.GetComment( 4 ) ).c_str() );
1514 m_out->Print( 0, "Comment6 %s\n", EscapedUTF8( tb.GetComment( 5 ) ).c_str() );
1515 m_out->Print( 0, "Comment7 %s\n", EscapedUTF8( tb.GetComment( 6 ) ).c_str() );
1516 m_out->Print( 0, "Comment8 %s\n", EscapedUTF8( tb.GetComment( 7 ) ).c_str() );
1517 m_out->Print( 0, "Comment9 %s\n", EscapedUTF8( tb.GetComment( 8 ) ).c_str() );
1518 m_out->Print( 0, "$EndDescr\n" );
1519
1520 for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
1521 saveBusAlias( alias );
1522
1523 // Enforce item ordering
1524 auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b ) { return *a < *b; };
1525 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
1526
1527 for( SCH_ITEM* item : screen->Items() )
1528 save_map.insert( item );
1529
1530
1531 for( auto& item : save_map )
1532 {
1533 switch( item->Type() )
1534 {
1535 case SCH_SYMBOL_T:
1536 saveSymbol( static_cast<SCH_SYMBOL*>( item ) );
1537 break;
1538 case SCH_BITMAP_T:
1539 saveBitmap( static_cast<SCH_BITMAP*>( item ) );
1540 break;
1541 case SCH_SHEET_T:
1542 saveSheet( static_cast<SCH_SHEET*>( item ) );
1543 break;
1544 case SCH_JUNCTION_T:
1545 saveJunction( static_cast<SCH_JUNCTION*>( item ) );
1546 break;
1547 case SCH_NO_CONNECT_T:
1548 saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ) );
1549 break;
1552 saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ) );
1553 break;
1554 case SCH_LINE_T:
1555 saveLine( static_cast<SCH_LINE*>( item ) );
1556 break;
1557 case SCH_TEXT_T:
1558 case SCH_LABEL_T:
1559 case SCH_GLOBAL_LABEL_T:
1560 case SCH_HIER_LABEL_T:
1561 saveText( static_cast<SCH_TEXT*>( item ) );
1562 break;
1563 default:
1564 wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1565 }
1566 }
1567
1568 m_out->Print( 0, "$EndSCHEMATC\n" );
1569}
int GetPageCount() const
Definition: base_screen.h:72
int GetVirtualPageNumber() const
Definition: base_screen.h:75
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:431
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
int GetHeightMils() const
Definition: page_info.h:133
int GetWidthMils() const
Definition: page_info.h:130
const wxString & GetType() const
Definition: page_info.h:94
bool IsCustom() const
Definition: page_info.cpp:181
bool IsPortrait() const
Definition: page_info.h:117
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:41
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:38
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
void saveSymbol(SCH_SYMBOL *aSymbol)
void saveSheet(SCH_SHEET *aSheet)
void saveText(SCH_TEXT *aText)
void saveJunction(SCH_JUNCTION *aJunction)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
void saveLine(SCH_LINE *aLine)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
void saveBitmap(SCH_BITMAP *aBitmap)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:131
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:155
std::set< std::shared_ptr< BUS_ALIAS > > GetBusAliases() const
Return a list of bus aliases defined in this screen.
Definition: sch_screen.h:484
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:55
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
Schematic symbol object.
Definition: sch_symbol.h:80
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:41
const wxString & GetCompany() const
Definition: title_block.h:96
const wxString & GetRevision() const
Definition: title_block.h:86
const wxString & GetDate() const
Definition: title_block.h:76
const wxString & GetComment(int aIdx) const
Definition: title_block.h:107
const wxString & GetTitle() const
Definition: title_block.h:63
#define SCHEMATIC_HEAD_STRING
Definition: general.h:36
#define EESCHEMA_VERSION
Definition: general.h:35
#define SCH_LAYER_ID_COUNT
Definition: layer_ids.h:391
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
@ SCH_LINE_T
Definition: typeinfo.h:146
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:143
@ SCH_SYMBOL_T
Definition: typeinfo.h:156
@ SCH_LABEL_T
Definition: typeinfo.h:151
@ SCH_SHEET_T
Definition: typeinfo.h:158
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:153
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:145
@ SCH_TEXT_T
Definition: typeinfo.h:150
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:144
@ SCH_BITMAP_T
Definition: typeinfo.h:148
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
@ SCH_JUNCTION_T
Definition: typeinfo.h:142

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 1572 of file sch_legacy_plugin.cpp.

1573{
1574 m_out = aFormatter;
1575
1576 for( unsigned i = 0; i < aSelection->GetSize(); ++i )
1577 {
1578 SCH_ITEM* item = (SCH_ITEM*) aSelection->GetItem( i );
1579
1580 switch( item->Type() )
1581 {
1582 case SCH_SYMBOL_T:
1583 saveSymbol( static_cast< SCH_SYMBOL* >( item ) );
1584 break;
1585 case SCH_BITMAP_T:
1586 saveBitmap( static_cast< SCH_BITMAP* >( item ) );
1587 break;
1588 case SCH_SHEET_T:
1589 saveSheet( static_cast< SCH_SHEET* >( item ) );
1590 break;
1591 case SCH_JUNCTION_T:
1592 saveJunction( static_cast< SCH_JUNCTION* >( item ) );
1593 break;
1594 case SCH_NO_CONNECT_T:
1595 saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
1596 break;
1599 saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1600 break;
1601 case SCH_LINE_T:
1602 saveLine( static_cast< SCH_LINE* >( item ) );
1603 break;
1604 case SCH_TEXT_T:
1605 case SCH_LABEL_T:
1606 case SCH_GLOBAL_LABEL_T:
1607 case SCH_HIER_LABEL_T:
1608 saveText( static_cast< SCH_TEXT* >( item ) );
1609 break;
1610 default:
1611 wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1612 }
1613 }
1614}
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:65
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:97

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 2259 of file sch_legacy_plugin.cpp.

2260{
2261 SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( symbol, formatter );
2262}
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_SYMBOL_MAP *aMap=nullptr)

References SCH_LEGACY_PLUGIN_CACHE::SaveSymbol().

◆ GetAvailableSymbolFields()

virtual void SCH_PLUGIN::GetAvailableSymbolFields ( std::vector< wxString > &  aNames)
inlinevirtualinherited

Retrieves a list of (custom) field names that are present on symbols in this library.

The plugin is responsible for guaranteeing that this list contains the set of unique custom field names present on any symbols contained in the library.

The required KiCad fields are not included in this list.

Parameters
aNameswill be filled with any custom fields present in this library.

Reimplemented in SCH_DATABASE_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 474 of file sch_io_mgr.h.

474{}

Referenced by SYMBOL_LIB_TABLE_ROW::GetAvailableSymbolFields(), and SCH_PLUGIN::GetDefaultSymbolFields().

◆ GetDefaultSymbolFields()

virtual void SCH_PLUGIN::GetDefaultSymbolFields ( std::vector< wxString > &  aNames)
inlinevirtualinherited

Retrieves a list of (custom) field names that should be shown by default for this library in the symbol chooser.

This list should be a subset of the result returned by GetAvailableSymbolFields().

The preference for which fields to hide and show for a given library is stored on a per-library basis in a user's preferences (or in the project local settings for a project- local library). The set of fields returned by GetDefaultSymbolFields() will be used if this preference is missing.

Parameters
aNameswill be filled with the custom field names that should be shown by default

Reimplemented in SCH_DATABASE_PLUGIN, and SCH_SEXPR_PLUGIN.

Definition at line 488 of file sch_io_mgr.h.

489 {
490 return GetAvailableSymbolFields( aNames );
491 }
virtual void GetAvailableSymbolFields(std::vector< wxString > &aNames)
Retrieves a list of (custom) field names that are present on symbols in this library.
Definition: sch_io_mgr.h:474

References SCH_PLUGIN::GetAvailableSymbolFields().

Referenced by SYMBOL_LIB_TABLE_ROW::GetDefaultSymbolFields().

◆ 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 2069 of file sch_legacy_plugin.cpp.

2070{
2071 if( m_cache )
2072 return m_cache->GetModifyHash();
2073
2074 // If the cache hasn't been loaded, it hasn't been modified.
2075 return 0;
2076}

References SCH_LIB_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 }

◆ GetSubLibraryNames()

virtual void SCH_PLUGIN::GetSubLibraryNames ( std::vector< wxString > &  aNames)
inlinevirtualinherited

Retrieves a list of sub-libraries in this library.

Some types of symbol library support sub-libraries, which are a single-level organizational hierarchy that is implementation-defined per plugin. Most of KiCad ignores sub-libraries and treats the hierarchy between library and symbol as flat, but the sub-libraries are used for sorting and grouping symbols in the symbol chooser.

Has no effect if SupportsSubLibraries() returns false.

Parameters
aNameswill be filled with a list of sub-libraries within this symbol library

Reimplemented in SCH_DATABASE_PLUGIN.

Definition at line 463 of file sch_io_mgr.h.

463{}

Referenced by SYMBOL_LIB_TABLE_ROW::GetSubLibraryNames().

◆ init()

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

initialize PLUGIN like a constructor would.

Definition at line 91 of file sch_legacy_plugin.cpp.

92{
93 m_version = 0;
94 m_rootSheet = nullptr;
95 m_currentSheet = nullptr;
96 m_schematic = aSchematic;
97 m_cache = nullptr;
98 m_out = nullptr;
99}
int m_version
Version of file being loaded.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
SCH_SHEET * m_currentSheet
The sheet currently being loaded.

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

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

◆ isBuffering()

bool SCH_LEGACY_PLUGIN::isBuffering ( const STRING_UTF8_MAP aProperties)
private

Definition at line 2063 of file sch_legacy_plugin.cpp.

2064{
2065 return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
2066}
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
bool Exists(const std::string &aProperty) const

References STRING_UTF8_MAP::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 2245 of file sch_legacy_plugin.cpp.

2246{
2247 // Writing legacy symbol libraries is deprecated.
2248 return false;
2249}

◆ Load()

SCH_SHEET * SCH_LEGACY_PLUGIN::Load ( const wxString &  aFileName,
SCHEMATIC aSchematic,
SCH_SHEET aAppendToMe = nullptr,
const STRING_UTF8_MAP 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 124 of file sch_legacy_plugin.cpp.

126{
127 wxASSERT( !aFileName || aSchematic != nullptr );
128
129 LOCALE_IO toggle; // toggles on, then off, the C locale.
130 SCH_SHEET* sheet;
131
132 wxFileName fn = aFileName;
133
134 // Unfortunately child sheet file names the legacy schematic file format are not fully
135 // qualified and are always appended to the project path. The aFileName attribute must
136 // always be an absolute path so the project path can be used for load child sheet files.
137 wxASSERT( fn.IsAbsolute() );
138
139 if( aAppendToMe )
140 {
141 wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
142 aFileName, aAppendToMe->GetFileName() );
143
144 wxFileName normedFn = aAppendToMe->GetFileName();
145
146 if( !normedFn.IsAbsolute() )
147 {
148 if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
149 m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
150 }
151
152 if( m_path.IsEmpty() )
153 m_path = aSchematic->Prj().GetProjectPath();
154
155 wxLogTrace( traceSchLegacyPlugin, "m_Normalized append path \"%s\".", m_path );
156 }
157 else
158 {
159 m_path = aSchematic->Prj().GetProjectPath();
160 }
161
162 m_currentPath.push( m_path );
163 init( aSchematic, aProperties );
164
165 if( aAppendToMe == nullptr )
166 {
167 // Clean up any allocated memory if an exception occurs loading the schematic.
168 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
169 newSheet->SetFileName( aFileName );
170 m_rootSheet = newSheet.get();
171 loadHierarchy( newSheet.get() );
172
173 // If we got here, the schematic loaded successfully.
174 sheet = newSheet.release();
175 m_rootSheet = nullptr; // Quiet Coverity warning.
176 }
177 else
178 {
179 m_appending = true;
180 wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
181 m_rootSheet = &aSchematic->Root();
182 sheet = aAppendToMe;
183 loadHierarchy( sheet );
184 }
185
186 wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
187
188 return sheet;
189}
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:126
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:107
SCH_SHEET & Root() const
Definition: schematic.h:91
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:76
wxString m_path
Root project path for loading child sheets.
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
void loadHierarchy(SCH_SHEET *aSheet)
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:299
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.

References SCH_SHEET::GetFileName(), PROJECT::GetProjectPath(), init(), SCHEMATIC::IsValid(), loadHierarchy(), m_appending, 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 643 of file sch_legacy_plugin.cpp.

644{
645 std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
646
647 const char* line = aReader.Line();
648
649 wxCHECK( strCompare( "$Bitmap", line, &line ), nullptr );
650
651 line = aReader.ReadLine();
652
653 while( line != nullptr )
654 {
655 if( strCompare( "Pos", line, &line ) )
656 {
657 VECTOR2I position;
658
659 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
660 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
661 bitmap->SetPosition( position );
662 }
663 else if( strCompare( "Scale", line, &line ) )
664 {
665 auto scalefactor = parseDouble( aReader, line, &line );
666
667 // Prevent scalefactor values that cannot be displayed.
668 // In the case of a bad value, we accept that the image might be mis-scaled
669 // rather than removing the full image. Users can then edit the scale factor in
670 // Eeschema to the appropriate value
671 if( !std::isnormal( scalefactor ) )
672 scalefactor = 1.0;
673
674 bitmap->GetImage()->SetScale( scalefactor );
675 }
676 else if( strCompare( "Data", line, &line ) )
677 {
678 wxMemoryOutputStream stream;
679
680 while( line )
681 {
682 if( !aReader.ReadLine() )
683 SCH_PARSE_ERROR( _( "Unexpected end of file" ), aReader, line );
684
685 line = aReader.Line();
686
687 if( strCompare( "EndData", line ) )
688 {
689 // all the PNG date is read.
690 // We expect here m_image and m_bitmap are void
691 wxImage* image = new wxImage();
692 wxMemoryInputStream istream( stream );
693 image->LoadFile( istream, wxBITMAP_TYPE_PNG );
694 bitmap->GetImage()->SetImage( image );
695 bitmap->GetImage()->SetBitmap( new wxBitmap( *image ) );
696 break;
697 }
698
699 // Read PNG data, stored in hexadecimal,
700 // each byte = 2 hexadecimal digits and a space between 2 bytes
701 // and put it in memory stream buffer
702 // Note:
703 // Some old files created bu the V4 schematic versions have a extra
704 // "$EndBitmap" at the end of the hexadecimal data. (Probably due to
705 // a bug). So discard it
706 int len = strlen( line );
707
708 for( ; len > 0 && !isspace( *line ) && '$' != *line; len -= 3, line += 3 )
709 {
710 int value = 0;
711
712 if( sscanf( line, "%X", &value ) == 1 )
713 stream.PutC( (char) value );
714 else
715 THROW_IO_ERROR( "invalid PNG data" );
716 }
717 }
718
719 if( line == nullptr )
720 THROW_IO_ERROR( _( "unexpected end of file" ) );
721 }
722 else if( strCompare( "$EndBitmap", line ) )
723 {
724 return bitmap.release();
725 }
726
727 line = aReader.ReadLine();
728 }
729
730 THROW_IO_ERROR( _( "unexpected end of file" ) );
731}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
bool strCompare(const char *aString, const char *aLine, const char **aOutput)
Compare aString to the string starting at aLine and advances the character point to the end of String...
double parseDouble(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parses an ASCII point string with possible leading whitespace into a double precision floating point ...
#define SCH_PARSE_ERROR(text, reader, pos)
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94

References _, image, LINE_READER::Line(), EDA_IU_SCALE::MilsToIU(), parseDouble(), parseInt(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, schIUScale, strCompare(), THROW_IO_ERROR, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by LoadContent().

◆ loadBusAlias()

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

Definition at line 1424 of file sch_legacy_plugin.cpp.

1426{
1427 auto busAlias = std::make_shared<BUS_ALIAS>( aScreen );
1428 const char* line = aReader.Line();
1429
1430 wxCHECK( strCompare( "BusAlias", line, &line ), nullptr );
1431
1432 wxString buf;
1433 parseUnquotedString( buf, aReader, line, &line );
1434 busAlias->SetName( buf );
1435
1436 while( *line != '\0' )
1437 {
1438 buf.clear();
1439 parseUnquotedString( buf, aReader, line, &line, true );
1440
1441 if( !buf.IsEmpty() )
1442 busAlias->Members().emplace_back( buf );
1443 }
1444
1445 return busAlias;
1446}
void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken, bool aCanBeEmpty)
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 884 of file sch_legacy_plugin.cpp.

885{
886 const char* line = aReader.Line();
887
888 wxCHECK( strCompare( "Entry", line, &line ), nullptr );
889
890 std::unique_ptr<SCH_BUS_ENTRY_BASE> busEntry;
891
892 if( strCompare( "Wire", line, &line ) )
893 {
894 busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>();
895
896 if( !strCompare( "Line", line, &line ) )
897 SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
898 }
899 else if( strCompare( "Bus", line, &line ) )
900 {
901 busEntry = std::make_unique<SCH_BUS_BUS_ENTRY>();
902
903 if( !strCompare( "Bus", line, &line ) )
904 SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
905 }
906 else
907 {
908 SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
909 }
910
911 line = aReader.ReadLine();
912
913 VECTOR2I pos;
914 wxSize size;
915
916 pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
917 pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
918 size.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
919 size.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
920
921 size.x -= pos.x;
922 size.y -= pos.y;
923
924 busEntry->SetPosition( pos );
925 busEntry->SetSize( size );
926
927 return busEntry.release();
928}

References LINE_READER::Line(), EDA_IU_SCALE::MilsToIU(), parseInt(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, schIUScale, strCompare(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by LoadContent().

◆ LoadContent()

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

Definition at line 317 of file sch_legacy_plugin.cpp.

318{
319 m_version = version;
320
321 // We cannot safely load content without a set root level.
322 wxCHECK_RET( m_rootSheet,
323 "Cannot call SCH_LEGACY_PLUGIN::LoadContent() without setting root sheet." );
324
325 while( aReader.ReadLine() )
326 {
327 checkpoint();
328
329 char* line = aReader.Line();
330
331 while( *line == ' ' )
332 line++;
333
334 // Either an object will be loaded properly or the file load will fail and raise
335 // an exception.
336 if( strCompare( "$Descr", line ) )
337 loadPageSettings( aReader, aScreen );
338 else if( strCompare( "$Comp", line ) )
339 aScreen->Append( loadSymbol( aReader ) );
340 else if( strCompare( "$Sheet", line ) )
341 aScreen->Append( loadSheet( aReader ) );
342 else if( strCompare( "$Bitmap", line ) )
343 aScreen->Append( loadBitmap( aReader ) );
344 else if( strCompare( "Connection", line ) )
345 aScreen->Append( loadJunction( aReader ) );
346 else if( strCompare( "NoConn", line ) )
347 aScreen->Append( loadNoConnect( aReader ) );
348 else if( strCompare( "Wire", line ) )
349 aScreen->Append( loadWire( aReader ) );
350 else if( strCompare( "Entry", line ) )
351 aScreen->Append( loadBusEntry( aReader ) );
352 else if( strCompare( "Text", line ) )
353 aScreen->Append( loadText( aReader ) );
354 else if( strCompare( "BusAlias", line ) )
355 aScreen->AddBusAlias( loadBusAlias( aReader, aScreen ) );
356 else if( strCompare( "$EndSCHEMATC", line ) )
357 return;
358 else
359 SCH_PARSE_ERROR( "unrecognized token", aReader, line );
360 }
361}
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_LINE * loadWire(LINE_READER &aReader)
SCH_JUNCTION * loadJunction(LINE_READER &aReader)
SCH_NO_CONNECT * loadNoConnect(LINE_READER &aReader)
SCH_BITMAP * loadBitmap(LINE_READER &aReader)
SCH_SYMBOL * loadSymbol(LINE_READER &aReader)
SCH_SHEET * loadSheet(LINE_READER &aReader)
std::shared_ptr< BUS_ALIAS > loadBusAlias(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_TEXT * loadText(LINE_READER &aReader)
SCH_BUS_ENTRY_BASE * loadBusEntry(LINE_READER &aReader)
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:141

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 278 of file sch_legacy_plugin.cpp.

279{
280 FILE_LINE_READER reader( aFileName );
281
283 {
284 m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
285
287 THROW_IO_ERROR( ( "Open cancelled by user." ) );
288
289 m_lineReader = &reader;
290 m_lineCount = 0;
291
292 while( reader.ReadLine() )
293 m_lineCount++;
294
295 reader.Rewind();
296 }
297
298 loadHeader( reader, aScreen );
299
300 LoadContent( reader, aScreen, m_version );
301
302 // Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
303 // so checking for its existance will fail so just exit here and take our chances. :(
304 if( m_version > 1 )
305 {
306 char* line = reader.Line();
307
308 while( *line == ' ' )
309 line++;
310
311 if( !strCompare( "$EndSCHEMATC", line ) )
312 THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
313 }
314}
A LINE_READER that reads from an open file.
Definition: richio.h:173
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
void loadHeader(LINE_READER &aReader, SCH_SCREEN *aScreen)
void LoadContent(LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)

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 364 of file sch_legacy_plugin.cpp.

365{
366 const char* line = aReader.ReadLine();
367
368 if( !line || !strCompare( "Eeschema Schematic File Version", line, &line ) )
369 {
370 m_error.Printf( _( "'%s' does not appear to be an Eeschema file." ),
371 aScreen->GetFileName() );
373 }
374
375 // get the file version here.
376 m_version = parseInt( aReader, line, &line );
377
378 // The next lines are the lib list section, and are mainly comments, like:
379 // LIBS:power
380 // the lib list is not used, but is in schematic file just in case.
381 // It is usually not empty, but we accept empty list.
382 // If empty, there is a legacy section, not used
383 // EELAYER i j
384 // and the last line is
385 // EELAYER END
386 // Skip all lines until the end of header "EELAYER END" is found
387 while( aReader.ReadLine() )
388 {
389 checkpoint();
390
391 line = aReader.Line();
392
393 while( *line == ' ' )
394 line++;
395
396 if( strCompare( "EELAYER END", line ) )
397 return;
398 }
399
400 THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
401}
const wxString & GetFileName() const
Definition: sch_screen.h:144

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 194 of file sch_legacy_plugin.cpp.

195{
196 SCH_SCREEN* screen = nullptr;
197
198 m_currentSheet = aSheet;
199
200 if( !aSheet->GetScreen() )
201 {
202 // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
203 // stores the file name and extension. Add the project path to the file name and
204 // extension to compare when calling SCH_SHEET::SearchHierarchy().
205 wxFileName fileName = aSheet->GetFileName();
206 fileName.SetExt( "sch" );
207
208 if( !fileName.IsAbsolute() )
209 fileName.MakeAbsolute( m_currentPath.top() );
210
211 // Save the current path so that it gets restored when descending and ascending the
212 // sheet hierarchy which allows for sheet schematic files to be nested in folders
213 // relative to the last path a schematic was loaded from.
214 wxLogTrace( traceSchLegacyPlugin, "Saving path '%s'", m_currentPath.top() );
215 m_currentPath.push( fileName.GetPath() );
216 wxLogTrace( traceSchLegacyPlugin, "Current path '%s'", m_currentPath.top() );
217 wxLogTrace( traceSchLegacyPlugin, "Loading '%s'", fileName.GetFullPath() );
218
219 m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
220
221 if( screen )
222 {
223 aSheet->SetScreen( screen );
224 screen->SetParent( m_schematic );
225 // Do not need to load the sub-sheets - this has already been done.
226 }
227 else
228 {
229 aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
230 aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
231
232 if( aSheet == m_rootSheet )
233 const_cast<KIID&>( aSheet->m_Uuid ) = aSheet->GetScreen()->GetUuid();
234
235 try
236 {
237 loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
238 }
239 catch( const IO_ERROR& ioe )
240 {
241 // If there is a problem loading the root sheet, there is no recovery.
242 if( aSheet == m_rootSheet )
243 throw( ioe );
244
245 // For all subsheets, queue up the error message for the caller.
246 if( !m_error.IsEmpty() )
247 m_error += "\n";
248
249 m_error += ioe.What();
250 }
251
252 aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() );
253 aSheet->GetScreen()->SetFileExists( true );
254
255 for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
256 {
257 wxCHECK2( aItem->Type() == SCH_SHEET_T, continue );
258 auto sheet = static_cast<SCH_SHEET*>( aItem );
259
260 // Set the parent to aSheet. This effectively creates a method to find
261 // the root sheet from any sheet so a pointer to the root sheet does not
262 // need to be stored globally. Note: this is not the same as a hierarchy.
263 // Complex hierarchies can have multiple copies of a sheet. This only
264 // provides a simple tree to find the root sheet.
265 sheet->SetParent( aSheet );
266
267 // Recursion starts here.
268 loadHierarchy( sheet );
269 }
270 }
271
272 m_currentPath.pop();
273 wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
274 }
275}
const KIID m_Uuid
Definition: eda_item.h:492
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
Definition: kiid.h:48
void loadFile(const wxString &aFileName, SCH_SCREEN *aScreen)
const KIID & GetUuid() const
Definition: sch_screen.h:499
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:106
void SetFileReadOnly(bool aIsReadOnly)
Definition: sch_screen.h:146
void SetFileExists(bool aFileExists)
Definition: sch_screen.h:149
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:707
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:162

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

Referenced by Load(), and loadHierarchy().

◆ loadJunction()

SCH_JUNCTION * SCH_LEGACY_PLUGIN::loadJunction ( LINE_READER aReader)
private

Definition at line 734 of file sch_legacy_plugin.cpp.

735{
736 std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
737
738 const char* line = aReader.Line();
739
740 wxCHECK( strCompare( "Connection", line, &line ), nullptr );
741
742 wxString name;
743
744 parseUnquotedString( name, aReader, line, &line );
745
746 VECTOR2I position;
747
748 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
749 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
750 junction->SetPosition( position );
751
752 return junction.release();
753}
const char * name
Definition: DXF_plotter.cpp:56

References LINE_READER::Line(), EDA_IU_SCALE::MilsToIU(), name, parseInt(), parseUnquotedString(), schIUScale, strCompare(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by LoadContent().

◆ loadNoConnect()

SCH_NO_CONNECT * SCH_LEGACY_PLUGIN::loadNoConnect ( LINE_READER aReader)
private

Definition at line 756 of file sch_legacy_plugin.cpp.

757{
758 std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>();
759
760 const char* line = aReader.Line();
761
762 wxCHECK( strCompare( "NoConn", line, &line ), nullptr );
763
764 wxString name;
765
766 parseUnquotedString( name, aReader, line, &line );
767
768 VECTOR2I position;
769
770 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
771 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
772 no_connect->SetPosition( position );
773
774 return no_connect.release();
775}

References LINE_READER::Line(), EDA_IU_SCALE::MilsToIU(), name, parseInt(), parseUnquotedString(), schIUScale, strCompare(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by LoadContent().

◆ loadPageSettings()

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

Definition at line 404 of file sch_legacy_plugin.cpp.

405{
406 wxASSERT( aScreen != nullptr );
407
408 wxString buf;
409 const char* line = aReader.Line();
410
411 PAGE_INFO pageInfo;
412 TITLE_BLOCK tb;
413
414 wxCHECK_RET( strCompare( "$Descr", line, &line ), "Invalid sheet description" );
415
416 parseUnquotedString( buf, aReader, line, &line );
417
418 if( !pageInfo.SetType( buf ) )
419 SCH_PARSE_ERROR( "invalid page size", aReader, line );
420
421 int pagew = parseInt( aReader, line, &line );
422 int pageh = parseInt( aReader, line, &line );
423
424 if( buf == PAGE_INFO::Custom )
425 {
426 pageInfo.SetWidthMils( pagew );
427 pageInfo.SetHeightMils( pageh );
428 }
429 else
430 {
431 wxString orientation;
432
433 // Non custom size, set portrait if its present. Can be empty string which defaults
434 // to landscape.
435 parseUnquotedString( orientation, aReader, line, &line, true );
436
437 if( orientation == "portrait" )
438 pageInfo.SetPortrait( true );
439 }
440
441 aScreen->SetPageSettings( pageInfo );
442
443 while( line != nullptr )
444 {
445 buf.clear();
446
447 if( !aReader.ReadLine() )
448 SCH_PARSE_ERROR( _( "unexpected end of file" ), aReader, line );
449
450 line = aReader.Line();
451
452 if( strCompare( "Sheet", line, &line ) )
453 {
454 aScreen->SetVirtualPageNumber( parseInt( aReader, line, &line ) );
455 aScreen->SetPageCount( parseInt( aReader, line, &line ) );
456 }
457 else if( strCompare( "Title", line, &line ) )
458 {
459 parseQuotedString( buf, aReader, line, &line, true );
460 tb.SetTitle( buf );
461 }
462 else if( strCompare( "Date", line, &line ) )
463 {
464 parseQuotedString( buf, aReader, line, &line, true );
465 tb.SetDate( buf );
466 }
467 else if( strCompare( "Rev", line, &line ) )
468 {
469 parseQuotedString( buf, aReader, line, &line, true );
470 tb.SetRevision( buf );
471 }
472 else if( strCompare( "Comp", line, &line ) )
473 {
474 parseQuotedString( buf, aReader, line, &line, true );
475 tb.SetCompany( buf );
476 }
477 else if( strCompare( "Comment1", line, &line ) )
478 {
479 parseQuotedString( buf, aReader, line, &line, true );
480 tb.SetComment( 0, buf );
481 }
482 else if( strCompare( "Comment2", line, &line ) )
483 {
484 parseQuotedString( buf, aReader, line, &line, true );
485 tb.SetComment( 1, buf );
486 }
487 else if( strCompare( "Comment3", line, &line ) )
488 {
489 parseQuotedString( buf, aReader, line, &line, true );
490 tb.SetComment( 2, buf );
491 }
492 else if( strCompare( "Comment4", line, &line ) )
493 {
494 parseQuotedString( buf, aReader, line, &line, true );
495 tb.SetComment( 3, buf );
496 }
497 else if( strCompare( "Comment5", line, &line ) )
498 {
499 parseQuotedString( buf, aReader, line, &line, true );
500 tb.SetComment( 4, buf );
501 }
502 else if( strCompare( "Comment6", line, &line ) )
503 {
504 parseQuotedString( buf, aReader, line, &line, true );
505 tb.SetComment( 5, buf );
506 }
507 else if( strCompare( "Comment7", line, &line ) )
508 {
509 parseQuotedString( buf, aReader, line, &line, true );
510 tb.SetComment( 6, buf );
511 }
512 else if( strCompare( "Comment8", line, &line ) )
513 {
514 parseQuotedString( buf, aReader, line, &line, true );
515 tb.SetComment( 7, buf );
516 }
517 else if( strCompare( "Comment9", line, &line ) )
518 {
519 parseQuotedString( buf, aReader, line, &line, true );
520 tb.SetComment( 8, buf );
521 }
522 else if( strCompare( "$EndDescr", line ) )
523 {
524 aScreen->SetTitleBlock( tb );
525 return;
526 }
527 }
528
529 SCH_PARSE_ERROR( "missing 'EndDescr'", aReader, line );
530}
void SetPageCount(int aPageCount)
Definition: base_screen.cpp:63
void SetVirtualPageNumber(int aPageNumber)
Definition: base_screen.h:76
void SetWidthMils(int aWidthInMils)
Definition: page_info.cpp:244
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
Definition: page_info.cpp:187
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:77
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:258
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:120
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:157
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:132
void SetRevision(const wxString &aRevision)
Definition: title_block.h:81
void SetComment(int aIdx, const wxString &aComment)
Definition: title_block.h:101
void SetTitle(const wxString &aTitle)
Definition: title_block.h:58
void SetCompany(const wxString &aCompany)
Definition: title_block.h:91
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
Definition: title_block.h:71
void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken, bool aCanBeEmpty)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.

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 533 of file sch_legacy_plugin.cpp.

534{
535 std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>();
536
537 const char* line = aReader.ReadLine();
538
539 while( line != nullptr )
540 {
541 if( strCompare( "S", line, &line ) ) // Sheet dimensions.
542 {
543 VECTOR2I position;
544
545 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
546 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
547 sheet->SetPosition( position );
548
549 wxSize size;
550
551 size.SetWidth( schIUScale.MilsToIU( parseInt( aReader, line, &line ) ) );
552 size.SetHeight( schIUScale.MilsToIU( parseInt( aReader, line, &line ) ) );
553 sheet->SetSize( size );
554 }
555 else if( strCompare( "U", line, &line ) ) // Sheet UUID.
556 {
557 wxString text;
558 parseUnquotedString( text, aReader, line );
559
560 if( text != "00000000" )
561 const_cast<KIID&>( sheet->m_Uuid ) = KIID( text );
562 }
563 else if( *line == 'F' ) // Sheet field.
564 {
565 line++;
566
567 wxString text;
568 int size;
569 int fieldId = parseInt( aReader, line, &line );
570
571 if( fieldId == 0 || fieldId == 1 ) // Sheet name and file name.
572 {
573 parseQuotedString( text, aReader, line, &line );
574 size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
575
576 SCH_FIELD& field = sheet->GetFields()[ fieldId ];
577 field.SetText( text );
578 field.SetTextSize( wxSize( size, size ) );
579 }
580 else // Sheet pin.
581 {
582 // Use a unique_ptr so that we clean up in the case of a throw
583 std::unique_ptr<SCH_SHEET_PIN> sheetPin = std::make_unique<SCH_SHEET_PIN>( sheet.get() );
584
585 sheetPin->SetNumber( fieldId );
586
587 // Can be empty fields.
588 parseQuotedString( text, aReader, line, &line, true );
589
590 sheetPin->SetText( ConvertToNewOverbarNotation( text ) );
591
592 if( line == nullptr )
593 THROW_IO_ERROR( _( "unexpected end of line" ) );
594
595 switch( parseChar( aReader, line, &line ) )
596 {
597 case 'I': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT ); break;
598 case 'O': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT ); break;
599 case 'B': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI ); break;
600 case 'T': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE ); break;
601 case 'U': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED ); break;
602 default: SCH_PARSE_ERROR( "invalid sheet pin type", aReader, line );
603 }
604
605 switch( parseChar( aReader, line, &line ) )
606 {
607 case 'R': sheetPin->SetSide( SHEET_SIDE::RIGHT ); break;
608 case 'T': sheetPin->SetSide( SHEET_SIDE::TOP ); break;
609 case 'B': sheetPin->SetSide( SHEET_SIDE::BOTTOM ); break;
610 case 'L': sheetPin->SetSide( SHEET_SIDE::LEFT ); break;
611 default:
612 SCH_PARSE_ERROR( "invalid sheet pin side", aReader, line );
613 }
614
615 VECTOR2I position;
616
617 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
618 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
619 sheetPin->SetPosition( position );
620
621 size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
622
623 sheetPin->SetTextSize( wxSize( size, size ) );
624
625 sheet->AddPin( sheetPin.release() );
626 }
627 }
628 else if( strCompare( "$EndSheet", line ) )
629 {
630 sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
631 return sheet.release();
632 }
633
634 line = aReader.ReadLine();
635 }
636
637 SCH_PARSE_ERROR( "missing '$EndSheet`", aReader, line );
638
639 return nullptr; // Prevents compiler warning. Should never get here.
640}
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:347
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:50
char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
@ L_BIDI
Definition: sch_text.h:99
@ L_TRISTATE
Definition: sch_text.h:100
@ L_UNSPECIFIED
Definition: sch_text.h:101
@ L_OUTPUT
Definition: sch_text.h:98
@ L_INPUT
Definition: sch_text.h:97
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.

References _, BOTTOM, ConvertToNewOverbarNotation(), L_BIDI, L_INPUT, L_OUTPUT, L_TRISTATE, L_UNSPECIFIED, LEFT, EDA_IU_SCALE::MilsToIU(), parseChar(), parseInt(), parseQuotedString(), parseUnquotedString(), LINE_READER::ReadLine(), RIGHT, SCH_PARSE_ERROR, schIUScale, EDA_TEXT::SetText(), EDA_TEXT::SetTextSize(), strCompare(), text, THROW_IO_ERROR, TOP, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by LoadContent().

◆ LoadSymbol()

LIB_SYMBOL * SCH_LEGACY_PLUGIN::LoadSymbol ( const wxString &  aLibraryPath,
const wxString &  aPartName,
const STRING_UTF8_MAP 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 2121 of file sch_legacy_plugin.cpp.

2124{
2125 LOCALE_IO toggle; // toggles on, then off, the C locale.
2126
2127 cacheLib( aLibraryPath, aProperties );
2128
2129 LIB_SYMBOL_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
2130
2131 if( it == m_cache->m_symbols.end() )
2132 return nullptr;
2133
2134 return it->second;
2135}

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

◆ loadSymbol()

SCH_SYMBOL * SCH_LEGACY_PLUGIN::loadSymbol ( LINE_READER aReader)
private

Definition at line 1076 of file sch_legacy_plugin.cpp.

1077{
1078 const char* line = aReader.Line();
1079
1080 wxCHECK( strCompare( "$Comp", line, &line ), nullptr );
1081
1082 std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
1083
1084 line = aReader.ReadLine();
1085
1086 while( line != nullptr )
1087 {
1088 if( strCompare( "L", line, &line ) )
1089 {
1090 wxString libName;
1091 size_t pos = 2; // "X" plus ' ' space character.
1092 wxString utf8Line = wxString::FromUTF8( line );
1093 wxStringTokenizer tokens( utf8Line, " \r\n\t" );
1094
1095 if( tokens.CountTokens() < 2 )
1096 THROW_PARSE_ERROR( "invalid symbol library definition", aReader.GetSource(),
1097 aReader.Line(), aReader.LineNumber(), pos );
1098
1099 libName = tokens.GetNextToken();
1100 libName.Replace( "~", " " );
1101
1102 LIB_ID libId;
1103
1104 // Prior to schematic version 4, library IDs did not have a library nickname so
1105 // parsing the symbol name with LIB_ID::Parse() would break symbol library links
1106 // that contained '/' and ':' characters.
1107 if( m_version > 3 )
1108 libId.Parse( libName, true );
1109 else
1110 libId.SetLibItemName( libName );
1111
1112 symbol->SetLibId( libId );
1113
1114 wxString refDesignator = tokens.GetNextToken();
1115
1116 refDesignator.Replace( "~", " " );
1117
1118 wxString prefix = refDesignator;
1119
1120 while( prefix.Length() )
1121 {
1122 if( ( prefix.Last() < '0' || prefix.Last() > '9') && prefix.Last() != '?' )
1123 break;
1124
1125 prefix.RemoveLast();
1126 }
1127
1128 // Avoid a prefix containing trailing/leading spaces
1129 prefix.Trim( true );
1130 prefix.Trim( false );
1131
1132 if( prefix.IsEmpty() )
1133 symbol->SetPrefix( wxString( "U" ) );
1134 else
1135 symbol->SetPrefix( prefix );
1136 }
1137 else if( strCompare( "U", line, &line ) )
1138 {
1139 // This fixes a potentially buggy files caused by unit being set to zero which
1140 // causes netlist issues. See https://bugs.launchpad.net/kicad/+bug/1677282.
1141 int unit = parseInt( aReader, line, &line );
1142
1143 if( unit == 0 )
1144 {
1145 unit = 1;
1146
1147 // Set the file as modified so the user can be warned.
1148 if( m_rootSheet->GetScreen() )
1150 }
1151
1152 symbol->SetUnit( unit );
1153
1154 // Same can also happen with the convert parameter
1155 int convert = parseInt( aReader, line, &line );
1156
1157 if( convert == 0 )
1158 {
1159 convert = 1;
1160
1161 // Set the file as modified so the user can be warned.
1162 if( m_rootSheet->GetScreen() )
1164 }
1165
1166 symbol->SetConvert( convert );
1167
1168 wxString text;
1169 parseUnquotedString( text, aReader, line, &line );
1170
1171 if( text != "00000000" )
1172 const_cast<KIID&>( symbol->m_Uuid ) = KIID( text );
1173 }
1174 else if( strCompare( "P", line, &line ) )
1175 {
1176 VECTOR2I pos;
1177
1178 pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1179 pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1180 symbol->SetPosition( pos );
1181 }
1182 else if( strCompare( "AR", line, &line ) )
1183 {
1184 const char* strCompare = "Path=";
1185 int len = strlen( strCompare );
1186
1187 if( strncasecmp( strCompare, line, len ) != 0 )
1188 SCH_PARSE_ERROR( "missing 'Path=' token", aReader, line );
1189
1190 line += len;
1191 wxString pathStr, reference, unit;
1192
1193 parseQuotedString( pathStr, aReader, line, &line );
1194
1195 // Note: AR path excludes root sheet, but includes symbol. Drop the symbol ID
1196 // since it's already defined in the symbol itself.
1197 KIID_PATH path( pathStr );
1198
1199 if( path.size() > 0 )
1200 path.pop_back();
1201
1202 // In the new file format, the root schematic UUID is used as the virtual SCH_SHEET
1203 // UUID so we need to prefix it to the symbol path so the symbol instance paths
1204 // get saved with the root schematic UUID.
1205 if( !m_appending )
1206 path.insert( path.begin(), m_rootSheet->GetScreen()->GetUuid() );
1207
1208 strCompare = "Ref=";
1209 len = strlen( strCompare );
1210
1211 if( strncasecmp( strCompare, line, len ) != 0 )
1212 SCH_PARSE_ERROR( "missing 'Ref=' token", aReader, line );
1213
1214 line+= len;
1215 parseQuotedString( reference, aReader, line, &line );
1216
1217 strCompare = "Part=";
1218 len = strlen( strCompare );
1219
1220 if( strncasecmp( strCompare, line, len ) != 0 )
1221 SCH_PARSE_ERROR( "missing 'Part=' token", aReader, line );
1222
1223 line+= len;
1224 parseQuotedString( unit, aReader, line, &line );
1225
1226 long tmp;
1227
1228 if( !unit.ToLong( &tmp, 10 ) )
1229 SCH_PARSE_ERROR( "expected integer value", aReader, line );
1230
1231 if( tmp < 0 || tmp > MAX_UNIT_COUNT_PER_PACKAGE )
1232 SCH_PARSE_ERROR( "unit value out of range", aReader, line );
1233
1234 symbol->AddHierarchicalReference( path, reference, (int)tmp );
1235 symbol->GetField( REFERENCE_FIELD )->SetText( reference );
1236 }
1237 else if( strCompare( "F", line, &line ) )
1238 {
1239 int index = parseInt( aReader, line, &line );
1240
1241 wxString text, name;
1242
1243 parseQuotedString( text, aReader, line, &line, true );
1244
1245 char orientation = parseChar( aReader, line, &line );
1246 VECTOR2I pos;
1247 pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1248 pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1249 int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1250 int attributes = parseHex( aReader, line, &line );
1251
1252 if( index >= symbol->GetFieldCount() )
1253 {
1254 // The first MANDATOR_FIELDS _must_ be constructed within the SCH_SYMBOL
1255 // constructor. This assert is simply here to guard against a change in that
1256 // constructor.
1257 wxASSERT( symbol->GetFieldCount() >= MANDATORY_FIELDS );
1258
1259 // Ignore the _supplied_ fieldNdx. It is not important anymore if within the
1260 // user defined fields region (i.e. >= MANDATORY_FIELDS).
1261 // We freely renumber the index to fit the next available field slot.
1262 index = symbol->GetFieldCount(); // new has this index after insertion
1263
1264 SCH_FIELD field( VECTOR2I( 0, 0 ), index, symbol.get(), name );
1265 symbol->AddField( field );
1266 }
1267
1268 SCH_FIELD& field = symbol->GetFields()[index];
1269
1270 // Prior to version 2 of the schematic file format, none of the following existed.
1271 if( m_version > 1 )
1272 {
1273 wxString textAttrs;
1274 char hjustify = parseChar( aReader, line, &line );
1275
1276 parseUnquotedString( textAttrs, aReader, line, &line );
1277
1278 // The name of the field is optional.
1279 parseQuotedString( name, aReader, line, &line, true );
1280
1281 if( hjustify == 'L' )
1283 else if( hjustify == 'R' )
1285 else if( hjustify != 'C' )
1286 SCH_PARSE_ERROR( "symbol field text horizontal justification must be "
1287 "L, R, or C", aReader, line );
1288
1289 // We are guaranteed to have a least one character here for older file formats
1290 // otherwise an exception would have been raised..
1291 if( textAttrs[0] == 'T' )
1293 else if( textAttrs[0] == 'B' )
1295 else if( textAttrs[0] != 'C' )
1296 SCH_PARSE_ERROR( "symbol field text vertical justification must be "
1297 "B, T, or C", aReader, line );
1298
1299 // Newer file formats include the bold and italics text attribute.
1300 if( textAttrs.Length() > 1 )
1301 {
1302 if( textAttrs.Length() != 3 )
1303 {
1304 SCH_PARSE_ERROR( _( "symbol field text attributes must be 3 characters wide" ),
1305 aReader, line );
1306 }
1307
1308 if( textAttrs[1] == 'I' )
1309 {
1310 field.SetItalic( true );
1311 }
1312 else if( textAttrs[1] != 'N' )
1313 {
1314 SCH_PARSE_ERROR( "symbol field text italics indicator must be I or N",
1315 aReader, line );
1316 }
1317
1318 if( textAttrs[2] == 'B' )
1319 {
1320 field.SetBold( true );
1321 }
1322 else if( textAttrs[2] != 'N' )
1323 {
1324 SCH_PARSE_ERROR( "symbol field text bold indicator must be B or N",
1325 aReader, line );
1326 }
1327 }
1328 }
1329
1330 field.SetText( text );
1331 field.SetTextPos( pos );
1332 field.SetVisible( !attributes );
1333 field.SetTextSize( wxSize( size, size ) );
1334
1335 if( orientation == 'H' )
1337 else if( orientation == 'V' )
1339 else
1340 SCH_PARSE_ERROR( "symbol field orientation must be H or V", aReader, line );
1341
1342 if( name.IsEmpty() )
1344
1345 field.SetName( name );
1346 }
1347 else if( strCompare( "$EndComp", line ) )
1348 {
1349 if( !m_appending )
1350 {
1352 {
1354 path.push_back( m_rootSheet->GetScreen()->GetUuid() );
1355 symbol->AddHierarchicalReference( path,
1356 symbol->GetField( REFERENCE_FIELD )->GetText(),
1357 symbol->GetUnit(),
1358 symbol->GetField( VALUE_FIELD )->GetText(),
1359 symbol->GetField( FOOTPRINT_FIELD )->GetText() );
1360 }
1361 else
1362 {
1363 for( const SYMBOL_INSTANCE_REFERENCE& instance : symbol->GetInstanceReferences() )
1364 {
1365 symbol->AddHierarchicalReference( instance.m_Path, instance.m_Reference,
1366 instance.m_Unit,
1367 symbol->GetField( VALUE_FIELD )->GetText(),
1368 symbol->GetField( FOOTPRINT_FIELD )->GetText() );
1369 }
1370 }
1371 }
1372
1373 // Ensure all flags (some are set by previous initializations) are reset:
1374 symbol->ClearFlags();
1375 return symbol.release();
1376 }
1377 else
1378 {
1379 // There are two lines that begin with a tab or spaces that includes a line with the
1380 // redundant position information and the transform matrix settings.
1381
1382 // Parse the redundant position information just the same to check for formatting
1383 // errors.
1384 parseInt( aReader, line, &line ); // Always 1.
1385 parseInt( aReader, line, &line ); // The X coordinate.
1386 parseInt( aReader, line, &line ); // The Y coordinate.
1387
1388 line = aReader.ReadLine();
1389
1390 TRANSFORM transform;
1391
1392 transform.x1 = parseInt( aReader, line, &line );
1393
1394 if( transform.x1 < -1 || transform.x1 > 1 )
1395 SCH_PARSE_ERROR( "invalid symbol X1 transform value", aReader, line );
1396
1397 transform.y1 = parseInt( aReader, line, &line );
1398
1399 if( transform.y1 < -1 || transform.y1 > 1 )
1400 SCH_PARSE_ERROR( "invalid symbol Y1 transform value", aReader, line );
1401
1402 transform.x2 = parseInt( aReader, line, &line );
1403
1404 if( transform.x2 < -1 || transform.x2 > 1 )
1405 SCH_PARSE_ERROR( "invalid symbol X2 transform value", aReader, line );
1406
1407 transform.y2 = parseInt( aReader, line, &line );
1408
1409 if( transform.y2 < -1 || transform.y2 > 1 )
1410 SCH_PARSE_ERROR( "invalid symbol Y2 transform value", aReader, line );
1411
1412 symbol->SetTransform( transform );
1413 }
1414
1415 line = aReader.ReadLine();
1416 }
1417
1418 SCH_PARSE_ERROR( "invalid symbol line", aReader, line );
1419
1420 return nullptr; // Prevents compiler warning. Should never get here.
1421}
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:371
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:248
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:217
void SetBold(bool aBold)
Definition: eda_text.cpp:209
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:193
void SetItalic(bool aItalic)
Definition: eda_text.cpp:201
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:240
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:50
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:109
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
Definition: richio.h:109
void SetName(const wxString &aName)
Definition: sch_field.h:114
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:47
int x2
Definition: transform.h:51
int y1
Definition: transform.h:50
int y2
Definition: transform.h:52
int x1
Definition: transform.h:49
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:408
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:409
#define MAX_UNIT_COUNT_PER_PACKAGE
The maximum number of units per package.
Definition: eeschema_id.h:44
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
uint32_t parseHex(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parse an ASCII hex integer string with possible leading whitespace into a long integer and updates th...
A simple container for schematic symbol instance information.
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_TOP
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References _, ANGLE_HORIZONTAL, ANGLE_VERTICAL, convert, FOOTPRINT_FIELD, TEMPLATE_FIELDNAME::GetDefaultFieldName(), SCH_SHEET::GetScreen(), LINE_READER::GetSource(), SCH_SCREEN::GetUuid(), GR_TEXT_H_ALIGN_LEFT, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_BOTTOM, GR_TEXT_V_ALIGN_TOP, LINE_READER::Line(), LINE_READER::LineNumber(), m_appending, m_currentSheet, m_rootSheet, m_version, MANDATORY_FIELDS, MAX_UNIT_COUNT_PER_PACKAGE, EDA_IU_SCALE::MilsToIU(), name, LIB_ID::Parse(), parseChar(), parseHex(), parseInt(), parseQuotedString(), parseUnquotedString(), path, LINE_READER::ReadLine(), REFERENCE_FIELD, SCH_PARSE_ERROR, schIUScale, 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, THROW_PARSE_ERROR, VALUE_FIELD, VECTOR2< T >::x, TRANSFORM::x1, TRANSFORM::x2, VECTOR2< T >::y, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by LoadContent().

◆ loadText()

SCH_TEXT * SCH_LEGACY_PLUGIN::loadText ( LINE_READER aReader)
private

Definition at line 943 of file sch_legacy_plugin.cpp.

944{
945 const char* line = aReader.Line();
946 KICAD_T textType = TYPE_NOT_INIT;
947
948 wxCHECK( strCompare( "Text", line, &line ), nullptr );
949
950 if( strCompare( "Notes", line, &line ) )
951 {
952 textType = SCH_TEXT_T;
953 }
954 else if( strCompare( "Label", line, &line ) )
955 {
956 textType = SCH_LABEL_T;
957 }
958 else if( strCompare( "HLabel", line, &line ) )
959 {
960 textType = SCH_HIER_LABEL_T;
961 }
962 else if( strCompare( "GLabel", line, &line ) )
963 {
964 // Prior to version 2, the SCH_GLOBALLABEL object did not exist.
965 if( m_version == 1 )
966 textType = SCH_HIER_LABEL_T;
967 else
968 textType = SCH_GLOBAL_LABEL_T;
969 }
970 else
971 {
972 SCH_PARSE_ERROR( "unknown Text type", aReader, line );
973 }
974
975 VECTOR2I position;
976
977 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
978 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
979
980 std::unique_ptr<SCH_TEXT> text;
981
982 switch( textType )
983 {
984 case SCH_TEXT_T: text.reset( new SCH_TEXT( position ) ); break;
985 case SCH_LABEL_T: text.reset( new SCH_LABEL( position ) ); break;
986 case SCH_HIER_LABEL_T: text.reset( new SCH_HIERLABEL( position ) ); break;
987 case SCH_GLOBAL_LABEL_T: text.reset( new SCH_GLOBALLABEL( position ) ); break;
988 default: break;
989 }
990
991 int spinStyle = parseInt( aReader, line, &line );
992
993 // Sadly we store the orientation of hierarchical and global labels using a different
994 // int encoding than that for local labels:
995 // Global Local
996 // Left justified 0 2
997 // Up 1 3
998 // Right justified 2 0
999 // Down 3 1
1000 // So we must flip it as the enum is setup with the "global" numbering
1001 if( text->Type() != SCH_GLOBAL_LABEL_T && text->Type() != SCH_HIER_LABEL_T )
1002 {
1003 if( spinStyle == 0 )
1004 spinStyle = 2;
1005 else if( spinStyle == 2 )
1006 spinStyle = 0;
1007 }
1008
1009 text->SetTextSpinStyle( static_cast<TEXT_SPIN_STYLE::SPIN>( spinStyle ) );
1010
1011 int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1012
1013 text->SetTextSize( wxSize( size, size ) );
1014
1015 // Parse the global and hierarchical label type.
1016 if( text->Type() == SCH_HIER_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
1017 {
1018 auto resultIt = std::find_if( sheetLabelNames.begin(), sheetLabelNames.end(),
1019 [ &line ]( const auto& it )
1020 {
1021 return strCompare( it.second, line, &line );
1022 } );
1023
1024 if( resultIt != sheetLabelNames.end() )
1025 text->SetShape( resultIt->first );
1026 else
1027 SCH_PARSE_ERROR( "invalid label type", aReader, line );
1028 }
1029
1030 int penWidth = 0;
1031
1032 // The following tokens do not exist in version 1 schematic files,
1033 // and not always in version 2 for HLabels and GLabels
1034 if( m_version > 1 )
1035 {
1036 if( m_version > 2 || *line >= ' ' )
1037 {
1038 if( strCompare( "Italic", line, &line ) )
1039 text->SetItalic( true );
1040 else if( !strCompare( "~", line, &line ) )
1041 SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
1042 }
1043
1044 // The penWidth token does not exist in older versions of the schematic file format
1045 // so calling parseInt will be made only if the EOL is not reached.
1046 if( *line >= ' ' )
1047 penWidth = parseInt( aReader, line, &line );
1048 }
1049
1050 text->SetBold( penWidth != 0 );
1051 text->SetTextThickness( penWidth != 0 ? GetPenSizeForBold( size ) : 0 );
1052
1053 // Read the text string for the text.
1054 char* tmp = aReader.ReadLine();
1055
1056 tmp = strtok( tmp, "\r\n" );
1057 wxString val = FROM_UTF8( tmp );
1058
1059 for( ; ; )
1060 {
1061 int i = val.find( wxT( "\\n" ) );
1062
1063 if( i == wxNOT_FOUND )
1064 break;
1065
1066 val.erase( i, 2 );
1067 val.insert( i, wxT( "\n" ) );
1068 }
1069
1070 text->SetText( ConvertToNewOverbarNotation( val ) );
1071
1072 return text.release();
1073}
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40
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
const std::map< LABEL_FLAG_SHAPE, const char * > sheetLabelNames
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ TYPE_NOT_INIT
Definition: typeinfo.h:81

References _, ConvertToNewOverbarNotation(), FROM_UTF8(), GetPenSizeForBold(), LINE_READER::Line(), m_version, EDA_IU_SCALE::MilsToIU(), parseInt(), LINE_READER::ReadLine(), SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_LABEL_T, SCH_PARSE_ERROR, SCH_TEXT_T, schIUScale, sheetLabelNames, strCompare(), text, TYPE_NOT_INIT, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by LoadContent().

◆ loadWire()

SCH_LINE * SCH_LEGACY_PLUGIN::loadWire ( LINE_READER aReader)
private

Definition at line 778 of file sch_legacy_plugin.cpp.

779{
780 std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
781
782 const char* line = aReader.Line();
783
784 wxCHECK( strCompare( "Wire", line, &line ), nullptr );
785
786 if( strCompare( "Wire", line, &line ) )
787 wire->SetLayer( LAYER_WIRE );
788 else if( strCompare( "Bus", line, &line ) )
789 wire->SetLayer( LAYER_BUS );
790 else if( strCompare( "Notes", line, &line ) )
791 wire->SetLayer( LAYER_NOTES );
792 else
793 SCH_PARSE_ERROR( "invalid line type", aReader, line );
794
795 if( !strCompare( "Line", line, &line ) )
796 SCH_PARSE_ERROR( "invalid wire definition", aReader, line );
797
798 // Since Sept 15, 2017, a line style is alloved (width, style, color)
799 // Only non default values are stored
800 while( !is_eol( *line ) )
801 {
802 wxString buf;
803
804 parseUnquotedString( buf, aReader, line, &line );
805
806 if( buf == ")" )
807 continue;
808
809 else if( buf == T_WIDTH )
810 {
811 int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
812 wire->SetLineWidth( size );
813 }
814 else if( buf == T_STYLE )
815 {
816 parseUnquotedString( buf, aReader, line, &line );
817
818 if( buf == wxT( "solid" ) )
819 wire->SetLineStyle( PLOT_DASH_TYPE::SOLID );
820 else if( buf == wxT( "dashed" ) )
821 wire->SetLineStyle( PLOT_DASH_TYPE::DASH );
822 else if( buf == wxT( "dash_dot" ) )
823 wire->SetLineStyle( PLOT_DASH_TYPE::DASHDOT );
824 else if( buf == wxT( "dotted" ) )
825 wire->SetLineStyle( PLOT_DASH_TYPE::DOT );
826 }
827 else // should be the color parameter.
828 {
829 // The color param is something like rgb(150, 40, 191)
830 // and because there is no space between ( and 150
831 // the first param is inside buf.
832 // So break keyword and the first param into 2 separate strings.
833 wxString prm, keyword;
834 keyword = buf.BeforeLast( '(', &prm );
835
836 if( ( keyword == T_COLOR ) || ( keyword == T_COLORA ) )
837 {
838 long color[4] = { 0 };
839
840 int ii = 0;
841
842 if( !prm.IsEmpty() )
843 {
844 prm.ToLong( &color[ii] );
845 ii++;
846 }
847
848 int prm_count = ( keyword == T_COLORA ) ? 4 : 3;
849
850 // fix opacity to 1.0 or 255, when not exists in file
851 color[3] = 255;
852
853 for(; ii < prm_count && !is_eol( *line ); ii++ )
854 {
855 color[ii] = parseInt( aReader, line, &line );
856
857 // Skip the separator between values
858 if( *line == ',' || *line == ' ')
859 line++;
860 }
861
862 wire->SetLineColor( color[0]/255.0, color[1]/255.0, color[2]/255.0,color[3]/255.0 );
863 }
864 }
865 }
866
867 // Read the segment en points coordinates:
868 line = aReader.ReadLine();
869
870 VECTOR2I begin, end;
871
872 begin.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
873 begin.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
874 end.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
875 end.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
876
877 wire->SetStartPoint( begin );
878 wire->SetEndPoint( end );
879
880 return wire.release();
881}
int color
Definition: DXF_plotter.cpp:57
@ LAYER_WIRE
Definition: layer_ids.h:344
@ LAYER_NOTES
Definition: layer_ids.h:358
@ LAYER_BUS
Definition: layer_ids.h:345
#define T_COLORA
#define T_WIDTH
#define T_COLOR
#define T_STYLE
bool is_eol(char c)

References color, DASH, DASHDOT, DOT, is_eol(), LAYER_BUS, LAYER_NOTES, LAYER_WIRE, LINE_READER::Line(), EDA_IU_SCALE::MilsToIU(), parseInt(), parseUnquotedString(), LINE_READER::ReadLine(), SCH_PARSE_ERROR, schIUScale, SOLID, strCompare(), T_COLOR, T_COLORA, T_STYLE, T_WIDTH, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by LoadContent().

◆ ParsePart()

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

Definition at line 2252 of file sch_legacy_plugin.cpp.

2254{
2255 return SCH_LEGACY_PLUGIN_CACHE::LoadPart( reader, aMajorVersion, aMinorVersion );
2256}
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 STRING_UTF8_MAP 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 1449 of file sch_legacy_plugin.cpp.

1451{
1452 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
1453 wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1454
1455 LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
1456
1457 init( aSchematic, aProperties );
1458
1459 wxFileName fn = aFileName;
1460
1461 // File names should be absolute. Don't assume everything relative to the project path
1462 // works properly.
1463 wxASSERT( fn.IsAbsolute() );
1464
1465 FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1466
1467 m_out = &formatter; // no ownership
1468
1469 Format( aSheet );
1470
1471 aSheet->GetScreen()->SetFileExists( true );
1472}
Used for text file output.
Definition: richio.h:457
void Format(SCH_SHEET *aSheet)

References Format(), SCH_SHEET::GetScreen(), init(), m_out, and SCH_SCREEN::SetFileExists().

◆ saveBitmap()

void SCH_LEGACY_PLUGIN::saveBitmap ( SCH_BITMAP aBitmap)
private

Definition at line 1759 of file sch_legacy_plugin.cpp.

1760{
1761 wxCHECK_RET( aBitmap != nullptr, "SCH_BITMAP* is NULL" );
1762
1763 const wxImage* image = aBitmap->GetImage()->GetImageData();
1764
1765 wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
1766
1767 m_out->Print( 0, "$Bitmap\n" );
1768 m_out->Print( 0, "Pos %-4d %-4d\n",
1769 schIUScale.IUToMils( aBitmap->GetPosition().x ),
1770 schIUScale.IUToMils( aBitmap->GetPosition().y ) );
1771 m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
1772 m_out->Print( 0, "Data\n" );
1773
1774 wxMemoryOutputStream stream;
1775
1776 image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1777
1778 // Write binary data in hexadecimal form (ASCII)
1779 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1780 char* begin = (char*) buffer->GetBufferStart();
1781
1782 for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
1783 {
1784 if( ii >= 32 )
1785 {
1786 ii = 0;
1787
1788 m_out->Print( 0, "\n" );
1789 }
1790
1791 m_out->Print( 0, "%2.2X ", *begin & 0xFF );
1792 }
1793
1794 m_out->Print( 0, "\nEndData\n" );
1795 m_out->Print( 0, "$EndBitmap\n" );
1796}
double GetScale() const
Definition: bitmap_base.h:78
wxImage * GetImageData()
Definition: bitmap_base.h:69
VECTOR2I GetPosition() const override
Definition: sch_bitmap.h:136
BITMAP_BASE * GetImage() const
Definition: sch_bitmap.h:54
constexpr int IUToMils(int iu) const
Definition: base_units.h:100

References SCH_BITMAP::GetImage(), BITMAP_BASE::GetImageData(), SCH_BITMAP::GetPosition(), BITMAP_BASE::GetScale(), image, EDA_IU_SCALE::IUToMils(), m_out, OUTPUTFORMATTER::Print(), schIUScale, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ saveBusAlias()

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

Definition at line 2027 of file sch_legacy_plugin.cpp.

2028{
2029 wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" );
2030
2031 wxString members = boost::algorithm::join( aAlias->Members(), " " );
2032
2033 m_out->Print( 0, "BusAlias %s %s\n",
2034 TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
2035}

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 1887 of file sch_legacy_plugin.cpp.

1888{
1889 wxCHECK_RET( aBusEntry != nullptr, "SCH_BUS_ENTRY_BASE* is NULL" );
1890
1891 if( aBusEntry->GetLayer() == LAYER_WIRE )
1892 {
1893 m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
1894 schIUScale.IUToMils( aBusEntry->GetPosition().x ),
1895 schIUScale.IUToMils( aBusEntry->GetPosition().y ),
1896 schIUScale.IUToMils( aBusEntry->GetEnd().x ),
1897 schIUScale.IUToMils( aBusEntry->GetEnd().y ) );
1898 }
1899 else
1900 {
1901 m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
1902 schIUScale.IUToMils( aBusEntry->GetPosition().x ),
1903 schIUScale.IUToMils( aBusEntry->GetPosition().y ),
1904 schIUScale.IUToMils( aBusEntry->GetEnd().x ),
1905 schIUScale.IUToMils( aBusEntry->GetEnd().y ) );
1906 }
1907}
VECTOR2I GetPosition() const override
VECTOR2I GetEnd() const
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:246

References SCH_BUS_ENTRY_BASE::GetEnd(), SCH_ITEM::GetLayer(), SCH_BUS_ENTRY_BASE::GetPosition(), EDA_IU_SCALE::IUToMils(), LAYER_WIRE, m_out, OUTPUTFORMATTER::Print(), schIUScale, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ saveField()

void SCH_LEGACY_PLUGIN::saveField ( SCH_FIELD aField)
private

Definition at line 1723 of file sch_legacy_plugin.cpp.

1724{
1725 char hjustify = 'C';
1726
1727 if( aField->GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
1728 hjustify = 'L';
1729 else if( aField->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
1730 hjustify = 'R';
1731
1732 char vjustify = 'C';
1733
1734 if( aField->GetVertJustify() == GR_TEXT_V_ALIGN_BOTTOM )
1735 vjustify = 'B';
1736 else if( aField->GetVertJustify() == GR_TEXT_V_ALIGN_TOP )
1737 vjustify = 'T';
1738
1739 m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1740 aField->GetId(),
1741 EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
1742 aField->GetTextAngle().IsHorizontal() ? 'H' : 'V',
1743 schIUScale.IUToMils( aField->GetLibPosition().x ),
1744 schIUScale.IUToMils( aField->GetLibPosition().y ),
1745 schIUScale.IUToMils( aField->GetTextWidth() ),
1746 !aField->IsVisible(),
1747 hjustify, vjustify,
1748 aField->IsItalic() ? 'I' : 'N',
1749 aField->IsBold() ? 'B' : 'N' );
1750
1751 // Save field name, if the name is user definable
1752 if( aField->GetId() >= MANDATORY_FIELDS )
1753 m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
1754
1755 m_out->Print( 0, "\n" );
1756}
bool IsHorizontal() const
Definition: eda_angle.h:174
bool IsItalic() const
Definition: eda_text.h:123
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:120
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
virtual bool IsVisible() const
Definition: eda_text.h:129
int GetTextWidth() const
Definition: eda_text.h:192
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:142
bool IsBold() const
Definition: eda_text.h:126
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:145
int GetId() const
Definition: sch_field.h:116
VECTOR2I GetLibPosition() const
Definition: sch_field.h:217
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:827

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_H_ALIGN_LEFT, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_BOTTOM, GR_TEXT_V_ALIGN_TOP, EDA_TEXT::IsBold(), EDA_ANGLE::IsHorizontal(), EDA_TEXT::IsItalic(), EDA_TEXT::IsVisible(), EDA_IU_SCALE::IUToMils(), m_out, MANDATORY_FIELDS, OUTPUTFORMATTER::Print(), schIUScale, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by saveSymbol().

◆ saveJunction()

void SCH_LEGACY_PLUGIN::saveJunction ( SCH_JUNCTION aJunction)
private

Definition at line 1867 of file sch_legacy_plugin.cpp.

1868{
1869 wxCHECK_RET( aJunction != nullptr, "SCH_JUNCTION* is NULL" );
1870
1871 m_out->Print( 0, "Connection ~ %-4d %-4d\n",
1872 schIUScale.IUToMils( aJunction->GetPosition().x ),
1873 schIUScale.IUToMils( aJunction->GetPosition().y ) );
1874}
VECTOR2I GetPosition() const override
Definition: sch_junction.h:102

References SCH_JUNCTION::GetPosition(), EDA_IU_SCALE::IUToMils(), m_out, OUTPUTFORMATTER::Print(), schIUScale, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ SaveLibrary()

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

Reimplemented from SCH_PLUGIN.

Definition at line 2211 of file sch_legacy_plugin.cpp.

2212{
2213 if( !m_cache )
2214 m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
2215
2216 wxString oldFileName = m_cache->GetFileName();
2217
2218 if( !m_cache->IsFile( aLibraryPath ) )
2219 {
2220 m_cache->SetFileName( aLibraryPath );
2221 }
2222
2223 // This is a forced save.
2225 m_cache->Save( writeDocFile( aProperties ) );
2226 m_cache->SetFileName( oldFileName );
2227}
wxString GetFileName() const
void SetFileName(const wxString &aFileName)

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

◆ saveLine()

void SCH_LEGACY_PLUGIN::saveLine ( SCH_LINE aLine)
private

Definition at line 1910 of file sch_legacy_plugin.cpp.

1911{
1912 wxCHECK_RET( aLine != nullptr, "SCH_LINE* is NULL" );
1913
1914 const char* layer = "Notes";
1915 const char* width = "Line";
1916
1917 if( aLine->GetLayer() == LAYER_WIRE )
1918 layer = "Wire";
1919 else if( aLine->GetLayer() == LAYER_BUS )
1920 layer = "Bus";
1921
1922 m_out->Print( 0, "Wire %s %s", layer, width );
1923
1924 // Write line style (width, type, color) only for non default values
1925 if( aLine->IsGraphicLine() )
1926 {
1927 if( aLine->GetLineSize() != 0 )
1928 m_out->Print( 0, " %s %d", T_WIDTH, schIUScale.IUToMils( aLine->GetLineSize() ) );
1929
1930 m_out->Print( 0, " %s %s", T_STYLE,
1932
1933 if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
1934 {
1935 m_out->Print( 0, " %s",
1936 TO_UTF8( aLine->GetLineColor().ToCSSString() ) );
1937 }
1938 }
1939
1940 m_out->Print( 0, "\n" );
1941
1942 m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
1943 schIUScale.IUToMils( aLine->GetStartPoint().x ),
1944 schIUScale.IUToMils( aLine->GetStartPoint().y ),
1945 schIUScale.IUToMils( aLine->GetEndPoint().x ),
1946 schIUScale.IUToMils( aLine->GetEndPoint().y ) );
1947
1948 m_out->Print( 0, "\n");
1949}
int GetLineSize() const
Definition: sch_line.h:189
VECTOR2I GetEndPoint() const
Definition: sch_line.h:137
VECTOR2I GetStartPoint() const
Definition: sch_line.h:132
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:263
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:919
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:237
static wxString GetLineStyleToken(PLOT_DASH_TYPE aStyle)

References SCH_LINE::GetEndPoint(), SCH_ITEM::GetLayer(), SCH_LINE::GetLineColor(), SCH_LINE::GetLineSize(), SCH_LINE::GetLineStyle(), STROKE_PARAMS::GetLineStyleToken(), SCH_LINE::GetStartPoint(), SCH_LINE::IsGraphicLine(), EDA_IU_SCALE::IUToMils(), LAYER_BUS, LAYER_WIRE, m_out, OUTPUTFORMATTER::Print(), schIUScale, T_STYLE, T_WIDTH, TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ saveNoConnect()

void SCH_LEGACY_PLUGIN::saveNoConnect ( SCH_NO_CONNECT aNoConnect)
private

Definition at line 1877 of file sch_legacy_plugin.cpp.

1878{
1879 wxCHECK_RET( aNoConnect != nullptr, "SCH_NOCONNECT* is NULL" );
1880
1881 m_out->Print( 0, "NoConn ~ %-4d %-4d\n",
1882 schIUScale.IUToMils( aNoConnect->GetPosition().x ),
1883 schIUScale.IUToMils( aNoConnect->GetPosition().y ) );
1884}
VECTOR2I GetPosition() const override

References SCH_NO_CONNECT::GetPosition(), EDA_IU_SCALE::IUToMils(), m_out, OUTPUTFORMATTER::Print(), schIUScale, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ saveSheet()

void SCH_LEGACY_PLUGIN::saveSheet ( SCH_SHEET aSheet)
private

Definition at line 1799 of file sch_legacy_plugin.cpp.

1800{
1801 wxCHECK_RET( aSheet != nullptr, "SCH_SHEET* is NULL" );
1802
1803 m_out->Print( 0, "$Sheet\n" );
1804 m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
1805 schIUScale.IUToMils( aSheet->GetPosition().x ),
1806 schIUScale.IUToMils( aSheet->GetPosition().y ),
1807 schIUScale.IUToMils( aSheet->GetSize().x ),
1808 schIUScale.IUToMils( aSheet->GetSize().y ) );
1809
1810 m_out->Print( 0, "U %8.8X\n", aSheet->m_Uuid.AsLegacyTimestamp() );
1811
1812 SCH_FIELD& sheetName = aSheet->GetFields()[SHEETNAME];
1813 SCH_FIELD& fileName = aSheet->GetFields()[SHEETFILENAME];
1814
1815 if( !sheetName.GetText().IsEmpty() )
1816 {
1817 m_out->Print( 0, "F0 %s %d\n",
1818 EscapedUTF8( sheetName.GetText() ).c_str(),
1819 schIUScale.IUToMils( sheetName.GetTextSize().x ) );
1820 }
1821
1822 if( !fileName.GetText().IsEmpty() )
1823 {
1824 m_out->Print( 0, "F1 %s %d\n",
1825 EscapedUTF8( fileName.GetText() ).c_str(),
1826 schIUScale.IUToMils( fileName.GetTextSize().x ) );
1827 }
1828
1829 for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
1830 {
1831 int type, side;
1832
1833 if( pin->GetText().IsEmpty() )
1834 break;
1835
1836 switch( pin->GetSide() )
1837 {
1838 default:
1839 case SHEET_SIDE::LEFT: side = 'L'; break;
1840 case SHEET_SIDE::RIGHT: side = 'R'; break;
1841 case SHEET_SIDE::TOP: side = 'T'; break;
1842 case SHEET_SIDE::BOTTOM: side = 'B'; break;
1843 }
1844
1845 switch( pin->GetShape() )
1846 {
1847 default:
1848 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: type = 'U'; break;
1849 case LABEL_FLAG_SHAPE::L_INPUT: type = 'I'; break;
1850 case LABEL_FLAG_SHAPE::L_OUTPUT: type = 'O'; break;
1851 case LABEL_FLAG_SHAPE::L_BIDI: type = 'B'; break;
1852 case LABEL_FLAG_SHAPE::L_TRISTATE: type = 'T'; break;
1853 }
1854
1855 m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n",
1856 pin->GetNumber(),
1857 EscapedUTF8( pin->GetText() ).c_str(), // supplies wrapping quotes
1858 type, side, schIUScale.IUToMils( pin->GetPosition().x ),
1859 schIUScale.IUToMils( pin->GetPosition().y ),
1860 schIUScale.IUToMils( pin->GetTextWidth() ) );
1861 }
1862
1863 m_out->Print( 0, "$EndSheet\n" );
1864}
VECTOR2I GetTextSize() const
Definition: eda_text.h:189
timestamp_t AsLegacyTimestamp() const
Definition: kiid.cpp:224
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:91
VECTOR2I GetPosition() const override
Definition: sch_sheet.h:365
wxSize GetSize() const
Definition: sch_sheet.h:105
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:172
@ SHEETNAME
Definition: sch_sheet.h:43
@ SHEETFILENAME
Definition: sch_sheet.h:44

References KIID::AsLegacyTimestamp(), BOTTOM, EscapedUTF8(), SCH_SHEET::GetFields(), SCH_SHEET::GetPins(), SCH_SHEET::GetPosition(), SCH_SHEET::GetSize(), EDA_TEXT::GetText(), EDA_TEXT::GetTextSize(), EDA_IU_SCALE::IUToMils(), L_BIDI, L_INPUT, L_OUTPUT, L_TRISTATE, L_UNSPECIFIED, LEFT, m_out, EDA_ITEM::m_Uuid, pin, OUTPUTFORMATTER::Print(), RIGHT, schIUScale, SHEETFILENAME, SHEETNAME, TOP, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ SaveSymbol()

void SCH_LEGACY_PLUGIN::SaveSymbol ( const wxString &  aLibraryPath,
const LIB_SYMBOL aSymbol,
const STRING_UTF8_MAP 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 2138 of file sch_legacy_plugin.cpp.

2140{
2141 LOCALE_IO toggle; // toggles on, then off, the C locale.
2142
2143 cacheLib( aLibraryPath, aProperties );
2144
2145 m_cache->AddSymbol( aSymbol );
2146
2147 if( !isBuffering( aProperties ) )
2148 m_cache->Save( writeDocFile( aProperties ) );
2149}
virtual void AddSymbol(const LIB_SYMBOL *aSymbol)

References SCH_LIB_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 1617 of file sch_legacy_plugin.cpp.

1618{
1619 std::string name1;
1620 std::string name2;
1621
1622 static wxString delimiters( wxT( " " ) );
1623
1624 // This is redundant with the AR entries below, but it makes the files backwards-compatible.
1625 if( aSymbol->GetInstanceReferences().size() > 0 )
1626 {
1627 const SYMBOL_INSTANCE_REFERENCE& instance = aSymbol->GetInstanceReferences()[0];
1628 name1 = toUTFTildaText( instance.m_Reference );
1629 }
1630 else
1631 {
1632 if( aSymbol->GetField( REFERENCE_FIELD )->GetText().IsEmpty() )
1633 name1 = toUTFTildaText( aSymbol->GetPrefix() );
1634 else
1635 name1 = toUTFTildaText( aSymbol->GetField( REFERENCE_FIELD )->GetText() );
1636 }
1637
1638 wxString symbol_name = aSymbol->GetLibId().Format();
1639
1640 if( symbol_name.size() )
1641 {
1642 name2 = toUTFTildaText( symbol_name );
1643 }
1644 else
1645 {
1646 name2 = "_NONAME_";
1647 }
1648
1649 m_out->Print( 0, "$Comp\n" );
1650 m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
1651
1652 // Generate unit number, conversion and timestamp
1653 m_out->Print( 0, "U %d %d %8.8X\n",
1654 aSymbol->GetUnit(),
1655 aSymbol->GetConvert(),
1656 aSymbol->m_Uuid.AsLegacyTimestamp() );
1657
1658 // Save the position
1659 m_out->Print( 0, "P %d %d\n",
1660 schIUScale.IUToMils( aSymbol->GetPosition().x ),
1661 schIUScale.IUToMils( aSymbol->GetPosition().y ) );
1662
1663 /* If this is a complex hierarchy; save hierarchical references.
1664 * but for simple hierarchies it is not necessary.
1665 * the reference inf is already saved
1666 * this is useful for old Eeschema version compatibility
1667 */
1668 if( aSymbol->GetInstanceReferences().size() > 1 )
1669 {
1670 for( const SYMBOL_INSTANCE_REFERENCE& instance : aSymbol->GetInstanceReferences() )
1671 {
1672 /*format:
1673 * AR Path="/140/2" Ref="C99" Part="1"
1674 * where 140 is the uid of the containing sheet and 2 is the timestamp of this symbol.
1675 * (timestamps are actually 8 hex chars)
1676 * Ref is the conventional symbol reference designator for this 'path'
1677 * Part is the conventional symbol unit selection for this 'path'
1678 */
1679 wxString path = "/";
1680
1681 // Skip root sheet
1682 for( int i = 1; i < (int) instance.m_Path.size(); ++i )
1683 path += instance.m_Path[i].AsLegacyTimestampString() + "/";
1684
1685 m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%d\" \n",
1687 TO_UTF8( instance.m_Reference ),
1688 instance.m_Unit );
1689 }
1690 }
1691
1692 // update the ugly field id, which I would like to see go away someday soon.
1693 for( int i = 0; i < aSymbol->GetFieldCount(); ++i )
1694 aSymbol->GetFields()[i].SetId( i );
1695
1696 // Fixed fields:
1697 // Save mandatory fields even if they are blank,
1698 // because the visibility, size and orientation are set from library editor.
1699 for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
1700 saveField( &aSymbol->GetFields()[i] );
1701
1702 // User defined fields:
1703 // The *policy* about which user defined fields are symbol of a symbol is now
1704 // only in the dialog editors. No policy should be enforced here, simply
1705 // save all the user defined fields, they are present because a dialog editor
1706 // thought they should be. If you disagree, go fix the dialog editors.
1707 for( int i = MANDATORY_FIELDS; i < aSymbol->GetFieldCount(); ++i )
1708 saveField( &aSymbol->GetFields()[i] );
1709
1710 // Unit number, position, box ( old standard )
1711 m_out->Print( 0, "\t%-4d %-4d %-4d\n", aSymbol->GetUnit(),
1712 schIUScale.IUToMils( aSymbol->GetPosition().x ),
1713 schIUScale.IUToMils( aSymbol->GetPosition().y ) );
1714
1715 TRANSFORM transform = aSymbol->GetTransform();
1716
1717 m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
1718 transform.x1, transform.y1, transform.x2, transform.y2 );
1719 m_out->Print( 0, "$EndComp\n" );
1720}
wxString AsLegacyTimestampString() const
Definition: kiid.cpp:257
UTF8 Format() const
Definition: lib_id.cpp:117
void saveField(SCH_FIELD *aField)
const std::vector< SYMBOL_INSTANCE_REFERENCE > & GetInstanceReferences()
Definition: sch_symbol.h:139
int GetUnit() const
Definition: sch_symbol.h:225
int GetFieldCount() const
Return the number of fields in this symbol.
Definition: sch_symbol.h:470
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:895
int GetConvert() const
Definition: sch_symbol.h:267
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:718
TRANSFORM & GetTransform()
Definition: sch_symbol.h:275
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:172
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:931
wxString GetPrefix() const
Definition: sch_symbol.h:271
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:47

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(), EDA_IU_SCALE::IUToMils(), m_out, SYMBOL_INSTANCE_REFERENCE::m_Reference, EDA_ITEM::m_Uuid, MANDATORY_FIELDS, path, OUTPUTFORMATTER::Print(), REFERENCE_FIELD, saveField(), schIUScale, TO_UTF8, toUTFTildaText(), VECTOR2< T >::x, TRANSFORM::x1, TRANSFORM::x2, VECTOR2< T >::y, TRANSFORM::y1, and TRANSFORM::y2.

Referenced by Format().

◆ saveText()

void SCH_LEGACY_PLUGIN::saveText ( SCH_TEXT aText)
private

Definition at line 1952 of file sch_legacy_plugin.cpp.

1953{
1954 wxCHECK_RET( aText != nullptr, "SCH_TEXT* is NULL" );
1955
1956 const char* italics = "~";
1957 const char* textType = "Notes";
1958
1959 if( aText->IsItalic() )
1960 italics = "Italic";
1961
1962 wxString text = aText->GetText();
1963
1964 SCH_LAYER_ID layer = aText->GetLayer();
1965
1966 if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
1967 {
1968 if( layer == LAYER_NOTES )
1969 {
1970 // For compatibility reasons, the text must be saved in only one text line
1971 // so replace all EOLs with \\n
1972 text.Replace( wxT( "\n" ), wxT( "\\n" ) );
1973
1974 // Here we should have no CR or LF character in line
1975 // This is not always the case if a multiline text was copied (using a copy/paste
1976 // function) from a text that uses E.O.L characters that differs from the current
1977 // EOL format. This is mainly the case under Linux using LF symbol when copying
1978 // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
1979 // (or LF left under MacOSX)
1980 for( unsigned ii = 0; ii < text.Len(); )
1981 {
1982 if( text[ii] == 0x0A || text[ii] == 0x0D )
1983 text.erase( ii, 1 );
1984 else
1985 ii++;
1986 }
1987 }
1988 else
1989 {
1990 textType = "Label";
1991 }
1992
1993 // Local labels must have their spin style inverted for left and right
1994 int spinStyle = static_cast<int>( aText->GetTextSpinStyle() );
1995
1996 if( spinStyle == 0 )
1997 spinStyle = 2;
1998 else if( spinStyle == 2 )
1999 spinStyle = 0;
2000
2001 m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2002 schIUScale.IUToMils( aText->GetPosition().x ),
2003 schIUScale.IUToMils( aText->GetPosition().y ),
2004 spinStyle,
2005 schIUScale.IUToMils( aText->GetTextWidth() ),
2006 italics, schIUScale.IUToMils( aText->GetTextThickness() ), TO_UTF8( text ) );
2007 }
2008 else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2009 {
2010 textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2011
2012 auto shapeLabelIt = sheetLabelNames.find( aText->GetShape() );
2013 wxCHECK_RET( shapeLabelIt != sheetLabelNames.end(), "Shape not found in names list" );
2014
2015 m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2016 schIUScale.IUToMils( aText->GetPosition().x ),
2017 schIUScale.IUToMils( aText->GetPosition().y ),
2018 static_cast<int>( aText->GetTextSpinStyle() ),
2019 schIUScale.IUToMils( aText->GetTextWidth() ),
2020 shapeLabelIt->second,
2021 italics,
2023 }
2024}
int GetTextThickness() const
Definition: eda_text.h:112
VECTOR2I GetPosition() const override
Definition: sch_text.h:203
TEXT_SPIN_STYLE GetTextSpinStyle() const
Definition: sch_text.h:148
virtual LABEL_FLAG_SHAPE GetShape() const
Definition: sch_text.h:150
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341
@ LAYER_HIERLABEL
Definition: layer_ids.h:349
@ LAYER_GLOBLABEL
Definition: layer_ids.h:348
@ LAYER_LOCLABEL
Definition: layer_ids.h:347

References SCH_ITEM::GetLayer(), SCH_TEXT::GetPosition(), SCH_TEXT::GetShape(), EDA_TEXT::GetText(), SCH_TEXT::GetTextSpinStyle(), EDA_TEXT::GetTextThickness(), EDA_TEXT::GetTextWidth(), EDA_TEXT::IsItalic(), EDA_IU_SCALE::IUToMils(), LAYER_GLOBLABEL, LAYER_HIERLABEL, LAYER_LOCLABEL, LAYER_NOTES, m_out, OUTPUTFORMATTER::Print(), schIUScale, sheetLabelNames, text, TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ SetLibTable()

virtual void SCH_PLUGIN::SetLibTable ( SYMBOL_LIB_TABLE aTable)
inlinevirtualinherited

Some library plugins need to have access to their parent library table.

Parameters
aTableis the table this plugin is registered within.

Reimplemented in SCH_DATABASE_PLUGIN.

Definition at line 515 of file sch_io_mgr.h.

515{}

Referenced by SYMBOL_LIB_TABLE::FindRow(), and SYMBOL_LIB_TABLE_ROW::Refresh().

◆ 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 }

References m_progressReporter.

◆ SetReporter()

virtual void SCH_PLUGIN::SetReporter ( REPORTER aReporter)
inlinevirtualinherited

Set an optional reporter for warnings/errors.

Reimplemented in SCH_ALTIUM_PLUGIN, CADSTAR_SCH_ARCHIVE_PLUGIN, and SCH_EAGLE_PLUGIN.

Definition at line 168 of file sch_io_mgr.h.

168{}

Referenced by SCH_EDIT_FRAME::importFile().

◆ SupportsSubLibraries()

virtual bool SCH_PLUGIN::SupportsSubLibraries ( ) const
inlinevirtualinherited
Returns
true if this plugin supports libraries that contain sub-libraries.

Reimplemented in SCH_DATABASE_PLUGIN.

Definition at line 449 of file sch_io_mgr.h.

449{ return false; }

Referenced by SYMBOL_LIB_TABLE_ROW::SupportsSubLibraries().

◆ SymbolLibOptions()

void SCH_PLUGIN::SymbolLibOptions ( STRING_UTF8_MAP 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:71

References _.

◆ writeDocFile()

bool SCH_LEGACY_PLUGIN::writeDocFile ( const STRING_UTF8_MAP aProperties)
private

Definition at line 2052 of file sch_legacy_plugin.cpp.

2053{
2054 std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
2055
2056 if( aProperties && aProperties->find( propName ) != aProperties->end() )
2057 return false;
2058
2059 return true;
2060}
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_appending

bool SCH_LEGACY_PLUGIN::m_appending
protected

Definition at line 182 of file sch_legacy_plugin.h.

Referenced by Load(), and loadSymbol().

◆ m_cache

◆ m_currentPath

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

Stack to maintain nested sheet paths.

Definition at line 192 of file sch_legacy_plugin.h.

Referenced by Load(), and loadHierarchy().

◆ m_currentSheet

SCH_SHEET* SCH_LEGACY_PLUGIN::m_currentSheet
protected

The sheet currently being loaded.

Definition at line 194 of file sch_legacy_plugin.h.

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

◆ m_error

wxString SCH_LEGACY_PLUGIN::m_error
protected

For throwing exceptions or errors on partial schematic loads.

Definition at line 184 of file sch_legacy_plugin.h.

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

◆ m_lastProgressLine

unsigned SCH_LEGACY_PLUGIN::m_lastProgressLine
protected

Definition at line 188 of file sch_legacy_plugin.h.

Referenced by checkpoint().

◆ m_lineCount

unsigned SCH_LEGACY_PLUGIN::m_lineCount
protected

for progress reporting

Definition at line 189 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 187 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 191 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 186 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 193 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 197 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.

Indicate if we are appending the loaded schemitic or loading a full project.

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(), SYMBOL_LIB::IsBuffering(), 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: