36#include <wx/wfstream.h>
37#include <wx/txtstrm.h>
50 catch(
const std::runtime_error& )
69 wxCHECK( !aFileName.IsEmpty() && aSchematic,
nullptr );
76 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr,
"Can't append to a schematic with no root!" );
77 rootSheet = &aSchematic->
Root();
83 aSchematic->
SetRoot( rootSheet );
94 csaLoader.
Load( aSchematic, rootSheet );
99 wxCHECK_MSG( libTable,
nullptr,
"Could not load symbol lib table." );
104 if( libName.IsEmpty() )
107 libName = fn.GetName();
110 if( libName.IsEmpty() )
123 sch_plugin->CreateLibrary( libFileName.GetFullPath() );
124 wxString libTableUri =
"${KIPRJMOD}/" + libFileName.GetFullName();
137 libTable->
Format( &formatter, 0 );
150 sch_plugin->SaveSymbol( libFileName.GetFullPath(), symbol, &properties );
152 sch_plugin->SaveLibrary( libFileName.GetFullPath() );
178 const wxString& aLibraryPath,
183 for(
auto& [libnameStr, libSymbol] :
m_libCache )
184 aSymbolNameList.Add( libSymbol->GetName() );
189 const wxString& aLibraryPath,
194 for(
auto& [libnameStr, libSymbol] :
m_libCache )
195 aSymbolList.push_back( libSymbol.get() );
200 const wxString& aAliasName,
214 std::set<wxString> fieldNames;
216 for(
auto& [libnameStr, libSymbol] :
m_libCache )
218 std::vector<SCH_FIELD*> fields;
219 libSymbol->GetFields( fields );
223 if( field->IsMandatory() )
226 fieldNames.insert( field->GetName() );
230 std::copy( fieldNames.begin(), fieldNames.end(), std::back_inserter( aNames ) );
236 ( *aListToAppendTo )[
"csa"] =
237 UTF8(
_(
"Path to the CADSTAR schematic archive (*.csa) file related to this CADSTAR "
238 "parts library. If none specified it is assumed to be 'symbol.csa' in the "
241 ( *aListToAppendTo )[
"fplib"] =
242 UTF8(
_(
"Name of the footprint library related to the symbols in this library. You "
243 "should create a separate entry for the CADSTAR PCB Archive (*.cpa) file in "
244 "the footprint library tables. If none specified, 'cadstarpcblib' is assumed." ) );
252 wxString fplibname =
"cadstarpcblib";
254 if( aProperties && aProperties->count(
"csa" ) )
256 csafn = wxFileName( aProperties->at(
"csa" ) );
258 if( !csafn.IsAbsolute() )
260 wxFileName libDir( aLibraryPath );
262 libDir.SetName(
"" );
271 csafn = wxFileName( aLibraryPath );
272 csafn.SetExt(
"csa" );
274 if( !csafn.FileExists() )
276 csafn.SetName(
"symbol" );
278 if( !csafn.FileExists() )
280 csafn = wxDir::FindFirst( csafn.GetPath(), wxS(
"*.csa" ),
281 wxDIR_FILES | wxDIR_HIDDEN );
283 if( !csafn.FileExists() )
286 _(
"Cannot find the .csa file corresponding to library '%s'." ),
293 if( aProperties && aProperties->count(
"fplib" ) )
295 fplibname = aProperties->at(
"fplib" ).wx_str();
299 long long timestamp = 0;
300 wxFileName fn( aLibraryPath );
302 if( fn.IsFileReadable() )
303 timestamp = fn.GetModificationTime().GetValue().GetValue();
306 if( fn.IsFileReadable()
321 std::vector<LIB_SYMBOL*> symbols = csaLoader.
LoadPartsLib( aLibraryPath );
325 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.
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.
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
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 GetProjectPath() const
Return the full path of the project.
virtual const wxString GetProjectName() const
Return the short name of the project.
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Holds all the data relating to one schematic.
void FixupJunctions()
Add junctions to this schematic where required.
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
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,...
int GetModifyHash() const override
Return the modification hash from the library cache.
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.
SCH_SHEET * LoadSchematicFile(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_IO implementation knows about,...
void ensureLoadedLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties)
long long m_cacheTimestamp
LIB_SYMBOL * LoadSymbol(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...
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
void GetLibraryOptions(STRING_UTF8_MAP *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)
wxString GetFileName() const
Return the filename corresponding to this sheet.
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
A name/value tuple with unique names and optional values.
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 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().