34#include <wx/wfstream.h>
35#include <wx/txtstrm.h>
48 catch(
const std::runtime_error& )
65 const std::map<std::string, UTF8>* aProperties )
67 wxCHECK( !aFileName.IsEmpty() && aSchematic,
nullptr );
77 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr,
"Can't append to a schematic with no root!" );
78 rootSheet = aAppendToMe;
98 csaLoader.
Load( aSchematic, rootSheet );
137 std::vector<LIB_SYMBOL*>
result;
149 const wxString& aLibraryPath,
150 const std::map<std::string, UTF8>* aProperties )
154 for(
auto& [libnameStr, libSymbol] :
m_libCache )
155 aSymbolNameList.Add( libSymbol->GetName() );
160 const wxString& aLibraryPath,
161 const std::map<std::string, UTF8>* aProperties )
165 for(
auto& [libnameStr, libSymbol] :
m_libCache )
166 aSymbolList.push_back( libSymbol.get() );
171 const wxString& aAliasName,
172 const std::map<std::string, UTF8>* aProperties )
185 std::set<wxString> fieldNames;
187 for(
auto& [libnameStr, libSymbol] :
m_libCache )
189 std::vector<SCH_FIELD*> fields;
190 libSymbol->GetFields( fields );
194 if( field->IsMandatory() )
197 fieldNames.insert( field->GetName() );
201 std::copy( fieldNames.begin(), fieldNames.end(), std::back_inserter( aNames ) );
207 ( *aListToAppendTo )[
"csa"] =
208 UTF8(
_(
"Path to the CADSTAR schematic archive (*.csa) file related to this CADSTAR "
209 "parts library. If none specified it is assumed to be 'symbol.csa' in the "
212 ( *aListToAppendTo )[
"fplib"] =
213 UTF8(
_(
"Name of the footprint library related to the symbols in this library. You "
214 "should create a separate entry for the CADSTAR PCB Archive (*.cpa) file in "
215 "the footprint library tables. If none specified, 'cadstarpcblib' is assumed." ) );
220 const std::map<std::string, UTF8>* aProperties )
223 wxString fplibname =
"cadstarpcblib";
228 if( aProperties && aProperties->contains(
"csa" ) )
230 csafn = wxFileName( aProperties->at(
"csa" ) );
232 if( !csafn.IsAbsolute() )
234 wxFileName libDir( aLibraryPath );
236 libDir.SetName(
"" );
245 csafn = wxFileName( aLibraryPath );
246 csafn.SetExt(
"csa" );
248 if( !csafn.FileExists() )
250 csafn.SetName(
"symbol" );
252 if( !csafn.FileExists() )
254 csafn = wxDir::FindFirst( csafn.GetPath(), wxS(
"*.csa" ), wxDIR_FILES | wxDIR_HIDDEN );
256 if( !csafn.FileExists() )
257 THROW_IO_ERRORF(
_(
"Cannot find the .csa file corresponding to library '%s'." ), aLibraryPath );
262 if( aProperties && aProperties->contains(
"fplib" ) )
263 fplibname = wxString::FromUTF8( aProperties->at(
"fplib" ) );
266 long long timestamp = 0;
267 wxFileName fn( aLibraryPath );
269 if( fn.IsFileReadable() && fn.GetModificationTime().IsValid() )
270 timestamp = fn.GetModificationTime().GetValue().GetValue();
272 if( fn.IsFileReadable()
287 std::vector<LIB_SYMBOL*> symbols = csaLoader.
LoadPartsLib( aLibraryPath );
291 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)
RAII class to set and restore the fontconfig reporter.
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.
static LOAD_INFO_REPORTER & GetInstance()
virtual const wxString GetProjectFullName() const
Return the full path and name 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.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
void SetTopLevelSheets(const std::vector< SCH_SHEET * > &aSheets)
Replace the top level sheets, rebuilding the hierarchy and connectivity around them.
int FixupJunctionsAfterImport(const std::function< void(SCH_LINE *, SCH_LINE *)> &aOnSplit={})
Add junctions to this schematic where required.
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)
std::vector< LIB_SYMBOL * > GetImportedCachedLibrarySymbols() override
Return the canonical symbol definitions produced by the last LoadSchematicFile().
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
std::vector< std::unique_ptr< LIB_SYMBOL > > m_importedLibSymbols
Definitions from the last LoadSchematicFile, cloned out to the import reconciler on request.
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
Base class for any item which can be embedded within the SCHEMATIC container class,...
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)
void SyncUuidToScreen()
Take the identity of the screen this sheet owns.
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 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
#define THROW_IO_ERRORF(msg,...)
wxString result
Test unit parsing edge cases and error handling.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().