KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sprint_layout_parser.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 * Binary format knowledge derived from:
24 * https://github.com/sergey-raevskiy/xlay (lay6.h)
25 * https://github.com/OpenBoardView/OpenBoardView (LAYFile.cpp)
26 */
27
28#ifndef SPRINT_LAYOUT_PARSER_H_
29#define SPRINT_LAYOUT_PARSER_H_
30
31#include <cstdint>
32#include <memory>
33#include <string>
34#include <vector>
35#include <map>
36
37#include <layer_ids.h>
38#include <math/vector2d.h>
39
40class BOARD;
41class FOOTPRINT;
42class PAD;
43class PCB_SHAPE;
44class PCB_TEXT;
45
47{
48
58
60{
61 LAYER_C1 = 1, // top copper
62 LAYER_S1 = 2, // top silkscreen
63 LAYER_C2 = 3, // bottom copper
64 LAYER_S2 = 4, // bottom silkscreen
65 LAYER_I1 = 5, // inner layer 1
66 LAYER_I2 = 6, // inner layer 2
67 LAYER_O = 7, // board outline
68};
69
76
77struct POINT
78{
79 float x;
80 float y;
81};
82
84{
85 bool valid = false;
86 float off_x = 0;
87 float off_y = 0;
88 uint8_t center_mode = 0;
89 double rotation = 0;
90 std::string package;
91 std::string comment;
92 uint8_t use = 0;
93};
94
95struct OBJECT
96{
97 uint8_t type = 0; // OBJECT_TYPE enum value
98 float x = 0;
99 float y = 0;
100 float outer = 0; // THT/circle outer radius, SMD half-width, text height
101 float inner = 0; // THT drill radius, SMD half-height, text stroke width
102 uint32_t line_width = 0; // line/poly stroke width, circle end_angle (deg*1000)
103 uint8_t layer = 0; // LAYER_ID enum value
104 uint8_t tht_shape = 0; // THT_SHAPE for pads, 1=component-ref for text
105 uint16_t component_id = 0;
106 int32_t start_angle = 0; // circle start angle (deg*1000), pad thermal style bytes
107 uint8_t filled = 0; // nonzero = filled polygon
108 int32_t clearance = 0; // ground plane clearance (1/10000 mm)
109 uint8_t mirror = 0;
110 uint8_t thermal_width = 0; // thermal relief spoke width
111 uint8_t keepout = 0; // nonzero = ground plane exclusion area
112 int32_t rotation = 0; // rotation in degrees * 1000
113 uint8_t plated = 0; // 0 = NPTH, nonzero = plated
114 uint8_t soldermask = 0; // 0 = no mask opening (tented)
115
116 std::string text;
117 std::string net_name;
118 std::vector<uint32_t> groups;
119 std::vector<POINT> points;
120 std::vector<OBJECT> text_children;
122};
123
125{
126 std::string name;
127 uint32_t size_x = 0; // 1/10000 mm
128 uint32_t size_y = 0; // 1/10000 mm
129 int32_t center_x = 0; // 1/10000 mm
130 int32_t center_y = 0; // 1/10000 mm
131 uint8_t ground_plane[7] = {};
132 uint8_t is_multilayer = 0;
133 std::vector<OBJECT> objects;
134};
135
137{
138 uint8_t version = 0;
139 std::vector<BOARD_DATA> boards;
140 std::string project_name;
141 std::string project_author;
142 std::string project_company;
143 std::string project_comment;
144};
145
146} // namespace SPRINT_LAYOUT
147
148
150{
151public:
154
155 bool Parse( const wxString& aFileName );
156
157 BOARD* CreateBoard( std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
158 size_t aBoardIndex = 0 );
159
161
162private:
163 // Binary reading helpers
164 uint8_t readUint8();
165 uint16_t readUint16();
166 uint32_t readUint32();
167 int32_t readInt32();
168 float readFloat();
169 double readDouble();
170 std::string readFixedString( size_t aMaxLen );
171 std::string readVarString();
172 void skip( size_t aBytes );
173
175 void parseObject( SPRINT_LAYOUT::OBJECT& aObject, bool aIsTextChild = false );
176 void parseTrailer();
177
178 // Board construction helpers
179 PCB_LAYER_ID mapLayer( uint8_t aSprintLayer ) const;
180 int sprintToKicadCoord( float aValue ) const;
181 VECTOR2I sprintToKicadPos( float aX, float aY ) const;
182
183 void addPadToBoard( BOARD* aBoard, const SPRINT_LAYOUT::OBJECT& aObj,
184 std::map<uint16_t, FOOTPRINT*>& aComponentMap,
185 std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap );
186
187 void addCircleToBoard( BOARD* aBoard, const SPRINT_LAYOUT::OBJECT& aObj,
188 std::vector<std::vector<VECTOR2I>>& aOutlineSegments );
189
190 void addLineToBoard( BOARD* aBoard, const SPRINT_LAYOUT::OBJECT& aObj,
191 std::vector<std::vector<VECTOR2I>>& aOutlineSegments );
192
193 void addPolyToBoard( BOARD* aBoard, const SPRINT_LAYOUT::OBJECT& aObj,
194 std::vector<std::vector<VECTOR2I>>& aOutlineSegments );
195
196 void addTextToBoard( BOARD* aBoard, const SPRINT_LAYOUT::OBJECT& aObj );
197
198 void buildOutline( BOARD* aBoard,
199 std::vector<std::vector<VECTOR2I>>& aOutlineSegments,
200 const SPRINT_LAYOUT::BOARD_DATA& aBoardData );
201
203 const uint8_t* m_pos = nullptr;
204 const uint8_t* m_start = nullptr;
205 const uint8_t* m_end = nullptr;
206 std::vector<uint8_t> m_buffer;
207};
208
209#endif // SPRINT_LAYOUT_PARSER_H_
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
Definition pad.h:55
void addLineToBoard(BOARD *aBoard, const SPRINT_LAYOUT::OBJECT &aObj, std::vector< std::vector< VECTOR2I > > &aOutlineSegments)
SPRINT_LAYOUT::FILE_DATA m_fileData
PCB_LAYER_ID mapLayer(uint8_t aSprintLayer) const
const SPRINT_LAYOUT::FILE_DATA & GetFileData() const
void addPolyToBoard(BOARD *aBoard, const SPRINT_LAYOUT::OBJECT &aObj, std::vector< std::vector< VECTOR2I > > &aOutlineSegments)
std::string readFixedString(size_t aMaxLen)
bool Parse(const wxString &aFileName)
void buildOutline(BOARD *aBoard, std::vector< std::vector< VECTOR2I > > &aOutlineSegments, const SPRINT_LAYOUT::BOARD_DATA &aBoardData)
void addTextToBoard(BOARD *aBoard, const SPRINT_LAYOUT::OBJECT &aObj)
void parseObject(SPRINT_LAYOUT::OBJECT &aObject, bool aIsTextChild=false)
void addPadToBoard(BOARD *aBoard, const SPRINT_LAYOUT::OBJECT &aObj, std::map< uint16_t, FOOTPRINT * > &aComponentMap, std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap)
BOARD * CreateBoard(std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, size_t aBoardIndex=0)
void parseBoardHeader(SPRINT_LAYOUT::BOARD_DATA &aBoard)
void addCircleToBoard(BOARD *aBoard, const SPRINT_LAYOUT::OBJECT &aObj, std::vector< std::vector< VECTOR2I > > &aOutlineSegments)
VECTOR2I sprintToKicadPos(float aX, float aY) const
int sprintToKicadCoord(float aValue) const
std::vector< uint8_t > m_buffer
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
std::vector< OBJECT > objects
std::vector< BOARD_DATA > boards
std::vector< POINT > points
std::vector< OBJECT > text_children
std::vector< uint32_t > groups
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687