35#include <wx/filename.h>
36#include <wx/wfstream.h>
41 PCB_IO( wxS(
"Sprint Layout" ) )
47 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
49 wxFileName libFn( aLibraryPath );
51 if( libFn.FileExists() && libFn.GetExt().Upper() == wxS(
"LMK" ) )
53 aFootprintNames.Add( libFn.GetName() );
57 if( wxDir::Exists( aLibraryPath ) )
62 for(
const wxString& filePath : files )
64 wxFileName file( filePath );
66 if( file.GetExt().Upper() != wxS(
"LMK" ) )
69 file.MakeRelativeTo( aLibraryPath );
70 aFootprintNames.Add( file.GetFullPath().BeforeLast(
'.' ) );
77 bool aKeepUUID,
const std::map<std::string, UTF8>* aProperties )
79 wxFileName libFn( aLibraryPath );
82 if( libFn.FileExists() && libFn.GetExt().Upper() == wxS(
"LMK" ) )
88 if( !wxDir::Exists( aLibraryPath ) )
91 lmkPath = wxFileName( aLibraryPath + wxFileName::GetPathSeparator() + aFootprintName + wxS(
".LMK" ) );
93 if( !lmkPath.FileExists() )
95 lmkPath.SetExt(
"lmk" );
97 if( !lmkPath.FileExists() )
120 const wxFileName fn( aFileName );
122 if( !fn.FileExists() )
125 wxString ext = fn.GetExt().Lower();
127 if( ext != wxS(
"lay6" ) && ext != wxS(
"lay" ) )
131 wxFFileInputStream stream( aFileName );
133 if( !stream.IsOk() || stream.GetLength() < 8 )
139 if( stream.LastRead() != 4 )
150 const std::map<std::string, UTF8>* aProperties,
162 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse Sprint Layout file '%s'" ),
167 size_t boardIndex = 0;
171 unsigned long idx = std::stoul(
m_props->at(
"pcb_id" ) );
172 boardIndex =
static_cast<size_t>( idx );
176 std::vector<IMPORT_PROJECT_DESC> options;
178 for(
size_t i = 0; i < fileData.boards.size(); i++ )
181 wxString
name = wxString::FromUTF8( fileData.boards[i].name );
184 name = wxString::Format( wxS(
"Board %zu" ), i + 1 );
187 desc.
PCBId = wxString::Format( wxS(
"%zu" ), i );
188 options.push_back( desc );
196 unsigned long idx = std::stoul( chosen[0].PCBId.ToStdString() );
197 boardIndex =
static_cast<size_t>( idx );
204 THROW_IO_ERROR( wxString::Format(
_(
"Failed to create board from Sprint Layout file '%s'" ),
210 for(
FOOTPRINT* fp : newBoard->Footprints() )
211 aAppendToMe->
Add(
static_cast<FOOTPRINT*
>( fp->Clone() ) );
213 for(
BOARD_ITEM* item : newBoard->Drawings() )
214 aAppendToMe->
Add(
static_cast<BOARD_ITEM*
>( item->Clone() ) );
216 for(
ZONE* zone : newBoard->Zones() )
217 aAppendToMe->
Add(
static_cast<ZONE*
>( zone->Clone() ) );
222 newBoard->SetFileName( aFileName );
223 return newBoard.release();
229 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.
void CollectFilesLoopSafe(const wxString &aRoot, wxArrayString &aFiles, const wxString &aFileSpec, int aFlags)
Recursively collect every file under aRoot, deduplicating subdirectories by their resolved path.
#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.