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 );
98 csaLoader.
Load( aSchematic, rootSheet );
103 wxCHECK_MSG( libTable,
nullptr,
"Could not load symbol lib table." );
116 sch_plugin->CreateLibrary( libFileName.GetFullPath() );
117 wxString libTableUri =
"${KIPRJMOD}/" + libFileName.GetFullName();
130 libTable->
Format( &formatter, 0 );
139 std::map<std::string, UTF8> properties;
143 sch_plugin->SaveSymbol( libFileName.GetFullPath(), symbol, &properties );
145 sch_plugin->SaveLibrary( libFileName.GetFullPath() );
171 const wxString& aLibraryPath,
172 const std::map<std::string, UTF8>* aProperties )
176 for(
auto& [libnameStr, libSymbol] :
m_libCache )
177 aSymbolNameList.Add( libSymbol->GetName() );
182 const wxString& aLibraryPath,
183 const std::map<std::string, UTF8>* aProperties )
187 for(
auto& [libnameStr, libSymbol] :
m_libCache )
188 aSymbolList.push_back( libSymbol.get() );
193 const wxString& aAliasName,
194 const std::map<std::string, UTF8>* aProperties )
207 std::set<wxString> fieldNames;
209 for(
auto& [libnameStr, libSymbol] :
m_libCache )
211 std::vector<SCH_FIELD*> fields;
212 libSymbol->GetFields( fields );
216 if( field->IsMandatory() )
219 fieldNames.insert( field->GetName() );
223 std::copy( fieldNames.begin(), fieldNames.end(), std::back_inserter( aNames ) );
229 ( *aListToAppendTo )[
"csa"] =
230 UTF8(
_(
"Path to the CADSTAR schematic archive (*.csa) file related to this CADSTAR "
231 "parts library. If none specified it is assumed to be 'symbol.csa' in the "
234 ( *aListToAppendTo )[
"fplib"] =
235 UTF8(
_(
"Name of the footprint library related to the symbols in this library. You "
236 "should create a separate entry for the CADSTAR PCB Archive (*.cpa) file in "
237 "the footprint library tables. If none specified, 'cadstarpcblib' is assumed." ) );
242 const std::map<std::string, UTF8>* aProperties )
245 wxString fplibname =
"cadstarpcblib";
250 if( aProperties && aProperties->contains(
"csa" ) )
252 csafn = wxFileName( aProperties->at(
"csa" ) );
254 if( !csafn.IsAbsolute() )
256 wxFileName libDir( aLibraryPath );
258 libDir.SetName(
"" );
267 csafn = wxFileName( aLibraryPath );
268 csafn.SetExt(
"csa" );
270 if( !csafn.FileExists() )
272 csafn.SetName(
"symbol" );
274 if( !csafn.FileExists() )
276 csafn = wxDir::FindFirst( csafn.GetPath(), wxS(
"*.csa" ),
277 wxDIR_FILES | wxDIR_HIDDEN );
279 if( !csafn.FileExists() )
282 _(
"Cannot find the .csa file corresponding to library '%s'." ),
289 if( aProperties && aProperties->contains(
"fplib" ) )
291 fplibname = aProperties->at(
"fplib" );
295 long long timestamp = 0;
296 wxFileName fn( aLibraryPath );
298 if( fn.IsFileReadable() )
299 timestamp = fn.GetModificationTime().GetValue().GetValue();
302 if( fn.IsFileReadable()
317 std::vector<LIB_SYMBOL*> symbols = csaLoader.
LoadPartsLib( aLibraryPath );
321 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,...
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().