40#include <wx/filename.h>
44 SCH_IO( wxS(
"Easy-PC / DesignSpark Schematic" ) )
80 if( it !=
m_libraries.end() && it->second.Timestamp == stamp )
86 std::unique_ptr<EASYPC::LIBRARY_FILE> file = std::make_unique<EASYPC::LIBRARY_FILE>( aLibraryPath );
89 for(
const wxString& warning : file->Warnings() )
93 lib.
File = std::move( file );
99 const std::map<std::string, UTF8>* aProperties )
102 for(
const wxString&
name :
library( aLibraryPath ).File->ItemNames() )
108 const std::map<std::string, UTF8>* aProperties )
110 for(
const wxString&
name :
library( aLibraryPath ).File->ItemNames() )
113 aSymbolList.push_back( symbol );
120 const std::vector<const EASYPC::SOURCE_PCB_COMPONENT*>& aPackages )
124 for(
size_t g = 0; g < gates.size(); ++g )
126 for(
int t = 0; t < static_cast<int>( gates[g]->PinNames.size() ); ++t )
145 const wxString& aName )
147 std::unique_ptr<EASYPC::LIBRARY_ITEM> item = aLib.
File->
LoadItem( aName );
148 std::vector<const EASYPC::SOURCE_PCB_COMPONENT*> packages;
160 wxString::Format(
_(
"Easy-PC component '%s' in '%s' has no schematic part" ), aName, aLibraryPath ) );
171 const wxString nickname = wxFileName( pcb->
Library, wxPATH_WIN ).GetName();
172 const wxString footprint = nickname.IsEmpty() ? pcb->
Symbol : nickname + wxS(
":" ) + pcb->
Symbol;
174 packages.push_back( pcb );
186 if( !src.
Board && !packages.empty() )
190 src.
Board = packages.front();
194 m_reporter->Report( wxString::Format(
_(
"Easy-PC component '%s' in '%s' has no default package and its "
195 "packages number the pins differently; its pins are left "
197 aName, aLibraryPath ),
203 std::vector<std::unique_ptr<EASYPC::LIBRARY_ITEM>> gateItems;
204 const wxString cmlName = wxFileName( aLibraryPath ).GetFullName();
214 THROW_IO_ERROR( wxString::Format(
_(
"Easy-PC component '%s' in '%s' has an empty gate slot" ), aName,
219 const wxString sslName = wxFileName( gate->
Library, wxPATH_WIN ).GetFullName();
224 if( !wxFileName::FileExists( sslPath ) )
226 msg = wxString::Format(
_(
"Component '%s': gate %d symbol library '%s' not found beside '%s'." ), aName,
227 gateNumber, sslName, cmlName );
233 gateItems.push_back(
library( sslPath ).File->LoadItem( gate->
Symbol ) );
235 if( !gateItems.back()->Streams.empty() )
240 msg = wxString::Format(
_(
"Component '%s': gate %d item '%s' in '%s' is not a symbol." ), aName,
241 gateNumber, gate->
Symbol, sslName );
246 msg = wxString::Format(
_(
"Component '%s': gate %d symbol '%s' could not be loaded from '%s' "
248 aName, gateNumber, gate->
Symbol, sslName, e.
What() );
258 src.
Gates.push_back( symbol );
267 const std::map<std::string, UTF8>* aProperties )
271 if(
auto it = lib.
Symbols.find( aPartName ); it != lib.
Symbols.end() )
272 return it->second.get();
279 std::unique_ptr<LIB_SYMBOL> symbol;
288 std::unique_ptr<EASYPC::LIBRARY_ITEM> loaded = lib.
File->
LoadItem( item );
291 if( !loaded->Streams.empty() )
297 wxString::Format(
_(
"Easy-PC library item '%s' in '%s' is not a symbol" ), item, aLibraryPath ) );
305 THROW_IO_ERROR( wxString::Format(
_(
"'%s' is not an Easy-PC symbol or component library" ), aLibraryPath ) );
309 lib.
Symbols[aPartName] = std::move( symbol );
315 const std::map<std::string, UTF8>* aProperties )
317 wxCHECK( !aFileName.IsEmpty() && aSchematic,
nullptr );
320 if( !aAppendToMe && aProperties && aProperties->count(
"hierarchical_sheet_load" ) )
322 THROW_IO_ERROR( wxString::Format(
_(
"'%s' is a complete Easy-PC schematic and cannot be loaded as a "
323 "hierarchical sheet. Use File > Import > Non-KiCad Schematic... "
336 std::vector<wxString> paths;
338 if( wxFileName( aFileName ).GetExt().CmpNoCase( wxS(
"prj" ) ) == 0 )
345 THROW_IO_ERROR( wxString::Format(
_(
"Project '%s' contains no schematics" ), aFileName ) );
349 paths.push_back( aFileName );
352 std::vector<std::unique_ptr<EASYPC::DESIGN_DOCUMENT>> docs;
353 std::vector<const EASYPC::DESIGN_DOCUMENT*> allDocs;
356 for(
const wxString&
path : paths )
359 allDocs.push_back( docs.back().get() );
369 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr, wxS(
"Can't append to a schematic with no root!" ) );
371 if( docs.size() != 1 )
373 THROW_IO_ERROR( wxString::Format(
_(
"'%s' holds %zu schematics; only one can be appended to a sheet" ),
374 aFileName, docs.size() ) );
379 wxFileName fn( paths.front() );
394 std::vector<SCH_SHEET*> sheets;
400 for(
size_t i = 0; i < docs.size(); ++i )
404 path.push_back( sheet );
405 sheets.push_back( sheet );
408 if( sheet != aAppendToMe )
410 wxFileName fn( paths[i] );
418 path.SetPageNumber( wxString::Format( wxS(
"%zu" ), i + 1 ) );
437 if( projectName.IsEmpty() )
438 projectName = wxFileName( aFileName ).GetName();
void SetPageNumber(const wxString &aPageNumber)
std::unique_ptr< LIBRARY_ITEM > LoadItem(const wxString &aItemName) const
Throws IO_ERROR if no item has that name.
bool HasItem(const wxString &aItemName) const
static long long Timestamp(const wxString &aPath)
A library file's modification time, 0 when it does not exist.
void BuildSheet(const DESIGN_DOCUMENT &aDoc, SCH_SHEET *aSheet, const SCH_SHEET_PATH &aSheetPath)
void SetProjectSymbols(const std::vector< const DESIGN_DOCUMENT * > &aDocs)
Symbols of every sheet, for gates placed on a sheet other than the one being built.
Project-wide net naming: a user name takes the spelling of its first occurrence.
void AddSheet(const DESIGN_DOCUMENT &aDoc)
const wxString & GetName() const
Return a brief hard coded name for this IO interface.
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.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
A logical library item identifier and consists of various portions much like a URI.
Define a library symbol object.
virtual const wxString GetProjectName() const
Return the short name of the project.
Holds all the data relating to one schematic.
SCH_SHEET_LIST BuildUnorderedSheetList() const
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.
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
LIBRARY & library(const wxString &aLibraryPath)
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,...
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
std::unique_ptr< LIB_SYMBOL > convertComponent(const LIBRARY &aLib, const wxString &aLibraryPath, const wxString &aName)
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Converted on first use and owned by the plugin until the file changes.
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.
std::map< wxString, LIBRARY > m_libraries
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_IO can read the specified schematic file.
SCH_IO(const wxString &aName)
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void AddNewSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath, const wxString &aProjectName)
Attempt to add new symbol instances for all symbols in this list of sheet paths prefixed with aPrefix...
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.
void SetName(const wxString &aName)
SCH_SCREEN * GetScreen() const
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
static REPORTER & GetInstance()
Symbols, components and gates, embedded in designs or the single object of a library item stream.
The project file (.prj), a bare archive stream.
Loading designs, library items and projects.
Builds KiCad sheets from Easy-PC / DesignSpark schematic designs.
Schematic graphics, texts and symbols shared by the sheet builder and the symbol libraries,...
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_CANCELLED()
static const std::string KiCadSchematicFileExtension
FILE_INFO Probe(const wxString &aPath)
Identify a file; projects are parsed fully, while designs and libraries are only inspected....
GATE_TERMINAL ResolveTerminal(const SOURCE_PCB_COMPONENT *aPcb, int aGate, int aTerminal)
Terminal aTerminal (0-based) of gate aGate; formats before 9000 map a bare pad number,...
std::unique_ptr< LIB_SYMBOL > ConvertComponentSymbol(const SCH_COMPONENT_SOURCE &aSrc, const LIB_ID &aId)
One unit per gate in symbol-local coordinates, zero-length passive pins at the pads,...
std::unique_ptr< DESIGN_DOCUMENT > LoadDesign(const wxString &aPath)
std::unique_ptr< LIB_SYMBOL > ConvertSymbol(const SOURCE_SYMBOL &aSymbol, const LIB_ID &aId)
A .ssl symbol alone: one unit, pins numbered by pad number.
std::vector< T * > TypedItems(const OBJECT *aList)
The items of ListItems that are a T, in order.
@ SCHEMATIC_SYMBOL_LIBRARY
wxString ResolveProjectItem(const wxString &aProjectPath, const wxString &aItemName)
The file a project item names, as Easy-PC opens it: the Windows path relative to the project's direct...
const std::vector< OBJECT * > & ListItems(const OBJECT *aList)
The items of a design list or array, empty for anything else.
std::unique_ptr< PROJECT_DOCUMENT > LoadProject(const wxString &aPath)
static bool packagesAgree(const EASYPC::SOURCE_SCM_COMPONENT &aScm, const std::vector< const EASYPC::SOURCE_PCB_COMPONENT * > &aPackages)
Whether every package gives every gate terminal the same pin number.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
What a package's gate map says about one gate terminal.
wxString Number
KiCad pin number, stacked notation for a pad list.
OBJECT * Item
what the stream's single ReadObject returned
Root of every deserialized object.
Everything one component LIB_SYMBOL is made from.
std::vector< const SOURCE_SYMBOL * > Gates
symbol per gate; null leaves that unit empty
const SOURCE_SCM_COMPONENT * Schematic
wxArrayString FootprintFilters
const SOURCE_PCB_COMPONENT * Board
the package whose gate map numbers the pins
A schematic symbol and its pin names.
The package half of a component.
wxString Symbol
footprint name
wxString Name
Windows path relative to the project directory.
Footprints and schematic symbols alike.
std::unique_ptr< EASYPC::LIBRARY_FILE > File
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > Symbols
wxString result
Test unit parsing edge cases and error handling.
Definition of file extensions used in Kicad.