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;
42class FOOTPRINT;
43class PAD;
44class PCB_SHAPE;
45class PCB_TEXT;
46
48{
49
59
61{
62 LAYER_C1 = 1, // top copper
63 LAYER_S1 = 2, // top silkscreen
64 LAYER_C2 = 3, // bottom copper
65 LAYER_S2 = 4, // bottom silkscreen
66 LAYER_I1 = 5, // inner layer 1
67 LAYER_I2 = 6, // inner layer 2
68 LAYER_O = 7, // board outline
69};
70
85
86struct POINT
87{
88 float x;
89 float y;
90};
91
93{
94 bool valid = false;
95 float off_x = 0;
96 float off_y = 0;
97 uint8_t center_mode = 0;
98 double rotation = 0;
99 std::string package;
100 std::string comment;
101 uint8_t use = 0;
102};
103
104struct OBJECT
105{
106 uint8_t type = 0; // OBJECT_TYPE enum value
107 float x = 0;
108 float y = 0;
109 float outer = 0; // THT/circle outer radius, SMD half-width, text height
110 float inner = 0; // THT drill radius, SMD half-height, text stroke width
111 uint32_t line_width = 0; // line/poly stroke width, circle end_angle (deg*1000)
112 uint8_t layer = 0; // LAYER_ID enum value
113 uint8_t tht_shape = 0; // THT_SHAPE for pads, 1=component-ref for text
114 uint16_t component_id = 0;
115 int32_t start_angle = 0; // circle start angle (deg*1000), pad thermal style bytes
116 uint8_t filled = 0; // nonzero = filled polygon
117 int32_t clearance = 0; // ground plane clearance (1/10000 mm)
118 uint8_t mirror = 0;
119 uint8_t thermal_width = 0; // thermal relief spoke width
120 uint8_t keepout = 0; // nonzero = ground plane exclusion area
121 int32_t rotation = 0; // rotation in degrees * 1000
122 uint8_t plated = 0; // 0 = NPTH, nonzero = plated
123 uint8_t soldermask = 0; // 0 = no mask opening (tented)
124
125 std::string text;
126 std::string net_name;
127 std::vector<uint32_t> groups;
128 std::vector<POINT> points;
129 std::vector<OBJECT> text_children;
131};
132
134{
135 std::string name;
136 uint32_t size_x = 0; // 1/10000 mm
137 uint32_t size_y = 0; // 1/10000 mm
138 int32_t center_x = 0; // 1/10000 mm
139 int32_t center_y = 0; // 1/10000 mm
140 uint8_t ground_plane[7] = {};
141 uint8_t is_multilayer = 0;
142 std::vector<OBJECT> objects;
143};
144
146{
147 uint8_t version = 0;
148 std::vector<BOARD_DATA> boards;
149 std::string project_name;
150 std::string project_author;
151 std::string project_company;
152 std::string project_comment;
153};
154
155} // namespace SPRINT_LAYOUT
156
157
159{
160public:
163
164 bool Parse( const wxString& aFileName );
165
166 BOARD* CreateBoard( std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
167 size_t aBoardIndex = 0 );
168
170
171private:
172 // Binary reading helpers
173 uint8_t readUint8();
174 uint16_t readUint16();
175 uint32_t readUint32();
176 int32_t readInt32();
177 float readFloat();
178 double readDouble();
179 std::string readFixedString( size_t aMaxLen );
180 std::string readVarString();
181 void skip( size_t aBytes );
182
184 void parseObject( SPRINT_LAYOUT::OBJECT& aObject, bool aIsTextChild = false );
185 void parseTrailer();
186
187 // Board construction helpers
188 PCB_LAYER_ID mapLayer( uint8_t aSprintLayer ) const;
189 int sprintToKicadCoord( float aValue ) const;
190 VECTOR2I sprintToKicadPos( float aX, float aY ) const;
191 wxString convertString( const std::string& aStr ) const;
192
193 void processPad( BOARD_ITEM_CONTAINER* aContainer, const SPRINT_LAYOUT::OBJECT& aObj );
194
195 void processCircle( BOARD_ITEM_CONTAINER* aContainer, const SPRINT_LAYOUT::OBJECT& aObj,
196 std::vector<std::vector<VECTOR2I>>& aOutlineSegments );
197
198 void processLine( BOARD_ITEM_CONTAINER* aContainer, const SPRINT_LAYOUT::OBJECT& aObj,
199 std::vector<std::vector<VECTOR2I>>& aOutlineSegments );
200
201 void processPoly( BOARD_ITEM_CONTAINER* aContainer, const SPRINT_LAYOUT::OBJECT& aObj,
202 std::vector<std::vector<VECTOR2I>>& aOutlineSegments );
203
204 void processText( BOARD_ITEM_CONTAINER* aContainer, const SPRINT_LAYOUT::OBJECT& aObj );
205
206 void buildOutline( BOARD* aBoard, std::vector<std::vector<VECTOR2I>>& aOutlineSegments,
207 const SPRINT_LAYOUT::BOARD_DATA& aBoardData );
208
210 const uint8_t* m_pos = nullptr;
211 const uint8_t* m_start = nullptr;
212 const uint8_t* m_end = nullptr;
213 std::vector<uint8_t> m_buffer;
214};
215
216#endif // SPRINT_LAYOUT_PARSER_H_
Abstract interface for BOARD_ITEMs capable of storing other items inside.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
Definition pad.h:55
wxString convertString(const std::string &aStr) const
SPRINT_LAYOUT::FILE_DATA m_fileData
void processText(BOARD_ITEM_CONTAINER *aContainer, const SPRINT_LAYOUT::OBJECT &aObj)
PCB_LAYER_ID mapLayer(uint8_t aSprintLayer) const
const SPRINT_LAYOUT::FILE_DATA & GetFileData() const
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 processCircle(BOARD_ITEM_CONTAINER *aContainer, const SPRINT_LAYOUT::OBJECT &aObj, std::vector< std::vector< VECTOR2I > > &aOutlineSegments)
void parseObject(SPRINT_LAYOUT::OBJECT &aObject, bool aIsTextChild=false)
BOARD * CreateBoard(std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, size_t aBoardIndex=0)
void parseBoardHeader(SPRINT_LAYOUT::BOARD_DATA &aBoard)
void processLine(BOARD_ITEM_CONTAINER *aContainer, const SPRINT_LAYOUT::OBJECT &aObj, std::vector< std::vector< VECTOR2I > > &aOutlineSegments)
void processPoly(BOARD_ITEM_CONTAINER *aContainer, 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
void processPad(BOARD_ITEM_CONTAINER *aContainer, const SPRINT_LAYOUT::OBJECT &aObj)
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