34#include <wx/filename.h>
35#include <wx/wfstream.h>
40 PCB_IO( wxS(
"Sprint Layout" ) )
46 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
48 wxFileName libFn( aLibraryPath );
50 if( libFn.FileExists() && libFn.GetExt().Upper() == wxS(
"LMK" ) )
52 aFootprintNames.Add( libFn.GetName() );
56 if( wxDir::Exists( aLibraryPath ) )
59 wxDir::GetAllFiles( aLibraryPath, &files, wxEmptyString, wxDIR_FILES | wxDIR_DIRS );
61 for(
const wxString& filePath : files )
63 wxFileName file( filePath );
65 if( file.GetExt().Upper() != wxS(
"LMK" ) )
68 file.MakeRelativeTo( aLibraryPath );
69 aFootprintNames.Add( file.GetFullPath().BeforeLast(
'.' ) );
76 bool aKeepUUID,
const std::map<std::string, UTF8>* aProperties )
78 wxFileName libFn( aLibraryPath );
81 if( libFn.FileExists() && libFn.GetExt().Upper() == wxS(
"LMK" ) )
87 if( !wxDir::Exists( aLibraryPath ) )
90 lmkPath = wxFileName( aLibraryPath + wxFileName::GetPathSeparator() + aFootprintName + wxS(
".LMK" ) );
92 if( !lmkPath.FileExists() )
94 lmkPath.SetExt(
"lmk" );
96 if( !lmkPath.FileExists() )
119 const wxFileName fn( aFileName );
121 if( !fn.FileExists() )
124 wxString ext = fn.GetExt().Lower();
126 if( ext != wxS(
"lay6" ) && ext != wxS(
"lay" ) )
130 wxFFileInputStream stream( aFileName );
132 if( !stream.IsOk() || stream.GetLength() < 8 )
138 if( stream.LastRead() != 4 )
149 const std::map<std::string, UTF8>* aProperties,
161 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse Sprint Layout file '%s'" ),
166 size_t boardIndex = 0;
170 unsigned long idx = std::stoul(
m_props->at(
"pcb_id" ) );
171 boardIndex =
static_cast<size_t>( idx );
175 std::vector<IMPORT_PROJECT_DESC> options;
177 for(
size_t i = 0; i < fileData.boards.size(); i++ )
180 wxString
name = wxString::FromUTF8( fileData.boards[i].name );
183 name = wxString::Format( wxS(
"Board %zu" ), i + 1 );
186 desc.
PCBId = wxString::Format( wxS(
"%zu" ), i );
187 options.push_back( desc );
195 unsigned long idx = std::stoul( chosen[0].PCBId.ToStdString() );
196 boardIndex =
static_cast<size_t>( idx );
203 THROW_IO_ERROR( wxString::Format(
_(
"Failed to create board from Sprint Layout file '%s'" ),
209 for(
FOOTPRINT* fp : newBoard->Footprints() )
210 aAppendToMe->
Add(
static_cast<FOOTPRINT*
>( fp->Clone() ) );
212 for(
BOARD_ITEM* item : newBoard->Drawings() )
213 aAppendToMe->
Add(
static_cast<BOARD_ITEM*
>( item->Clone() ) );
215 for(
ZONE* zone : newBoard->Zones() )
216 aAppendToMe->
Add(
static_cast<ZONE*
>( zone->Clone() ) );
221 newBoard->SetFileName( aFileName );
222 return newBoard.release();
228 std::vector<FOOTPRINT*>
result;
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
virtual void SetParent(EDA_ITEM *aParent)
RAII class to set and restore the fontconfig reporter.
static LOAD_INFO_REPORTER & GetInstance()
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
~PCB_IO_SPRINT_LAYOUT() override
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
std::map< wxString, std::unique_ptr< FOOTPRINT > > m_loadedFootprints
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
PCB_IO(const wxString &aName)
const std::map< std::string, UTF8 > * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
CHOOSE_PROJECT_HANDLER m_choose_project_handler
Callback to choose projects to import.
Container for project specific data.
const SPRINT_LAYOUT::FILE_DATA & GetFileData() const
BOARD * CreateBoard(std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, size_t aBoardIndex=0)
FOOTPRINT * CreateFootprint()
bool ParseMacroFile(const wxString &aFileName)
bool ParseBoard(const wxString &aFileName)
Handle a list of polygons defining a copper zone.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
Describes how non-KiCad boards and schematics should be imported as KiCad projects.
std::vector< std::string > header
wxString result
Test unit parsing edge cases and error handling.