KiCad PCB EDA Suite
Loading...
Searching...
No Matches
EAGLE_BIN_PARSER Class Reference

Read-only parser for the pre-v6 binary Eagle .brd format. More...

#include <eagle_bin_parser.h>

Classes

struct  DRC_CTX
 DRC values pulled from the trailing 244-byte block (or sane defaults). More...
 
struct  EGB_NODE
 Lightweight mutable tree node for the intermediate Eagle binary tree. More...
 

Public Member Functions

 EAGLE_BIN_PARSER ()
 
 ~EAGLE_BIN_PARSER ()
 
std::unique_ptr< wxXmlDocument > Parse (const std::vector< uint8_t > &aBytes)
 Parse a binary Eagle board into an XML DOM compatible with the XML walker.
 

Static Public Member Functions

static bool IsBinaryEagle (wxInputStream &aStream)
 Probe the first two bytes for the binary magic.
 

Private Member Functions

int readBlock (long &aNumBlocks, EGB_NODE *aParent)
 
bool readNotes ()
 
bool readDrc (DRC_CTX &aDrc)
 
const wxString & nextLongText ()
 
void postProcess (EGB_NODE *aRoot, const DRC_CTX &aDrc)
 
void postprocLayers (EGB_NODE *aDrawing, EGB_NODE *aLayers)
 
void postprocDrc (EGB_NODE *aDrcNode, const DRC_CTX &aDrc)
 
void postprocLibs (EGB_NODE *aLibraries)
 
void postprocElements (EGB_NODE *aElements)
 
void postprocNames (EGB_NODE *aLibraries, EGB_NODE *aElements)
 
void postprocSignals (EGB_NODE *aSignals)
 
void postprocContactRefs (EGB_NODE *aSignals, EGB_NODE *aElements, EGB_NODE *aLibraries)
 
void postprocWires (EGB_NODE *aRoot)
 
void postprocArcs (EGB_NODE *aRoot)
 
void postprocVias (EGB_NODE *aRoot)
 
void postprocUnits (EGB_NODE *aRoot)
 
void postprocCircles (EGB_NODE *aRoot)
 
void postprocSmd (EGB_NODE *aRoot)
 
void postprocDimensions (EGB_NODE *aRoot)
 
void postprocFreeText (EGB_NODE *aRoot)
 
void postprocRotation (EGB_NODE *aRoot)
 
bool isRotatable (int aId) const
 
void arcDecode (EGB_NODE *aElem, int aArcType, int aLineType)
 
void fixLongText (EGB_NODE *aNode, const wxString &aField)
 
wxXmlNode * toXml (const EGB_NODE *aNode) const
 
void requireBytes (size_t aOffs, size_t aLen) const
 
uint32_t loadU32 (size_t aOffs, unsigned aLen) const
 
int32_t loadS32 (size_t aOffs, unsigned aLen) const
 
bool loadBmb (size_t aOffs, uint32_t aMask) const
 
uint32_t loadUbf (size_t aOffs, uint32_t aField) const
 
wxString loadStr (size_t aOffs, unsigned aLen) const
 
double loadDouble (size_t aOffs) const
 

Private Attributes

const std::vector< uint8_t > * m_buf = nullptr
 file contents, not owned
 
size_t m_pos = 0
 current read cursor
 
std::unique_ptr< EGB_NODEm_root
 
std::vector< wxString > m_freeText
 NUL-delimited notes strings.
 
size_t m_freeTextCursor = 0
 
wxString m_invalidText
 returned when out of strings
 

Detailed Description

Read-only parser for the pre-v6 binary Eagle .brd format.

Eagle stored boards in a flat stream of fixed 24-byte records before the XML era (versions 6+). The binary is decoded into a node tree structurally identical to the Eagle XML DOM, then fed to the same XML tree-walker, so KiCad's existing PCB_IO_EAGLE::loadAllSections() can consume the result unchanged.

There is no separate binary-to-board mapping. The binary is parsed into a generic intermediate tree (EGB_NODE), rewritten in place by a series of post-processing passes so its element names and attribute names match the XML schema, and finally emitted as a wxXmlDocument.

Definition at line 62 of file eagle_bin_parser.h.

Constructor & Destructor Documentation

◆ EAGLE_BIN_PARSER()

EAGLE_BIN_PARSER::EAGLE_BIN_PARSER ( )
default

◆ ~EAGLE_BIN_PARSER()

EAGLE_BIN_PARSER::~EAGLE_BIN_PARSER ( )
default

Member Function Documentation

◆ arcDecode()

void EAGLE_BIN_PARSER::arcDecode ( EGB_NODE * aElem,
int aArcType,
int aLineType )
private

◆ fixLongText()

void EAGLE_BIN_PARSER::fixLongText ( EGB_NODE * aNode,
const wxString & aField )
private

Definition at line 1167 of file eagle_bin_parser.cpp.

References nextLongText(), and EAGLE_BIN_PARSER::EGB_NODE::props.

Referenced by postprocFreeText().

◆ IsBinaryEagle()

bool EAGLE_BIN_PARSER::IsBinaryEagle ( wxInputStream & aStream)
static

Probe the first two bytes for the binary magic.

Returns
true for v4/v5 (0x10 0x00) or v3 (0x10 0x80) binary boards.

Definition at line 813 of file eagle_bin_parser.cpp.

Referenced by PCB_IO_EAGLE::checkHeader(), and PCB_IO_EAGLE::LoadBoard().

◆ isRotatable()

◆ loadBmb()

bool EAGLE_BIN_PARSER::loadBmb ( size_t aOffs,
uint32_t aMask ) const
private

Definition at line 874 of file eagle_bin_parser.cpp.

References m_buf, and requireBytes().

Referenced by readBlock().

◆ loadDouble()

double EAGLE_BIN_PARSER::loadDouble ( size_t aOffs) const
private

Definition at line 913 of file eagle_bin_parser.cpp.

References m_buf, and requireBytes().

Referenced by readBlock(), and readDrc().

◆ loadS32()

int32_t EAGLE_BIN_PARSER::loadS32 ( size_t aOffs,
unsigned aLen ) const
private

Definition at line 855 of file eagle_bin_parser.cpp.

References m_buf, and requireBytes().

Referenced by readBlock(), readDrc(), and readNotes().

◆ loadStr()

wxString EAGLE_BIN_PARSER::loadStr ( size_t aOffs,
unsigned aLen ) const
private

Definition at line 896 of file eagle_bin_parser.cpp.

References m_buf, and requireBytes().

Referenced by readBlock().

◆ loadU32()

uint32_t EAGLE_BIN_PARSER::loadU32 ( size_t aOffs,
unsigned aLen ) const
private

Definition at line 839 of file eagle_bin_parser.cpp.

References requireBytes().

Referenced by loadUbf(), and readBlock().

◆ loadUbf()

uint32_t EAGLE_BIN_PARSER::loadUbf ( size_t aOffs,
uint32_t aField ) const
private

Definition at line 882 of file eagle_bin_parser.cpp.

References loadU32().

Referenced by readBlock().

◆ nextLongText()

const wxString & EAGLE_BIN_PARSER::nextLongText ( )
private

Definition at line 1091 of file eagle_bin_parser.cpp.

References m_freeText, m_freeTextCursor, m_invalidText, and traceEagleIo.

Referenced by fixLongText().

◆ Parse()

std::unique_ptr< wxXmlDocument > EAGLE_BIN_PARSER::Parse ( const std::vector< uint8_t > & aBytes)

Parse a binary Eagle board into an XML DOM compatible with the XML walker.

Parameters
aBytesis the entire file content.
Returns
a document owning the synthesized DOM; throws IO_ERROR on failure.

Definition at line 2103 of file eagle_bin_parser.cpp.

References _, drc, m_buf, m_pos, m_root, postProcess(), readBlock(), readDrc(), readNotes(), THROW_IO_ERROR, and toXml().

Referenced by PCB_IO_EAGLE::LoadBoard().

◆ postprocArcs()

◆ postprocCircles()

◆ postprocContactRefs()

◆ postprocDimensions()

◆ postprocDrc()

◆ postprocElements()

void EAGLE_BIN_PARSER::postprocElements ( EGB_NODE * aElements)
private

Definition at line 1772 of file eagle_bin_parser.cpp.

References EAGLE_BIN_PARSER::EGB_NODE::children, and EGKW_SECT_ELEMENT2.

Referenced by postProcess().

◆ postProcess()

◆ postprocFreeText()

◆ postprocLayers()

void EAGLE_BIN_PARSER::postprocLayers ( EGB_NODE * aDrawing,
EGB_NODE * aLayers )
private

Definition at line 1693 of file eagle_bin_parser.cpp.

References EAGLE_BIN_PARSER::EGB_NODE::children, and EGKW_SECT_LAYER.

Referenced by postProcess().

◆ postprocLibs()

void EAGLE_BIN_PARSER::postprocLibs ( EGB_NODE * aLibraries)
private

◆ postprocNames()

◆ postprocRotation()

◆ postprocSignals()

void EAGLE_BIN_PARSER::postprocSignals ( EGB_NODE * aSignals)
private

◆ postprocSmd()

◆ postprocUnits()

void EAGLE_BIN_PARSER::postprocUnits ( EGB_NODE * aRoot)
private

◆ postprocVias()

void EAGLE_BIN_PARSER::postprocVias ( EGB_NODE * aRoot)
private

◆ postprocWires()

◆ readBlock()

int EAGLE_BIN_PARSER::readBlock ( long & aNumBlocks,
EGB_NODE * aParent )
private

◆ readDrc()

◆ readNotes()

bool EAGLE_BIN_PARSER::readNotes ( )
private

Definition at line 1047 of file eagle_bin_parser.cpp.

References end, loadS32(), m_buf, m_freeText, m_freeTextCursor, and m_pos.

Referenced by Parse().

◆ requireBytes()

void EAGLE_BIN_PARSER::requireBytes ( size_t aOffs,
size_t aLen ) const
private

Definition at line 832 of file eagle_bin_parser.cpp.

References _, m_buf, and THROW_IO_ERROR.

Referenced by loadBmb(), loadDouble(), loadS32(), loadStr(), and loadU32().

◆ toXml()

wxXmlNode * EAGLE_BIN_PARSER::toXml ( const EGB_NODE * aNode) const
private

Member Data Documentation

◆ m_buf

const std::vector<uint8_t>* EAGLE_BIN_PARSER::m_buf = nullptr
private

file contents, not owned

Definition at line 161 of file eagle_bin_parser.h.

Referenced by loadBmb(), loadDouble(), loadS32(), loadStr(), Parse(), readBlock(), readDrc(), readNotes(), and requireBytes().

◆ m_freeText

std::vector<wxString> EAGLE_BIN_PARSER::m_freeText
private

NUL-delimited notes strings.

Definition at line 166 of file eagle_bin_parser.h.

Referenced by nextLongText(), and readNotes().

◆ m_freeTextCursor

size_t EAGLE_BIN_PARSER::m_freeTextCursor = 0
private

Definition at line 167 of file eagle_bin_parser.h.

Referenced by nextLongText(), and readNotes().

◆ m_invalidText

wxString EAGLE_BIN_PARSER::m_invalidText
private

returned when out of strings

Definition at line 168 of file eagle_bin_parser.h.

Referenced by nextLongText().

◆ m_pos

size_t EAGLE_BIN_PARSER::m_pos = 0
private

current read cursor

Definition at line 162 of file eagle_bin_parser.h.

Referenced by Parse(), readBlock(), readDrc(), and readNotes().

◆ m_root

std::unique_ptr<EGB_NODE> EAGLE_BIN_PARSER::m_root
private

Definition at line 164 of file eagle_bin_parser.h.

Referenced by Parse().


The documentation for this class was generated from the following files: