37#include <wx/wfstream.h>
38#include <wx/txtstrm.h>
51 catch(
const std::runtime_error& )
68 const std::map<std::string, UTF8>* aProperties )
70 wxCHECK( !aFileName.IsEmpty() && aSchematic,
nullptr );
80 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr,
"Can't append to a schematic with no root!" );
81 rootSheet = &aSchematic->
Root();
87 aSchematic->
SetRoot( rootSheet );
101 csaLoader.
Load( aSchematic, rootSheet );
106 wxCHECK_MSG( libTable,
nullptr,
"Could not load symbol lib table." );
119 sch_plugin->CreateLibrary( libFileName.GetFullPath() );
120 wxString libTableUri =
"${KIPRJMOD}/" + libFileName.GetFullName();
133 libTable->
Format( &formatter, 0 );
142 std::map<std::string, UTF8> properties;
146 sch_plugin->SaveSymbol( libFileName.GetFullPath(), symbol, &properties );
148 sch_plugin->SaveLibrary( libFileName.GetFullPath() );
174 const wxString& aLibraryPath,
175 const std::map<std::string, UTF8>* aProperties )
179 for(
auto& [libnameStr, libSymbol] :
m_libCache )
180 aSymbolNameList.Add( libSymbol->GetName() );
185 const wxString& aLibraryPath,
186 const std::map<std::string, UTF8>* aProperties )
190 for(
auto& [libnameStr, libSymbol] :
m_libCache )
191 aSymbolList.push_back( libSymbol.get() );
196 const wxString& aAliasName,
197 const std::map<std::string, UTF8>* aProperties )
210 std::set<wxString> fieldNames;
212 for(
auto& [libnameStr, libSymbol] :
m_libCache )
214 std::vector<SCH_FIELD*> fields;
215 libSymbol->GetFields( fields );
219 if( field->IsMandatory() )
222 fieldNames.insert( field->GetName() );
226 std::copy( fieldNames.begin(), fieldNames.end(), std::back_inserter( aNames ) );
232 ( *aListToAppendTo )[
"csa"] =
233 UTF8(
_(
"Path to the CADSTAR schematic archive (*.csa) file related to this CADSTAR "
234 "parts library. If none specified it is assumed to be 'symbol.csa' in the "
237 ( *aListToAppendTo )[
"fplib"] =
238 UTF8(
_(
"Name of the footprint library related to the symbols in this library. You "
239 "should create a separate entry for the CADSTAR PCB Archive (*.cpa) file in "
240 "the footprint library tables. If none specified, 'cadstarpcblib' is assumed." ) );
245 const std::map<std::string, UTF8>* aProperties )
248 wxString fplibname =
"cadstarpcblib";
253 if( aProperties && aProperties->contains(
"csa" ) )
255 csafn = wxFileName( aProperties->at(
"csa" ) );
257 if( !csafn.IsAbsolute() )
259 wxFileName libDir( aLibraryPath );
261 libDir.SetName(
"" );
270 csafn = wxFileName( aLibraryPath );
271 csafn.SetExt(
"csa" );
273 if( !csafn.FileExists() )
275 csafn.SetName(
"symbol" );
277 if( !csafn.FileExists() )
279 csafn = wxDir::FindFirst( csafn.GetPath(), wxS(
"*.csa" ),
280 wxDIR_FILES | wxDIR_HIDDEN );
282 if( !csafn.FileExists() )
285 _(
"Cannot find the .csa file corresponding to library '%s'." ),
292 if( aProperties && aProperties->contains(
"fplib" ) )
294 fplibname = wxString::FromUTF8( aProperties->at(
"fplib" ) );
298 long long timestamp = 0;
299 wxFileName fn( aLibraryPath );
301 if( fn.IsFileReadable() )
302 timestamp = fn.GetModificationTime().GetValue().GetValue();
305 if( fn.IsFileReadable()
320 std::vector<LIB_SYMBOL*> symbols = csaLoader.
LoadPartsLib( aLibraryPath );
324 m_libCache.insert( { sym->GetName(), std::unique_ptr<LIB_SYMBOL>( sym ) } );
Loads a csa file into a KiCad SCHEMATIC object.
bool CheckFileHeader(const std::filesystem::path &aPath) const
const std::vector< LIB_SYMBOL * > & GetLoadedSymbols() const
void Load(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet)
Loads a CADSTAR Schematic Archive file into the KiCad SCHEMATIC object given.
static wxString CreateLibName(const wxFileName &aFileName, const SCH_SHEET *aRootSheet)
std::vector< LIB_SYMBOL * > LoadPartsLib(const wxString &aFilename)
void SetFpLibName(const wxString &aLibName)
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this IO object can read the specified library file/directory.
A logical library item identifier and consists of various portions much like a URI.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Define a library symbol object.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
bool InsertRow(LIB_TABLE_ROW *aRow, bool doReplace=false)
Adds aRow if it does not already exist or if doReplace is true.
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
virtual const wxString GetProjectPath() const
Return the full path of the project.
Holds all the data relating to one schematic.
void FixupJunctions()
Add junctions to this schematic where required.
SCH_SHEET_LIST Hierarchy() const override
Return the full schematic flattened hierarchical sheet list.
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
int GetModifyHash() const override
Return the modification hash from the library cache.
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
long long m_cacheTimestamp
void ensureLoadedLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties)
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
void GetLibraryOptions(std::map< std::string, UTF8 > *aListToAppendTo) const override
Append supported SCH_IO options to aListToAppenTo along with internationalized descriptions.
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
NAME_TO_SYMBOL_MAP m_libCache
wxString m_cachefplibname
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
Base class for any item which can be embedded within the SCHEMATIC container class,...
const KIID & GetUuid() const
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void SetFileName(const wxString &aFilename)
SCH_SCREEN * GetScreen() const
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
void SetLibId(const LIB_ID &aName)
const LIB_ID & GetLibId() const override
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
static const wxString GetSymbolLibTableFileName()
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
static REPORTER & GetInstance()
static void SetReporter(REPORTER *aReporter)
Set the reporter to use for reporting font substitution warnings.
static const std::string KiCadSymbolLibFileExtension
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
#define THROW_IO_ERROR(msg)
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().