KiCad PCB EDA Suite
Loading...
Searching...
No Matches
DIPTRACE::SCH_PARSER Class Reference

Parser for DipTrace .dch schematic binary files. More...

#include <diptrace_sch_parser.h>

Public Member Functions

 SCH_PARSER (const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, PROGRESS_REPORTER *aProgressReporter=nullptr, REPORTER *aReporter=nullptr)
 
 ~SCH_PARSER ()
 
void Parse ()
 Parse the .dch file and populate the schematic with KiCad objects.
 
int ComponentBoundaryScanCount () const
 

Private Member Functions

void parseHeader ()
 
void parseSheetDefinitions ()
 
void parseDisplaySettings ()
 
void parseTextStyles ()
 
void parsePreComponentSettings ()
 
void parseComponents (size_t aBusSectionOffset)
 
void parseOneComponent (size_t aCompEnd, bool aUseCompEnd=true)
 
void parsePin (int aPinIndex, DCH_COMPONENT &aComp)
 
void parseShape (DCH_COMPONENT &aComp)
 
void parseFontBearingShape (DCH_COMPONENT &aComp)
 
bool parseComponentTextField (DCH_COMPONENT &aComp, size_t aCompEnd)
 
void parseEmbeddedPattern (DCH_COMPONENT &aComp, size_t aCompEnd)
 
void parseBusSection ()
 
void parseNetSection ()
 
void parseWireSection ()
 
void parseSheetShapes ()
 
void findPageGeometry ()
 Locate the page-geometry record (width/height/margins, each mm*30000) in the binary and fill m_page.
 
VECTOR2I applyPageOffset (const VECTOR2I &aPos) const
 Apply the page-center offset to an absolute KiCad-nm placement so 0,0-centered DipTrace content lands on the top-left-origin KiCad page.
 
size_t findBusSection (size_t aSearchStart) const
 Find the bus section start offset by searching for the characteristic marker pattern: int4(10000) int4(10000) byte(0) byte(0) int3(count).
 
size_t findTailStart () const
 Find where the int3(0) tail padding begins by scanning backward from the end of file.
 
std::vector< size_t > scanComponentBoundaries (size_t aFirstComp, size_t aBusSectionOffset) const
 Pre-scan the file to find component start offsets using the bbox(4*int4) + 5-string pattern.
 
bool isShapeStart (size_t aOffset) const
 Check if the data at the given offset looks like a shape/polyline start.
 
bool isFontBearingShapeStart (size_t aOffset) const
 
void createKiCadObjects ()
 Create KiCad objects from the parsed intermediate data and add them to the appropriate schematic sheets.
 
SCH_SCREENgetOrCreateSheet (int aSheetIndex)
 Get or create the KiCad sheet and screen for the given DipTrace sheet index.
 
void finalizeFlatSheetOrder ()
 
void assignSheetPageNumbers ()
 
LIB_SYMBOLgetOrCreateLibSymbol (const DCH_COMPONENT &aComp, int aUnit)
 Create a LIB_SYMBOL from the DipTrace component data.
 
void populateLibSymbolUnit (LIB_SYMBOL *aLibSymbol, const DCH_COMPONENT &aComp, int aUnit)
 
void syncEmbeddedLibrarySymbols ()
 
wxString componentSymbolName (const DCH_COMPONENT &aComp) const
 Library symbol name for a component.
 
wxString normalizedRefdes (const DCH_COMPONENT &aComp) const
 
void createSymbolInstance (const DCH_COMPONENT &aComp, SCH_SCREEN *aFallbackScreen)
 Create a SCH_SYMBOL instance on the given screen from a DipTrace component.
 
void createNetPortLabels ()
 Create a global net label for every DipTrace net-port component (auto_net_ports library).
 
int sheetForNearestWire (const VECTOR2I &aPos) const
 Sheet whose decoded wire geometry is closest to aPos, or -1 when no wire exists.
 
void createWires ()
 Emit SCH_LINE wire segments decoded from the net/wire section.
 
void createSheetShapes ()
 
void createJunctions ()
 Synthesize junctions where conductors coincide (DipTrace stores none explicitly).
 
void buildWirePointSheets ()
 Build the maps from wire-point position to the sheet(s) and part(s) connecting there, and the part-id -> sheet map used for deterministic sheet assignment.
 
void buildComponentPartIds ()
 Enumerate every component header in the file (real components and net ports alike) so each component's file offset maps to its DipTrace part id.
 
bool isComponentHeaderAt (size_t aOffset) const
 True if a component record header (placement + five header strings) starts at aOffset.
 
int sheetForPositions (const std::vector< VECTOR2I > &aPositions, int aFallback) const
 Pick the sheet a placed item belongs to by matching its connection points against the decoded wire geometry (DipTrace does not store a per-component sheet field).
 
int sheetForComponentPins (const std::vector< VECTOR2I > &aConnectionPoints)
 Resolve a symbol's sheet from its pin connection points.
 
int resolveSheetTally (const std::map< std::pair< int, int >, int > &aTally)
 Resolve a (partId, sheet) -> hit-count tally to a sheet, preferring the highest-count pair with a part id greater than the last assigned (monotonic).
 
wxString getLibName () const
 Build a library name string for the import.
 

Static Private Member Functions

static int pinOrientationFromOffset (int aOffsetX, int aOffsetY, int aHalfWidth, int aHalfHeight)
 Determine the pin orientation from the pin connection-point offset relative to the symbol body center.
 
static int toKiCadCoordX (int aDipTraceCoord)
 Convert a DipTrace coordinate to KiCad schematic internal units.
 
static int toKiCadCoordY (int aDipTraceCoord)
 
static int toKiCadSize (int aDipTraceCoord)
 Convert a DipTrace length or stroke width to KiCad schematic internal units.
 

Private Attributes

BINARY_READER m_reader
 
SCHEMATICm_schematic
 
SCH_SHEETm_rootSheet
 
PROGRESS_REPORTERm_progressReporter
 
REPORTERm_reporter
 
int m_version
 
int m_magicMajor
 
int m_componentCount
 
int m_componentBoundaryScanCount = 0
 
wxString m_fileName
 
int m_numSheets
 
std::vector< DCH_SHEET_DEFm_sheetDefs
 
std::vector< DCH_COMPONENTm_components
 
std::vector< DCH_BUS_ENTRYm_buses
 
std::vector< DCH_NET_ENTRYm_nets
 
std::vector< DCH_WIREm_wires
 
std::vector< DCH_SHEET_SHAPEm_sheetShapes
 
std::map< std::pair< int, int >, std::set< int > > m_wirePointSheets
 Wire-point position (KiCad nm) -> set of sheet indices carrying a wire there.
 
std::map< std::pair< int, int >, std::vector< std::pair< int, int > > > m_pointPartSheets
 Wire-endpoint position (KiCad nm) -> (partId, sheet) pairs of the parts connecting there.
 
int m_lastSymbolPartId = -1
 Largest part id assigned to a symbol so far; enforces the monotonic part-id order used to disambiguate identical duplicate sheets.
 
DCH_PAGE m_page
 Decoded page geometry and the resulting half-page placement offset (KiCad nm).
 
VECTOR2I m_pageOffset
 
size_t m_componentSectionStart = 0
 File offset of the component section start, used to enumerate components in part-id order.
 
size_t m_wireSectionEnd = 0
 End offset of the decoded wire section; the sheet-shape section follows it in modern files.
 
std::map< size_t, int > m_offsetToPartId
 Component start offset -> DipTrace part id (its index in the in-file component order).
 
std::map< int, int > m_partIdSheet
 DipTrace part id -> sheet index, resolved from the wire connectivity.
 
std::set< wxString > m_netPortNames
 Names of nets that own a placed net-port component; these are the only nets DipTrace draws a label for, so they are the only labels emitted (createNetPortLabels).
 
size_t m_netPortLabelCount = 0
 Count of net-port labels emitted, for the import summary report.
 
std::vector< SCH_SHEET * > m_sheets
 One per DipTrace sheet.
 
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > m_libSymbols
 Symbol library cache.
 
std::map< wxString, std::vector< SCH_SYMBOL * > > m_placedSymbolsByLibName
 
std::map< wxString, int > m_refdesUnitMap
 Map from refdes to the number of units already created for multi-unit symbols.
 
size_t m_busSectionOffset
 
size_t m_tailOffset
 

Detailed Description

Parser for DipTrace .dch schematic binary files.

Reads the binary file using DIPTRACE::BINARY_READER, populates intermediate data structures, then creates KiCad schematic objects (SCH_SYMBOL, SCH_LINE, SCH_LABEL, SCH_SHEET, LIB_SYMBOL).

Supports format versions 31 through 49.

Definition at line 238 of file diptrace_sch_parser.h.

Constructor & Destructor Documentation

◆ SCH_PARSER()

SCH_PARSER::SCH_PARSER ( const wxString & aFileName,
SCHEMATIC * aSchematic,
SCH_SHEET * aRootSheet,
PROGRESS_REPORTER * aProgressReporter = nullptr,
REPORTER * aReporter = nullptr )
Parameters
aFileNamepath to the DipTrace .dch file.
aSchematicthe KiCad schematic object being populated.
aRootSheetthe root sheet to populate.
aProgressReporteroptional progress reporter (may be nullptr).
aReporteroptional message reporter (may be nullptr).

Definition at line 78 of file diptrace_sch_parser.cpp.

References m_busSectionOffset, m_componentCount, m_fileName, m_magicMajor, m_numSheets, m_progressReporter, m_reader, m_reporter, m_rootSheet, m_schematic, m_tailOffset, and m_version.

◆ ~SCH_PARSER()

SCH_PARSER::~SCH_PARSER ( )

Definition at line 96 of file diptrace_sch_parser.cpp.

Member Function Documentation

◆ applyPageOffset()

VECTOR2I SCH_PARSER::applyPageOffset ( const VECTOR2I & aPos) const
private

Apply the page-center offset to an absolute KiCad-nm placement so 0,0-centered DipTrace content lands on the top-left-origin KiCad page.

A no-op when no page was decoded.

Definition at line 181 of file diptrace_sch_parser.cpp.

References m_page, and m_pageOffset.

Referenced by buildWirePointSheets(), createJunctions(), createNetPortLabels(), createSheetShapes(), createSymbolInstance(), and createWires().

◆ assignSheetPageNumbers()

void SCH_PARSER::assignSheetPageNumbers ( )
private

◆ buildComponentPartIds()

void SCH_PARSER::buildComponentPartIds ( )
private

Enumerate every component header in the file (real components and net ports alike) so each component's file offset maps to its DipTrace part id.

Fills m_offsetToPartId.

Definition at line 2963 of file diptrace_sch_parser.cpp.

References isComponentHeaderAt(), m_busSectionOffset, m_componentSectionStart, and m_offsetToPartId.

Referenced by createKiCadObjects().

◆ buildWirePointSheets()

void SCH_PARSER::buildWirePointSheets ( )
private

Build the maps from wire-point position to the sheet(s) and part(s) connecting there, and the part-id -> sheet map used for deterministic sheet assignment.

Definition at line 2820 of file diptrace_sch_parser.cpp.

References applyPageOffset(), m_numSheets, m_partIdSheet, m_pointPartSheets, m_wirePointSheets, m_wires, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by createKiCadObjects().

◆ ComponentBoundaryScanCount()

int DIPTRACE::SCH_PARSER::ComponentBoundaryScanCount ( ) const
inline

Definition at line 260 of file diptrace_sch_parser.h.

References m_componentBoundaryScanCount.

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ componentSymbolName()

wxString SCH_PARSER::componentSymbolName ( const DCH_COMPONENT & aComp) const
private

Library symbol name for a component.

Multi-part components group by normalized reference so their units share one symbol. Single-part symbols keep a rotation suffix because their pin and shape coordinates are stored already rotated.

Definition at line 2505 of file diptrace_sch_parser.cpp.

References DIPTRACE::DCH_COMPONENT::compName, LIB_ID::FixIllegalChars(), DIPTRACE::DCH_COMPONENT::isMultiPart, normalizedRefdes(), DIPTRACE::DCH_COMPONENT::rotationE4, and UTF8::wx_str().

Referenced by createSymbolInstance(), and getOrCreateLibSymbol().

◆ createJunctions()

void SCH_PARSER::createJunctions ( )
private

Synthesize junctions where conductors coincide (DipTrace stores none explicitly).

Definition at line 4074 of file diptrace_sch_parser.cpp.

References applyPageOffset(), getOrCreateSheet(), m_numSheets, m_rootSheet, m_sheets, m_wires, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by createKiCadObjects().

◆ createKiCadObjects()

◆ createNetPortLabels()

void SCH_PARSER::createNetPortLabels ( )
private

Create a global net label for every DipTrace net-port component (auto_net_ports library).

The label name is the port's component name (which equals its net name) and its placement is the port's stored bbox center, so ports without an explicit wire still appear. This is the only label source; internal auto-named nets own no port object and so carry no label, matching the DipTrace rendering. Fills m_netPortNames and m_netPortLabelCount.

Definition at line 3408 of file diptrace_sch_parser.cpp.

References std::abs(), SCH_SCREEN::Append(), applyPageOffset(), SPIN_STYLE::BOTTOM, comp, getOrCreateSheet(), L_BIDI, SPIN_STYLE::LEFT, DIPTRACE::DCH_PIN::length, m_components, m_lastSymbolPartId, m_netPortLabelCount, m_netPortNames, m_offsetToPartId, m_partIdSheet, SPIN_STYLE::RIGHT, SCH_LABEL_BASE::SetShape(), SCH_GLOBALLABEL::SetSpinStyle(), sheetForComponentPins(), sheetForNearestWire(), toKiCadCoordX(), toKiCadCoordY(), toKiCadSize(), SPIN_STYLE::UP, DIPTRACE::DCH_PIN::x, VECTOR2< T >::x, DIPTRACE::DCH_PIN::y, and VECTOR2< T >::y.

Referenced by createKiCadObjects().

◆ createSheetShapes()

◆ createSymbolInstance()

void SCH_PARSER::createSymbolInstance ( const DCH_COMPONENT & aComp,
SCH_SCREEN * aFallbackScreen )
private

Create a SCH_SYMBOL instance on the given screen from a DipTrace component.

Definition at line 3087 of file diptrace_sch_parser.cpp.

References std::abs(), SCH_SYMBOL::AddField(), DIPTRACE::DCH_COMPONENT::additionalFields, ANGLE_VERTICAL, SCH_SCREEN::Append(), applyPageOffset(), DIPTRACE::DCH_COMPONENT::bboxX1, DIPTRACE::DCH_COMPONENT::bboxY1, center, DIPTRACE::DCH_COMPONENT::compName, componentSymbolName(), DIPTRACE::DCH_COMPONENT_TEXT::coordX, DIPTRACE::DCH_COMPONENT_TEXT::coordY, DATASHEET, DIPTRACE::DCH_COMPONENT::datasheet, DIPTRACE::DCH_COMPONENT::fileOffset, LIB_SYMBOL::GetBodyBoundingBox(), BOX2< Vec >::GetBottom(), SCH_SYMBOL::GetField(), BOX2< Vec >::GetHeight(), BOX2< Vec >::GetLeft(), getLibName(), getOrCreateLibSymbol(), getOrCreateSheet(), BOX2< Vec >::GetRight(), BOX2< Vec >::GetTop(), BOX2< Vec >::GetWidth(), GR_TEXT_H_ALIGN_CENTER, GR_TEXT_H_ALIGN_LEFT, GR_TEXT_H_ALIGN_RIGHT, GR_TEXT_V_ALIGN_CENTER, DIPTRACE::DCH_PIN::length, DIPTRACE::DCH_COMPONENT::libPath, m_offsetToPartId, m_partIdSheet, m_placedSymbolsByLibName, m_refdesUnitMap, m_schematic, normalizedRefdes(), DIPTRACE::DCH_COMPONENT::patternName, DIPTRACE::DCH_COMPONENT::pins, DIPTRACE::DCH_COMPONENT::refdes, REFERENCE, DIPTRACE::DCH_COMPONENT::rotationE4, schIUScale, SCH_SYMBOL::SetFootprintFieldText(), SCH_SYMBOL::SetLibSymbol(), SCH_FIELD::SetPosition(), SCH_SYMBOL::SetRef(), SCH_FIELD::SetText(), EDA_TEXT::SetVisible(), sheetForComponentPins(), DIPTRACE::DCH_COMPONENT::texts, toKiCadCoordX(), toKiCadCoordY(), toKiCadSize(), DIPTRACE::DCH_COMPONENT_TEXT::type, USER, VALUE, DIPTRACE::DCH_COMPONENT::value, DIPTRACE::DCH_PIN::x, VECTOR2< T >::x, DIPTRACE::DCH_PIN::y, and VECTOR2< T >::y.

Referenced by createKiCadObjects().

◆ createWires()

void SCH_PARSER::createWires ( )
private

Emit SCH_LINE wire segments decoded from the net/wire section.

Definition at line 4044 of file diptrace_sch_parser.cpp.

References SCH_SCREEN::Append(), applyPageOffset(), getOrCreateSheet(), LAYER_WIRE, m_numSheets, m_wires, and SCH_LINE::SetEndPoint().

Referenced by createKiCadObjects().

◆ finalizeFlatSheetOrder()

void SCH_PARSER::finalizeFlatSheetOrder ( )
private

Definition at line 2460 of file diptrace_sch_parser.cpp.

References assignSheetPageNumbers(), m_rootSheet, m_schematic, and m_sheets.

Referenced by createKiCadObjects().

◆ findBusSection()

size_t SCH_PARSER::findBusSection ( size_t aSearchStart) const
private

Find the bus section start offset by searching for the characteristic marker pattern: int4(10000) int4(10000) byte(0) byte(0) int3(count).

Definition at line 446 of file diptrace_sch_parser.cpp.

References _, DIPTRACE::INT3_BIAS, m_reader, and THROW_IO_ERROR.

Referenced by Parse().

◆ findPageGeometry()

void SCH_PARSER::findPageGeometry ( )
private

Locate the page-geometry record (width/height/margins, each mm*30000) in the binary and fill m_page.

The record is not present in every file; m_page.found stays false when absent.

Definition at line 123 of file diptrace_sch_parser.cpp.

References DIPTRACE::INT4_BIAS, m_page, m_pageOffset, m_reader, and toKiCadSize().

Referenced by Parse().

◆ findTailStart()

size_t SCH_PARSER::findTailStart ( ) const
private

Find where the int3(0) tail padding begins by scanning backward from the end of file.

Definition at line 477 of file diptrace_sch_parser.cpp.

References m_reader.

Referenced by Parse().

◆ getLibName()

wxString SCH_PARSER::getLibName ( ) const
private

Build a library name string for the import.

Definition at line 190 of file diptrace_sch_parser.cpp.

References LIB_ID::FixIllegalChars(), m_rootSheet, m_schematic, and UTF8::wx_str().

Referenced by createSymbolInstance().

◆ getOrCreateLibSymbol()

LIB_SYMBOL * SCH_PARSER::getOrCreateLibSymbol ( const DCH_COMPONENT & aComp,
int aUnit )
private

Create a LIB_SYMBOL from the DipTrace component data.

If a library symbol with the same name already exists, returns the existing one (handles multi-unit symbols by adding units).

Definition at line 2778 of file diptrace_sch_parser.cpp.

References componentSymbolName(), LIB_SYMBOL::GetUnitCount(), m_libSymbols, DIPTRACE::DCH_COMPONENT::patternName, DIPTRACE::DCH_COMPONENT::pins, populateLibSymbolUnit(), DIPTRACE::DCH_COMPONENT::refdes, and LIB_SYMBOL::SetUnitCount().

Referenced by createSymbolInstance().

◆ getOrCreateSheet()

SCH_SCREEN * SCH_PARSER::getOrCreateSheet ( int aSheetIndex)
private

◆ isComponentHeaderAt()

bool SCH_PARSER::isComponentHeaderAt ( size_t aOffset) const
private

True if a component record header (placement + five header strings) starts at aOffset.

Looser than scanComponentBoundaries so net ports are enumerated too.

Definition at line 2882 of file diptrace_sch_parser.cpp.

References std::abs(), DIPTRACE::INT3_BIAS, DIPTRACE::INT4_BIAS, m_reader, m_version, and SCHEMATIC_UTF16_STRING_VERSION.

Referenced by buildComponentPartIds(), parseEmbeddedPattern(), parseOneComponent(), and scanComponentBoundaries().

◆ isFontBearingShapeStart()

bool SCH_PARSER::isFontBearingShapeStart ( size_t aOffset) const
private

◆ isShapeStart()

bool SCH_PARSER::isShapeStart ( size_t aOffset) const
private

Check if the data at the given offset looks like a shape/polyline start.

Definition at line 531 of file diptrace_sch_parser.cpp.

References DIPTRACE::INT3_BIAS, DIPTRACE::INT4_BIAS, m_reader, m_version, and V31_CUTOVER.

Referenced by parseOneComponent().

◆ normalizedRefdes()

wxString SCH_PARSER::normalizedRefdes ( const DCH_COMPONENT & aComp) const
private

◆ Parse()

◆ parseBusSection()

◆ parseComponents()

void SCH_PARSER::parseComponents ( size_t aBusSectionOffset)
private

◆ parseComponentTextField()

bool SCH_PARSER::parseComponentTextField ( DCH_COMPONENT & aComp,
size_t aCompEnd )
private

◆ parseDisplaySettings()

void SCH_PARSER::parseDisplaySettings ( )
private

Definition at line 340 of file diptrace_sch_parser.cpp.

References m_reader, m_version, and V31_CUTOVER.

Referenced by Parse().

◆ parseEmbeddedPattern()

void SCH_PARSER::parseEmbeddedPattern ( DCH_COMPONENT & aComp,
size_t aCompEnd )
private

◆ parseFontBearingShape()

◆ parseHeader()

void SCH_PARSER::parseHeader ( )
private

Definition at line 280 of file diptrace_sch_parser.cpp.

References _, m_magicMajor, m_numSheets, m_reader, m_version, and THROW_IO_ERROR.

Referenced by Parse().

◆ parseNetSection()

◆ parseOneComponent()

◆ parsePin()

void SCH_PARSER::parsePin ( int aPinIndex,
DCH_COMPONENT & aComp )
private

Definition at line 1457 of file diptrace_sch_parser.cpp.

References m_reader, m_version, pin, DIPTRACE::DCH_COMPONENT::pins, and V31_CUTOVER.

Referenced by parseOneComponent().

◆ parsePreComponentSettings()

void SCH_PARSER::parsePreComponentSettings ( )
private

◆ parseShape()

◆ parseSheetDefinitions()

void SCH_PARSER::parseSheetDefinitions ( )
private

◆ parseSheetShapes()

◆ parseTextStyles()

void SCH_PARSER::parseTextStyles ( )
private

Definition at line 373 of file diptrace_sch_parser.cpp.

References _, DIPTRACE::LEGACY_STRING_VERSION, m_magicMajor, m_reader, m_version, and THROW_IO_ERROR.

Referenced by Parse().

◆ parseWireSection()

◆ pinOrientationFromOffset()

int SCH_PARSER::pinOrientationFromOffset ( int aOffsetX,
int aOffsetY,
int aHalfWidth,
int aHalfHeight )
staticprivate

Determine the pin orientation from the pin connection-point offset relative to the symbol body center.

DipTrace stores the connection point and a length; the body extends inward, so a pin on the right side of the body points left, and so on. Returns a KiCad orientation code (0 = right, 1 = up, 2 = left, 3 = down).

Definition at line 2362 of file diptrace_sch_parser.cpp.

References std::abs().

Referenced by populateLibSymbolUnit().

◆ populateLibSymbolUnit()

◆ resolveSheetTally()

int SCH_PARSER::resolveSheetTally ( const std::map< std::pair< int, int >, int > & aTally)
private

Resolve a (partId, sheet) -> hit-count tally to a sheet, preferring the highest-count pair with a part id greater than the last assigned (monotonic).

Updates m_lastSymbolPartId.

Definition at line 2988 of file diptrace_sch_parser.cpp.

References m_lastSymbolPartId.

Referenced by sheetForComponentPins().

◆ scanComponentBoundaries()

std::vector< size_t > SCH_PARSER::scanComponentBoundaries ( size_t aFirstComp,
size_t aBusSectionOffset ) const
private

Pre-scan the file to find component start offsets using the bbox(4*int4) + 5-string pattern.

Definition at line 502 of file diptrace_sch_parser.cpp.

References end, and isComponentHeaderAt().

Referenced by parseComponents().

◆ sheetForComponentPins()

int SCH_PARSER::sheetForComponentPins ( const std::vector< VECTOR2I > & aConnectionPoints)
private

Resolve a symbol's sheet from its pin connection points.

Wire endpoints carry both a part id and a sheet, so the candidate (partId, sheet) pairs are tallied; on identical/duplicate sheets the tie is broken by the monotonic part-id order (components are stored in part-id order), which selects the correct one of the duplicated sheets. Falls back to position voting, then to the root sheet. Updates m_lastSymbolPartId.

Definition at line 3023 of file diptrace_sch_parser.cpp.

References m_pointPartSheets, resolveSheetTally(), and sheetForPositions().

Referenced by createNetPortLabels(), and createSymbolInstance().

◆ sheetForNearestWire()

int SCH_PARSER::sheetForNearestWire ( const VECTOR2I & aPos) const
private

Sheet whose decoded wire geometry is closest to aPos, or -1 when no wire exists.

Used as the final fallback for an isolated net port whose pin matched no wire and whose part id has no wire-derived sheet.

Definition at line 3527 of file diptrace_sch_parser.cpp.

References m_wirePointSheets, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by createNetPortLabels().

◆ sheetForPositions()

int SCH_PARSER::sheetForPositions ( const std::vector< VECTOR2I > & aPositions,
int aFallback ) const
private

Pick the sheet a placed item belongs to by matching its connection points against the decoded wire geometry (DipTrace does not store a per-component sheet field).

Returns the majority-voted sheet, or aFallback when no point coincides with a wire.

Definition at line 3053 of file diptrace_sch_parser.cpp.

References m_wirePointSheets.

Referenced by sheetForComponentPins().

◆ syncEmbeddedLibrarySymbols()

void SCH_PARSER::syncEmbeddedLibrarySymbols ( )
private

Definition at line 4164 of file diptrace_sch_parser.cpp.

References m_libSymbols, and m_placedSymbolsByLibName.

Referenced by createKiCadObjects().

◆ toKiCadCoordX()

int SCH_PARSER::toKiCadCoordX ( int aDipTraceCoord)
staticprivate

Convert a DipTrace coordinate to KiCad schematic internal units.

One DipTrace coordinate unit is 100/3 nm and one schematic IU is 100 nm, so the conversion divides by 3. The PCB importer shares the 100/3 nm unit but multiplies by 100/3 because pcbnew IU is 1 nm.

DipTrace .dch stores schematic Y already in screen-down convention (matching KiCad), with any placement rotation baked into the stored coordinates, so Y is scaled without an axis flip.

Definition at line 101 of file diptrace_sch_parser.cpp.

Referenced by createNetPortLabels(), createSheetShapes(), createSymbolInstance(), parseWireSection(), and populateLibSymbolUnit().

◆ toKiCadCoordY()

int SCH_PARSER::toKiCadCoordY ( int aDipTraceCoord)
staticprivate

◆ toKiCadSize()

int SCH_PARSER::toKiCadSize ( int aDipTraceCoord)
staticprivate

Convert a DipTrace length or stroke width to KiCad schematic internal units.

Same unit as coordinates but unsigned and without the Y axis flip.

Definition at line 117 of file diptrace_sch_parser.cpp.

References std::abs().

Referenced by createNetPortLabels(), createSheetShapes(), createSymbolInstance(), findPageGeometry(), and populateLibSymbolUnit().

Member Data Documentation

◆ m_buses

std::vector<DCH_BUS_ENTRY> DIPTRACE::SCH_PARSER::m_buses
private

Definition at line 459 of file diptrace_sch_parser.h.

Referenced by createKiCadObjects(), and parseBusSection().

◆ m_busSectionOffset

size_t DIPTRACE::SCH_PARSER::m_busSectionOffset
private

◆ m_componentBoundaryScanCount

int DIPTRACE::SCH_PARSER::m_componentBoundaryScanCount = 0
private

Definition at line 452 of file diptrace_sch_parser.h.

Referenced by ComponentBoundaryScanCount(), and parseComponents().

◆ m_componentCount

int DIPTRACE::SCH_PARSER::m_componentCount
private

Definition at line 451 of file diptrace_sch_parser.h.

Referenced by parseComponents(), parsePreComponentSettings(), and SCH_PARSER().

◆ m_components

std::vector<DCH_COMPONENT> DIPTRACE::SCH_PARSER::m_components
private

◆ m_componentSectionStart

size_t DIPTRACE::SCH_PARSER::m_componentSectionStart = 0
private

File offset of the component section start, used to enumerate components in part-id order.

Definition at line 481 of file diptrace_sch_parser.h.

Referenced by buildComponentPartIds(), and parseComponents().

◆ m_fileName

wxString DIPTRACE::SCH_PARSER::m_fileName
private

Definition at line 453 of file diptrace_sch_parser.h.

Referenced by getOrCreateSheet(), and SCH_PARSER().

◆ m_lastSymbolPartId

int DIPTRACE::SCH_PARSER::m_lastSymbolPartId = -1
private

Largest part id assigned to a symbol so far; enforces the monotonic part-id order used to disambiguate identical duplicate sheets.

Definition at line 474 of file diptrace_sch_parser.h.

Referenced by createKiCadObjects(), createNetPortLabels(), and resolveSheetTally().

◆ m_libSymbols

std::map<wxString, std::unique_ptr<LIB_SYMBOL> > DIPTRACE::SCH_PARSER::m_libSymbols
private

Symbol library cache.

Definition at line 502 of file diptrace_sch_parser.h.

Referenced by getOrCreateLibSymbol(), and syncEmbeddedLibrarySymbols().

◆ m_magicMajor

int DIPTRACE::SCH_PARSER::m_magicMajor
private

◆ m_netPortLabelCount

size_t DIPTRACE::SCH_PARSER::m_netPortLabelCount = 0
private

Count of net-port labels emitted, for the import summary report.

Definition at line 498 of file diptrace_sch_parser.h.

Referenced by createKiCadObjects(), and createNetPortLabels().

◆ m_netPortNames

std::set<wxString> DIPTRACE::SCH_PARSER::m_netPortNames
private

Names of nets that own a placed net-port component; these are the only nets DipTrace draws a label for, so they are the only labels emitted (createNetPortLabels).

Definition at line 495 of file diptrace_sch_parser.h.

Referenced by createNetPortLabels().

◆ m_nets

std::vector<DCH_NET_ENTRY> DIPTRACE::SCH_PARSER::m_nets
private

Definition at line 460 of file diptrace_sch_parser.h.

Referenced by parseNetSection().

◆ m_numSheets

◆ m_offsetToPartId

std::map<size_t, int> DIPTRACE::SCH_PARSER::m_offsetToPartId
private

Component start offset -> DipTrace part id (its index in the in-file component order).

Definition at line 487 of file diptrace_sch_parser.h.

Referenced by buildComponentPartIds(), createNetPortLabels(), and createSymbolInstance().

◆ m_page

DCH_PAGE DIPTRACE::SCH_PARSER::m_page
private

Decoded page geometry and the resulting half-page placement offset (KiCad nm).

Definition at line 477 of file diptrace_sch_parser.h.

Referenced by applyPageOffset(), createKiCadObjects(), and findPageGeometry().

◆ m_pageOffset

VECTOR2I DIPTRACE::SCH_PARSER::m_pageOffset
private

Definition at line 478 of file diptrace_sch_parser.h.

Referenced by applyPageOffset(), and findPageGeometry().

◆ m_partIdSheet

std::map<int, int> DIPTRACE::SCH_PARSER::m_partIdSheet
private

DipTrace part id -> sheet index, resolved from the wire connectivity.

This places a symbol on its true sheet even when its pin geometry was mis-parsed.

Definition at line 491 of file diptrace_sch_parser.h.

Referenced by buildWirePointSheets(), createNetPortLabels(), and createSymbolInstance().

◆ m_placedSymbolsByLibName

std::map<wxString, std::vector<SCH_SYMBOL*> > DIPTRACE::SCH_PARSER::m_placedSymbolsByLibName
private

◆ m_pointPartSheets

std::map<std::pair<int, int>, std::vector<std::pair<int, int> > > DIPTRACE::SCH_PARSER::m_pointPartSheets
private

Wire-endpoint position (KiCad nm) -> (partId, sheet) pairs of the parts connecting there.

Lets a symbol recover its exact part id and disambiguate duplicate sheets.

Definition at line 470 of file diptrace_sch_parser.h.

Referenced by buildWirePointSheets(), and sheetForComponentPins().

◆ m_progressReporter

PROGRESS_REPORTER* DIPTRACE::SCH_PARSER::m_progressReporter
private

Definition at line 447 of file diptrace_sch_parser.h.

Referenced by SCH_PARSER().

◆ m_reader

◆ m_refdesUnitMap

std::map<wxString, int> DIPTRACE::SCH_PARSER::m_refdesUnitMap
private

Map from refdes to the number of units already created for multi-unit symbols.

Definition at line 506 of file diptrace_sch_parser.h.

Referenced by createKiCadObjects(), and createSymbolInstance().

◆ m_reporter

REPORTER* DIPTRACE::SCH_PARSER::m_reporter
private

Definition at line 448 of file diptrace_sch_parser.h.

Referenced by createKiCadObjects(), parseOneComponent(), and SCH_PARSER().

◆ m_rootSheet

SCH_SHEET* DIPTRACE::SCH_PARSER::m_rootSheet
private

◆ m_schematic

SCHEMATIC* DIPTRACE::SCH_PARSER::m_schematic
private

◆ m_sheetDefs

std::vector<DCH_SHEET_DEF> DIPTRACE::SCH_PARSER::m_sheetDefs
private

◆ m_sheets

std::vector<SCH_SHEET*> DIPTRACE::SCH_PARSER::m_sheets
private

◆ m_sheetShapes

std::vector<DCH_SHEET_SHAPE> DIPTRACE::SCH_PARSER::m_sheetShapes
private

Definition at line 462 of file diptrace_sch_parser.h.

Referenced by createSheetShapes(), and parseSheetShapes().

◆ m_tailOffset

size_t DIPTRACE::SCH_PARSER::m_tailOffset
private

◆ m_version

◆ m_wirePointSheets

std::map<std::pair<int, int>, std::set<int> > DIPTRACE::SCH_PARSER::m_wirePointSheets
private

Wire-point position (KiCad nm) -> set of sheet indices carrying a wire there.

Used to recover each symbol's / label's owning sheet, which DipTrace stores only implicitly.

Definition at line 466 of file diptrace_sch_parser.h.

Referenced by buildWirePointSheets(), sheetForNearestWire(), and sheetForPositions().

◆ m_wires

std::vector<DCH_WIRE> DIPTRACE::SCH_PARSER::m_wires
private

◆ m_wireSectionEnd

size_t DIPTRACE::SCH_PARSER::m_wireSectionEnd = 0
private

End offset of the decoded wire section; the sheet-shape section follows it in modern files.

Definition at line 484 of file diptrace_sch_parser.h.

Referenced by parseSheetShapes(), and parseWireSection().


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