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
43
44#ifndef ORCAD_STRUCTURES_H_
45#define ORCAD_STRUCTURES_H_
46
47#include <cstdint>
48#include <map>
49#include <string>
50#include <utility>
51#include <variant>
52#include <vector>
53
54#include <wx/string.h>
55
58
59
64{
65 int typeId = 0;
66 std::vector<uint32_t> bodyLens;
67 std::vector<std::pair<uint32_t, uint32_t>> props;
68 size_t start = 0;
69 size_t bodyStart = 0;
70 size_t end = 0;
73 std::vector<size_t> stops;
75};
76
77
84 std::variant<std::monostate, ORCAD_DISPLAY_PROP, ORCAD_ALIAS, ORCAD_WIRE, ORCAD_PIN_INST,
87
93
94
105{
106public:
107 ORCAD_STRUCT_READER( ORCAD_STREAM& aStream, const std::vector<std::string>* aStrings = nullptr,
108 ORCAD_WARN_FN aWarn = nullptr );
109
111
122 ORCAD_PREFIXES TryReadPrefixes( int aCount );
123
131
133 std::string Resolve( uint32_t aIndex ) const;
134
136 std::map<std::string, std::string> PropsDict( const ORCAD_PREFIXES& aPrefixes ) const;
137
142 void SkipStructure( const ORCAD_PREFIXES& aPrefixes, const wxString& aWhat );
143
166
168 void Warn( const wxString& aMsg ) const;
169
170private:
172 const std::vector<std::string>* m_strings;
174};
175
176
177// -- per-type body readers ----------------------------------------------------------------
178//
179// Each reader is entered with the stream positioned at the structure body (right
180// after ReadPrefixes()) and must leave the cursor at the end of everything it
181// consumed. All throw IO_ERROR on malformed data; recovery is ReadStructure()'s
182// job. Byte layouts are documented on the corresponding structs in
183// orcad_records.h.
184
186 const ORCAD_PREFIXES& aPrefixes );
187
189
191ORCAD_WIRE OrcadReadWire( ORCAD_STRUCT_READER& aReader, const ORCAD_PREFIXES& aPrefixes );
192
194 const ORCAD_PREFIXES& aPrefixes );
195
198 const ORCAD_PREFIXES& aPrefixes );
199
202
205 const ORCAD_PREFIXES& aPrefixes );
206
209 const ORCAD_PREFIXES& aPrefixes );
210
212
214
219std::vector<ORCAD_DISPLAY_PROP> OrcadReadDisplayPropList( ORCAD_STRUCT_READER& aReader );
220
226void OrcadReadT0x34Raw( ORCAD_STREAM& aStream );
227
229void OrcadReadT0x35Raw( ORCAD_STREAM& aStream );
230
231#endif // ORCAD_STRUCTURES_H_
Little-endian byte cursor over one OrCAD Capture DSN stream.
Stateful reader shared by all structure parsers.
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)
Seek to the end of a structure using its outermost prefix length.
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()
Read one structure of any type: prefixes, then the type-specific body via the reader dispatch below.
const std::vector< std::string > * m_strings
ORCAD_PREFIXES TryReadPrefixes(int aCount)
Attempt to read exactly aCount prefixes (aCount - 1 long + 1 short) at the current position and verif...
ORCAD_PREFIXES ReadPrefixes()
Discover the prefix count by trial from 10 down to 1 (longest chain first), then consume the prefixes...
ORCAD_STREAM & m_stream
Plain data records produced by the OrCAD Capture DSN stream parsers and consumed by ORCAD_CONVERTER.
std::function< void(const wxString &aMsg)> ORCAD_WARN_FN
Warning sink shared by all parser entry points (recoverable-issue channel).
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)
void OrcadReadT0x34Raw(ORCAD_STREAM &aStream)
T0x34 records are NOT prefix-framed.
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)
Read a u16-counted list of framed DisplayProp structures via ReadStructure(), keeping only the succes...
ORCAD_PIN_INST OrcadReadPinInst(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
ORCAD_DISPLAY_PROP OrcadReadDisplayProp(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
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
Result of reading one structure of any type.
ORCAD_GRAPHIC_INST OrcadReadErcObject(ORCAD_STRUCT_READER &aReader, const ORCAD_PREFIXES &aPrefixes)
GraphicInst body followed by 3 lzt strings.
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)
void OrcadReadT0x35Raw(ORCAD_STREAM &aStream)
T0x35 = the T0x34 raw layout followed by u16 n and 4 * n bytes.
Net alias attached to a wire (becomes a local label).
Bus entry (structure type 29).
One displayed property of an instance (Part Reference, Value, user fields).
Structure type 12: a hierarchical block instance placed on a page.
Shared body of Port / Global / OffPageConnector / TitleBlock / ERCObject and the Graphic*Inst shapes ...
T0x10: one pin of a placed instance, carrying the pin's absolute page position (the connection point ...
A placed part instance on a page (structure type 13).
The decoded prefix chain of one framed structure.
std::vector< size_t > stops
checkpoint offsets, one per long prefix: start + 9 * i + 9 + bodyLens[i]
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 (from the outermost long prefix); 0 when unknown
size_t start
stream offset where the chain began
ORCAD_RECORD_VARIANT record
A symbol definition from the design Cache (LibraryPart / GlobalSymbol / PortSymbol / OffPageSymbol / ...
One wire or bus segment.