KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pads_sdb.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 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#pragma once
25
26#include <cstdint>
27#include <vector>
28
29#include <wx/string.h>
30
32
33namespace PADS_IO
34{
35
51
58{
59 int index = 0;
60 uint32_t count = 0;
61 uint32_t totalBytes = 0;
62 uint32_t stride = 0;
63
64 uint32_t physicalOffset = 0;
65 uint32_t physicalBytes = 0;
66 uint32_t physicalCount = 0;
67 uint32_t physicalLiveCount = 0;
68
69 bool IsEmpty() const { return totalBytes == 0; }
70};
71
79{
80public:
81 int32_t OriginX() const { return m_originX; }
82 int32_t OriginY() const { return m_originY; }
83 bool Found() const { return m_found; }
84
85 int32_t DesignX( int32_t aRaw ) const { return aRaw - m_originX; }
86 int32_t DesignY( int32_t aRaw ) const { return aRaw - m_originY; }
87
92 uint32_t HeaderBase() const { return m_headerBase; }
93
94private:
95 friend class PADS_SDB;
96
97 int32_t m_originX = 0;
98 int32_t m_originY = 0;
99 bool m_found = false;
100 uint32_t m_headerBase = 0;
101};
102
111{
112public:
113 PADS_SDB() = default;
114
115 PADS_SDB( const PADS_SDB& ) = delete;
116 PADS_SDB& operator=( const PADS_SDB& ) = delete;
117
122 void Load( std::vector<uint8_t> aBytes );
123
125 static bool HasMagic( const std::vector<uint8_t>& aBytes );
126
127 static bool IsSupportedVersion( uint16_t aVersion );
128
129 uint16_t Version() const { return m_version; }
130 bool IsOldFormat() const { return m_version <= 0x2022; }
131 const std::vector<uint8_t>& Bytes() const { return m_data; }
132 const BINARY_CURSOR& Cursor() const { return m_cursor; }
133 const SDB_COORDS& Coords() const { return m_coords; }
134
135 size_t SectionCount() const { return m_sections.size(); }
136 const SDB_SECTION* Section( int aIndex ) const;
137
140 SDB_RECORD RecordAt( uint32_t aBase ) const { return SDB_RECORD( m_cursor, aBase ); }
141
142private:
143 void parseHeader();
144 void parseDirectory();
146 void verifyFooter() const;
147 void readBoardSetup();
148 int directoryEntryCount() const;
149
150 static constexpr uint8_t MAGIC0 = 0x00;
151 static constexpr uint8_t MAGIC1 = 0xFF;
152 static constexpr int HEADER_SIZE = 10;
153 static constexpr int FOOTER_SIZE = 42;
154 static constexpr int DIR_ENTRY_SIZE = 16;
155
157 static constexpr int VIEW_STATE_RECORD_BYTES = 48;
158
159 std::vector<uint8_t> m_data;
160
161 // Declared after m_data so the bound reference targets a live buffer.
163
164 uint16_t m_version = 0;
165 std::vector<SDB_SECTION> m_sections;
167};
168
169} // namespace PADS_IO
Bounds-checked little-endian read cursor over a PADS binary buffer.
const SDB_COORDS & Coords() const
Definition pads_sdb.h:133
const BINARY_CURSOR & Cursor() const
Definition pads_sdb.h:132
const SDB_SECTION * Section(int aIndex) const
Definition pads_sdb.cpp:436
static constexpr int HEADER_SIZE
Definition pads_sdb.h:152
PADS_SDB & operator=(const PADS_SDB &)=delete
PADS_SDB(const PADS_SDB &)=delete
void parseDirectory()
Definition pads_sdb.cpp:99
static constexpr int FOOTER_SIZE
Definition pads_sdb.h:153
uint16_t Version() const
Definition pads_sdb.h:129
static constexpr int VIEW_STATE_RECORD_BYTES
Stride of the section 2 view-state records that precede the board-setup block.
Definition pads_sdb.h:157
const std::vector< uint8_t > & Bytes() const
Definition pads_sdb.h:131
std::vector< uint8_t > m_data
Definition pads_sdb.h:159
uint16_t m_version
Definition pads_sdb.h:164
BINARY_CURSOR m_cursor
Definition pads_sdb.h:162
std::vector< SDB_SECTION > m_sections
Definition pads_sdb.h:165
size_t SectionCount() const
Definition pads_sdb.h:135
SDB_COORDS m_coords
Definition pads_sdb.h:166
static bool HasMagic(const std::vector< uint8_t > &aBytes)
True if the first two bytes match the PADS binary magic.
Definition pads_sdb.cpp:37
static constexpr uint8_t MAGIC1
Definition pads_sdb.h:151
static constexpr uint8_t MAGIC0
Definition pads_sdb.h:150
void parsePhysicalFraming()
Definition pads_sdb.cpp:127
bool IsOldFormat() const
Definition pads_sdb.h:130
static constexpr int DIR_ENTRY_SIZE
Definition pads_sdb.h:154
PADS_SDB()=default
void Load(std::vector< uint8_t > aBytes)
Validate the header and footer, parse the section directory, and derive the coordinate origin.
Definition pads_sdb.cpp:60
static bool IsSupportedVersion(uint16_t aVersion)
Definition pads_sdb.cpp:43
SDB_RECORD RecordAt(uint32_t aBase) const
A reader positioned at an absolute file offset, for walking a pool or byte region rather than a secti...
Definition pads_sdb.h:140
int directoryEntryCount() const
Definition pads_sdb.cpp:72
void verifyFooter() const
Definition pads_sdb.cpp:93
The per-axis coordinate origin and the design <-> raw transform.
Definition pads_sdb.h:79
int32_t DesignY(int32_t aRaw) const
Definition pads_sdb.h:86
bool Found() const
Definition pads_sdb.h:83
uint32_t HeaderBase() const
Absolute file offset of the PCB board-setup parameter block read by PADS_SDB (the origin sits at Head...
Definition pads_sdb.h:92
int32_t OriginY() const
Definition pads_sdb.h:82
uint32_t m_headerBase
Definition pads_sdb.h:100
int32_t OriginX() const
Definition pads_sdb.h:81
friend class PADS_SDB
Definition pads_sdb.h:95
int32_t DesignX(int32_t aRaw) const
Definition pads_sdb.h:85
A bounds-checked reader positioned at one record inside a buffer.
The PADS PowerPCB .pcb file is a serialized snapshot of PADS' in-memory SDB (System DataBase) object ...
Definition pads_sdb.h:58
bool IsEmpty() const
Definition pads_sdb.h:69
uint32_t physicalLiveCount
Definition pads_sdb.h:67
uint32_t physicalCount
Definition pads_sdb.h:66
uint32_t physicalOffset
Definition pads_sdb.h:64
uint32_t physicalBytes
Definition pads_sdb.h:65
uint32_t totalBytes
Definition pads_sdb.h:61