38#include <compoundfilereader.h>
91 const std::map<ALTIUM_PCB_DIR, std::string> mapping = {
92 { ALTIUM_PCB_DIR::FILE_HEADER,
"FileHeader" },
93 { ALTIUM_PCB_DIR::ARCS6,
"Arcs6" },
94 { ALTIUM_PCB_DIR::BOARD6,
"Board6" },
95 { ALTIUM_PCB_DIR::BOARDREGIONS,
"BoardRegions" },
96 { ALTIUM_PCB_DIR::CLASSES6,
"Classes6" },
97 { ALTIUM_PCB_DIR::COMPONENTS6,
"Components6" },
98 { ALTIUM_PCB_DIR::COMPONENTBODIES6,
"ComponentBodies6" },
99 { ALTIUM_PCB_DIR::DIMENSIONS6,
"Dimensions6" },
100 { ALTIUM_PCB_DIR::EXTENDPRIMITIVEINFORMATION,
"ExtendedPrimitiveInformation" },
101 { ALTIUM_PCB_DIR::FILLS6,
"Fills6" },
102 { ALTIUM_PCB_DIR::MODELS,
"Models" },
103 { ALTIUM_PCB_DIR::NETS6,
"Nets6" },
104 { ALTIUM_PCB_DIR::PADS6,
"Pads6" },
105 { ALTIUM_PCB_DIR::POLYGONS6,
"Polygons6" },
106 { ALTIUM_PCB_DIR::REGIONS6,
"Regions6" },
107 { ALTIUM_PCB_DIR::RULES6,
"Rules6" },
108 { ALTIUM_PCB_DIR::SHAPEBASEDREGIONS6,
"ShapeBasedRegions6" },
109 { ALTIUM_PCB_DIR::TEXTS6,
"Texts6" },
110 { ALTIUM_PCB_DIR::TRACKS6,
"Tracks6" },
111 { ALTIUM_PCB_DIR::VIAS6,
"Vias6" },
112 { ALTIUM_PCB_DIR::WIDESTRINGS6,
"WideStrings6" }
122 pcb.
Parse( altiumPcbFile, mapping );
124 catch( CFB::CFBException& exception )
135 if( aLibraryPath.IsEmpty() )
140 wxFileName fn( aLibraryPath );
142 if( fn.IsFileReadable() )
144 return fn.GetModificationTime().GetValue().GetValue();
153 const wxString& aLibraryPath,
bool aBestEfforts,
161 auto new_it =
m_fplibFiles.emplace( aLibraryPath, std::make_unique<ALTIUM_COMPOUND_FILE>( aLibraryPath ) );
162 altiumLibFile = new_it.first->second.get();
166 altiumLibFile = it->second.get();
174 const std::vector<std::string> streamName = {
"Library",
"Data" };
175 const CFB::COMPOUND_FILE_ENTRY* libraryData = altiumLibFile->
FindStream( streamName );
177 if( libraryData ==
nullptr )
180 wxString::Format(
_(
"File not found: '%s'." ),
FormatPath( streamName ) ) );
185 std::map<wxString, wxString> properties = parser.
ReadProperties();
187 uint32_t numberOfFootprints = parser.
Read<uint32_t>();
188 aFootprintNames.Alloc( numberOfFootprints );
190 for(
size_t i = 0; i < numberOfFootprints; i++ )
195 wxString fpPattern( charBuffer, wxConvISO8859_1 );
197 auto it = patternMap.find( fpPattern );
198 if( it != patternMap.end() )
200 aFootprintNames.Add( it->second );
204 THROW_IO_ERROR( wxString::Format(
"Component name not found: '%s'", fpPattern ) );
212 THROW_IO_ERROR( wxString::Format(
"%s stream was not parsed correctly",
219 wxString::Format(
"%s stream is not fully parsed",
FormatPath( streamName ) ) );
222 catch( CFB::CFBException& exception )
229 const wxString& aFootprintName,
bool aKeepUUID,
237 auto new_it =
m_fplibFiles.emplace( aLibraryPath, std::make_unique<ALTIUM_COMPOUND_FILE>( aLibraryPath ) );
238 altiumLibFile = new_it.first->second.get();
242 altiumLibFile = it->second.get();
251 catch( CFB::CFBException& exception )
std::string FormatPath(const std::vector< std::string > &aVectorPath)
Helper for debug logging (vector -> string)
std::map< wxString, wxString > ListLibFootprints()
const CFB::COMPOUND_FILE_ENTRY * FindStream(const std::vector< std::string > &aStreamPath) const
~ALTIUM_DESIGNER_PLUGIN()
std::map< wxString, std::unique_ptr< ALTIUM_COMPOUND_FILE > > m_fplibFiles
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PL...
static bool checkFileHeader(const wxString &aFileName)
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PLUGIN can read the specified board file.
bool CanReadFootprintLib(const wxString &aFileName) const override
Checks if this PLUGIN can read footprint library from specified file or directory.
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const STRING_UTF8_MAP *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
const STRING_UTF8_MAP * m_props
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
wxScopedCharBuffer ReadCharBuffer()
size_t GetRemainingBytes() const
std::map< wxString, wxString > ReadProperties(std::function< std::map< wxString, wxString >(const std::string &)> handleBinaryData=[](const std::string &) { return std::map< wxString, wxString >();})
size_t ReadAndSetSubrecordLength()
void Parse(const ALTIUM_COMPOUND_FILE &aAltiumPcbFile, const std::map< ALTIUM_PCB_DIR, std::string > &aFileMapping)
FOOTPRINT * ParseFootprint(ALTIUM_COMPOUND_FILE &altiumLibFile, const wxString &aFootprintName)
Information pertinent to a Pcbnew printed circuit board.
void SetFileName(const wxString &aFileName)
virtual bool CanReadFootprintLib(const wxString &aFileName) const
Checks if this PLUGIN can read footprint library from specified file or directory.
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PLUGIN can read the specified board file.
static bool fileStartsWithBinaryHeader(const wxString &aFilePath, const std::vector< uint8_t > &aHeader)
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
A name/value tuple with unique names and optional values.
#define THROW_IO_ERROR(msg)