KiCad PCB EDA Suite
Loading...
Searching...
No Matches
orcad_page.cpp File Reference
#include <sch_io/orcad/orcad_page.h>
#include <algorithm>
#include <optional>
#include <utility>
#include <ki_exception.h>
#include <sch_io/orcad/orcad_cache.h>
#include <sch_io/orcad/orcad_library.h>
#include <sch_io/orcad/orcad_stream.h>
#include <sch_io/orcad/orcad_structures.h>

Go to the source code of this file.

Classes

struct  V2_PART_CELL
 

Functions

ORCAD_RAW_PAGE OrcadParsePage (const std::vector< char > &aData, const std::vector< std::string > &aStrings, const ORCAD_WARN_FN &aWarn)
 Parse one 'Views/<folder>/Pages/<page>' stream into raw structure lists.
 
std::vector< std::string > OrcadParsePageOrder (const std::vector< char > &aData)
 Parse the 'Views/<folder>/Schematic' stream and return the folder's page names in display order.
 
std::map< uint32_t, std::string > OrcadReadHierarchyLinks (const std::vector< char > &aData, const std::vector< std::string > &aStrings, const ORCAD_WARN_FN &aWarn, std::map< uint32_t, std::string > *aOccurrenceRefs)
 Parse a 'Views/<folder>/Hierarchy/Hierarchy' stream into block-instance links: block db id -> child folder name.
 
static uint8_t readOccHeader (ORCAD_STREAM &aStream, int aExpectType)
 
static ORCAD_OCC_SCOPE readOccScope (ORCAD_STREAM &aStream)
 
static void readOccurrence (ORCAD_STREAM &aStream, ORCAD_OCC_SCOPE &aScope)
 
static std::string v2Resolve (const std::vector< std::string > &aStrings, uint16_t aIdx)
 
static void v2CheckCount (ORCAD_STREAM &aStream, uint32_t aCount)
 
static uint8_t v2Prefix (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings, std::map< std::string, std::string > *aProps=nullptr)
 
static ORCAD_DISPLAY_PROP v2DisplayProp (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static std::vector< ORCAD_DISPLAY_PROPv2DisplayPropList (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static ORCAD_ALIAS v2Alias (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static void v2Structure (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static ORCAD_WIRE v2Wire (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static ORCAD_PIN_INST v2PinInst (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static ORCAD_PLACED_INSTANCE v2PlacedInstance (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static ORCAD_PRIMITIVE v2PrimBody (ORCAD_STREAM &aStream, uint8_t aType, int aDepth=0)
 
static ORCAD_PRIMITIVE v2Primitive (ORCAD_STREAM &aStream)
 
static ORCAD_SYMBOL_DEF v2SymbolDef (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static ORCAD_GRAPHIC_INST v2GraphicInst (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static ORCAD_PORT_TYPE v2PortType (uint32_t aRaw)
 
static bool v2SymbolPin (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings, ORCAD_SYMBOL_PIN &aOut)
 
static ORCAD_SYMBOL_DEF v2LibSymbolDef (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings, int aTypeId)
 
static V2_PART_CELL v2PartCell (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static ORCAD_DEVICE v2Device (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
static ORCAD_PACKAGE v2Package (ORCAD_STREAM &aStream, const std::vector< std::string > &aStrings)
 
ORCAD_RAW_PAGE OrcadParsePageV2 (const std::vector< char > &aData, const std::vector< std::string > &aStrings, const ORCAD_WARN_FN &)
 Parse one v2.0 (pre-2003) 'Views/<folder>/Pages/<page>' stream.
 
void OrcadParseOlbSymbolStreamV2 (const std::vector< char > &aData, const std::vector< std::string > &aStrings, std::map< std::string, ORCAD_SYMBOL_DEF > &aSymbols)
 Parse one v2.0 .OLB 'Symbols/<name>' stream (a single special symbol: power, port, off-page, title block or ERC) into aSymbols, keyed by symbol name.
 
void OrcadParseOlbPackageStreamV2 (const std::vector< char > &aData, const std::vector< std::string > &aStrings, std::map< std::string, ORCAD_SYMBOL_DEF > &aSymbols, std::map< std::string, ORCAD_PACKAGE > &aPackages)
 Parse one v2.0 .OLB 'Packages/<name>' stream (a part's inline symbol definitions plus its package/device pin maps) into aSymbols (keyed by view name, e.g.
 
ORCAD_OCC_SCOPE OrcadReadOccurrenceTree (const std::vector< char > &aData, const ORCAD_WARN_FN &aWarn)
 Parse the root folder 'Hierarchy/Hierarchy' stream into the full occurrence tree: per-scope part reference designators (keyed by placed-instance db id) and the hierarchical block occurrences that descend into child schematics, each with its own nested scope so a schematic reused N times yields N per-occurrence ref sets.
 

Variables

static thread_local bool g_v2ShortDisplayProp = false
 

Function Documentation

◆ OrcadParseOlbPackageStreamV2()

void OrcadParseOlbPackageStreamV2 ( const std::vector< char > & aData,
const std::vector< std::string > & aStrings,
std::map< std::string, ORCAD_SYMBOL_DEF > & aSymbols,
std::map< std::string, ORCAD_PACKAGE > & aPackages )

Parse one v2.0 .OLB 'Packages/<name>' stream (a part's inline symbol definitions plus its package/device pin maps) into aSymbols (keyed by view name, e.g.

"7400.Normal") and aPackages (keyed by package name). Throws on a framing error.

Definition at line 1156 of file orcad_page.cpp.

References g_v2ShortDisplayProp, ORCAD_PACKAGE::name, ORCAD_SYMBOL_DEF::name, ORCAD_STREAM::ReadU16(), ORCAD_PACKAGE::refDes, ORCAD_STREAM::Remaining(), THROW_IO_ERROR, v2CheckCount(), v2Package(), and v2PartCell().

Referenced by SCH_IO_ORCAD::loadOlbSymbols().

◆ OrcadParseOlbSymbolStreamV2()

void OrcadParseOlbSymbolStreamV2 ( const std::vector< char > & aData,
const std::vector< std::string > & aStrings,
std::map< std::string, ORCAD_SYMBOL_DEF > & aSymbols )

Parse one v2.0 .OLB 'Symbols/<name>' stream (a single special symbol: power, port, off-page, title block or ERC) into aSymbols, keyed by symbol name.

Throws IO_ERROR on a framing error.

Definition at line 1119 of file orcad_page.cpp.

References g_v2ShortDisplayProp, ORCAD_SYMBOL_DEF::name, ORCAD_STREAM::Remaining(), THROW_IO_ERROR, v2LibSymbolDef(), and v2Prefix().

Referenced by SCH_IO_ORCAD::loadOlbSymbols().

◆ OrcadParsePage()

ORCAD_RAW_PAGE OrcadParsePage ( const std::vector< char > & aData,
const std::vector< std::string > & aStrings,
const ORCAD_WARN_FN & aWarn )

Parse one 'Views/<folder>/Pages/<page>' stream into raw structure lists.

Stream layout: one framed structure of type 10 (Page) whose body starts with lzt page name, lzt page-size name, then the 156-byte PageSettings block (OrcadParsePageSettings — supplies width/height/isMetric), followed by these u16-counted lists in order:

  1. title blocks framed structures (type 65)
  2. T0x34 records raw, NOT prefix-framed (OrcadReadT0x34Raw)
  3. T0x35 records raw, NOT prefix-framed (OrcadReadT0x35Raw)
  4. net table per entry: lzt net name + u32 net db id
  5. wires framed (types 20/21)
  6. placed parts framed; type 13 -> instances, type 12 -> blocks
  7. ports framed (type 23)
  8. globals framed (type 37), each entry followed by 5 bytes
  9. off-page connectors framed (type 38), each entry followed by 5 bytes

ERC objects framed (type 77)

  1. bus entries framed (type 29)
  2. graphic instances framed (types 55..62, 88, 89)

The net table is authoritative for net names and junction computation: wires carry ids that key it. Structures that fail to parse are skipped with a warning via aWarn (never aborting the page); only a structurally unreadable Page structure itself throws IO_ERROR.

Definition at line 68 of file orcad_page.cpp.

References ORCAD_RAW_PAGE::blocks, ORCAD_RAW_PAGE::busEntries, ORCAD_RAW_PAGE::ercObjects, ORCAD_RAW_PAGE::globals, ORCAD_RAW_PAGE::graphics, ORCAD_PAGE_SETTINGS::height, ORCAD_RAW_PAGE::height, ORCAD_RAW_PAGE::instances, ORCAD_PAGE_SETTINGS::isMetric, ORCAD_RAW_PAGE::isMetric, ORCAD_RAW_PAGE::name, ORCAD_RAW_PAGE::netmap, ORCAD_RAW_PAGE::offpage, ORCAD_ST_PAGE, OrcadParsePageSettings(), OrcadReadT0x34Raw(), OrcadReadT0x35Raw(), ORCAD_RAW_PAGE::pageSize, ORCAD_RAW_PAGE::ports, ORCAD_STREAM::ReadLzt(), ORCAD_STRUCT_READER::ReadPrefixes(), ORCAD_STRUCT_READER::ReadStructure(), ORCAD_STREAM::ReadU16(), ORCAD_STREAM::ReadU32(), result, ORCAD_STREAM::Skip(), THROW_IO_ERROR, ORCAD_RAW_PAGE::titleBlocks, ORCAD_PREFIXES::typeId, ORCAD_PAGE_SETTINGS::width, ORCAD_RAW_PAGE::width, and ORCAD_RAW_PAGE::wires.

Referenced by SCH_IO_ORCAD::LoadSchematicFile().

◆ OrcadParsePageOrder()

std::vector< std::string > OrcadParsePageOrder ( const std::vector< char > & aData)

Parse the 'Views/<folder>/Schematic' stream and return the folder's page names in display order.

Layout: one prefix chain, lzt folder name, 4 bytes, u16 page count, then the lzt page names stored LAST-FIRST (the returned vector is already reversed into display order).

The caller (plugin shell) must intersect the result with the page streams that actually exist under 'Views/<folder>/Pages/', append any pages missing from the order stream, and fall back to name-sorted order with a warning when this parser throws IO_ERROR.

Definition at line 159 of file orcad_page.cpp.

References ORCAD_STREAM::ReadLzt(), ORCAD_STRUCT_READER::ReadPrefixes(), ORCAD_STREAM::ReadU16(), and ORCAD_STREAM::Skip().

Referenced by SCH_IO_ORCAD::LoadSchematicFile().

◆ OrcadParsePageV2()

ORCAD_RAW_PAGE OrcadParsePageV2 ( const std::vector< char > & aData,
const std::vector< std::string > & aStrings,
const ORCAD_WARN_FN & aWarn )

◆ OrcadReadHierarchyLinks()

std::map< uint32_t, std::string > OrcadReadHierarchyLinks ( const std::vector< char > & aData,
const std::vector< std::string > & aStrings,
const ORCAD_WARN_FN & aWarn,
std::map< uint32_t, std::string > * aOccurrenceRefs = nullptr )

Parse a 'Views/<folder>/Hierarchy/Hierarchy' stream into block-instance links: block db id -> child folder name.

Used to name skipped child folders in hierarchy warnings (hierarchical designs are converted flat).

The stream header is version-fragile, so the reader scans for preambles and backtracks prefix chains (OrcadFindStructureStart), keeping only type-66 structures. Type-66 body: u32, u32 instance db id, u8 inner-frame marker that must equal 0x42, u32, u32, lzt child folder name, lzt occurrence reference. Bad candidates are skipped silently; the scan never throws.

When aOccurrenceRefs is non-null it receives instance db id -> reference designator from the second lzt, which occurrence-annotated designs use to store the real refdes that the placed instance itself leaves as "C?".

Definition at line 184 of file orcad_page.cpp.

References ORCAD_STREAM::Data(), ORCAD_PREFIXES::end, ORCAD_STREAM::ExpectByte(), ORCAD_STREAM::FindPreamble(), ORCAD_STREAM::GetOffset(), ORCAD_STREAM::npos, ORCAD_ST_HIERARCHY_LINK, OrcadFindStructureStart(), ORCAD_STREAM::ReadLzt(), ORCAD_STRUCT_READER::ReadPrefixes(), ORCAD_STREAM::ReadU32(), and ORCAD_STREAM::Seek().

Referenced by SCH_IO_ORCAD::LoadSchematicFile().

◆ OrcadReadOccurrenceTree()

ORCAD_OCC_SCOPE OrcadReadOccurrenceTree ( const std::vector< char > & aData,
const ORCAD_WARN_FN & aWarn )

Parse the root folder 'Hierarchy/Hierarchy' stream into the full occurrence tree: per-scope part reference designators (keyed by placed-instance db id) and the hierarchical block occurrences that descend into child schematics, each with its own nested scope so a schematic reused N times yields N per-occurrence ref sets.

Returns an empty scope for legacy pre-preamble streams (which are instance- annotated) and on any parse error (the caller then falls back to the scan-based OrcadReadHierarchyLinks for the flat root-scope refs).

Definition at line 1212 of file orcad_page.cpp.

References ORCAD_STREAM::ReadLzt(), readOccScope(), ORCAD_STREAM::ReadU32(), ORCAD_STREAM::ReadU8(), ORCAD_STREAM::Skip(), and IO_ERROR::What().

Referenced by SCH_IO_ORCAD::LoadSchematicFile().

◆ readOccHeader()

static uint8_t readOccHeader ( ORCAD_STREAM & aStream,
int aExpectType )
static

◆ readOccScope()

◆ readOccurrence()

◆ v2Alias()

static ORCAD_ALIAS v2Alias ( ORCAD_STREAM & aStream,
const std::vector< std::string > & aStrings )
static

◆ v2CheckCount()

static void v2CheckCount ( ORCAD_STREAM & aStream,
uint32_t aCount )
static

◆ v2Device()

◆ v2DisplayProp()

◆ v2DisplayPropList()

static std::vector< ORCAD_DISPLAY_PROP > v2DisplayPropList ( ORCAD_STREAM & aStream,
const std::vector< std::string > & aStrings )
static

Definition at line 461 of file orcad_page.cpp.

References ORCAD_STREAM::ReadU16(), and v2DisplayProp().

Referenced by v2GraphicInst(), v2PinInst(), and v2PlacedInstance().

◆ v2GraphicInst()

◆ v2LibSymbolDef()

◆ v2Package()

◆ v2PartCell()

◆ v2PinInst()

static ORCAD_PIN_INST v2PinInst ( ORCAD_STREAM & aStream,
const std::vector< std::string > & aStrings )
static

◆ v2PlacedInstance()

◆ v2PortType()

static ORCAD_PORT_TYPE v2PortType ( uint32_t aRaw)
static

Definition at line 810 of file orcad_page.cpp.

References PASSIVE.

Referenced by v2SymbolPin().

◆ v2Prefix()

static uint8_t v2Prefix ( ORCAD_STREAM & aStream,
const std::vector< std::string > & aStrings,
std::map< std::string, std::string > * aProps = nullptr )
static

◆ v2PrimBody()

◆ v2Primitive()

static ORCAD_PRIMITIVE v2Primitive ( ORCAD_STREAM & aStream)
static

Definition at line 587 of file orcad_page.cpp.

References ORCAD_STREAM::ReadU8(), and v2PrimBody().

Referenced by v2LibSymbolDef(), and v2SymbolDef().

◆ v2Resolve()

static std::string v2Resolve ( const std::vector< std::string > & aStrings,
uint16_t aIdx )
static

Definition at line 384 of file orcad_page.cpp.

Referenced by v2DisplayProp(), v2GraphicInst(), v2PlacedInstance(), and v2Prefix().

◆ v2Structure()

◆ v2SymbolDef()

◆ v2SymbolPin()

◆ v2Wire()

Variable Documentation

◆ g_v2ShortDisplayProp

thread_local bool g_v2ShortDisplayProp = false
static