32#include <wx/filename.h>
33#include <wx/wfstream.h>
38 PCB_IO( wxS(
"Sprint Layout" ) )
44 bool aBestEfforts,
const std::map<std::string, UTF8>* aProperties )
46 wxFileName libFn( aLibraryPath );
48 if( libFn.FileExists() && libFn.GetExt().Upper() == wxS(
"LMK" ) )
50 aFootprintNames.Add( libFn.GetName() );
54 if( wxDir::Exists( aLibraryPath ) )
59 for(
const wxString& filePath : files )
61 wxFileName file( filePath );
63 if( file.GetExt().Upper() != wxS(
"LMK" ) )
66 file.MakeRelativeTo( aLibraryPath );
67 aFootprintNames.Add( file.GetFullPath().BeforeLast(
'.' ) );
74 const wxString& aFootprintName,
bool aKeepUUID,
75 const std::map<std::string, UTF8>* aProperties )
77 wxFileName libFn( aLibraryPath );
80 if( libFn.FileExists() && libFn.GetExt().Upper() == wxS(
"LMK" ) )
86 if( !wxDir::Exists( aLibraryPath ) )
89 lmkPath = wxFileName( aLibraryPath + wxFileName::GetPathSeparator() + aFootprintName + wxS(
".LMK" ) );
91 if( !lmkPath.FileExists() )
93 lmkPath.SetExt(
"lmk" );
95 if( !lmkPath.FileExists() )
118 const wxFileName fn( aFileName );
120 if( !fn.FileExists() )
123 wxString ext = fn.GetExt().Lower();
125 if( ext != wxS(
"lay6" ) && ext != wxS(
"lay" ) )
129 wxFFileInputStream stream( aFileName );
131 if( !stream.IsOk() || stream.GetLength() < 8 )
135 stream.Read( header, 4 );
137 if( stream.LastRead() != 4 )
140 if( header[0] > 6 || header[1] != 0x33 || header[2] != 0xAA || header[3] != 0xFF )
148 const std::map<std::string, UTF8>* aProperties,
PROJECT* aProject )
158 THROW_IO_ERRORF(
_(
"Failed to parse Sprint Layout file '%s'" ), aFileName );
161 size_t boardIndex = 0;
165 unsigned long idx = std::stoul(
m_props->at(
"pcb_id" ) );
166 boardIndex =
static_cast<size_t>( idx );
170 std::vector<IMPORT_PROJECT_DESC> options;
172 for(
size_t i = 0; i < fileData.boards.size(); i++ )
175 wxString
name = wxString::FromUTF8( fileData.boards[i].name );
178 name = wxString::Format( wxS(
"Board %zu" ), i + 1 );
181 desc.
PCBId = wxString::Format( wxS(
"%zu" ), i );
182 options.push_back( desc );
190 unsigned long idx = std::stoul( chosen[0].PCBId.ToStdString() );
191 boardIndex =
static_cast<size_t>( idx );
197 THROW_IO_ERRORF(
_(
"Failed to create board from Sprint Layout file '%s'" ), aFileName );
203 std::unique_ptr<BOARD> scratchBoard = std::make_unique<BOARD>();
204 std::map<EDA_ITEM*, EDA_ITEM*> ptrMap;
207 THROW_IO_ERRORF(
_(
"Failed to create board from Sprint Layout file '%s'" ), aFileName );
209 for(
NETINFO_ITEM* netInfo : scratchBoard->GetNetInfo() )
212 ptrMap[netInfo] = newNetInfo;
213 aBoard.
Add( newNetInfo );
216 for(
FOOTPRINT* fp : scratchBoard->Footprints() )
219 ptrMap[ fp ] = newFP;
223 for(
BOARD_ITEM* drawing : scratchBoard->Drawings() )
226 ptrMap[drawing] = newDrawing;
227 aBoard.
Add( newDrawing );
230 for(
ZONE* zone : scratchBoard->Zones() )
232 ZONE* newZone =
static_cast<ZONE*
>( zone->Clone() );
233 ptrMap[zone] = newZone;
234 aBoard.
Add( newZone );
240 ptrMap[
group] = newGroup;
241 aBoard.
Add( newGroup );
253 if( ptrMap.count( member ) )
254 newGroup->
AddItem( ptrMap[ member ] );
259 for(
ZONE* zone : scratchBoard->Zones() )
261 ZONE* newZone =
static_cast<ZONE*
>( ptrMap[zone] );
263 if( newZone && newZone->
GetNet() )
272 std::vector<FOOTPRINT*>
result;
NETINFO_ITEM * GetNet() const
Return NETINFO_ITEM object for a given item.
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.
std::unordered_set< EDA_ITEM * > & GetItems()
void AddItem(EDA_ITEM *aItem)
Add item to group.
A base class for most all the KiCad significant classes used in schematics and boards.
virtual void SetParent(EDA_ITEM *aParent)
RAII class to set and restore the fontconfig reporter.
static LOAD_INFO_REPORTER & GetInstance()
Handle the data for a net.
A set of BOARD_ITEMs (i.e., without duplicates).
std::unique_ptr< 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::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
void loadBoard(const wxString &aFileName, BOARD &aBoard, bool aIsNewLoad, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Parse aFileName into aBoard.
bool CanReadBoard(const wxString &aFileName) const override
~PCB_IO_SPRINT_LAYOUT() override
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.
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.
std::unique_ptr< FOOTPRINT > CreateFootprint()
bool CreateBoard(BOARD &aBoard, std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, size_t aBoardIndex=0)
const SPRINT_LAYOUT::FILE_DATA & GetFileData() const
bool ParseMacroFile(const wxString &aFileName)
bool ParseBoard(const wxString &aFileName)
Handle a list of polygons defining a copper zone.
void SetNet(NETINFO_ITEM *aNetInfo) override
Override that drops aNetInfo when this zone is in copper-thieving fill mode.
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_ERRORF(msg,...)
#define THROW_IO_CANCELLED()
Class to handle a set of BOARD_ITEMs.
Describes how non-KiCad boards and schematics should be imported as KiCad projects.
wxString result
Test unit parsing edge cases and error handling.