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<int64_t> PolygonId() const;
110
112 std::optional<std::pair<int32_t, int32_t>> TextRightEnd() const;
113
115 std::vector<uint8_t> Picture() const;
116};
117
118
119struct LINE
120{
121 int32_t x2 = 0;
122 int32_t y2 = 0;
123 int32_t width = 0;
124 int32_t clearance = 0;
125 uint8_t dashStyle = 0;
126 uint8_t roundEnds = 0;
127};
128
129
131struct PIN
132{
133 float direction = 0.0f;
134 int32_t length = 0;
135 int32_t width = 0;
136 uint8_t electricalType = 0;
137 uint16_t swapLevel = 0;
138 uint8_t inverted = 0;
139 uint8_t clock = 0;
140 uint8_t showNumber = 0;
141 uint8_t supplyPin = 0;
142 uint16_t pinNumber = 0;
143};
144
145
146enum class PAD_SHAPE : uint8_t
147{
148 ROUND = 0,
151 OVAL = 3,
153};
154
155
156struct PAD
157{
158 float direction = 0.0f;
159 uint8_t shape = 0;
160 int32_t width = 0;
161 int32_t height = 0;
162 int32_t clearance = 0;
163 int32_t drill = 0;
164 int32_t reserved = 0;
165 uint16_t number = 0;
166};
167
168
171{
172 int32_t x2 = 0;
173 int32_t y2 = 0;
174 int32_t x3 = 0;
175 int32_t y3 = 0;
176};
177
178
181{
182 int32_t height = 0;
183 int32_t width = 0;
184 float direction = 0.0f;
185};
186
187
189struct ARC
190{
191 int32_t endX = 0;
192 int32_t endY = 0;
193 int32_t centerX = 0;
194 int32_t centerY = 0;
195 int32_t radius = 0;
196 int32_t width = 0;
197 int32_t clearance = 0;
198 float startAngle = 0.0f;
199 float endAngle = 0.0f;
200
202 double Sweep() const
203 {
204 double sweep = std::fmod( double( endAngle ) - double( startAngle ), 360.0 );
205 return sweep <= 0.0 ? sweep + 360.0 : sweep;
206 }
207};
208
209
211struct DISC
212{
213 int32_t radius = 0;
214};
215
216
225
226
228{
229 uint8_t kind = 0;
230 int32_t radius = 0;
231 int32_t width = 0;
232 float direction = 0.0f;
233};
234
235
237struct SPLINE
238{
239 int32_t endX = 0;
240 int32_t endY = 0;
241 int32_t controlX = 0;
242 int32_t controlY = 0;
243 int32_t width = 0;
244 int32_t clearance = 0;
245};
246
247
266
267
268enum class TEXT_LANGUAGE : uint8_t
269{
273};
274
275
276struct TEXT
277{
278 std::string text;
279 int32_t height = 0;
280 int32_t width = 0;
281 float direction = 0.0f;
282 uint8_t weight = 0;
283 uint8_t noAutoUpright = 0;
284 uint8_t mirrored = 0;
285 uint8_t function = 0;
286 std::string font;
287};
288
289
291{
292 int32_t radius = 0;
293 std::string text;
294};
295
296
297struct ELEMENT;
298
299
301struct SYMBOL
302{
303 std::string name;
304 std::string suffix;
305 uint16_t gateOrdinal = 0;
306 uint8_t insertRequired = 0;
307 uint16_t swapLevel = 0;
308 std::vector<ELEMENT> children;
309};
310
311
314{
315 std::string package;
316 std::string library;
317 uint16_t padCount = 0;
318 uint8_t bottomSide = 0;
319 float direction = 0.0f;
320};
321
322
324{
325 std::string name;
326 std::string value;
327 std::string prefix;
328 std::string library;
329 std::string package;
330 std::string packageSource;
331 uint16_t referenceNumber = 0;
332 std::optional<uint16_t> referenceExtension;
333 uint16_t connectionCount = 0;
334 uint8_t gateState = 0;
335 std::vector<ELEMENT> packageItems;
336 std::vector<ELEMENT> symbols;
337 uint8_t setBitmap[5] = {};
338};
339
340
346{
347 int layer = 0;
348 int64_t id = 0;
349 int32_t width = 0;
350 int32_t rank = 0;
351 bool thermals = true;
352 bool removeIslands = false;
353 int32_t edgeClearance = 0;
354 int32_t aura = 0;
355
356 std::vector<std::pair<int32_t, int32_t>> outline;
357};
358
359
360struct SIGNAL
361{
362 std::string name;
363 std::vector<ELEMENT> connections;
364 std::vector<ELEMENT> tracks;
365 std::vector<POLYGON_POUR> polygons;
366 int32_t minWidth = 0;
367 int32_t minSpacing = 0;
368 std::string string3;
369 std::string string4;
370 std::vector<uint8_t> record;
371 std::string string5;
372};
373
374
380{
383
395
396 // Larger aggregates are held indirectly to keep ELEMENT small.
397 std::shared_ptr<SYMBOL> symbol;
398 std::shared_ptr<PACKAGE> package;
399 std::shared_ptr<COMPONENT> component;
400 std::shared_ptr<SIGNAL> signal;
401
403 std::vector<ELEMENT> children;
404};
405
406
408constexpr int BOARD_LAYER_COUNT = 100;
409
410
412constexpr int FIRST_PADSTACK_LAYER = 101;
413
414
417{
418 std::string name;
419 std::array<bool, BOARD_LAYER_COUNT> onLayer{};
420 std::array<int32_t, BOARD_LAYER_COUNT> oversize{};
421};
422
423
426{
427 std::vector<std::string> sheetNames;
428 std::string savedBy;
429
431 std::optional<TEXT_LANGUAGE> textLanguage;
432
434 std::vector<std::pair<std::string, std::string>> properties;
435 std::vector<PADSTACK_DEF> padstacks;
436};
437
438
473
475constexpr uint8_t NO_ASSOCIATION = 255;
476
477
479{
480 int32_t version = 0;
481
483 std::array<uint8_t, BOARD_LAYER_COUNT> layerFunctions{};
484
486 std::array<uint8_t, BOARD_LAYER_COUNT> layerAssociations{};
487
488 std::string schematicTextFont;
489 std::string boardTextFont;
490 std::string signalNameFont;
491
492 std::vector<ELEMENT> signals;
493 std::vector<ELEMENT> components;
494 std::vector<ELEMENT> schematicItems;
495 std::vector<ELEMENT> boardItems;
496
498
499 wxString fileName;
500 wxDateTime fileModified;
501
503 const std::string* FindProperty( const std::string& aKey ) const;
504
511 std::optional<wxString> FunctionText( const TEXT& aText, bool aSchematic ) const;
512
514 const ELEMENT* FindSignal( uint16_t aId ) const;
515
518 void ApplyTextLanguage();
519};
520
521
527PROJECT ParseFile( const wxString& aFileName );
528
530PROJECT ParseBuffer( const std::vector<uint8_t>& aData );
531
535bool LooksLikeProject( const wxString& aFileName );
536
538wxString ToWx( const std::string& aRaw );
539
540
542wxString PadNumber( const ELEMENT& aPad );
543
544} // namespace TARGET3001
545
546#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.
std::optional< int64_t > PolygonId() const
ID of the signal polygon whose stored fill this element is part of, if any.
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.
Copper polygon of a signal, stored in a "$%&POLY" signal property.
int32_t rank
a polygon is cut out of every one of lower rank on its layer
std::vector< std::pair< int32_t, int32_t > > outline
closed, first vertex repeated last
int32_t aura
distance kept from other signals' polygons, 0 for the default
int32_t edgeClearance
distance kept from the board contour, 0 for none
int32_t width
fill stroke width, 0 for the board default
bool thermals
own pads join by spokes rather than solidly
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< POLYGON_POUR > polygons
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)