KiCad PCB EDA Suite
Loading...
Searching...
No Matches
orcad_structures.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * Based on the dsn2kicad reference implementation and on OrCAD file format
7 * documentation from the OpenOrCadParser project (MIT licensed).
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
24
25#ifndef ORCAD_STRUCTURES_H_
26#define ORCAD_STRUCTURES_H_
27
28#include <cstdint>
29#include <map>
30#include <optional>
31#include <string>
32#include <utility>
33#include <variant>
34#include <vector>
35
36#include <wx/string.h>
37
40
41
43{
44 int typeId = 0;
45 std::vector<uint32_t> bodyLens;
46 std::vector<std::pair<uint32_t, uint32_t>> props;
47 size_t start = 0;
48 size_t bodyStart = 0;
49 size_t end = 0;
52 std::vector<size_t> stops;
54};
55
56
61
67
68
70std::optional<size_t> OrcadLongPrefixCount( int aTypeId );
71
72
75{
76public:
77 ORCAD_STRUCT_READER( ORCAD_STREAM& aStream, const std::vector<std::string>* aStrings = nullptr,
78 ORCAD_WARN_FN aWarn = nullptr );
79
81
84 ORCAD_PREFIXES ReadPrefixes( int aExpectedType = -1, size_t aEnclosingEnd = ORCAD_STREAM::npos,
85 size_t aLongPrefixCount = ORCAD_STREAM::npos );
86
88 std::string Resolve( uint32_t aIndex ) const;
89
91 std::map<std::string, std::string> PropsDict( const ORCAD_PREFIXES& aPrefixes ) const;
92
94 void SkipStructure( const ORCAD_PREFIXES& aPrefixes, const wxString& aWhat );
95
98
100 void Warn( const wxString& aMsg ) const;
101
102private:
104 const std::vector<std::string>* m_strings;
106};
107
108
110
112
114
116ORCAD_WIRE OrcadReadWire( ORCAD_STRUCT_READER& aReader, const ORCAD_PREFIXES& aPrefixes );
117
119
122
125
128
131
133
135
137
139std::vector<ORCAD_DISPLAY_PROP> OrcadReadDisplayPropList( ORCAD_STRUCT_READER& aReader );
140
143
146
147#endif // ORCAD_STRUCTURES_H_
The caller owns the buffer.
static constexpr size_t npos
Generic invalid offset sentinel.
ReadStructure can recover from a body error when the prefix supplies a valid end offset.
std::map< std::string, std::string > PropsDict(const ORCAD_PREFIXES &aPrefixes) const
Resolve the short-prefix (nameIdx, valueIdx) pairs; empty names are dropped.
void SkipStructure(const ORCAD_PREFIXES &aPrefixes, const wxString &aWhat)
Throws IO_ERROR if the end is unknown or behind the cursor.
ORCAD_PREFIXES ReadPrefixes(int aExpectedType=-1, size_t aEnclosingEnd=ORCAD_STREAM::npos, size_t aLongPrefixCount=ORCAD_STREAM::npos)
aLongPrefixCount overrides the type depth; aEnclosingEnd bounds all stops.
ORCAD_STREAM & Stream()
void Warn(const wxString &aMsg) const
Report a recoverable problem to the warning sink (no-op when none was given).
std::string Resolve(uint32_t aIndex) const
String-table lookup; returns "" for out-of-range indices.
ORCAD_STRUCT_READER(ORCAD_STREAM &aStream, const std::vector< std::string > *aStrings=nullptr, ORCAD_WARN_FN aWarn=nullptr)
ORCAD_READ_RESULT ReadStructure()
Skip unknown bodies.
const std::vector< std::string > * m_strings
ORCAD_STREAM & m_stream
std::function< void(const wxString &aMsg)> ORCAD_WARN_FN
Coordinates use DBU with Y down.
ORCAD_WIRE OrcadReadWire(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
Types 20 (wire) and 21 (bus); isBus is set from the prefix type.
ORCAD_PLACED_INSTANCE OrcadReadPlacedInstance(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
ORCAD_GRAPHIC_INST OrcadReadPort(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
GraphicInst body followed by a 9-byte trailer.
std::vector< ORCAD_DISPLAY_PROP > OrcadReadDisplayPropList(ORCAD_STRUCT_READER &aReader)
Keep only display properties that ReadStructure decodes.
ORCAD_NET_GROUP OrcadReadT0x34Raw(ORCAD_STREAM &aStream)
T0x34 records have no prefixes; consume their fixed layout to preserve alignment.
ORCAD_PIN_INST OrcadReadPinInst(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
ORCAD_DISPLAY_PROP OrcadReadDisplayProp(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
Body readers start after the prefixes.
ORCAD_BUS_ENTRY OrcadReadBusEntryBody(ORCAD_STREAM &aStream)
ORCAD_GRAPHIC_INST OrcadReadErcObject(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
GraphicInst body followed by 3 lzt strings.
std::variant< std::monostate, ORCAD_DISPLAY_PROP, ORCAD_ALIAS, ORCAD_WIRE, ORCAD_PIN_INST, ORCAD_BUS_ENTRY, ORCAD_PLACED_INSTANCE, ORCAD_GRAPHIC_INST, ORCAD_DRAWN_INSTANCE, ORCAD_SYMBOL_DEF > ORCAD_RECORD_VARIANT
A skipped or unreadable body produces monostate.
ORCAD_GRAPHIC_INST OrcadReadTitleBlock(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
GraphicInst body followed by a 12-byte trailer.
ORCAD_GRAPHIC_INST OrcadReadGraphicInst(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
Common body of Port/Global/OffPageConnector/TitleBlock/ERCObject/Graphic*Inst.
ORCAD_BUS_ENTRY OrcadReadBusEntry(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
ORCAD_ALIAS OrcadReadAlias(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
std::optional< size_t > OrcadLongPrefixCount(int aTypeId)
Registered number of long prefixes for a modern framed structure type.
ORCAD_NET_GROUP OrcadReadT0x35Raw(ORCAD_STREAM &aStream)
T0x35 = the T0x34 raw layout followed by u16 n and 4 * n bytes.
The owning wire defines the connection.
Display positions use symbol coordinates; rotFont combines the font index and quarter turns.
The inline LibraryPart defines the block interface; placed pin records supply absolute positions.
Free graphics use nested primitive coordinates.
Pin positions are absolute page connection points.
The placed box includes displayed text.
Prefix lengths supply structure bounds.
std::vector< size_t > stops
< (from the outermost long prefix); < 0 when unknown
int typeId
ORCAD_ST value (u8 in the stream)
size_t bodyStart
offset right after the preamble trail
std::vector< std::pair< uint32_t, uint32_t > > props
short prefix (nameIdx, valueIdx) pairs
std::vector< uint32_t > bodyLens
one per long prefix, outermost first
size_t end
offset right after the whole structure
size_t start
stream offset where the chain began
ORCAD_RECORD_VARIANT record
The bounding box occupies the final eight bytes before the next prefix stop.
The wire ID refers to the page net table.