33#include <wx/filename.h>
34#include <wx/wfstream.h>
38 PCB_IO( wxS(
"Sprint Layout" ) )
48 const wxFileName fn( aFileName );
50 if( !fn.FileExists() )
53 wxString ext = fn.GetExt().Lower();
55 if( ext != wxS(
"lay6" ) && ext != wxS(
"lay" ) )
59 wxFFileInputStream stream( aFileName );
61 if( !stream.IsOk() || stream.GetLength() < 8 )
67 if( stream.LastRead() != 4 )
78 const std::map<std::string, UTF8>* aProperties,
88 if( !parser.
Parse( aFileName ) )
90 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse Sprint Layout file '%s'" ),
95 size_t boardIndex = 0;
99 unsigned long idx = std::stoul(
m_props->at(
"pcb_id" ) );
100 boardIndex =
static_cast<size_t>( idx );
104 std::vector<IMPORT_PROJECT_DESC> options;
106 for(
size_t i = 0; i < fileData.boards.size(); i++ )
109 wxString
name = wxString::FromUTF8( fileData.boards[i].name );
112 name = wxString::Format( wxS(
"Board %zu" ), i + 1 );
115 desc.
PCBId = wxString::Format( wxS(
"%zu" ), i );
116 options.push_back( desc );
124 unsigned long idx = std::stoul( chosen[0].PCBId.ToStdString() );
125 boardIndex =
static_cast<size_t>( idx );
132 THROW_IO_ERROR( wxString::Format(
_(
"Failed to create board from Sprint Layout file '%s'" ),
138 for(
FOOTPRINT* fp : newBoard->Footprints() )
139 aAppendToMe->
Add(
static_cast<FOOTPRINT*
>( fp->Clone() ) );
141 for(
BOARD_ITEM* item : newBoard->Drawings() )
142 aAppendToMe->
Add(
static_cast<BOARD_ITEM*
>( item->Clone() ) );
144 for(
ZONE* zone : newBoard->Zones() )
145 aAppendToMe->
Add(
static_cast<ZONE*
>( zone->Clone() ) );
150 newBoard->SetFileName( aFileName );
151 return newBoard.release();
157 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.
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
std::map< wxString, std::unique_ptr< FOOTPRINT > > m_loadedFootprints
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
bool Parse(const wxString &aFileName)
BOARD * CreateBoard(std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, size_t aBoardIndex=0)
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.