40#include <compoundfilereader.h>
57 const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector )
59 std::map<wxString, PCB_LAYER_ID> retval;
64 retval.insert( { layerDesc.Name, layerDesc.AutoMapLayer } );
108 const std::map<ALTIUM_PCB_DIR, std::string> mapping = {
109 { ALTIUM_PCB_DIR::FILE_HEADER,
"FileHeader" },
110 { ALTIUM_PCB_DIR::ARCS6,
"Arcs6" },
111 { ALTIUM_PCB_DIR::BOARD6,
"Board6" },
112 { ALTIUM_PCB_DIR::BOARDREGIONS,
"BoardRegions" },
113 { ALTIUM_PCB_DIR::CLASSES6,
"Classes6" },
114 { ALTIUM_PCB_DIR::COMPONENTS6,
"Components6" },
115 { ALTIUM_PCB_DIR::COMPONENTBODIES6,
"ComponentBodies6" },
116 { ALTIUM_PCB_DIR::DIMENSIONS6,
"Dimensions6" },
117 { ALTIUM_PCB_DIR::EXTENDPRIMITIVEINFORMATION,
"ExtendedPrimitiveInformation" },
118 { ALTIUM_PCB_DIR::FILLS6,
"Fills6" },
119 { ALTIUM_PCB_DIR::MODELS,
"Models" },
120 { ALTIUM_PCB_DIR::NETS6,
"Nets6" },
121 { ALTIUM_PCB_DIR::PADS6,
"Pads6" },
122 { ALTIUM_PCB_DIR::POLYGONS6,
"Polygons6" },
123 { ALTIUM_PCB_DIR::REGIONS6,
"Regions6" },
124 { ALTIUM_PCB_DIR::RULES6,
"Rules6" },
125 { ALTIUM_PCB_DIR::SHAPEBASEDREGIONS6,
"ShapeBasedRegions6" },
126 { ALTIUM_PCB_DIR::TEXTS6,
"Texts6" },
127 { ALTIUM_PCB_DIR::TRACKS6,
"Tracks6" },
128 { ALTIUM_PCB_DIR::VIAS6,
"Vias6" },
129 { ALTIUM_PCB_DIR::WIDESTRINGS6,
"WideStrings6" }
139 pcb.
Parse( altiumPcbFile, mapping );
141 catch( CFB::CFBException& exception )
153 if( aLibraryPath.IsEmpty() )
158 wxFileName fn( aLibraryPath );
160 if( fn.IsFileReadable() && fn.GetModificationTime().IsValid() )
162 return fn.GetModificationTime().GetValue().GetValue();
180 if( aLibraryPath.Lower().EndsWith( wxS(
".pcblib" ) ) )
183 std::make_unique<ALTIUM_COMPOUND_FILE>( aLibraryPath ) );
185 else if( aLibraryPath.Lower().EndsWith( wxS(
".intlib" ) ) )
187 std::unique_ptr<ALTIUM_COMPOUND_FILE> intCom =
188 std::make_unique<ALTIUM_COMPOUND_FILE>( aLibraryPath );
190 std::map<wxString, const CFB::COMPOUND_FILE_ENTRY*> pcbLibFiles =
191 intCom->EnumDir( L
"PCBLib" );
193 for(
const auto& [pcbLibName, pcbCfe] : pcbLibFiles )
194 m_fplibFiles[aLibraryPath].push_back( intCom->DecodeIntLibStream( *pcbCfe ) );
197 catch( CFB::CFBException& exception )
205 const wxString& aLibraryPath,
bool aBestEfforts,
217 for(
auto& altiumLibFile : it->second )
220 std::map<wxString, wxString> patternMap = altiumLibFile->ListLibFootprints();
222 const std::vector<std::string> streamName = {
"Library",
"Data" };
223 const CFB::COMPOUND_FILE_ENTRY* libraryData = altiumLibFile->FindStream( streamName );
225 if( libraryData ==
nullptr )
233 std::map<wxString, wxString> properties = parser.
ReadProperties();
235 uint32_t numberOfFootprints = parser.
Read<uint32_t>();
236 aFootprintNames.Alloc( numberOfFootprints );
238 for(
size_t i = 0; i < numberOfFootprints; i++ )
243 wxString fpPattern( charBuffer, wxConvISO8859_1 );
245 auto it = patternMap.find( fpPattern );
246 if( it != patternMap.end() )
248 aFootprintNames.Add( it->second );
253 wxString::Format(
"Component name not found: '%s'", fpPattern ) );
261 THROW_IO_ERROR( wxString::Format(
"%s stream was not parsed correctly",
267 THROW_IO_ERROR( wxString::Format(
"%s stream is not fully parsed",
272 catch( CFB::CFBException& exception )
280 const wxString& aFootprintName,
bool aKeepUUID,
288 THROW_IO_ERROR( wxString::Format(
_(
"No footprints in library '%s'" ), aLibraryPath ) );
292 for( std::unique_ptr<ALTIUM_COMPOUND_FILE>& altiumLibFile : it->second )
294 auto [dirName, fpCfe] = altiumLibFile->FindLibFootprintDirName( aFootprintName );
296 if( dirName.IsEmpty() )
304 catch( CFB::CFBException& exception )
309 THROW_IO_ERROR( wxString::Format(
_(
"Footprint '%s' not found in '%s'." ),
std::string FormatPath(const std::vector< std::string > &aVectorPath)
Helper for debug logging (vector -> string)
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 >();})
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)
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.
LAYER_MAPPING_HANDLER m_layer_mapping_handler
Callback to get layer mapping.
virtual void RegisterLayerMappingCallback(LAYER_MAPPING_HANDLER aLayerMappingHandler)
Register a different handler to be called when mapping of input layers to KiCad layers occurs.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
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 PC...
~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.
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.
std::map< wxString, std::vector< std::unique_ptr< ALTIUM_COMPOUND_FILE > > > m_fplibFiles
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
A base class that BOARD loading and saving plugins should derive from.
BOARD * m_board
The board BOARD being worked on, no ownership here.
const STRING_UTF8_MAP * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PCB_IO can read the specified board file.
Container for project specific data.
A name/value tuple with unique names and optional values.
static REPORTER & GetInstance()
#define THROW_IO_ERROR(msg)
static const std::vector< uint8_t > COMPOUND_FILE_HEADER
bool fileStartsWithBinaryHeader(const wxString &aFilePath, const std::vector< uint8_t > &aHeader)
Check if a file starts with a defined binary header.