KiCad PCB EDA Suite
Loading...
Searching...
No Matches
target3001_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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef TARGET3001_PARSER_H
21#define TARGET3001_PARSER_H
22
23#include <array>
24#include <cmath>
25#include <cstdint>
26#include <memory>
27#include <optional>
28#include <string>
29#include <utility>
30#include <vector>
31
32#include <wx/datetime.h>
33#include <wx/string.h>
34
35
48namespace TARGET3001
49{
50
52enum class ELEMENT_TYPE : uint8_t
53{
54 LINE = 1,
55 PIN = 2,
56 PAD = 3,
59 ARC = 6,
60 DISC = 7,
61 TEXT = 8,
64 SYMBOL = 11,
65 PACKAGE = 12,
66 SIGNAL = 13,
67 SPLINE = 14,
69 LIST = 16,
71 NONE = 255
72};
73
74
76constexpr int SCHEMATIC_LAYER_BASE = 100;
77
79constexpr int SCHEMATIC_SHEET_COUNT = 100;
80
82constexpr int ALL_COPPER_LAYER = 100;
83
84
87{
88 uint16_t component = 0;
89 uint16_t signal = 0;
90 int32_t x = 0;
91 int32_t y = 0;
92 uint8_t flags = 0;
93 uint8_t status = 0;
94 uint8_t layer = 0;
95 uint8_t classTag = 0;
96
97 std::optional<uint32_t> extra;
98
100 std::vector<std::pair<std::string, std::string>> props;
101
103 const std::string* FindProp( const std::string& aKey ) const;
104
106 bool FlagProp( const std::string& aKey ) const;
107
109 std::optional<std::pair<int32_t, int32_t>> TextRightEnd() const;
110
112 std::vector<uint8_t> Picture() const;
113};
114
115
116struct LINE
117{
118 int32_t x2 = 0;
119 int32_t y2 = 0;
120 int32_t width = 0;
121 int32_t clearance = 0;
122 uint8_t dashStyle = 0;
123 uint8_t roundEnds = 0;
124};
125
126
128struct PIN
129{
130 float direction = 0.0f;
131 int32_t length = 0;
132 int32_t width = 0;
133 uint8_t electricalType = 0;
134 uint16_t swapLevel = 0;
135 uint8_t inverted = 0;
136 uint8_t clock = 0;
137 uint8_t showNumber = 0;
138 uint8_t supplyPin = 0;
139 uint16_t pinNumber = 0;
140};
141
142
143enum class PAD_SHAPE : uint8_t
144{
145 ROUND = 0,
148 OVAL = 3,
150};
151
152
153struct PAD
154{
155 float direction = 0.0f;
156 uint8_t shape = 0;
157 int32_t width = 0;
158 int32_t height = 0;
159 int32_t clearance = 0;
160 int32_t drill = 0;
161 int32_t reserved = 0;
162 uint16_t number = 0;
163};
164
165
168{
169 int32_t x2 = 0;
170 int32_t y2 = 0;
171 int32_t x3 = 0;
172 int32_t y3 = 0;
173};
174
175
178{
179 int32_t height = 0;
180 int32_t width = 0;
181 float direction = 0.0f;
182};
183
184
186struct ARC
187{
188 int32_t endX = 0;
189 int32_t endY = 0;
190 int32_t centerX = 0;
191 int32_t centerY = 0;
192 int32_t radius = 0;
193 int32_t width = 0;
194 int32_t clearance = 0;
195 float startAngle = 0.0f;
196 float endAngle = 0.0f;
197
199 double Sweep() const
200 {
201 double sweep = std::fmod( double( endAngle ) - double( startAngle ), 360.0 );
202 return sweep <= 0.0 ? sweep + 360.0 : sweep;
203 }
204};
205
206
208struct DISC
209{
210 int32_t radius = 0;
211};
212
213
222
223
225{
226 uint8_t kind = 0;
227 int32_t radius = 0;
228 int32_t width = 0;
229 float direction = 0.0f;
230};
231
232
234struct SPLINE
235{
236 int32_t endX = 0;
237 int32_t endY = 0;
238 int32_t controlX = 0;
239 int32_t controlY = 0;
240 int32_t width = 0;
241 int32_t clearance = 0;
242};
243
244
263
264
265enum class TEXT_LANGUAGE : uint8_t
266{
270};
271
272
273struct TEXT
274{
275 std::string text;
276 int32_t height = 0;
277 int32_t width = 0;
278 float direction = 0.0f;
279 uint8_t weight = 0;
280 uint8_t noAutoUpright = 0;
281 uint8_t mirrored = 0;
282 uint8_t function = 0;
283 std::string font;
284};
285
286
288{
289 int32_t radius = 0;
290 std::string text;
291};
292
293
294struct ELEMENT;
295
296
298struct SYMBOL
299{
300 std::string name;
301 std::string suffix;
302 uint16_t gateOrdinal = 0;
303 uint8_t insertRequired = 0;
304 uint16_t swapLevel = 0;
305 std::vector<ELEMENT> children;
306};
307
308
311{
312 std::string package;
313 std::string library;
314 uint16_t padCount = 0;
315 uint8_t bottomSide = 0;
316 float direction = 0.0f;
317};
318
319
321{
322 std::string name;
323 std::string value;
324 std::string prefix;
325 std::string library;
326 std::string package;
327 std::string packageSource;
328 uint16_t referenceNumber = 0;
329 std::optional<uint16_t> referenceExtension;
330 uint16_t connectionCount = 0;
331 uint8_t gateState = 0;
332 std::vector<ELEMENT> packageItems;
333 std::vector<ELEMENT> symbols;
334 uint8_t setBitmap[5] = {};
335};
336
337
338struct SIGNAL
339{
340 std::string name;
341 std::vector<ELEMENT> connections;
342 std::vector<ELEMENT> tracks;
343 int32_t minWidth = 0;
344 int32_t minSpacing = 0;
345 std::string string3;
346 std::string string4;
347 std::vector<uint8_t> record;
348 std::string string5;
349};
350
351
357{
360
372
373 // Larger aggregates are held indirectly to keep ELEMENT small.
374 std::shared_ptr<SYMBOL> symbol;
375 std::shared_ptr<PACKAGE> package;
376 std::shared_ptr<COMPONENT> component;
377 std::shared_ptr<SIGNAL> signal;
378
380 std::vector<ELEMENT> children;
381};
382
383
385constexpr int BOARD_LAYER_COUNT = 100;
386
387
389constexpr int FIRST_PADSTACK_LAYER = 101;
390
391
394{
395 std::string name;
396 std::array<bool, BOARD_LAYER_COUNT> onLayer{};
397 std::array<int32_t, BOARD_LAYER_COUNT> oversize{};
398};
399
400
403{
404 std::vector<std::string> sheetNames;
405 std::string savedBy;
406
408 std::optional<TEXT_LANGUAGE> textLanguage;
409
411 std::vector<std::pair<std::string, std::string>> properties;
412 std::vector<PADSTACK_DEF> padstacks;
413};
414
415
450
452constexpr uint8_t NO_ASSOCIATION = 255;
453
454
456{
457 int32_t version = 0;
458
460 std::array<uint8_t, BOARD_LAYER_COUNT> layerFunctions{};
461
463 std::array<uint8_t, BOARD_LAYER_COUNT> layerAssociations{};
464
465 std::string schematicTextFont;
466 std::string boardTextFont;
467 std::string signalNameFont;
468
469 std::vector<ELEMENT> signals;
470 std::vector<ELEMENT> components;
471 std::vector<ELEMENT> schematicItems;
472 std::vector<ELEMENT> boardItems;
473
475
476 wxString fileName;
477 wxDateTime fileModified;
478
480 const std::string* FindProperty( const std::string& aKey ) const;
481
488 std::optional<wxString> FunctionText( const TEXT& aText, bool aSchematic ) const;
489
491 const ELEMENT* FindSignal( uint16_t aId ) const;
492
495 void ApplyTextLanguage();
496};
497
498
504PROJECT ParseFile( const wxString& aFileName );
505
507PROJECT ParseBuffer( const std::vector<uint8_t>& aData );
508
512bool LooksLikeProject( const wxString& aFileName );
513
515wxString ToWx( const std::string& aRaw );
516
517
519wxString PadNumber( const ELEMENT& aPad );
520
521} // namespace TARGET3001
522
523#endif // TARGET3001_PARSER_H
Reader for TARGET 3001!
LAYER_FUNCTION
Board layer function codes stored per layer in the project header.
constexpr int FIRST_PADSTACK_LAYER
A pad on board layer FIRST_PADSTACK_LAYER + n takes its layers from project padstack n.
wxString PadNumber(const ELEMENT &aPad)
Number of a pad element in KiCad, its PADNAME when present, else its stored number.
PROJECT ParseBuffer(const std::vector< uint8_t > &aData)
Parse a project held in memory.
constexpr int ALL_COPPER_LAYER
Board elements on this layer exist on every copper layer.
@ POLYGON
vertices in the POLY_PAD property
FIDUCIAL_KIND
Drawing of a fiducial mark.
@ CROSSHAIR_RINGS
cross and rings at 1, 2/3 and 1/3 of the outer centreline radius
@ FILLED_CIRCLE
solid disc of the outer radius
PROJECT ParseFile(const wxString &aFileName)
Parse a complete .T3001 file.
constexpr int SCHEMATIC_SHEET_COUNT
Sheets occupy layers 101 to 200.
bool LooksLikeProject(const wxString &aFileName)
Cheap check used by the plugin managers: the extension matches and the header is plausible.
wxString ToWx(const std::string &aRaw)
Convert a stored ANSI string to a wxString.
ELEMENT_TYPE
Element class tags as stored in the file.
constexpr int BOARD_LAYER_COUNT
Board layers 0..99 carry a per-project function; 100 and above have fixed meanings.
constexpr uint8_t NO_ASSOCIATION
Layer association value for a layer that belongs to no copper layer.
constexpr int SCHEMATIC_LAYER_BASE
First layer number used for schematic sheets; sheet N (1-based) is layer 100 + N.
Stroked arc or circle. The base position is the start point.
double Sweep() const
Counter-clockwise sweep in (0, 360]; equal angles give a full circle.
float startAngle
degrees, counter-clockwise from +X
std::vector< ELEMENT > symbols
std::vector< ELEMENT > packageItems
std::string prefix
reference designator prefix
std::optional< uint16_t > referenceExtension
Filled disc centred on the base position.
Fields shared by every drawable element.
std::vector< uint8_t > Picture() const
Encoded image a rectangle shows stretched over its area instead of its fill, empty for none.
bool FlagProp(const std::string &aKey) const
True when property aKey holds one of the format's boolean true words.
std::optional< uint32_t > extra
uint16_t component
ID of the owning component (a component stores its own), 0 for none.
uint16_t signal
ID of the owning signal (a signal stores its own), 0 for none.
std::vector< std::pair< std::string, std::string > > props
Free-form key/value properties in file order.
uint8_t classTag
repeats the element's class tag
std::optional< std::pair< int32_t, int32_t > > TextRightEnd() const
Right end of right-aligned text from its ARXY property, in file coordinates.
const std::string * FindProp(const std::string &aKey) const
Return the value of the first property named aKey, if any.
One element of any class.
std::shared_ptr< COMPONENT > component
std::shared_ptr< SYMBOL > symbol
std::shared_ptr< SIGNAL > signal
std::shared_ptr< PACKAGE > package
std::vector< ELEMENT > children
Children of a pin (its number text).
uint8_t kind
FIDUCIAL_KIND.
uint8_t dashStyle
0 solid, 1 long dash, 2 dash-dot, 3 other, 4 short dash
Footprint placement. Pads and graphics of the footprint are stored in board coordinates.
Project padstack; the board layers a pad exists on and how far it grows on each.
std::array< bool, BOARD_LAYER_COUNT > onLayer
std::array< int32_t, BOARD_LAYER_COUNT > oversize
growth per side, nm
int32_t width
along the pad's own X axis before rotation
int32_t drill
0 for no hole
Schematic pin. The base position is the connection point; the pin extends along direction.
Settings that the importers use. The rest of the settings block is validated and skipped.
std::vector< std::string > sheetNames
one entry per schematic sheet slot
std::vector< std::pair< std::string, std::string > > properties
Project properties in file order, as (key, value)
std::vector< PADSTACK_DEF > padstacks
std::optional< TEXT_LANGUAGE > textLanguage
Language whose text variants the project shows; absent in older files.
void ApplyTextLanguage()
Replace literal texts by their variant in the project's stored language when a text reads AUTOLANGUAG...
std::array< uint8_t, BOARD_LAYER_COUNT > layerFunctions
Function code of each board layer, see LAYER_FUNCTION.
const std::string * FindProperty(const std::string &aKey) const
Value of project property aKey, compared case-insensitively.
wxString fileName
source file name without directory, empty for a buffer
const ELEMENT * FindSignal(uint16_t aId) const
Signal element whose ID is aId, or nullptr.
std::vector< ELEMENT > signals
PROJECT_SETTINGS settings
std::vector< ELEMENT > boardItems
std::vector< ELEMENT > components
std::vector< ELEMENT > schematicItems
wxDateTime fileModified
source file modification time, invalid for a buffer
std::array< uint8_t, BOARD_LAYER_COUNT > layerAssociations
Copper layer each board layer belongs to; area and deletion layers point at the copper they affect.
std::optional< wxString > FunctionText(const TEXT &aText, bool aSchematic) const
Text that a computed text function shows, where KiCad has an equivalent.
Filled rectangle anchored at a corner (the base position); sizes are signed.
std::vector< uint8_t > record
std::vector< ELEMENT > tracks
board copper
std::vector< ELEMENT > connections
schematic wires, junctions and labels
Quadratic Bezier from the base position to the end point.
One schematic gate of a component. Children are already in sheet coordinates.
std::string suffix
gate suffix, e.g. "a"
std::string name
full gate name, e.g. "R1a"
std::vector< ELEMENT > children
Filled triangle given by three absolute corners (the first is the base position).
static double sweep(float aStart, float aEnd)