42#include <compoundfilereader.h>
46 PCB_IO( wxS(
"Altium Designer" ) )
60 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector )
62 std::map<wxString, PCB_LAYER_ID> retval;
67 retval.insert( { layerDesc.Name, layerDesc.AutoMapLayer } );
100 const std::map<std::string, UTF8>* aProperties,
PROJECT* aProject )
111 m_board->SetFileName( aFileName );
114 const std::map<ALTIUM_PCB_DIR, std::string> mapping = {
145 pcb.
Parse( altiumPcbFile, mapping );
147 catch( CFB::CFBException& exception )
159 if( aLibraryPath.IsEmpty() )
162 wxFileName fn( aLibraryPath );
164 if( fn.IsFileReadable() && fn.GetModificationTime().IsValid() )
165 return fn.GetModificationTime().GetValue().GetValue();
184 if( aLibraryPath.Lower().EndsWith( wxS(
".pcblib" ) ) )
186 libFiles.
m_Files.emplace_back( std::make_unique<ALTIUM_PCB_COMPOUND_FILE>( aLibraryPath ) );
188 else if( aLibraryPath.Lower().EndsWith( wxS(
".intlib" ) ) )
190 std::unique_ptr<ALTIUM_PCB_COMPOUND_FILE> lib = std::make_unique<ALTIUM_PCB_COMPOUND_FILE>( aLibraryPath );
192 for(
const auto& [pcbLibName, pcbCfe] : lib->EnumDir( L
"PCBLib" ) )
194 std::unique_ptr<ALTIUM_PCB_COMPOUND_FILE> libFile = std::make_unique<ALTIUM_PCB_COMPOUND_FILE>();
196 if( lib->DecodeIntLibStream( *pcbCfe, libFile.get() ) )
197 libFiles.
m_Files.emplace_back( std::move( libFile ) );
203 catch( CFB::CFBException& exception )
211 const wxString& aLibraryPath,
bool aBestEfforts,
212 const std::map<std::string, UTF8>* aProperties )
221 for( std::unique_ptr<ALTIUM_PCB_COMPOUND_FILE>& altiumLibFile :
m_fplibFiles[aLibraryPath].m_Files )
226 const std::vector<std::string> streamName = {
"Library",
"Data" };
227 const CFB::COMPOUND_FILE_ENTRY* libraryData = altiumLibFile->FindStream( streamName );
229 if( libraryData ==
nullptr )
237 std::map<wxString, wxString> properties = parser.
ReadProperties();
239 uint32_t numberOfFootprints = parser.
Read<uint32_t>();
248 bool footprintListNotTruncated =
true;
250 if ( patternMap.size() < numberOfFootprints )
252 numberOfFootprints = patternMap.size();
253 footprintListNotTruncated =
false;
256 aFootprintNames.Alloc( numberOfFootprints );
258 for(
size_t i = 0; i < numberOfFootprints; i++ )
263 wxString fpPattern( charBuffer, wxConvISO8859_1 );
265 auto it = patternMap.find( fpPattern );
267 if( it != patternMap.end() )
269 aFootprintNames.Add( it->second );
273 THROW_IO_ERROR( wxString::Format(
"Component name not found: '%s'", fpPattern ) );
281 THROW_IO_ERROR( wxString::Format(
"%s stream was not parsed correctly",
287 THROW_IO_ERROR( wxString::Format(
"%s stream is not fully parsed",
292 catch( CFB::CFBException& exception )
300 const wxString& aFootprintName,
bool aKeepUUID,
301 const std::map<std::string, UTF8>* aProperties )
306 THROW_IO_ERROR( wxString::Format(
_(
"No footprints in library '%s'" ), aLibraryPath ) );
310 for( std::unique_ptr<ALTIUM_PCB_COMPOUND_FILE>& altiumLibFile :
m_fplibFiles[aLibraryPath].m_Files )
312 altiumLibFile->CacheLibModels();
313 auto [dirName, fpCfe] = altiumLibFile->FindLibFootprintDirName( aFootprintName );
315 if( dirName.IsEmpty() )
323 catch( CFB::CFBException& exception )
328 THROW_IO_ERROR( wxString::Format(
_(
"Footprint '%s' not found in '%s'." ),
336 std::vector<FOOTPRINT*> footprints;
339 footprints.push_back( fp );
std::string FormatPath(const std::vector< std::string > &aVectorPath)
Helper for debug logging (vector -> string)
@ EXTENDPRIMITIVEINFORMATION
std::map< wxString, ValueType, DETAIL::CASE_INSENSITIVE_COMPARER > CASE_INSENSITIVE_MAP
size_t GetRemainingBytes() const
wxScopedCharBuffer ReadCharBuffer()
size_t ReadAndSetSubrecordLength()
std::map< wxString, wxString > ReadProperties(std::function< std::map< wxString, wxString >(const std::string &)> handleBinaryData=[](const std::string &) { return std::map< wxString, wxString >();})
FOOTPRINT * ParseFootprint(ALTIUM_PCB_COMPOUND_FILE &altiumLibFile, const wxString &aFootprintName)
void Parse(const ALTIUM_PCB_COMPOUND_FILE &aAltiumPcbFile, const std::map< ALTIUM_PCB_DIR, std::string > &aFileMapping)
Information pertinent to a Pcbnew printed circuit board.
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this IO object can read the specified library file/directory.
virtual void RegisterCallback(LAYER_MAPPING_HANDLER aLayerMappingHandler)
Register a different handler to be called when mapping of input layers to KiCad layers occurs.
LAYER_MAPPING_HANDLER m_layer_mapping_handler
Callback to get layer mapping.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
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...
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.
std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints() override
Return a container with the cached library footprints generated in the last call to Load.
~PCB_IO_ALTIUM_DESIGNER()
static bool checkFileHeader(const wxString &aFileName)
PCB_IO_ALTIUM_DESIGNER()
Pcbnew PLUGIN for Altium *.PcbDoc format.
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
void loadAltiumLibrary(const wxString &aLibraryPath)
static std::map< wxString, PCB_LAYER_ID > DefaultLayerMappingCallback(const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
Return the automapped layers.
std::map< wxString, ALTIUM_FILE_CACHE > m_fplibFiles
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
BOARD * m_board
The board BOARD being worked on, no ownership here.
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PCB_IO can read the specified board file.
PCB_IO(const wxString &aName)
const std::map< std::string, UTF8 > * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
Container for project specific data.
static REPORTER & GetInstance()
static void SetReporter(REPORTER *aReporter)
Set the reporter to use for reporting font substitution warnings.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
bool fileStartsWithBinaryHeader(const wxString &aFilePath, const std::vector< uint8_t > &aHeader)
Check if a file starts with a defined binary header.
const std::vector< uint8_t > COMPOUND_FILE_HEADER
std::vector< std::unique_ptr< ALTIUM_PCB_COMPOUND_FILE > > m_Files