44#include <compoundfilereader.h>
49 const std::vector<ALTIUM_PROJECT_VARIANT>& aVariants )
51 std::map<wxString, FOOTPRINT*> fpByRef;
52 std::map<KIID, FOOTPRINT*> fpByUid;
56 fpByRef[fp->GetReference()] = fp;
62 if(
path.size() >= 2 )
63 fpByUid[
path.back()] = fp;
70 if( !pv.description.empty() && pv.description != pv.name )
80 wxString normalizedUid = entry.
uniqueId;
82 if( normalizedUid.starts_with( wxT(
"\\" ) ) )
83 normalizedUid = normalizedUid.Mid( 1 );
85 auto it = fpByUid.find(
KIID( normalizedUid ) );
87 if( it != fpByUid.end() )
95 if( it != fpByRef.end() )
107 if( entry.
kind == 1 )
109 fpVariant->
SetDNP(
true );
113 else if( entry.
kind == 0 )
117 if( key.CmpNoCase( wxS(
"LibReference" ) ) == 0 )
119 else if( key.CmpNoCase( wxS(
"Description" ) ) == 0 )
121 else if( key.CmpNoCase( wxS(
"Footprint" ) ) == 0 )
130 PCB_IO( wxS(
"Altium Designer" ) )
144 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector )
146 std::map<wxString, PCB_LAYER_ID> retval;
151 retval.insert( { layerDesc.Name, layerDesc.AutoMapLayer } );
184 const std::map<std::string, UTF8>* aProperties,
PROJECT* aProject )
196 m_board->SetFileName( aFileName );
199 const std::map<ALTIUM_PCB_DIR, std::string> mapping = {
230 pcb.
Parse( altiumPcbFile, mapping );
232 catch( CFB::CFBException& exception )
241 if( !variants.empty() )
252 if( aLibraryPath.IsEmpty() )
255 wxFileName fn( aLibraryPath );
257 if( fn.IsFileReadable() && fn.GetModificationTime().IsValid() )
258 return fn.GetModificationTime().GetValue().GetValue();
278 if( aLibraryPath.Lower().EndsWith( wxS(
".pcblib" ) ) )
280 libFiles.
m_Files.emplace_back( std::make_unique<ALTIUM_PCB_COMPOUND_FILE>( aLibraryPath ) );
282 else if( aLibraryPath.Lower().EndsWith( wxS(
".intlib" ) ) )
284 std::unique_ptr<ALTIUM_PCB_COMPOUND_FILE> lib = std::make_unique<ALTIUM_PCB_COMPOUND_FILE>( aLibraryPath );
286 for(
const auto& [pcbLibName, pcbCfe] : lib->EnumDir(
L"PCBLib" ) )
288 std::unique_ptr<ALTIUM_PCB_COMPOUND_FILE> libFile = std::make_unique<ALTIUM_PCB_COMPOUND_FILE>();
290 if( lib->DecodeIntLibStream( *pcbCfe, libFile.get() ) )
291 libFiles.
m_Files.emplace_back( std::move( libFile ) );
297 catch( CFB::CFBException& exception )
305 const wxString& aLibraryPath,
bool aBestEfforts,
306 const std::map<std::string, UTF8>* aProperties )
315 for( std::unique_ptr<ALTIUM_PCB_COMPOUND_FILE>& altiumLibFile :
m_fplibFiles[aLibraryPath].m_Files )
320 const std::vector<std::string> streamName = {
"Library",
"Data" };
321 const CFB::COMPOUND_FILE_ENTRY* libraryData = altiumLibFile->FindStream( streamName );
323 if( libraryData ==
nullptr )
331 std::map<wxString, wxString> properties = parser.
ReadProperties();
333 uint32_t numberOfFootprints = parser.
Read<uint32_t>();
342 bool footprintListNotTruncated =
true;
344 if ( patternMap.size() < numberOfFootprints )
346 numberOfFootprints = patternMap.size();
347 footprintListNotTruncated =
false;
350 aFootprintNames.Alloc( numberOfFootprints );
352 for(
size_t i = 0; i < numberOfFootprints; i++ )
357 wxString fpPattern( charBuffer, wxConvISO8859_1 );
359 auto it = patternMap.find( fpPattern );
361 if( it != patternMap.end() )
363 aFootprintNames.Add( it->second );
367 THROW_IO_ERROR( wxString::Format(
"Component name not found: '%s'", fpPattern ) );
375 THROW_IO_ERROR( wxString::Format(
"%s stream was not parsed correctly",
381 THROW_IO_ERROR( wxString::Format(
"%s stream is not fully parsed",
386 catch( CFB::CFBException& exception )
394 const wxString& aFootprintName,
bool aKeepUUID,
395 const std::map<std::string, UTF8>* aProperties )
400 THROW_IO_ERROR( wxString::Format(
_(
"No footprints in library '%s'" ), aLibraryPath ) );
404 for( std::unique_ptr<ALTIUM_PCB_COMPOUND_FILE>& altiumLibFile :
m_fplibFiles[aLibraryPath].m_Files )
406 altiumLibFile->CacheLibModels();
407 auto [dirName, fpCfe] = altiumLibFile->FindLibFootprintDirName( aFootprintName );
409 if( dirName.IsEmpty() )
417 catch( CFB::CFBException& exception )
422 THROW_IO_ERROR( wxString::Format(
_(
"Footprint '%s' not found in '%s'." ),
430 std::vector<FOOTPRINT*> footprints;
433 footprints.push_back( fp );
std::string FormatPath(const std::vector< std::string > &aVectorPath)
Helper for debug logging (vector -> string)
@ EXTENDPRIMITIVEINFORMATION
std::vector< ALTIUM_PROJECT_VARIANT > ParseAltiumProjectVariants(const wxString &aPrjPcbPath)
Parse all [ProjectVariantN] sections from an Altium .PrjPcb project file.
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.
void AddVariant(const wxString &aVariantName)
const FOOTPRINTS & Footprints() const
void SetVariantDescription(const wxString &aVariantName, const wxString &aDescription)
RAII class to set and restore the fontconfig reporter.
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.
static LOAD_INFO_REPORTER & GetInstance()
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)
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()
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
const std::vector< uint8_t > COMPOUND_FILE_HEADER
bool fileHasBinaryHeader(const wxString &aFilePath, const std::vector< uint8_t > &aHeader, size_t aOffset)
Check if a file starts with a defined binary header.
void ApplyAltiumProjectVariantsToBoard(BOARD *aBoard, const std::vector< ALTIUM_PROJECT_VARIANT > &aVariants)
Pcbnew PLUGIN for Altium *.PcbDoc format.
void ApplyAltiumProjectVariantsToBoard(BOARD *aBoard, const std::vector< ALTIUM_PROJECT_VARIANT > &aVariants)
Apply parsed Altium project variants to a board by setting FOOTPRINT_VARIANT data on each footprint w...
A project-level assembly variant parsed from an Altium .PrjPcb file.
A single component variation within an Altium project variant.
std::map< wxString, wxString > alternateFields
std::vector< std::unique_ptr< ALTIUM_PCB_COMPOUND_FILE > > m_Files