38#include <wx/wfstream.h>
39#include <wx/txtstrm.h>
52 catch(
const std::runtime_error& )
69 const std::map<std::string, UTF8>* aProperties )
71 wxCHECK( !aFileName.IsEmpty() && aSchematic,
nullptr );
81 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr,
"Can't append to a schematic with no root!" );
82 rootSheet = &aSchematic->
Root();
88 aSchematic->
SetRoot( rootSheet );
102 csaLoader.
Load( aSchematic, rootSheet );
107 wxCHECK_MSG(
table,
nullptr,
"Could not load symbol lib table." );
117 if( !
table->HasRow( libName ) )
120 sch_plugin->CreateLibrary( libFileName.GetFullPath() );
121 wxString libTableUri =
"${KIPRJMOD}/" + libFileName.GetFullName();
126 row.
SetURI( libTableUri );
135 std::map<std::string, UTF8> properties;
139 sch_plugin->SaveSymbol( libFileName.GetFullPath(), symbol, &properties );
141 sch_plugin->SaveLibrary( libFileName.GetFullPath() );
167 const wxString& aLibraryPath,
168 const std::map<std::string, UTF8>* aProperties )
172 for(
auto& [libnameStr, libSymbol] :
m_libCache )
173 aSymbolNameList.Add( libSymbol->GetName() );
178 const wxString& aLibraryPath,
179 const std::map<std::string, UTF8>* aProperties )
183 for(
auto& [libnameStr, libSymbol] :
m_libCache )
184 aSymbolList.push_back( libSymbol.get() );
189 const wxString& aAliasName,
190 const std::map<std::string, UTF8>* aProperties )
203 std::set<wxString> fieldNames;
205 for(
auto& [libnameStr, libSymbol] :
m_libCache )
207 std::vector<SCH_FIELD*> fields;
208 libSymbol->GetFields( fields );
212 if( field->IsMandatory() )
215 fieldNames.insert( field->GetName() );
219 std::copy( fieldNames.begin(), fieldNames.end(), std::back_inserter( aNames ) );
225 ( *aListToAppendTo )[
"csa"] =
226 UTF8(
_(
"Path to the CADSTAR schematic archive (*.csa) file related to this CADSTAR "
227 "parts library. If none specified it is assumed to be 'symbol.csa' in the "
230 ( *aListToAppendTo )[
"fplib"] =
231 UTF8(
_(
"Name of the footprint library related to the symbols in this library. You "
232 "should create a separate entry for the CADSTAR PCB Archive (*.cpa) file in "
233 "the footprint library tables. If none specified, 'cadstarpcblib' is assumed." ) );
238 const std::map<std::string, UTF8>* aProperties )
241 wxString fplibname =
"cadstarpcblib";
246 if( aProperties && aProperties->contains(
"csa" ) )
248 csafn = wxFileName( aProperties->at(
"csa" ) );
250 if( !csafn.IsAbsolute() )
252 wxFileName libDir( aLibraryPath );
254 libDir.SetName(
"" );
263 csafn = wxFileName( aLibraryPath );
264 csafn.SetExt(
"csa" );
266 if( !csafn.FileExists() )
268 csafn.SetName(
"symbol" );
270 if( !csafn.FileExists() )
272 csafn = wxDir::FindFirst( csafn.GetPath(), wxS(
"*.csa" ),
273 wxDIR_FILES | wxDIR_HIDDEN );
275 if( !csafn.FileExists() )
278 _(
"Cannot find the .csa file corresponding to library '%s'." ),
285 if( aProperties && aProperties->contains(
"fplib" ) )
287 fplibname = wxString::FromUTF8( aProperties->at(
"fplib" ) );
291 long long timestamp = 0;
292 wxFileName fn( aLibraryPath );
294 if( fn.IsFileReadable() && fn.GetModificationTime().IsValid() )
295 timestamp = fn.GetModificationTime().GetValue().GetValue();
297 if( fn.IsFileReadable()
312 std::vector<LIB_SYMBOL*> symbols = csaLoader.
LoadPartsLib( aLibraryPath );
316 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.
std::optional< LIBRARY_TABLE * > ProjectTable() const
Retrieves the project library table for this adapter type, or nullopt if one doesn't exist.
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetURI(const wxString &aUri)
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.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Holds all the data relating to one schematic.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
void FixupJunctionsAfterImport()
Add junctions to this schematic where required.
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.
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
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::optional< LIB_STATUS > LoadOne(const wxString &aNickname)
Loads or reloads the given library, if it exists.
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)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().