34#include <wx/filename.h>
35#include <wx/wfstream.h>
39 PCB_IO( wxS(
"Sprint Layout" ) )
47 fp->SetParent(
nullptr );
53 const wxFileName fn( aFileName );
55 if( !fn.FileExists() )
58 wxString ext = fn.GetExt().Lower();
60 if( ext != wxS(
"lay6" ) && ext != wxS(
"lay" ) )
64 wxFFileInputStream stream( aFileName );
66 if( !stream.IsOk() || stream.GetLength() < 8 )
72 if( stream.LastRead() != 4 )
83 const std::map<std::string, UTF8>* aProperties,
93 if( !parser.
Parse( aFileName ) )
95 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse Sprint Layout file '%s'" ),
100 size_t boardIndex = 0;
104 unsigned long idx = std::stoul(
m_props->at(
"pcb_id" ) );
105 boardIndex =
static_cast<size_t>( idx );
109 std::vector<IMPORT_PROJECT_DESC> options;
111 for(
size_t i = 0; i < fileData.boards.size(); i++ )
114 wxString
name = wxString::FromUTF8( fileData.boards[i].name );
117 name = wxString::Format( wxS(
"Board %zu" ), i + 1 );
120 desc.
PCBId = wxString::Format( wxS(
"%zu" ), i );
121 options.push_back( desc );
129 unsigned long idx = std::stoul( chosen[0].PCBId.ToStdString() );
130 boardIndex =
static_cast<size_t>( idx );
137 THROW_IO_ERROR( wxString::Format(
_(
"Failed to create board from Sprint Layout file '%s'" ),
143 for(
FOOTPRINT* fp : newBoard->Footprints() )
144 aAppendToMe->
Add(
static_cast<FOOTPRINT*
>( fp->Clone() ) );
146 for(
BOARD_ITEM* item : newBoard->Drawings() )
147 aAppendToMe->
Add(
static_cast<BOARD_ITEM*
>( item->Clone() ) );
149 for(
ZONE* zone : newBoard->Zones() )
150 aAppendToMe->
Add(
static_cast<ZONE*
>( zone->Clone() ) );
155 newBoard->SetFileName( aFileName );
156 return newBoard.release();
162 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.