KiCad PCB EDA Suite
SCH_SEXPR_PLUGIN Class Reference

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

#include <sch_sexpr_plugin.h>

Inheritance diagram for SCH_SEXPR_PLUGIN:
SCH_PLUGIN

Public Member Functions

 SCH_SEXPR_PLUGIN ()
 
virtual ~SCH_SEXPR_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_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
 
void Save (const wxString &aFileName, SCH_SHEET *aSheet, 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 (EE_SELECTION *aSelection, SCH_SHEET_PATH *aSelectionPath, SCHEMATIC &aSchematic, OUTPUTFORMATTER *aFormatter, bool aForClipboard)
 
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...
 
void GetAvailableSymbolFields (std::vector< wxString > &aNames) override
 Retrieves a list of (custom) field names that are present on symbols in this library. More...
 
void GetDefaultSymbolFields (std::vector< wxString > &aNames) override
 Retrieves a list of (custom) field names that should be shown by default for this library in the symbol chooser. 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 SetLibTable (SYMBOL_LIB_TABLE *aTable)
 Some library plugins need to have access to their parent library table. More...
 

Static Public Member Functions

static LIB_SYMBOLParseLibSymbol (LINE_READER &aReader, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
 
static void FormatLibSymbol (LIB_SYMBOL *aPart, 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...
 

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...
 
int m_nextFreeFieldId
 
bool m_appending
 Schematic load append status. More...
 
wxString m_error
 For throwing exceptions or errors on partial loads. More...
 
PROGRESS_REPORTERm_progressReporter
 
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...
 
SCHEMATICm_schematic
 
OUTPUTFORMATTERm_out
 The formatter for saving SCH_SCREEN objects. More...
 
SCH_SEXPR_PLUGIN_CACHEm_cache
 

Private Member Functions

void loadHierarchy (const SCH_SHEET_PATH &aParentSheetPath, SCH_SHEET *aSheet)
 
void loadFile (const wxString &aFileName, SCH_SHEET *aSheet)
 
void saveSymbol (SCH_SYMBOL *aSymbol, const SCHEMATIC &aSchematic, int aNestLevel, bool aForClipboard)
 
void saveField (SCH_FIELD *aField, int aNestLevel)
 
void saveBitmap (SCH_BITMAP *aBitmap, int aNestLevel)
 
void saveSheet (SCH_SHEET *aSheet, int aNestLevel)
 
void saveJunction (SCH_JUNCTION *aJunction, int aNestLevel)
 
void saveNoConnect (SCH_NO_CONNECT *aNoConnect, int aNestLevel)
 
void saveBusEntry (SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
 
void saveLine (SCH_LINE *aLine, int aNestLevel)
 
void saveShape (SCH_SHAPE *aShape, int aNestLevel)
 
void saveText (SCH_TEXT *aText, int aNestLevel)
 
void saveTextBox (SCH_TEXTBOX *aText, int aNestLevel)
 
void saveBusAlias (std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
 
void saveInstances (const std::vector< SCH_SHEET_INSTANCE > &aSheets, int aNestLevel)
 
void cacheLib (const wxString &aLibraryFileName, const STRING_UTF8_MAP *aProperties)
 
bool isBuffering (const STRING_UTF8_MAP *aProperties)
 

Detailed Description

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

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

Definition at line 62 of file sch_sexpr_plugin.h.

Constructor & Destructor Documentation

◆ SCH_SEXPR_PLUGIN()

SCH_SEXPR_PLUGIN::SCH_SEXPR_PLUGIN ( )

Definition at line 75 of file sch_sexpr_plugin.cpp.

75 :
76 m_progressReporter( nullptr )
77{
78 init( nullptr );
79}
PROGRESS_REPORTER * m_progressReporter
void init(SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
initialize PLUGIN like a constructor would.

References init().

◆ ~SCH_SEXPR_PLUGIN()

SCH_SEXPR_PLUGIN::~SCH_SEXPR_PLUGIN ( )
virtual

Definition at line 82 of file sch_sexpr_plugin.cpp.

83{
84 delete m_cache;
85}
SCH_SEXPR_PLUGIN_CACHE * m_cache

References m_cache.

Member Function Documentation

◆ cacheLib()

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

Definition at line 1373 of file sch_sexpr_plugin.cpp.

1374{
1375 if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
1376 {
1377 // a spectacular episode in memory management:
1378 delete m_cache;
1379 m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryFileName );
1380
1381 if( !isBuffering( aProperties ) )
1382 m_cache->Load();
1383 }
1384}
bool IsFile(const wxString &aFullPathAndFileName) const
A cache assistant for the KiCad s-expression symbol libraries.
bool isBuffering(const STRING_UTF8_MAP *aProperties)

References isBuffering(), SCH_LIB_PLUGIN_CACHE::IsFile(), SCH_LIB_PLUGIN_CACHE::IsFileChanged(), SCH_SEXPR_PLUGIN_CACHE::Load(), and m_cache.

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

◆ CheckHeader()

bool SCH_SEXPR_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 1553 of file sch_sexpr_plugin.cpp.

1554{
1555 // Open file and check first line
1556 wxTextFile tempFile;
1557
1558 tempFile.Open( aFileName );
1559 wxString firstline;
1560 // read the first line
1561 firstline = tempFile.GetFirstLine();
1562 tempFile.Close();
1563
1564 return firstline.StartsWith( "EESchema" );
1565}

◆ CreateSymbolLib()

void SCH_SEXPR_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 1489 of file sch_sexpr_plugin.cpp.

1491{
1492 if( wxFileExists( aLibraryPath ) )
1493 {
1494 THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' already exists." ),
1495 aLibraryPath.GetData() ) );
1496 }
1497
1498 LOCALE_IO toggle;
1499
1500 delete m_cache;
1501 m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
1503 m_cache->Save();
1504 m_cache->Load(); // update m_writable and m_mod_time
1505}
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
void SetModified(bool aModified=true)
void Save(const std::optional< bool > &aOpt=std::nullopt) override
Save the entire library to file m_libFileName;.
#define _(s)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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_SEXPR_PLUGIN_CACHE::Load(), m_cache, SCH_SEXPR_PLUGIN_CACHE::Save(), SCH_LIB_PLUGIN_CACHE::SetModified(), and THROW_IO_ERROR.

◆ DeleteSymbol()

void SCH_SEXPR_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 1475 of file sch_sexpr_plugin.cpp.

1477{
1478 LOCALE_IO toggle; // toggles on, then off, the C locale.
1479
1480 cacheLib( aLibraryPath, aProperties );
1481
1482 m_cache->DeleteSymbol( aSymbolName );
1483
1484 if( !isBuffering( aProperties ) )
1485 m_cache->Save();
1486}
void DeleteSymbol(const wxString &aName) override
void cacheLib(const wxString &aLibraryFileName, const STRING_UTF8_MAP *aProperties)

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

◆ DeleteSymbolLib()

bool SCH_SEXPR_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 1508 of file sch_sexpr_plugin.cpp.

1510{
1511 wxFileName fn = aLibraryPath;
1512
1513 if( !fn.FileExists() )
1514 return false;
1515
1516 // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
1517 // we don't want that. we want bare metal portability with no UI here.
1518 if( wxRemove( aLibraryPath ) )
1519 {
1520 THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' cannot be deleted." ),
1521 aLibraryPath.GetData() ) );
1522 }
1523
1524 if( m_cache && m_cache->IsFile( aLibraryPath ) )
1525 {
1526 delete m_cache;
1527 m_cache = nullptr;
1528 }
1529
1530 return true;
1531}

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

◆ EnumerateSymbolLib() [1/2]

void SCH_SEXPR_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 1424 of file sch_sexpr_plugin.cpp.

1427{
1428 LOCALE_IO toggle; // toggles on, then off, the C locale.
1429
1430 bool powerSymbolsOnly = ( aProperties &&
1431 aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
1432
1433 cacheLib( aLibraryPath, aProperties );
1434
1435 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
1436
1437 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
1438 {
1439 if( !powerSymbolsOnly || it->second->IsPower() )
1440 aSymbolList.push_back( it->second );
1441 }
1442}
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_SEXPR_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 1403 of file sch_sexpr_plugin.cpp.

1406{
1407 LOCALE_IO toggle; // toggles on, then off, the C locale.
1408
1409 bool powerSymbolsOnly = ( aProperties &&
1410 aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
1411
1412 cacheLib( aLibraryPath, aProperties );
1413
1414 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
1415
1416 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
1417 {
1418 if( !powerSymbolsOnly || it->second->IsPower() )
1419 aSymbolNameList.Add( it->first );
1420 }
1421}

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

◆ Format() [1/2]

void SCH_SEXPR_PLUGIN::Format ( EE_SELECTION aSelection,
SCH_SHEET_PATH aSelectionPath,
SCHEMATIC aSchematic,
OUTPUTFORMATTER aFormatter,
bool  aForClipboard 
)

Definition at line 486 of file sch_sexpr_plugin.cpp.

489{
490 wxCHECK( aSelection && aSelectionPath && aFormatter, /* void */ );
491
492 LOCALE_IO toggle;
493 SCH_SHEET_LIST fullHierarchy = aSchematic.GetSheets();
494
495 m_schematic = &aSchematic;
496 m_out = aFormatter;
497
498 size_t i;
499 SCH_ITEM* item;
500 std::map<wxString, LIB_SYMBOL*> libSymbols;
501 SCH_SCREEN* screen = aSelection->GetScreen();
502
503 for( i = 0; i < aSelection->GetSize(); ++i )
504 {
505 item = dynamic_cast<SCH_ITEM*>( aSelection->GetItem( i ) );
506
507 wxCHECK2( item, continue );
508
509 if( item->Type() != SCH_SYMBOL_T )
510 continue;
511
512 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
513
514 wxCHECK2( symbol, continue );
515
516 wxString libSymbolLookup = symbol->GetLibId().Format().wx_str();
517
518 if( !symbol->UseLibIdLookup() )
519 libSymbolLookup = symbol->GetSchSymbolLibraryName();
520
521 auto it = screen->GetLibSymbols().find( libSymbolLookup );
522
523 if( it != screen->GetLibSymbols().end() )
524 libSymbols[ libSymbolLookup ] = it->second;
525 }
526
527 if( !libSymbols.empty() )
528 {
529 m_out->Print( 0, "(lib_symbols\n" );
530
531 for( const std::pair<const wxString, LIB_SYMBOL*>& libSymbol : libSymbols )
532 SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( libSymbol.second, *m_out, 1, libSymbol.first );
533
534 m_out->Print( 0, ")\n\n" );
535 }
536
537 // Store the selected sheets instance information
538 SCH_SHEET_LIST selectedSheets;
539 SCH_REFERENCE_LIST selectedSymbols;
540
541 for( i = 0; i < aSelection->GetSize(); ++i )
542 {
543 item = (SCH_ITEM*) aSelection->GetItem( i );
544
545 switch( item->Type() )
546 {
547 case SCH_SYMBOL_T:
548 saveSymbol( static_cast<SCH_SYMBOL*>( item ), aSchematic, 0, aForClipboard );
549
550 aSelectionPath->AppendSymbol( selectedSymbols, static_cast<SCH_SYMBOL*>( item ),
551 true, true );
552 break;
553
554 case SCH_BITMAP_T:
555 saveBitmap( static_cast< SCH_BITMAP* >( item ), 0 );
556 break;
557
558 case SCH_SHEET_T:
559 saveSheet( static_cast< SCH_SHEET* >( item ), 0 );
560
561 {
562 SCH_SHEET_PATH subSheetPath = *aSelectionPath;
563 subSheetPath.push_back( static_cast<SCH_SHEET*>( item ) );
564
565 fullHierarchy.GetSheetsWithinPath( selectedSheets, subSheetPath );
566 fullHierarchy.GetSymbolsWithinPath( selectedSymbols, subSheetPath, true, true );
567 }
568
569 break;
570
571 case SCH_JUNCTION_T:
572 saveJunction( static_cast< SCH_JUNCTION* >( item ), 0 );
573 break;
574
575 case SCH_NO_CONNECT_T:
576 saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ), 0 );
577 break;
578
581 saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ), 0 );
582 break;
583
584 case SCH_LINE_T:
585 saveLine( static_cast< SCH_LINE* >( item ), 0 );
586 break;
587
588 case SCH_SHAPE_T:
589 saveShape( static_cast<SCH_SHAPE*>( item ), 0 );
590 break;
591
592 case SCH_TEXT_T:
593 case SCH_LABEL_T:
595 case SCH_HIER_LABEL_T:
597 saveText( static_cast<SCH_TEXT*>( item ), 0 );
598 break;
599
600 case SCH_TEXTBOX_T:
601 saveTextBox( static_cast<SCH_TEXTBOX*>( item ), 0 );
602 break;
603
604 default:
605 wxASSERT( "Unexpected schematic object type in SCH_SEXPR_PLUGIN::Format()" );
606 }
607 }
608
609 // Make all instance information relative to the selection path
610 KIID_PATH selectionPath = aSelectionPath->Path();
611
612 selectedSheets.SortByPageNumbers();
613 std::vector<SCH_SHEET_INSTANCE> sheetinstances = selectedSheets.GetSheetInstances();
614
615 for( SCH_SHEET_INSTANCE& sheetInstance : sheetinstances )
616 {
617 wxASSERT_MSG( sheetInstance.m_Path.MakeRelativeTo( selectionPath ),
618 "Sheet is not inside the selection path?" );
619 }
620
621 selectionPath = aSelectionPath->Path();
622 selectedSymbols.SortByReferenceOnly();
623 std::vector<SYMBOL_INSTANCE_REFERENCE> symbolInstances = selectedSymbols.GetSymbolInstances();
624
625 for( SYMBOL_INSTANCE_REFERENCE& symbolInstance : symbolInstances )
626 {
627 wxASSERT_MSG( symbolInstance.m_Path.MakeRelativeTo( selectionPath ),
628 "Symbol is not inside the selection path?" );
629 }
630}
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
SCH_SCREEN * GetScreen()
Definition: ee_selection.h:52
UTF8 Format() const
Definition: lib_id.cpp:117
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:431
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:86
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
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
std::vector< SYMBOL_INSTANCE_REFERENCE > GetSymbolInstances() const
void SortByReferenceOnly()
Sort the list of references by reference.
std::map< wxString, LIB_SYMBOL * > & GetLibSymbols()
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition: sch_screen.h:454
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString)
void saveTextBox(SCH_TEXTBOX *aText, int aNestLevel)
SCHEMATIC * m_schematic
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
void saveLine(SCH_LINE *aLine, int aNestLevel)
void saveText(SCH_TEXT *aText, int aNestLevel)
void saveSymbol(SCH_SYMBOL *aSymbol, const SCHEMATIC &aSchematic, int aNestLevel, bool aForClipboard)
void saveSheet(SCH_SHEET *aSheet, int aNestLevel)
void saveShape(SCH_SHAPE *aShape, int aNestLevel)
void saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect, int aNestLevel)
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
std::vector< SCH_SHEET_INSTANCE > GetSheetInstances() const
Fetch the instance information for all of the sheets in the hiearchy.
void GetSymbolsWithinPath(SCH_REFERENCE_LIST &aReferences, const SCH_SHEET_PATH &aSheetPath, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets that are contained wi...
void GetSheetsWithinPath(SCH_SHEET_PATHS &aSheets, const SCH_SHEET_PATH &aSheetPath) const
Add a SCH_SHEET_PATH object to aSheets for each sheet in the list that are contained within aSheetPat...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void AppendSymbol(SCH_REFERENCE_LIST &aReferences, SCH_SYMBOL *aSymbol, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Append a SCH_REFERENCE object to aReferences based on aSymbol.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:55
Schematic symbol object.
Definition: sch_symbol.h:80
bool UseLibIdLookup() const
Definition: sch_symbol.h:189
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:286
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:174
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
wxString wx_str() const
Definition: utf8.cpp:46
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
@ SCH_LINE_T
Definition: typeinfo.h:146
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:143
@ SCH_SYMBOL_T
Definition: typeinfo.h:156
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:154
@ SCH_LABEL_T
Definition: typeinfo.h:151
@ SCH_SHEET_T
Definition: typeinfo.h:158
@ SCH_SHAPE_T
Definition: typeinfo.h:147
@ 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_TEXTBOX_T
Definition: typeinfo.h:149
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
@ SCH_JUNCTION_T
Definition: typeinfo.h:142

References SCH_SHEET_PATH::AppendSymbol(), LIB_ID::Format(), SELECTION::GetItem(), SCH_SYMBOL::GetLibId(), SCH_SCREEN::GetLibSymbols(), SCH_SYMBOL::GetSchSymbolLibraryName(), EE_SELECTION::GetScreen(), SCH_SHEET_LIST::GetSheetInstances(), SCHEMATIC::GetSheets(), SCH_SHEET_LIST::GetSheetsWithinPath(), SELECTION::GetSize(), SCH_REFERENCE_LIST::GetSymbolInstances(), SCH_SHEET_LIST::GetSymbolsWithinPath(), m_out, m_schematic, SCH_SHEET_PATH::Path(), OUTPUTFORMATTER::Print(), SCH_SHEET_PATH::push_back(), saveBitmap(), saveBusEntry(), saveJunction(), saveLine(), saveNoConnect(), saveShape(), saveSheet(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), saveSymbol(), saveText(), saveTextBox(), SCH_BITMAP_T, SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T, SCH_DIRECTIVE_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_JUNCTION_T, SCH_LABEL_T, SCH_LINE_T, SCH_NO_CONNECT_T, SCH_SHAPE_T, SCH_SHEET_T, SCH_SYMBOL_T, SCH_TEXT_T, SCH_TEXTBOX_T, SCH_SHEET_LIST::SortByPageNumbers(), SCH_REFERENCE_LIST::SortByReferenceOnly(), EDA_ITEM::Type(), SCH_SYMBOL::UseLibIdLookup(), and UTF8::wx_str().

◆ Format() [2/2]

void SCH_SEXPR_PLUGIN::Format ( SCH_SHEET aSheet)

Definition at line 348 of file sch_sexpr_plugin.cpp.

349{
350 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." );
351 wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." );
352
353 SCH_SCREEN* screen = aSheet->GetScreen();
354
355 wxCHECK( screen, /* void */ );
356
357 m_out->Print( 0, "(kicad_sch (version %d) (generator eeschema)\n\n",
359
360 m_out->Print( 1, "(uuid %s)\n\n", TO_UTF8( screen->m_uuid.AsString() ) );
361
362 screen->GetPageSettings().Format( m_out, 1, 0 );
363 m_out->Print( 0, "\n" );
364 screen->GetTitleBlock().Format( m_out, 1, 0 );
365
366 // Save cache library.
367 m_out->Print( 1, "(lib_symbols\n" );
368
369 for( std::pair<const wxString, LIB_SYMBOL*>& libSymbol : screen->GetLibSymbols() )
370 SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( libSymbol.second, *m_out, 2, libSymbol.first );
371
372 m_out->Print( 1, ")\n\n" );
373
374 for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
375 saveBusAlias( alias, 1 );
376
377 // Enforce item ordering
378 auto cmp =
379 []( const SCH_ITEM* a, const SCH_ITEM* b )
380 {
381 if( a->Type() != b->Type() )
382 return a->Type() < b->Type();
383
384 return a->m_Uuid < b->m_Uuid;
385 };
386
387 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
388
389 for( SCH_ITEM* item : screen->Items() )
390 save_map.insert( item );
391
392 KICAD_T itemType = TYPE_NOT_INIT;
394
395 for( SCH_ITEM* item : save_map )
396 {
397 if( itemType != item->Type() )
398 {
399 itemType = item->Type();
400
401 if( itemType != SCH_SYMBOL_T
402 && itemType != SCH_JUNCTION_T
403 && itemType != SCH_SHEET_T )
404 {
405 m_out->Print( 0, "\n" );
406 }
407 }
408
409 switch( item->Type() )
410 {
411 case SCH_SYMBOL_T:
412 m_out->Print( 0, "\n" );
413 saveSymbol( static_cast<SCH_SYMBOL*>( item ), *m_schematic, 1, false );
414 break;
415
416 case SCH_BITMAP_T:
417 saveBitmap( static_cast<SCH_BITMAP*>( item ), 1 );
418 break;
419
420 case SCH_SHEET_T:
421 m_out->Print( 0, "\n" );
422 saveSheet( static_cast<SCH_SHEET*>( item ), 1 );
423 break;
424
425 case SCH_JUNCTION_T:
426 saveJunction( static_cast<SCH_JUNCTION*>( item ), 1 );
427 break;
428
429 case SCH_NO_CONNECT_T:
430 saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ), 1 );
431 break;
432
435 saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ), 1 );
436 break;
437
438 case SCH_LINE_T:
439 if( layer != item->GetLayer() )
440 {
441 if( layer == SCH_LAYER_ID_START )
442 {
443 layer = item->GetLayer();
444 }
445 else
446 {
447 layer = item->GetLayer();
448 m_out->Print( 0, "\n" );
449 }
450 }
451
452 saveLine( static_cast<SCH_LINE*>( item ), 1 );
453 break;
454
455 case SCH_SHAPE_T:
456 saveShape( static_cast<SCH_SHAPE*>( item ), 1 );
457 break;
458
459 case SCH_TEXT_T:
460 case SCH_LABEL_T:
462 case SCH_HIER_LABEL_T:
464 saveText( static_cast<SCH_TEXT*>( item ), 1 );
465 break;
466
467 case SCH_TEXTBOX_T:
468 saveTextBox( static_cast<SCH_TEXTBOX*>( item ), 1 );
469 break;
470
471 default:
472 wxASSERT( "Unexpected schematic object type in SCH_SEXPR_PLUGIN::Format()" );
473 }
474 }
475
476 // If this is the root sheet, save the virtual root sheet instance information.
477 if( aSheet->IsRootSheet() )
478 {
479 saveInstances( aSheet->GetInstances(), 1 );
480 }
481
482 m_out->Print( 0, ")\n" );
483}
const KIID m_Uuid
Definition: eda_item.h:494
wxString AsString() const
Definition: kiid.cpp:251
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the page class to aFormatter in s-expression form.
Definition: page_info.cpp:272
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
KIID m_uuid
A unique identifier for each schematic file.
Definition: sch_screen.h:605
std::set< std::shared_ptr< BUS_ALIAS > > GetBusAliases() const
Return a list of bus aliases defined in this screen.
Definition: sch_screen.h:484
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
void saveInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheets, int aNestLevel)
bool IsRootSheet() const
Definition: sch_sheet.cpp:194
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:104
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition: sch_sheet.h:379
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: title_block.cpp:30
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341
@ SCH_LAYER_ID_START
Definition: layer_ids.h:342
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
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 KIID::AsString(), PAGE_INFO::Format(), TITLE_BLOCK::Format(), SCH_SCREEN::GetBusAliases(), SCH_SHEET::GetInstances(), SCH_SCREEN::GetLibSymbols(), SCH_SCREEN::GetPageSettings(), SCH_SHEET::GetScreen(), SCH_SCREEN::GetTitleBlock(), SCH_SHEET::IsRootSheet(), SCH_SCREEN::Items(), m_out, m_schematic, SCH_SCREEN::m_uuid, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), saveBitmap(), saveBusAlias(), saveBusEntry(), saveInstances(), saveJunction(), saveLine(), saveNoConnect(), saveShape(), saveSheet(), SCH_SEXPR_PLUGIN_CACHE::SaveSymbol(), saveSymbol(), saveText(), saveTextBox(), SCH_BITMAP_T, SCH_BUS_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T, SCH_DIRECTIVE_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_JUNCTION_T, SCH_LABEL_T, SCH_LAYER_ID_START, SCH_LINE_T, SCH_NO_CONNECT_T, SCH_SHAPE_T, SCH_SHEET_T, SCH_SYMBOL_T, SCH_TEXT_T, SCH_TEXTBOX_T, SEXPR_SCHEMATIC_FILE_VERSION, TO_UTF8, EDA_ITEM::Type(), and TYPE_NOT_INIT.

Referenced by SCH_EDITOR_CONTROL::doCopy(), and Save().

◆ FormatLibSymbol()

void SCH_SEXPR_PLUGIN::FormatLibSymbol ( LIB_SYMBOL aPart,
OUTPUTFORMATTER aFormatter 
)
static

Definition at line 1624 of file sch_sexpr_plugin.cpp.

1625{
1626
1627 LOCALE_IO toggle; // toggles on, then off, the C locale.
1628 SCH_SEXPR_PLUGIN_CACHE::SaveSymbol( symbol, formatter );
1629}

References SCH_SEXPR_PLUGIN_CACHE::SaveSymbol().

Referenced by SYMBOL_EDITOR_EDIT_TOOL::Copy(), and SYMBOL_EDIT_FRAME::CopySymbolToClipboard().

◆ GetAvailableSymbolFields()

void SCH_SEXPR_PLUGIN::GetAvailableSymbolFields ( std::vector< wxString > &  aNames)
overridevirtual

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 from SCH_PLUGIN.

Definition at line 1576 of file sch_sexpr_plugin.cpp.

1577{
1578 if( !m_cache )
1579 return;
1580
1581 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
1582
1583 std::set<wxString> fieldNames;
1584
1585 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
1586 {
1587 std::vector<LIB_FIELD*> fields;
1588 it->second->GetFields( fields );
1589
1590 for( LIB_FIELD* field : fields )
1591 {
1592 if( field->IsMandatory() )
1593 continue;
1594
1595 // TODO(JE): enable configurability of this outside database libraries?
1596 // if( field->ShowInChooser() )
1597 fieldNames.insert( field->GetName() );
1598 }
1599 }
1600
1601 std::copy( fieldNames.begin(), fieldNames.end(), std::back_inserter( aNames ) );
1602}
Field object used in symbol libraries.
Definition: lib_field.h:60

References m_cache, and SCH_LIB_PLUGIN_CACHE::m_symbols.

Referenced by GetDefaultSymbolFields().

◆ GetDefaultSymbolFields()

void SCH_SEXPR_PLUGIN::GetDefaultSymbolFields ( std::vector< wxString > &  aNames)
overridevirtual

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 from SCH_PLUGIN.

Definition at line 1605 of file sch_sexpr_plugin.cpp.

1606{
1607 GetAvailableSymbolFields( aNames );
1608}
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.

References GetAvailableSymbolFields().

◆ GetError()

const wxString & SCH_SEXPR_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 138 of file sch_sexpr_plugin.h.

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

References m_error.

◆ GetFileExtension()

const wxString SCH_SEXPR_PLUGIN::GetFileExtension ( ) const
inlineoverridevirtual

Return the file extension for the SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 74 of file sch_sexpr_plugin.h.

75 {
76 return wxT( "kicad_sch" );
77 }

◆ GetLibraryFileExtension()

const wxString SCH_SEXPR_PLUGIN::GetLibraryFileExtension ( ) const
inlineoverridevirtual

Return the library file extension for the SCH_PLUGIN object.

Implements SCH_PLUGIN.

Definition at line 79 of file sch_sexpr_plugin.h.

80 {
81 return wxT( "kicad_sym" );
82 }

◆ GetModifyHash()

int SCH_SEXPR_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 1393 of file sch_sexpr_plugin.cpp.

1394{
1395 if( m_cache )
1396 return m_cache->GetModifyHash();
1397
1398 // If the cache hasn't been loaded, it hasn't been modified.
1399 return 0;
1400}

References SCH_LIB_PLUGIN_CACHE::GetModifyHash(), and m_cache.

◆ GetName()

const wxString SCH_SEXPR_PLUGIN::GetName ( ) const
inlineoverridevirtual

Return a brief hard coded name for this SCH_PLUGIN.

Implements SCH_PLUGIN.

Definition at line 69 of file sch_sexpr_plugin.h.

70 {
71 return wxT( "Eeschema s-expression" );
72 }

◆ 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_SEXPR_PLUGIN::init ( SCHEMATIC aSchematic,
const STRING_UTF8_MAP aProperties = nullptr 
)
protected

initialize PLUGIN like a constructor would.

Definition at line 88 of file sch_sexpr_plugin.cpp.

89{
90 m_version = 0;
91 m_appending = false;
92 m_rootSheet = nullptr;
93 m_schematic = aSchematic;
94 m_cache = nullptr;
95 m_out = nullptr;
96 m_nextFreeFieldId = 100; // number arbitrarily > MANDATORY_FIELDS or SHEET_MANDATORY_FIELDS
97}
bool m_appending
Schematic load append status.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
int m_version
Version of file being loaded.

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

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

◆ isBuffering()

bool SCH_SEXPR_PLUGIN::isBuffering ( const STRING_UTF8_MAP aProperties)
private

Definition at line 1387 of file sch_sexpr_plugin.cpp.

1388{
1389 return ( aProperties && aProperties->Exists( SCH_SEXPR_PLUGIN::PropBuffering ) );
1390}
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_SEXPR_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 1568 of file sch_sexpr_plugin.cpp.

1569{
1570 wxFileName fn( aLibraryPath );
1571
1572 return ( fn.FileExists() && fn.IsFileWritable() ) || fn.IsDirWritable();
1573}

◆ Load()

SCH_SHEET * SCH_SEXPR_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 100 of file sch_sexpr_plugin.cpp.

102{
103 wxASSERT( !aFileName || aSchematic != nullptr );
104
105 LOCALE_IO toggle; // toggles on, then off, the C locale.
106 SCH_SHEET* sheet;
107
108 wxFileName fn = aFileName;
109
110 // Unfortunately child sheet file names the legacy schematic file format are not fully
111 // qualified and are always appended to the project path. The aFileName attribute must
112 // always be an absolute path so the project path can be used for load child sheet files.
113 wxASSERT( fn.IsAbsolute() );
114
115 if( aAppendToMe )
116 {
117 m_appending = true;
118 wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
119 aFileName, aAppendToMe->GetFileName() );
120
121 wxFileName normedFn = aAppendToMe->GetFileName();
122
123 if( !normedFn.IsAbsolute() )
124 {
125 if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
126 m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
127 }
128
129 if( m_path.IsEmpty() )
130 m_path = aSchematic->Prj().GetProjectPath();
131
132 wxLogTrace( traceSchLegacyPlugin, "Normalized append path \"%s\".", m_path );
133 }
134 else
135 {
136 m_path = aSchematic->Prj().GetProjectPath();
137 }
138
139 m_currentPath.push( m_path );
140 init( aSchematic, aProperties );
141
142 if( aAppendToMe == nullptr )
143 {
144 // Clean up any allocated memory if an exception occurs loading the schematic.
145 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
146
147 wxFileName relPath( aFileName );
148
149 // Do not use wxPATH_UNIX as option in MakeRelativeTo(). It can create incorrect
150 // relative paths on Windows, because paths have a disk identifier (C:, D: ...)
151 relPath.MakeRelativeTo( aSchematic->Prj().GetProjectPath() );
152
153 newSheet->SetFileName( relPath.GetFullPath() );
154 m_rootSheet = newSheet.get();
155 loadHierarchy( SCH_SHEET_PATH(), newSheet.get() );
156
157 // If we got here, the schematic loaded successfully.
158 sheet = newSheet.release();
159 m_rootSheet = nullptr; // Quiet Coverity warning.
160 }
161 else
162 {
163 wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
164 m_rootSheet = &aSchematic->Root();
165 sheet = aAppendToMe;
166 loadHierarchy( SCH_SHEET_PATH(), sheet );
167 }
168
169 wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
170
171 m_currentPath.pop(); // Clear the path stack for next call to Load
172
173 return sheet;
174}
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(const SCH_SHEET_PATH &aParentSheetPath, SCH_SHEET *aSheet)
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:300
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.

◆ LoadContent()

void SCH_SEXPR_PLUGIN::LoadContent ( LINE_READER aReader,
SCH_SHEET aSheet,
int  aVersion = SEXPR_SCHEMATIC_FILE_VERSION 
)

Definition at line 311 of file sch_sexpr_plugin.cpp.

312{
313 wxCHECK( aSheet, /* void */ );
314
315 LOCALE_IO toggle;
316 SCH_SEXPR_PARSER parser( &aReader );
317
318 parser.ParseSchematic( aSheet, true, aFileVersion );
319}
Object to parser s-expression symbol library and schematic file formats.

References SCH_SEXPR_PARSER::ParseSchematic().

Referenced by SCH_EDITOR_CONTROL::Paste().

◆ loadFile()

void SCH_SEXPR_PLUGIN::loadFile ( const wxString &  aFileName,
SCH_SHEET aSheet 
)
private

Definition at line 286 of file sch_sexpr_plugin.cpp.

287{
288 FILE_LINE_READER reader( aFileName );
289
290 size_t lineCount = 0;
291
293 {
294 m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
295
297 THROW_IO_ERROR( ( "Open cancelled by user." ) );
298
299 while( reader.ReadLine() )
300 lineCount++;
301
302 reader.Rewind();
303 }
304
305 SCH_SEXPR_PARSER parser( &reader, m_progressReporter, lineCount, m_rootSheet, m_appending );
306
307 parser.ParseSchematic( aSheet );
308}
A LINE_READER that reads from an open file.
Definition: richio.h:173
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.

References _, Format(), PROGRESS_REPORTER::KeepRefreshing(), m_appending, m_progressReporter, m_rootSheet, SCH_SEXPR_PARSER::ParseSchematic(), FILE_LINE_READER::ReadLine(), PROGRESS_REPORTER::Report(), FILE_LINE_READER::Rewind(), and THROW_IO_ERROR.

Referenced by loadHierarchy().

◆ loadHierarchy()

void SCH_SEXPR_PLUGIN::loadHierarchy ( const SCH_SHEET_PATH aParentSheetPath,
SCH_SHEET aSheet 
)
private

Definition at line 179 of file sch_sexpr_plugin.cpp.

180{
181 SCH_SCREEN* screen = nullptr;
182
183 if( !aSheet->GetScreen() )
184 {
185 // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
186 // stores the file name and extension. Add the project path to the file name and
187 // extension to compare when calling SCH_SHEET::SearchHierarchy().
188 wxFileName fileName = aSheet->GetFileName();
189
190 if( !fileName.IsAbsolute() )
191 fileName.MakeAbsolute( m_currentPath.top() );
192
193 // Save the current path so that it gets restored when descending and ascending the
194 // sheet hierarchy which allows for sheet schematic files to be nested in folders
195 // relative to the last path a schematic was loaded from.
196 wxLogTrace( traceSchLegacyPlugin, "Saving path '%s'", m_currentPath.top() );
197 m_currentPath.push( fileName.GetPath() );
198 wxLogTrace( traceSchLegacyPlugin, "Current path '%s'", m_currentPath.top() );
199 wxLogTrace( traceSchLegacyPlugin, "Loading '%s'", fileName.GetFullPath() );
200
201 SCH_SHEET_PATH ancestorSheetPath = aParentSheetPath;
202
203 while( !ancestorSheetPath.empty() )
204 {
205 if( ancestorSheetPath.LastScreen()->GetFileName() == fileName.GetFullPath() )
206 {
207 if( !m_error.IsEmpty() )
208 m_error += "\n";
209
210 m_error += wxString::Format( _( "Could not load sheet '%s' because it already "
211 "appears as a direct ancestor in the schematic "
212 "hierarchy." ),
213 fileName.GetFullPath() );
214
215 fileName = wxEmptyString;
216
217 break;
218 }
219
220 ancestorSheetPath.pop_back();
221 }
222
223 if( ancestorSheetPath.empty() )
224 m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
225
226 if( screen )
227 {
228 aSheet->SetScreen( screen );
229 aSheet->GetScreen()->SetParent( m_schematic );
230 // Do not need to load the sub-sheets - this has already been done.
231 }
232 else
233 {
234 aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
235 aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
236
237 try
238 {
239 loadFile( fileName.GetFullPath(), aSheet );
240 }
241 catch( const IO_ERROR& ioe )
242 {
243 // If there is a problem loading the root sheet, there is no recovery.
244 if( aSheet == m_rootSheet )
245 throw;
246
247 // For all subsheets, queue up the error message for the caller.
248 if( !m_error.IsEmpty() )
249 m_error += "\n";
250
251 m_error += ioe.What();
252 }
253
254 if( fileName.FileExists() )
255 {
256 aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() );
257 aSheet->GetScreen()->SetFileExists( true );
258 }
259 else
260 {
261 aSheet->GetScreen()->SetFileReadOnly( !fileName.IsDirWritable() );
262 aSheet->GetScreen()->SetFileExists( false );
263 }
264
265 SCH_SHEET_PATH currentSheetPath = aParentSheetPath;
266 currentSheetPath.push_back( aSheet );
267
268 // This was moved out of the try{} block so that any sheet definitions that
269 // the plugin fully parsed before the exception was raised will be loaded.
270 for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
271 {
272 wxCHECK2( aItem->Type() == SCH_SHEET_T, /* do nothing */ );
273 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
274
275 // Recursion starts here.
276 loadHierarchy( currentSheetPath, sheet );
277 }
278 }
279
280 m_currentPath.pop();
281 wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
282 }
283}
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
const wxString & GetFileName() const
Definition: sch_screen.h:144
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:110
void SetFileReadOnly(bool aIsReadOnly)
Definition: sch_screen.h:146
void SetFileExists(bool aFileExists)
Definition: sch_screen.h:149
void loadFile(const wxString &aFileName, SCH_SHEET *aSheet)
bool empty() const
Forwarded method from std::vector.
SCH_SCREEN * LastScreen()
void pop_back()
Forwarded method from std::vector.
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_PATH::empty(), Format(), SCH_SCREEN::GetFileName(), SCH_SHEET::GetFileName(), SCH_SHEET::GetScreen(), SCH_SCREEN::Items(), SCH_SHEET_PATH::LastScreen(), loadFile(), loadHierarchy(), m_currentPath, m_error, m_rootSheet, m_schematic, EE_RTREE::OfType(), SCH_SHEET_PATH::pop_back(), SCH_SHEET_PATH::push_back(), 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().

◆ LoadSymbol()

LIB_SYMBOL * SCH_SEXPR_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 1445 of file sch_sexpr_plugin.cpp.

1447{
1448 LOCALE_IO toggle; // toggles on, then off, the C locale.
1449
1450 cacheLib( aLibraryPath, aProperties );
1451
1452 LIB_SYMBOL_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
1453
1454 if( it == m_cache->m_symbols.end() )
1455 return nullptr;
1456
1457 return it->second;
1458}

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

◆ ParseLibSymbol()

LIB_SYMBOL * SCH_SEXPR_PLUGIN::ParseLibSymbol ( LINE_READER aReader,
int  aVersion = SEXPR_SCHEMATIC_FILE_VERSION 
)
static

Definition at line 1611 of file sch_sexpr_plugin.cpp.

1612{
1613 LOCALE_IO toggle; // toggles on, then off, the C locale.
1614 LIB_SYMBOL_MAP map;
1615 SCH_SEXPR_PARSER parser( &aReader );
1616
1617 parser.NeedLEFT();
1618 parser.NextTok();
1619
1620 return parser.ParseSymbol( map, aFileVersion );
1621}

References SCH_SEXPR_PARSER::ParseSymbol().

Referenced by SYMBOL_EDIT_FRAME::DuplicateSymbol(), and SYMBOL_EDITOR_EDIT_TOOL::Paste().

◆ Save()

void SCH_SEXPR_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 322 of file sch_sexpr_plugin.cpp.

324{
325 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
326 wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
327
328 LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
329
330 init( aSchematic, aProperties );
331
332 wxFileName fn = aFileName;
333
334 // File names should be absolute. Don't assume everything relative to the project path
335 // works properly.
336 wxASSERT( fn.IsAbsolute() );
337
338 FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
339
340 m_out = &formatter; // no ownership
341
342 Format( aSheet );
343
344 aSheet->GetScreen()->SetFileExists( true );
345}
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().

Referenced by KI_TEST::DumpSchematicToFile().

◆ saveBitmap()

void SCH_SEXPR_PLUGIN::saveBitmap ( SCH_BITMAP aBitmap,
int  aNestLevel 
)
private

Definition at line 897 of file sch_sexpr_plugin.cpp.

898{
899 wxCHECK_RET( aBitmap != nullptr && m_out != nullptr, "" );
900
901 const wxImage* image = aBitmap->GetImage()->GetImageData();
902
903 wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
904
905 m_out->Print( aNestLevel, "(image (at %s %s)",
907 aBitmap->GetPosition().x ).c_str(),
909 aBitmap->GetPosition().y ).c_str() );
910
911 if( aBitmap->GetImage()->GetScale() != 1.0 )
912 m_out->Print( 0, " (scale %g)", aBitmap->GetImage()->GetScale() );
913
914 m_out->Print( 0, "\n" );
915
916 m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aBitmap->m_Uuid.AsString() ) );
917
918 m_out->Print( aNestLevel + 1, "(data" );
919
920 wxMemoryOutputStream stream;
921
922 image->SaveFile( stream, wxBITMAP_TYPE_PNG );
923
924 // Write binary data in hexadecimal form (ASCII)
925 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
926 wxString out = wxBase64Encode( buffer->GetBufferStart(), buffer->GetBufferSize() );
927
928 // Apparently the MIME standard character width for base64 encoding is 76 (unconfirmed)
929 // so use it in a vein attempt to be standard like.
930#define MIME_BASE64_LENGTH 76
931
932 size_t first = 0;
933
934 while( first < out.Length() )
935 {
936 m_out->Print( 0, "\n" );
937 m_out->Print( aNestLevel + 2, "%s", TO_UTF8( out( first, MIME_BASE64_LENGTH ) ) );
938 first += MIME_BASE64_LENGTH;
939 }
940
941 m_out->Print( 0, "\n" );
942 m_out->Print( aNestLevel + 1, ")\n" ); // Closes data token.
943 m_out->Print( aNestLevel, ")\n" ); // Closes image token.
944}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
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
std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
Definition: eda_units.cpp:139
#define MIME_BASE64_LENGTH

References KIID::AsString(), EDA_UNIT_UTILS::FormatInternalUnits(), SCH_BITMAP::GetImage(), BITMAP_BASE::GetImageData(), SCH_BITMAP::GetPosition(), BITMAP_BASE::GetScale(), image, m_out, EDA_ITEM::m_Uuid, MIME_BASE64_LENGTH, OUTPUTFORMATTER::Print(), schIUScale, TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ saveBusAlias()

void SCH_SEXPR_PLUGIN::saveBusAlias ( std::shared_ptr< BUS_ALIAS aAlias,
int  aNestLevel 
)
private

Definition at line 1328 of file sch_sexpr_plugin.cpp.

1329{
1330 wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" );
1331
1332 wxString members;
1333
1334 for( const wxString& member : aAlias->Members() )
1335 {
1336 if( !members.IsEmpty() )
1337 members += wxS( " " );
1338
1339 members += m_out->Quotew( member );
1340 }
1341
1342 m_out->Print( aNestLevel, "(bus_alias %s (members %s))\n",
1343 m_out->Quotew( aAlias->GetName() ).c_str(),
1344 TO_UTF8( members ) );
1345}
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:499

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

Referenced by Format().

◆ saveBusEntry()

void SCH_SEXPR_PLUGIN::saveBusEntry ( SCH_BUS_ENTRY_BASE aBusEntry,
int  aNestLevel 
)
private

Definition at line 1107 of file sch_sexpr_plugin.cpp.

1108{
1109 wxCHECK_RET( aBusEntry != nullptr && m_out != nullptr, "" );
1110
1111 // Bus to bus entries are converted to bus line segments.
1112 if( aBusEntry->GetClass() == "SCH_BUS_BUS_ENTRY" )
1113 {
1114 SCH_LINE busEntryLine( aBusEntry->GetPosition(), LAYER_BUS );
1115
1116 busEntryLine.SetEndPoint( aBusEntry->GetEnd() );
1117 saveLine( &busEntryLine, aNestLevel );
1118 }
1119 else
1120 {
1121 m_out->Print( aNestLevel, "(bus_entry (at %s %s) (size %s %s)\n",
1123 aBusEntry->GetPosition().x ).c_str(),
1125 aBusEntry->GetPosition().y ).c_str(),
1127 aBusEntry->GetSize().GetWidth() ).c_str(),
1129 aBusEntry->GetSize().GetHeight() ).c_str() );
1130
1131 aBusEntry->GetStroke().Format( m_out, schIUScale, aNestLevel + 1 );
1132
1133 m_out->Print( 0, "\n" );
1134
1135 m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aBusEntry->m_Uuid.AsString() ) );
1136
1137 m_out->Print( aNestLevel, ")\n" );
1138 }
1139}
VECTOR2I GetPosition() const override
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_bus_entry.h:77
VECTOR2I GetEnd() const
wxSize GetSize() const
Definition: sch_bus_entry.h:71
virtual wxString GetClass() const override
Return the class name.
Definition: sch_item.h:157
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale, int nestLevel) const
@ LAYER_BUS
Definition: layer_ids.h:345

References KIID::AsString(), STROKE_PARAMS::Format(), EDA_UNIT_UTILS::FormatInternalUnits(), SCH_ITEM::GetClass(), SCH_BUS_ENTRY_BASE::GetEnd(), SCH_BUS_ENTRY_BASE::GetPosition(), SCH_BUS_ENTRY_BASE::GetSize(), SCH_BUS_ENTRY_BASE::GetStroke(), LAYER_BUS, m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), saveLine(), schIUScale, SCH_LINE::SetEndPoint(), TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ saveField()

void SCH_SEXPR_PLUGIN::saveField ( SCH_FIELD aField,
int  aNestLevel 
)
private

Definition at line 850 of file sch_sexpr_plugin.cpp.

851{
852 wxCHECK_RET( aField != nullptr && m_out != nullptr, "" );
853
854 wxString fieldName = aField->GetCanonicalName();
855 // For some reason (bug in legacy parser?) the field ID for non-mandatory fields is -1 so
856 // check for this in order to correctly use the field name.
857
858 if( aField->GetId() == -1 /* undefined ID */ )
859 {
860 aField->SetId( m_nextFreeFieldId );
862 }
863 else if( aField->GetId() >= m_nextFreeFieldId )
864 {
865 m_nextFreeFieldId = aField->GetId() + 1;
866 }
867
868 m_out->Print( aNestLevel, "(property %s %s (at %s %s %s)",
869 m_out->Quotew( fieldName ).c_str(),
870 m_out->Quotew( aField->GetText() ).c_str(),
872 aField->GetPosition().x ).c_str(),
874 aField->GetPosition().y ).c_str(),
875 EDA_UNIT_UTILS::FormatAngle( aField->GetTextAngle() ).c_str() );
876
877 if( aField->IsNameShown() )
878 m_out->Print( 0, " (show_name)" );
879
880 if( !aField->CanAutoplace() )
881 m_out->Print( 0, " (do_not_autoplace)" );
882
883 if( !aField->IsDefaultFormatting()
884 || ( aField->GetTextHeight() != schIUScale.MilsToIU( DEFAULT_SIZE_TEXT ) ) )
885 {
886 m_out->Print( 0, "\n" );
887 aField->Format( m_out, aNestLevel, 0 );
888 m_out->Print( aNestLevel, ")\n" ); // Closes property token with font effects.
889 }
890 else
891 {
892 m_out->Print( 0, ")\n" ); // Closes property token without font effects.
893 }
894}
int GetTextHeight() const
Definition: eda_text.h:202
bool IsDefaultFormatting() const
Definition: eda_text.cpp:766
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 void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:781
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1070
bool IsNameShown() const
Definition: sch_field.h:149
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: sch_field.cpp:859
int GetId() const
Definition: sch_field.h:116
bool CanAutoplace() const
Definition: sch_field.h:152
void SetId(int aId)
Definition: sch_field.cpp:132
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:61
std::string FormatAngle(const EDA_ANGLE &aAngle)
Converts aAngle from board units to a string appropriate for writing to file.
Definition: eda_units.cpp:131
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94

References SCH_FIELD::CanAutoplace(), DEFAULT_SIZE_TEXT, EDA_TEXT::Format(), EDA_UNIT_UTILS::FormatAngle(), EDA_UNIT_UTILS::FormatInternalUnits(), SCH_FIELD::GetCanonicalName(), SCH_FIELD::GetId(), SCH_FIELD::GetPosition(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextHeight(), EDA_TEXT::IsDefaultFormatting(), SCH_FIELD::IsNameShown(), m_nextFreeFieldId, m_out, EDA_IU_SCALE::MilsToIU(), OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), schIUScale, SCH_FIELD::SetId(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by saveSheet(), saveSymbol(), and saveText().

◆ saveInstances()

void SCH_SEXPR_PLUGIN::saveInstances ( const std::vector< SCH_SHEET_INSTANCE > &  aSheets,
int  aNestLevel 
)
private

Definition at line 1348 of file sch_sexpr_plugin.cpp.

1350{
1351 if( aSheets.size() )
1352 {
1353 m_out->Print( 0, "\n" );
1354 m_out->Print( aNestLevel, "(sheet_instances\n" );
1355
1356 for( const SCH_SHEET_INSTANCE& instance : aSheets )
1357 {
1358 wxString path = instance.m_Path.AsString();
1359
1360 if( path.IsEmpty() )
1361 path = wxT( "/" ); // Root path
1362
1363 m_out->Print( aNestLevel + 1, "(path %s (page %s))\n",
1364 m_out->Quotew( path ).c_str(),
1365 m_out->Quotew( instance.m_PageNumber ).c_str() );
1366 }
1367
1368 m_out->Print( aNestLevel, ")\n" ); // Close sheet instances token.
1369 }
1370}

References m_out, path, OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

Referenced by Format().

◆ saveJunction()

void SCH_SEXPR_PLUGIN::saveJunction ( SCH_JUNCTION aJunction,
int  aNestLevel 
)
private

Definition at line 1072 of file sch_sexpr_plugin.cpp.

1073{
1074 wxCHECK_RET( aJunction != nullptr && m_out != nullptr, "" );
1075
1076 m_out->Print( aNestLevel, "(junction (at %s %s) (diameter %s) (color %d %d %d %s)\n",
1078 aJunction->GetPosition().x ).c_str(),
1080 aJunction->GetPosition().y ).c_str(),
1082 aJunction->GetDiameter() ).c_str(),
1083 KiROUND( aJunction->GetColor().r * 255.0 ),
1084 KiROUND( aJunction->GetColor().g * 255.0 ),
1085 KiROUND( aJunction->GetColor().b * 255.0 ),
1086 FormatDouble2Str( aJunction->GetColor().a ).c_str() );
1087
1088 m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aJunction->m_Uuid.AsString() ) );
1089
1090 m_out->Print( aNestLevel, ")\n" );
1091}
double r
Red component.
Definition: color4d.h:384
double g
Green component.
Definition: color4d.h:385
double a
Alpha component.
Definition: color4d.h:387
double b
Blue component.
Definition: color4d.h:386
COLOR4D GetColor() const
Definition: sch_junction.h:114
int GetDiameter() const
Definition: sch_junction.h:109
VECTOR2I GetPosition() const override
Definition: sch_junction.h:102
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85

References KIGFX::COLOR4D::a, KIID::AsString(), KIGFX::COLOR4D::b, FormatDouble2Str(), EDA_UNIT_UTILS::FormatInternalUnits(), KIGFX::COLOR4D::g, SCH_JUNCTION::GetColor(), SCH_JUNCTION::GetDiameter(), SCH_JUNCTION::GetPosition(), KiROUND(), m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), KIGFX::COLOR4D::r, schIUScale, TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ SaveLibrary()

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

Reimplemented from SCH_PLUGIN.

Definition at line 1534 of file sch_sexpr_plugin.cpp.

1535{
1536 if( !m_cache )
1537 m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
1538
1539 wxString oldFileName = m_cache->GetFileName();
1540
1541 if( !m_cache->IsFile( aLibraryPath ) )
1542 {
1543 m_cache->SetFileName( aLibraryPath );
1544 }
1545
1546 // This is a forced save.
1548 m_cache->Save();
1549 m_cache->SetFileName( oldFileName );
1550}
wxString GetFileName() const
void SetFileName(const wxString &aFileName)

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

◆ saveLine()

void SCH_SEXPR_PLUGIN::saveLine ( SCH_LINE aLine,
int  aNestLevel 
)
private

Definition at line 1179 of file sch_sexpr_plugin.cpp.

1180{
1181 wxCHECK_RET( aLine != nullptr && m_out != nullptr, "" );
1182
1183 wxString lineType;
1184
1185 STROKE_PARAMS line_stroke = aLine->GetStroke();
1186
1187 switch( aLine->GetLayer() )
1188 {
1189 case LAYER_BUS: lineType = "bus"; break;
1190 case LAYER_WIRE: lineType = "wire"; break;
1191 case LAYER_NOTES: lineType = "polyline"; break;
1192 default:
1193 UNIMPLEMENTED_FOR( LayerName( aLine->GetLayer() ) );
1194 }
1195
1196 m_out->Print( aNestLevel, "(%s (pts (xy %s %s) (xy %s %s))\n",
1197 TO_UTF8( lineType ),
1199 aLine->GetStartPoint().x ).c_str(),
1201 aLine->GetStartPoint().y ).c_str(),
1203 aLine->GetEndPoint().x ).c_str(),
1205 aLine->GetEndPoint().y ).c_str() );
1206
1207 line_stroke.Format( m_out, schIUScale, aNestLevel + 1 );
1208 m_out->Print( 0, "\n" );
1209
1210 m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aLine->m_Uuid.AsString() ) );
1211
1212 m_out->Print( aNestLevel, ")\n" );
1213}
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:246
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:176
VECTOR2I GetEndPoint() const
Definition: sch_line.h:143
VECTOR2I GetStartPoint() const
Definition: sch_line.h:138
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:30
@ LAYER_WIRE
Definition: layer_ids.h:344
@ LAYER_NOTES
Definition: layer_ids.h:358
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:120

References KIID::AsString(), STROKE_PARAMS::Format(), EDA_UNIT_UTILS::FormatInternalUnits(), SCH_LINE::GetEndPoint(), SCH_ITEM::GetLayer(), SCH_LINE::GetStartPoint(), SCH_LINE::GetStroke(), LAYER_BUS, LAYER_NOTES, LAYER_WIRE, LayerName(), m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), schIUScale, TO_UTF8, UNIMPLEMENTED_FOR, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format(), and saveBusEntry().

◆ saveNoConnect()

void SCH_SEXPR_PLUGIN::saveNoConnect ( SCH_NO_CONNECT aNoConnect,
int  aNestLevel 
)
private

Definition at line 1094 of file sch_sexpr_plugin.cpp.

1095{
1096 wxCHECK_RET( aNoConnect != nullptr && m_out != nullptr, "" );
1097
1098 m_out->Print( aNestLevel, "(no_connect (at %s %s) (uuid %s))\n",
1100 aNoConnect->GetPosition().x ).c_str(),
1102 aNoConnect->GetPosition().y ).c_str(),
1103 TO_UTF8( aNoConnect->m_Uuid.AsString() ) );
1104}
VECTOR2I GetPosition() const override

References KIID::AsString(), EDA_UNIT_UTILS::FormatInternalUnits(), SCH_NO_CONNECT::GetPosition(), m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), schIUScale, TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ saveShape()

void SCH_SEXPR_PLUGIN::saveShape ( SCH_SHAPE aShape,
int  aNestLevel 
)
private

Definition at line 1142 of file sch_sexpr_plugin.cpp.

1143{
1144 wxCHECK_RET( aShape != nullptr && m_out != nullptr, "" );
1145
1146 switch( aShape->GetShape() )
1147 {
1148 case SHAPE_T::ARC:
1149 formatArc( m_out, aNestLevel, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1150 aShape->GetFillColor(), aShape->m_Uuid );
1151 break;
1152
1153 case SHAPE_T::CIRCLE:
1154 formatCircle( m_out, aNestLevel, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1155 aShape->GetFillColor(), aShape->m_Uuid );
1156 break;
1157
1158 case SHAPE_T::RECT:
1159 formatRect( m_out, aNestLevel, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1160 aShape->GetFillColor(), aShape->m_Uuid );
1161 break;
1162
1163 case SHAPE_T::BEZIER:
1164 formatBezier( m_out, aNestLevel, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1165 aShape->GetFillColor(), aShape->m_Uuid );
1166 break;
1167
1168 case SHAPE_T::POLY:
1169 formatPoly( m_out, aNestLevel, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1170 aShape->GetFillColor(), aShape->m_Uuid );
1171 break;
1172
1173 default:
1175 }
1176}
FILL_T GetFillMode() const
Definition: eda_shape.h:101
SHAPE_T GetShape() const
Definition: eda_shape.h:113
COLOR4D GetFillColor() const
Definition: eda_shape.h:105
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:75
STROKE_PARAMS GetStroke() const override
Definition: sch_shape.h:64
void formatCircle(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aCircle, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
void formatArc(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aArc, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
void formatRect(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aRect, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
void formatBezier(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aBezier, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)
void formatPoly(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aPolyLine, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, const KIID &aUuid)

References ARC, BEZIER, CIRCLE, formatArc(), formatBezier(), formatCircle(), formatPoly(), formatRect(), EDA_SHAPE::GetFillColor(), EDA_SHAPE::GetFillMode(), EDA_SHAPE::GetShape(), SCH_SHAPE::GetStroke(), m_out, EDA_ITEM::m_Uuid, POLY, RECT, EDA_SHAPE::SHAPE_T_asString(), and UNIMPLEMENTED_FOR.

Referenced by Format().

◆ saveSheet()

void SCH_SEXPR_PLUGIN::saveSheet ( SCH_SHEET aSheet,
int  aNestLevel 
)
private

Definition at line 947 of file sch_sexpr_plugin.cpp.

948{
949 wxCHECK_RET( aSheet != nullptr && m_out != nullptr, "" );
950
951 m_out->Print( aNestLevel, "(sheet (at %s %s) (size %s %s)",
953 aSheet->GetPosition().x ).c_str(),
955 aSheet->GetPosition().y ).c_str(),
957 aSheet->GetSize().GetWidth() ).c_str(),
959 aSheet->GetSize().GetHeight() ).c_str() );
960
962 m_out->Print( 0, " (fields_autoplaced)" );
963
964 m_out->Print( 0, "\n" );
965
967 aSheet->GetBorderColor() );
968
969 stroke.SetWidth( aSheet->GetBorderWidth() );
970 stroke.Format( m_out, schIUScale, aNestLevel + 1 );
971
972 m_out->Print( 0, "\n" );
973
974 m_out->Print( aNestLevel + 1, "(fill (color %d %d %d %0.4f))\n",
975 KiROUND( aSheet->GetBackgroundColor().r * 255.0 ),
976 KiROUND( aSheet->GetBackgroundColor().g * 255.0 ),
977 KiROUND( aSheet->GetBackgroundColor().b * 255.0 ),
978 aSheet->GetBackgroundColor().a );
979
980 m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSheet->m_Uuid.AsString() ) );
981
983
984 for( SCH_FIELD& field : aSheet->GetFields() )
985 {
986 saveField( &field, aNestLevel + 1 );
987 }
988
989 for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
990 {
991 m_out->Print( aNestLevel + 1, "(pin %s %s (at %s %s %s)\n",
992 EscapedUTF8( pin->GetText() ).c_str(),
993 getSheetPinShapeToken( pin->GetShape() ),
995 pin->GetPosition().x ).c_str(),
997 pin->GetPosition().y ).c_str(),
998 EDA_UNIT_UTILS::FormatAngle( getSheetPinAngle( pin->GetSide() ) ).c_str() );
999
1000 pin->Format( m_out, aNestLevel + 1, 0 );
1001
1002 m_out->Print( aNestLevel + 2, "(uuid %s)\n", TO_UTF8( pin->m_Uuid.AsString() ) );
1003
1004 m_out->Print( aNestLevel + 1, ")\n" ); // Closes pin token.
1005 }
1006
1007 if( !aSheet->GetInstances().empty() )
1008 {
1009 m_out->Print( aNestLevel + 1, "(instances\n" );
1010
1011 KIID lastProjectUuid;
1012 KIID rootSheetUuid = m_schematic->Root().m_Uuid;
1013 SCH_SHEET_LIST fullHierarchy = m_schematic->GetSheets();
1014 bool project_open = false;
1015
1016 for( size_t i = 0; i < aSheet->GetInstances().size(); i++ )
1017 {
1018 // If the instance data is part of this design but no longer has an associated sheet
1019 // path, don't save it. This prevents large amounts of orphaned instance data for the
1020 // current project from accumulating in the schematic files.
1021 //
1022 // Keep all instance data when copying to the clipboard. It may be needed on paste.
1023 if( ( aSheet->GetInstances()[i].m_Path[0] == rootSheetUuid )
1024 && !fullHierarchy.GetSheetPathByKIIDPath( aSheet->GetInstances()[i].m_Path ) )
1025 {
1026 if( project_open && ( ( i + 1 == aSheet->GetInstances().size() )
1027 || lastProjectUuid != aSheet->GetInstances()[i+1].m_Path[0] ) )
1028 {
1029 m_out->Print( aNestLevel + 2, ")\n" ); // Closes `project`.
1030 project_open = false;
1031 }
1032
1033 continue;
1034 }
1035
1036 if( lastProjectUuid != aSheet->GetInstances()[i].m_Path[0] )
1037 {
1038 wxString projectName;
1039
1040 if( aSheet->GetInstances()[i].m_Path[0] == rootSheetUuid )
1041 projectName = m_schematic->Prj().GetProjectName();
1042 else
1043 projectName = aSheet->GetInstances()[i].m_ProjectName;
1044
1045 lastProjectUuid = aSheet->GetInstances()[i].m_Path[0];
1046 m_out->Print( aNestLevel + 2, "(project %s\n",
1047 m_out->Quotew( projectName ).c_str() );
1048 project_open = true;
1049 }
1050
1051 wxString path = aSheet->GetInstances()[i].m_Path.AsString();
1052
1053 m_out->Print( aNestLevel + 3, "(path %s (page %s))\n",
1054 m_out->Quotew( path ).c_str(),
1055 m_out->Quotew( aSheet->GetInstances()[i].m_PageNumber ).c_str() );
1056
1057 if( project_open && ( ( i + 1 == aSheet->GetInstances().size() )
1058 || lastProjectUuid != aSheet->GetInstances()[i+1].m_Path[0] ) )
1059 {
1060 m_out->Print( aNestLevel + 2, ")\n" ); // Closes `project`.
1061 project_open = false;
1062 }
1063 }
1064
1065 m_out->Print( aNestLevel + 1, ")\n" ); // Closes `instances`.
1066 }
1067
1068 m_out->Print( aNestLevel, ")\n" ); // Closes sheet token.
1069}
Definition: kiid.h:48
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:132
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:50
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:424
void saveField(SCH_FIELD *aField, int aNestLevel)
std::optional< SCH_SHEET_PATH > GetSheetPathByKIIDPath(const KIID_PATH &aPath) const
Finds a SCH_SHEET_PATH that matches the provided KIID_PATH.
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:366
wxSize GetSize() const
Definition: sch_sheet.h:106
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:112
int GetBorderWidth() const
Definition: sch_sheet.h:109
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:173
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:115
@ FIELDS_AUTOPLACED_NO
Definition: sch_item.h:56
const char * getSheetPinShapeToken(LABEL_FLAG_SHAPE aShape)
EDA_ANGLE getSheetPinAngle(SHEET_SIDE aSide)
@ SHEET_MANDATORY_FIELDS
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:47
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.

References KIGFX::COLOR4D::a, KIID::AsString(), KIGFX::COLOR4D::b, EscapedUTF8(), FIELDS_AUTOPLACED_NO, STROKE_PARAMS::Format(), EDA_UNIT_UTILS::FormatAngle(), EDA_UNIT_UTILS::FormatInternalUnits(), KIGFX::COLOR4D::g, SCH_SHEET::GetBackgroundColor(), SCH_SHEET::GetBorderColor(), SCH_SHEET::GetBorderWidth(), SCH_SHEET::GetFields(), SCH_ITEM::GetFieldsAutoplaced(), SCH_SHEET::GetInstances(), SCH_SHEET::GetPins(), SCH_SHEET::GetPosition(), PROJECT::GetProjectName(), SCH_SHEET_LIST::GetSheetPathByKIIDPath(), getSheetPinAngle(), getSheetPinShapeToken(), SCHEMATIC::GetSheets(), SCH_SHEET::GetSize(), KiROUND(), m_nextFreeFieldId, m_out, m_schematic, EDA_ITEM::m_Uuid, path, pin, OUTPUTFORMATTER::Print(), SCHEMATIC::Prj(), OUTPUTFORMATTER::Quotew(), KIGFX::COLOR4D::r, SCHEMATIC::Root(), saveField(), schIUScale, STROKE_PARAMS::SetWidth(), SHEET_MANDATORY_FIELDS, SOLID, TO_UTF8, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ SaveSymbol()

void SCH_SEXPR_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 1461 of file sch_sexpr_plugin.cpp.

1463{
1464 LOCALE_IO toggle; // toggles on, then off, the C locale.
1465
1466 cacheLib( aLibraryPath, aProperties );
1467
1468 m_cache->AddSymbol( aSymbol );
1469
1470 if( !isBuffering( aProperties ) )
1471 m_cache->Save();
1472}
virtual void AddSymbol(const LIB_SYMBOL *aSymbol)

References SCH_LIB_PLUGIN_CACHE::AddSymbol(), cacheLib(), isBuffering(), m_cache, and SCH_SEXPR_PLUGIN_CACHE::Save().

◆ saveSymbol()

void SCH_SEXPR_PLUGIN::saveSymbol ( SCH_SYMBOL aSymbol,
const SCHEMATIC aSchematic,
int  aNestLevel,
bool  aForClipboard 
)
private

Definition at line 633 of file sch_sexpr_plugin.cpp.

635{
636 wxCHECK_RET( aSymbol != nullptr && m_out != nullptr, "" );
637
638 // Sort symbol instance data to minimize file churn.
640
641 std::string libName;
642
643 wxString symbol_name = aSymbol->GetLibId().Format();
644
645 if( symbol_name.size() )
646 {
647 libName = toUTFTildaText( symbol_name );
648 }
649 else
650 {
651 libName = "_NONAME_";
652 }
653
655 int orientation = aSymbol->GetOrientation() & ~( SYM_MIRROR_X | SYM_MIRROR_Y );
656
657 if( orientation == SYM_ORIENT_90 )
658 angle = ANGLE_90;
659 else if( orientation == SYM_ORIENT_180 )
661 else if( orientation == SYM_ORIENT_270 )
663 else
664 angle = ANGLE_0;
665
666 m_out->Print( aNestLevel, "(symbol" );
667
668 if( !aSymbol->UseLibIdLookup() )
669 {
670 m_out->Print( 0, " (lib_name %s)",
671 m_out->Quotew( aSymbol->GetSchSymbolLibraryName() ).c_str() );
672 }
673
674 m_out->Print( 0, " (lib_id %s) (at %s %s %s)",
675 m_out->Quotew( aSymbol->GetLibId().Format().wx_str() ).c_str(),
677 aSymbol->GetPosition().x ).c_str(),
679 aSymbol->GetPosition().y ).c_str(),
681
682 bool mirrorX = aSymbol->GetOrientation() & SYM_MIRROR_X;
683 bool mirrorY = aSymbol->GetOrientation() & SYM_MIRROR_Y;
684
685 if( mirrorX || mirrorY )
686 {
687 m_out->Print( 0, " (mirror" );
688
689 if( mirrorX )
690 m_out->Print( 0, " x" );
691
692 if( mirrorY )
693 m_out->Print( 0, " y" );
694
695 m_out->Print( 0, ")" );
696 }
697
698 // The symbol unit is always set to the first instance regardless of the current sheet
699 // instance to prevent file churn.
700 int unit = ( aSymbol->GetInstanceReferences().size() == 0 ) ?
701 aSymbol->GetUnit() :
702 aSymbol->GetInstanceReferences()[0].m_Unit;
703
704 m_out->Print( 0, " (unit %d)", unit );
705
706 if( aSymbol->GetConvert() == LIB_ITEM::LIB_CONVERT::DEMORGAN )
707 m_out->Print( 0, " (convert %d)", aSymbol->GetConvert() );
708
709 m_out->Print( 0, "\n" );
710
711 m_out->Print( aNestLevel + 1, "(in_bom %s)", ( aSymbol->GetIncludeInBom() ) ? "yes" : "no" );
712 m_out->Print( 0, " (on_board %s)", ( aSymbol->GetIncludeOnBoard() ) ? "yes" : "no" );
713 m_out->Print( 0, " (dnp %s)", ( aSymbol->GetDNP() ) ? "yes" : "no" );
714
715 if( aSymbol->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO )
716 m_out->Print( 0, " (fields_autoplaced)" );
717
718 m_out->Print( 0, "\n" );
719
720 m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aSymbol->m_Uuid.AsString() ) );
721
723
724 for( SCH_FIELD& field : aSymbol->GetFields() )
725 {
726 int id = field.GetId();
727 wxString value = field.GetText();
728
729 if( !aForClipboard && aSymbol->GetInstanceReferences().size() )
730 {
731 // The instance fields are always set to the default instance regardless of the
732 // sheet instance to prevent file churn.
733 if( id == REFERENCE_FIELD )
734 {
735 field.SetText( aSymbol->GetInstanceReferences()[0].m_Reference );
736 }
737 else if( id == VALUE_FIELD )
738 {
739 field.SetText( aSymbol->GetValueFieldText( false ) );
740 }
741 else if( id == FOOTPRINT_FIELD )
742 {
743 field.SetText( aSymbol->GetFootprintFieldText( false ) );
744 }
745 }
746
747 try
748 {
749 saveField( &field, aNestLevel + 1 );
750 }
751 catch( ... )
752 {
753 // Restore the changed field text on write error.
754 if( id == REFERENCE_FIELD || id == VALUE_FIELD || id == FOOTPRINT_FIELD )
755 field.SetText( value );
756
757 throw;
758 }
759
760 if( id == REFERENCE_FIELD || id == VALUE_FIELD || id == FOOTPRINT_FIELD )
761 field.SetText( value );
762 }
763
764 for( const std::unique_ptr<SCH_PIN>& pin : aSymbol->GetRawPins() )
765 {
766 if( pin->GetAlt().IsEmpty() )
767 {
768 m_out->Print( aNestLevel + 1, "(pin %s (uuid %s))\n",
769 m_out->Quotew( pin->GetNumber() ).c_str(),
770 TO_UTF8( pin->m_Uuid.AsString() ) );
771 }
772 else
773 {
774 m_out->Print( aNestLevel + 1, "(pin %s (uuid %s) (alternate %s))\n",
775 m_out->Quotew( pin->GetNumber() ).c_str(),
776 TO_UTF8( pin->m_Uuid.AsString() ),
777 m_out->Quotew( pin->GetAlt() ).c_str() );
778 }
779 }
780
781 if( !aSymbol->GetInstanceReferences().empty() )
782 {
783 m_out->Print( aNestLevel + 1, "(instances\n" );
784
785 KIID lastProjectUuid;
786 KIID rootSheetUuid = aSchematic.Root().m_Uuid;
787 SCH_SHEET_LIST fullHierarchy = aSchematic.GetSheets();
788 bool project_open = false;
789
790 for( size_t i = 0; i < aSymbol->GetInstanceReferences().size(); i++ )
791 {
792 // If the instance data is part of this design but no longer has an associated sheet
793 // path, don't save it. This prevents large amounts of orphaned instance data for the
794 // current project from accumulating in the schematic files.
795 //
796 // Keep all instance data when copying to the clipboard. It may be needed on paste.
797 if( !aForClipboard
798 && ( aSymbol->GetInstanceReferences()[i].m_Path[0] == rootSheetUuid )
799 && !fullHierarchy.GetSheetPathByKIIDPath( aSymbol->GetInstanceReferences()[i].m_Path ) )
800 {
801 if( project_open && ( ( i + 1 == aSymbol->GetInstanceReferences().size() )
802 || lastProjectUuid != aSymbol->GetInstanceReferences()[i+1].m_Path[0] ) )
803 {
804 m_out->Print( aNestLevel + 2, ")\n" ); // Closes `project`.
805 project_open = false;
806 }
807
808 continue;
809 }
810
811 if( lastProjectUuid != aSymbol->GetInstanceReferences()[i].m_Path[0] )
812 {
813 wxString projectName;
814
815 if( aSymbol->GetInstanceReferences()[i].m_Path[0] == rootSheetUuid )
816 projectName = aSchematic.Prj().GetProjectName();
817 else
818 projectName = aSymbol->GetInstanceReferences()[i].m_ProjectName;
819
820 lastProjectUuid = aSymbol->GetInstanceReferences()[i].m_Path[0];
821 m_out->Print( aNestLevel + 2, "(project %s\n",
822 m_out->Quotew( projectName ).c_str() );
823 project_open = true;
824 }
825
826 wxString path = aSymbol->GetInstanceReferences()[i].m_Path.AsString();
827
828 m_out->Print( aNestLevel + 3, "(path %s\n",
829 m_out->Quotew( path ).c_str() );
830 m_out->Print( aNestLevel + 4, "(reference %s) (unit %d)\n",
831 m_out->Quotew( aSymbol->GetInstanceReferences()[i].m_Reference ).c_str(),
832 aSymbol->GetInstanceReferences()[i].m_Unit );
833 m_out->Print( aNestLevel + 3, ")\n" );
834
835 if( project_open && ( ( i + 1 == aSymbol->GetInstanceReferences().size() )
836 || lastProjectUuid != aSymbol->GetInstanceReferences()[i+1].m_Path[0] ) )
837 {
838 m_out->Print( aNestLevel + 2, ")\n" ); // Closes `project`.
839 project_open = false;
840 }
841 }
842
843 m_out->Print( aNestLevel + 1, ")\n" ); // Closes `instances`.
844 }
845
846 m_out->Print( aNestLevel, ")\n" ); // Closes `symbol`.
847}
const std::vector< SYMBOL_INSTANCE_REFERENCE > & GetInstanceReferences()
Definition: sch_symbol.h:139
std::vector< std::unique_ptr< SCH_PIN > > & GetRawPins()
Definition: sch_symbol.h:537
int GetUnit() const
Definition: sch_symbol.h:227
bool GetIncludeOnBoard() const
Definition: sch_symbol.h:732
bool GetIncludeInBom() const
Definition: sch_symbol.h:729
int GetConvert() const
Definition: sch_symbol.h:269
const wxString GetFootprintFieldText(bool aResolve) const
Definition: sch_symbol.cpp:798
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:702
const wxString GetValueFieldText(bool aResolve) const
Definition: sch_symbol.cpp:783
int GetOrientation() const
Get the display symbol orientation.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:849
void SortInstances(bool(*aSortFunction)(const SYMBOL_INSTANCE_REFERENCE &aLhs, const SYMBOL_INSTANCE_REFERENCE &aRhs))
Definition: sch_symbol.cpp:515
bool GetDNP() const
Definition: sch_symbol.h:735
static constexpr EDA_ANGLE & ANGLE_180
Definition: eda_angle.h:416
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:414
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:412
static constexpr EDA_ANGLE & ANGLE_270
Definition: eda_angle.h:417
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
@ SYM_ORIENT_270
@ SYM_MIRROR_Y
@ SYM_ORIENT_180
@ SYM_MIRROR_X
@ SYM_ORIENT_90
bool SortSymbolInstancesByProjectUuid(const SYMBOL_INSTANCE_REFERENCE &aLhs, const SYMBOL_INSTANCE_REFERENCE &aRhs)
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
@ 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".

References PNS::angle(), ANGLE_0, ANGLE_180, ANGLE_270, ANGLE_90, KIID::AsString(), FIELDS_AUTOPLACED_NO, FOOTPRINT_FIELD, LIB_ID::Format(), EDA_UNIT_UTILS::FormatAngle(), EDA_UNIT_UTILS::FormatInternalUnits(), SCH_SYMBOL::GetConvert(), SCH_SYMBOL::GetDNP(), SCH_SYMBOL::GetFields(), SCH_ITEM::GetFieldsAutoplaced(), SCH_SYMBOL::GetFootprintFieldText(), SCH_SYMBOL::GetIncludeInBom(), SCH_SYMBOL::GetIncludeOnBoard(), SCH_SYMBOL::GetInstanceReferences(), SCH_SYMBOL::GetLibId(), SCH_SYMBOL::GetOrientation(), SCH_SYMBOL::GetPosition(), PROJECT::GetProjectName(), SCH_SYMBOL::GetRawPins(), SCH_SYMBOL::GetSchSymbolLibraryName(), SCH_SHEET_LIST::GetSheetPathByKIIDPath(), SCHEMATIC::GetSheets(), SCH_SYMBOL::GetUnit(), SCH_SYMBOL::GetValueFieldText(), m_nextFreeFieldId, m_out, EDA_ITEM::m_Uuid, MANDATORY_FIELDS, path, pin, OUTPUTFORMATTER::Print(), SCHEMATIC::Prj(), OUTPUTFORMATTER::Quotew(), REFERENCE_FIELD, SCHEMATIC::Root(), saveField(), schIUScale, SCH_SYMBOL::SortInstances(), SortSymbolInstancesByProjectUuid(), SYM_MIRROR_X, SYM_MIRROR_Y, SYM_ORIENT_180, SYM_ORIENT_270, SYM_ORIENT_90, TO_UTF8, toUTFTildaText(), SCH_SYMBOL::UseLibIdLookup(), VALUE_FIELD, UTF8::wx_str(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ saveText()

void SCH_SEXPR_PLUGIN::saveText ( SCH_TEXT aText,
int  aNestLevel 
)
private

Definition at line 1216 of file sch_sexpr_plugin.cpp.

1217{
1218 wxCHECK_RET( aText != nullptr && m_out != nullptr, "" );
1219
1220 // Note: label is nullptr SCH_TEXT, but not for SCH_LABEL_XXX,
1221 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aText );
1222
1223 m_out->Print( aNestLevel, "(%s %s",
1224 getTextTypeToken( aText->Type() ),
1225 m_out->Quotew( aText->GetText() ).c_str() );
1226
1227 if( aText->Type() == SCH_DIRECTIVE_LABEL_T )
1228 {
1229 SCH_DIRECTIVE_LABEL* flag = static_cast<SCH_DIRECTIVE_LABEL*>( aText );
1230
1231 m_out->Print( 0, " (length %s)",
1233 flag->GetPinLength() ).c_str() );
1234 }
1235
1236 EDA_ANGLE angle = aText->GetTextAngle();
1237
1238 if( label )
1239 {
1240 if( aText->Type() == SCH_GLOBAL_LABEL_T
1241 || aText->Type() == SCH_HIER_LABEL_T
1242 || aText->Type() == SCH_DIRECTIVE_LABEL_T )
1243 {
1244 m_out->Print( 0, " (shape %s)", getSheetPinShapeToken( label->GetShape() ) );
1245 }
1246
1247 // The angle of the text is always 0 or 90 degrees for readibility reasons,
1248 // but the item itself can have more rotation (-90 and 180 deg)
1249 switch( aText->GetTextSpinStyle() )
1250 {
1251 default:
1252 case TEXT_SPIN_STYLE::LEFT: angle += ANGLE_180; break;
1253 case TEXT_SPIN_STYLE::UP: break;
1254 case TEXT_SPIN_STYLE::RIGHT: break;
1255 case TEXT_SPIN_STYLE::BOTTOM: angle += ANGLE_180; break;
1256 }
1257 }
1258
1259 if( aText->GetText().Length() < 50 )
1260 {
1261 m_out->Print( 0, " (at %s %s %s)",
1263 aText->GetPosition().x ).c_str(),
1265 aText->GetPosition().y ).c_str(),
1267 }
1268 else
1269 {
1270 m_out->Print( 0, "\n" );
1271 m_out->Print( aNestLevel + 1, "(at %s %s %s)",
1273 aText->GetPosition().x ).c_str(),
1275 aText->GetPosition().y ).c_str(),
1277 }
1278
1280 m_out->Print( 0, " (fields_autoplaced)" );
1281
1282 m_out->Print( 0, "\n" );
1283 aText->EDA_TEXT::Format( m_out, aNestLevel, 0 );
1284
1285 m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aText->m_Uuid.AsString() ) );
1286
1287 if( label )
1288 {
1289 for( SCH_FIELD& field : label->GetFields() )
1290 saveField( &field, aNestLevel + 1 );
1291 }
1292
1293 m_out->Print( aNestLevel, ")\n" ); // Closes text token.
1294}
LABEL_FLAG_SHAPE GetShape() const override
Definition: sch_label.h:73
std::vector< SCH_FIELD > & GetFields()
Definition: sch_label.h:90
VECTOR2I GetPosition() const override
Definition: sch_text.h:203
TEXT_SPIN_STYLE GetTextSpinStyle() const
Definition: sch_text.h:148
const char * getTextTypeToken(KICAD_T aType)

References PNS::angle(), ANGLE_180, KIID::AsString(), TEXT_SPIN_STYLE::BOTTOM, FIELDS_AUTOPLACED_NO, flag, EDA_UNIT_UTILS::FormatAngle(), EDA_UNIT_UTILS::FormatInternalUnits(), SCH_LABEL_BASE::GetFields(), SCH_ITEM::GetFieldsAutoplaced(), SCH_TEXT::GetPosition(), SCH_LABEL_BASE::GetShape(), getSheetPinShapeToken(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), SCH_TEXT::GetTextSpinStyle(), getTextTypeToken(), TEXT_SPIN_STYLE::LEFT, m_out, EDA_ITEM::m_Uuid, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), TEXT_SPIN_STYLE::RIGHT, saveField(), SCH_DIRECTIVE_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, schIUScale, TO_UTF8, EDA_ITEM::Type(), TEXT_SPIN_STYLE::UP, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Format().

◆ saveTextBox()

void SCH_SEXPR_PLUGIN::saveTextBox ( SCH_TEXTBOX aText,
int  aNestLevel 
)
private

Definition at line 1297 of file sch_sexpr_plugin.cpp.

1298{
1299 wxCHECK_RET( aTextBox != nullptr && m_out != nullptr, "" );
1300
1301 m_out->Print( aNestLevel, "(text_box %s\n",
1302 m_out->Quotew( aTextBox->GetText() ).c_str() );
1303
1304 VECTOR2I pos = aTextBox->GetStart();
1305 VECTOR2I size = aTextBox->GetEnd() - pos;
1306
1307 m_out->Print( aNestLevel + 1, "(at %s %s %s) (size %s %s)\n",
1310 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
1313
1314 aTextBox->GetStroke().Format( m_out, schIUScale, aNestLevel + 1 );
1315 m_out->Print( 0, "\n" );
1316 formatFill( m_out, aNestLevel + 1, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
1317 m_out->Print( 0, "\n" );
1318
1319 aTextBox->EDA_TEXT::Format( m_out, aNestLevel, 0 );
1320
1321 if( aTextBox->m_Uuid != niluuid )
1322 m_out->Print( aNestLevel + 1, "(uuid %s)\n", TO_UTF8( aTextBox->m_Uuid.AsString() ) );
1323
1324 m_out->Print( aNestLevel, ")\n" );
1325}
KIID niluuid(0)
void formatFill(OUTPUTFORMATTER *aFormatter, int aNestLevel, FILL_T aFillMode, const COLOR4D &aFillColor)
Fill token formatting helper.

References KIID::AsString(), STROKE_PARAMS::Format(), EDA_UNIT_UTILS::FormatAngle(), formatFill(), EDA_UNIT_UTILS::FormatInternalUnits(), EDA_SHAPE::GetEnd(), EDA_SHAPE::GetFillColor(), EDA_SHAPE::GetFillMode(), EDA_SHAPE::GetStart(), SCH_SHAPE::GetStroke(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), m_out, EDA_ITEM::m_Uuid, niluuid, OUTPUTFORMATTER::Print(), OUTPUTFORMATTER::Quotew(), schIUScale, 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_SEXPR_PLUGIN::SetProgressReporter ( PROGRESS_REPORTER aReporter)
inlineoverridevirtual

Set an optional progress reporter.

Reimplemented from SCH_PLUGIN.

Definition at line 84 of file sch_sexpr_plugin.h.

85 {
86 m_progressReporter = aReporter;
87 }

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 _.

Member Data Documentation

◆ m_appending

bool SCH_SEXPR_PLUGIN::m_appending
protected

Schematic load append status.

Definition at line 169 of file sch_sexpr_plugin.h.

Referenced by init(), Load(), and loadFile().

◆ m_cache

◆ m_currentPath

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

Stack to maintain nested sheet paths.

Definition at line 175 of file sch_sexpr_plugin.h.

Referenced by Load(), and loadHierarchy().

◆ m_error

wxString SCH_SEXPR_PLUGIN::m_error
protected

For throwing exceptions or errors on partial loads.

Definition at line 170 of file sch_sexpr_plugin.h.

Referenced by GetError(), and loadHierarchy().

◆ m_nextFreeFieldId

int SCH_SEXPR_PLUGIN::m_nextFreeFieldId
protected

Definition at line 168 of file sch_sexpr_plugin.h.

Referenced by init(), saveField(), saveSheet(), and saveSymbol().

◆ m_out

OUTPUTFORMATTER* SCH_SEXPR_PLUGIN::m_out
protected

◆ m_path

wxString SCH_SEXPR_PLUGIN::m_path
protected

Root project path for loading child sheets.

Definition at line 174 of file sch_sexpr_plugin.h.

Referenced by Load().

◆ m_progressReporter

PROGRESS_REPORTER* SCH_SEXPR_PLUGIN::m_progressReporter
protected

Definition at line 172 of file sch_sexpr_plugin.h.

Referenced by loadFile(), and SetProgressReporter().

◆ m_rootSheet

SCH_SHEET* SCH_SEXPR_PLUGIN::m_rootSheet
protected

The root sheet of the schematic being loaded.

Definition at line 176 of file sch_sexpr_plugin.h.

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

◆ m_schematic

SCHEMATIC* SCH_SEXPR_PLUGIN::m_schematic
protected

Definition at line 177 of file sch_sexpr_plugin.h.

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

◆ m_version

int SCH_SEXPR_PLUGIN::m_version
protected

Version of file being loaded.

Definition at line 167 of file sch_sexpr_plugin.h.

Referenced by init().

◆ PropBuffering

const char * SCH_SEXPR_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 94 of file sch_sexpr_plugin.h.

Referenced by isBuffering().


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