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
76{
77 bool legacy = false;
78 bool shortDisplayProp = false;
79};
80
81
84{
85public:
86 ORCAD_STRUCT_READER( ORCAD_STREAM& aStream, const std::vector<std::string>* aStrings = nullptr,
87 ORCAD_WARN_FN aWarn = nullptr, ORCAD_DIALECT aDialect = {} );
88
90
91 const ORCAD_DIALECT& Dialect() const { return m_dialect; }
92
95 ORCAD_PREFIXES ReadPrefixes( int aExpectedType = -1, size_t aEnclosingEnd = ORCAD_STREAM::npos,
96 size_t aLongPrefixCount = ORCAD_STREAM::npos );
97
99 uint32_t ReadStrIdx();
100
103 uint16_t ReadCount();
104
106 std::string Resolve( uint32_t aIndex ) const;
107
109 std::map<std::string, std::string> PropsDict( const ORCAD_PREFIXES& aPrefixes ) const;
110
112 void SkipStructure( const ORCAD_PREFIXES& aPrefixes, const wxString& aWhat );
113
116
118 void Warn( const wxString& aMsg ) const;
119
120private:
121 ORCAD_PREFIXES readLegacyPrefix( int aExpectedType );
122
124 const std::vector<std::string>* m_strings;
127};
128
129
131
133
135
137ORCAD_WIRE OrcadReadWire( ORCAD_STRUCT_READER& aReader, const ORCAD_PREFIXES& aPrefixes );
138
140
143
145
147
149std::vector<ORCAD_DISPLAY_PROP> OrcadReadDisplayPropList( ORCAD_STRUCT_READER& aReader );
150
153
156
157#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.
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.
const ORCAD_DIALECT & Dialect() const
ORCAD_STREAM & Stream()
uint32_t ReadStrIdx()
A string-table index in the dialect's width.
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 and the legacy sentinel.
uint16_t ReadCount()
A u16 list count.
ORCAD_READ_RESULT ReadStructure()
Always resumes at the prefix end, skipping unknown bodies and undecoded trailers.
const std::vector< std::string > * m_strings
ORCAD_PREFIXES readLegacyPrefix(int aExpectedType)
ORCAD_STREAM & m_stream
ORCAD_STRUCT_READER(ORCAD_STREAM &aStream, const std::vector< std::string > *aStrings=nullptr, ORCAD_WARN_FN aWarn=nullptr, ORCAD_DIALECT aDialect={})
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)
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)
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 OrcadReadGraphicInst(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
Common body of Port/Global/OffPageConnector/TitleBlock/ERCObject/Graphic*Inst.
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.
Legacy (pre-v3) files have short prefixes only, u16 string indices with a 0xFFFF sentinel and nested ...
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.