KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pads_sch_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 (C) 2025 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 3
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#pragma once
21
22#include <string>
23#include <vector>
24#include <map>
25#include <set>
26#include <optional>
27
28#include <math/vector2d.h>
29
30class REPORTER;
31
32
33namespace PADS_SCH
34{
35
36enum class UNIT_TYPE
37{
41};
42
43
45{
46 std::string product;
47 std::string version;
48 std::string codepage;
49 std::string description;
50 bool valid = false;
51};
52
53
55{
56 double width = 11000.0;
57 double height = 8500.0;
58 std::string name;
59};
60
61
63{
65 double grid_x = 100.0;
66 double grid_y = 100.0;
67 std::string border_template;
68 std::string job_name;
70 double text_size = 60.0;
71 double line_width = 1.0;
72
73 int cur_sheet = 0;
74 int conn_width = 0;
75 int bus_width = 0;
76 int bus_angle = 0;
77 int pin_name_h = 0;
78 int pin_name_w = 0;
79 int ref_name_h = 0;
80 int ref_name_w = 0;
81 int part_name_h = 0;
82 int part_name_w = 0;
83 int pin_no_h = 0;
84 int pin_no_w = 0;
85 int net_name_h = 0;
86 int net_name_w = 0;
87 int text_h = 0;
88 int text_w = 0;
89 int dot_grid = 0;
91 int real_width = 0;
92 std::string font_mode;
93 std::string default_font;
94
95 std::map<std::string, std::string> fields;
96};
97
98
102VECTOR2I padsSchArcMidpoint( const VECTOR2I& aStart, const VECTOR2I& aEnd, const VECTOR2I& aCenter );
103
104
105struct POINT
106{
107 double x = 0.0;
108 double y = 0.0;
109};
110
111
113{
114 double bulge = 0.0;
115 double angle = 0.0;
116 double bbox_x1 = 0.0;
117 double bbox_y1 = 0.0;
118 double bbox_x2 = 0.0;
119 double bbox_y2 = 0.0;
120};
121
122
124{
126 std::optional<ARC_DATA> arc;
127};
128
129
142
143
145{
146 std::string name;
147 std::string number;
150 double length = 200.0;
151 double rotation = 0.0;
152 bool inverted = false;
153 bool clock = false;
154
155 int side = 0;
156 int pn_h = 0;
157 int pn_w = 0;
158 int pn_angle = 0;
159 int pn_just = 0;
160 int pl_h = 0;
161 int pl_w = 0;
162 int pl_angle = 0;
163 int pl_just = 0;
164 std::string pin_decal_name;
165
168 int pn_off_just = 0;
171 int pl_off_just = 0;
172 int p_flags = 0;
173};
174
175
184
185
187{
189 double line_width = 0.0;
190 bool filled = false;
191 int line_style = 255;
192 std::vector<GRAPHIC_POINT> points;
194 double radius = 0.0;
195 double start_angle = 0.0;
196 double end_angle = 0.0;
197};
198
199
201{
202 std::string content;
204 double size = 60.0;
205 double rotation = 0.0;
206 bool visible = true;
209 int attr_flag = 0;
210 std::string font_name;
211};
212
213
215{
217 int angle = 0;
219 int height = 0;
220 int width = 0;
221 int visibility = 0;
222 std::string font_name;
223 std::string attr_name;
224};
225
226
228{
229 std::string name;
230 std::string timestamp;
231 int gate_count = 1;
233 std::vector<SYMBOL_PIN> pins;
234 std::vector<SYMBOL_GRAPHIC> graphics;
235 std::vector<SYMBOL_TEXT> texts;
236
237 int f1 = 0;
238 int f2 = 0;
239 int height = 0;
240 int width = 0;
241 int h2 = 0;
242 int w2 = 0;
243 int num_attrs = 0;
244 int num_pieces = 0;
246 int num_pins = 0;
249
250 std::string font1;
251 std::string font2;
252 std::vector<CAEDECAL_ATTR> attrs;
253};
254
255
257{
258 std::string name;
259 std::string value;
261 double rotation = 0.0;
262 double size = 60.0;
263 bool visible = true;
264
266 int height = 0;
267 int width = 0;
268 int visibility = 0;
269 std::string font_name;
270};
271
272
274{
275 std::string reference;
276 std::string symbol_name;
277 std::string decal_name;
278 std::string part_type;
280 double rotation = 0.0;
282 std::string power_net_name;
284 int gate_number = 1;
285 std::vector<PART_ATTRIBUTE> attributes;
286
287 int h1 = 0;
288 int w1 = 0;
289 int h2 = 0;
290 int w2 = 0;
291 int num_attrs = 0;
293 int num_pins = 0;
294 int gate_index = 0;
296 std::string font1;
297 std::string font2;
298
299 std::map<std::string, std::string> attr_overrides;
300
302 {
303 int height = 0;
304 int width = 0;
305 int angle = 0;
307 };
308
309 std::vector<PIN_OVERRIDE> pin_overrides;
310};
311
312
317{
321
322 std::string endpoint_a;
323 std::string endpoint_b;
325 int flags = 0;
326 std::vector<POINT> vertices;
327};
328
329
331{
332 std::string reference;
333 std::string pin_number;
335};
336
337
339{
340 std::string name;
341 std::vector<WIRE_SEGMENT> wires;
342 std::vector<PIN_CONNECTION> connections;
343
344 int flags1 = 0;
345 int flags2 = 0;
346 std::string function;
347};
348
349
351{
352 std::string signal_name;
356
357 int id = 0;
358 std::string symbol_lib;
359 int rotation = 0;
360 int flags1 = 0;
361 int flags2 = 0;
362};
363
364
366{
367 std::string member_net;
369 int rotation = 0;
370};
371
372
374{
375 std::string handle;
376 std::string name;
378 std::vector<POINT> path;
379 std::vector<BUS_ENTRY> entries;
380 std::vector<std::string> aliases;
381 std::vector<std::string> member_nets;
382};
383
384
386{
388 std::string name;
390};
391
392
394{
395 int sheet_num = 0;
396 std::string sheet_name;
397 int parent_num = -1;
398 std::string parent_name;
399};
400
401
403{
404 int id = 0;
407};
408
409
411{
413 int rotation = 0;
415 int height = 0;
417 int attr_flag = 0;
419 std::string font_name;
420 std::string content;
421};
422
423
425{
426 std::string name;
428 int param1 = 0;
429 int param2 = 0;
431 std::vector<SYMBOL_GRAPHIC> primitives;
432 std::vector<TEXT_ITEM> texts;
433};
434
435
437{
438 std::string net_name;
439 std::string anchor_ref;
440 int x_offset = 0;
441 int y_offset = 0;
442 int rotation = 0;
444 int f3 = 0;
445 int f4 = 0;
446 int f5 = 0;
447 int f6 = 0;
448 int f7 = 0;
449 int height = 0;
450 int width_pct = 0;
451 std::string font_name;
452};
453
454
456{
457 std::string pin_id;
458 int swap_group = 0;
459 char pin_type = 'U';
460 std::string pin_name;
461};
462
463
465{
467 int num_pins = 0;
468 int swap_flag = 0;
469 std::vector<std::string> decal_names;
470 std::vector<PARTTYPE_PIN> pins;
471};
472
473
475{
476 std::string name;
477 std::string category;
479 int num_sigpins = 0;
480 int unused = 0;
482 std::string timestamp;
483
484 std::vector<GATE_DEF> gates;
485
486 std::string special_keyword;
488 {
489 std::string decal_name;
490 std::string pin_type;
491 std::string net_suffix;
492 };
493
494 std::vector<SPECIAL_VARIANT> special_variants;
495
496 bool is_connector = false;
497
498 struct SIGPIN
499 {
500 std::string pin_number;
501 std::string net_name;
502 };
503 std::vector<SIGPIN> sigpins;
504
505 std::vector<std::string> swap_lines;
506};
507
508
513{
514public:
517
518 void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
519
520 bool Parse( const std::string& aFileName );
521
522 static bool CheckFileHeader( const std::string& aFileName );
523
524 static PIN_TYPE ParsePinTypeChar( char aTypeChar );
525
526 const FILE_HEADER& GetHeader() const { return m_header; }
527 const PARAMETERS& GetParameters() const { return m_parameters; }
528
529 const std::vector<SYMBOL_DEF>& GetSymbolDefs() const { return m_symbolDefs; }
530 const SYMBOL_DEF* GetSymbolDef( const std::string& aName ) const;
531
532 const std::vector<PART_PLACEMENT>& GetPartPlacements() const { return m_partPlacements; }
533 const PART_PLACEMENT* GetPartPlacement( const std::string& aReference ) const;
534
535 const std::vector<SCH_SIGNAL>& GetSignals() const { return m_signals; }
536 const SCH_SIGNAL* GetSignal( const std::string& aName ) const;
537
538 std::string GetVersion() const { return m_header.version; }
539 bool IsValid() const { return m_header.valid; }
540
541 int GetSheetCount() const;
542 std::set<int> GetSheetNumbers() const;
543
544 const std::vector<OFF_PAGE_CONNECTOR>& GetOffPageConnectors() const { return m_offPageConnectors; }
545 const std::vector<BUS_DEF>& GetBuses() const { return m_buses; }
546
547 std::vector<SCH_SIGNAL> GetSignalsOnSheet( int aSheetNumber ) const;
548 std::vector<PART_PLACEMENT> GetPartsOnSheet( int aSheetNumber ) const;
549
550 const std::map<std::string, PARTTYPE_DEF>& GetPartTypes() const { return m_partTypes; }
551 const std::vector<TIED_DOT>& GetTiedDots() const { return m_tiedDots; }
552 const std::vector<SHEET_HEADER>& GetSheetHeaders() const { return m_sheetHeaders; }
553 const std::vector<TEXT_ITEM>& GetTextItems() const { return m_textItems; }
554 const std::vector<LINES_ITEM>& GetLinesItems() const { return m_linesItems; }
555 const std::vector<NETNAME_LABEL>& GetNetNameLabels() const { return m_netNameLabels; }
556
557private:
558 bool parseHeader( const std::string& aLine );
559
560 size_t parseSectionSCH( const std::vector<std::string>& aLines, size_t aStartLine );
561 size_t parseSectionFIELDS( const std::vector<std::string>& aLines, size_t aStartLine );
562 size_t parseSectionSHT( const std::vector<std::string>& aLines, size_t aStartLine );
563 size_t parseSectionCAE( const std::vector<std::string>& aLines, size_t aStartLine );
564 size_t parseSectionTEXT( const std::vector<std::string>& aLines, size_t aStartLine );
565 size_t parseSectionLINES( const std::vector<std::string>& aLines, size_t aStartLine );
566 size_t parseSectionCAEDECAL( const std::vector<std::string>& aLines, size_t aStartLine );
567 size_t parseSectionPARTTYPE( const std::vector<std::string>& aLines, size_t aStartLine );
568 size_t parseSectionPART( const std::vector<std::string>& aLines, size_t aStartLine );
569 size_t parseSectionBUSSES( const std::vector<std::string>& aLines, size_t aStartLine );
570 size_t parseSectionOFFPAGEREFS( const std::vector<std::string>& aLines, size_t aStartLine );
571 size_t parseSectionTIEDOTS( const std::vector<std::string>& aLines, size_t aStartLine );
572 size_t parseSectionCONNECTION( const std::vector<std::string>& aLines, size_t aStartLine );
573 size_t parseSectionNETNAMES( const std::vector<std::string>& aLines, size_t aStartLine );
574
575 size_t skipBraceDelimitedSection( const std::vector<std::string>& aLines, size_t aStartLine );
576
577 size_t parseSymbolDef( const std::vector<std::string>& aLines, size_t aStartLine, SYMBOL_DEF& aSymbol );
578 size_t parsePartPlacement( const std::vector<std::string>& aLines, size_t aStartLine, PART_PLACEMENT& aPart );
579 size_t parseSignalDef( const std::vector<std::string>& aLines, size_t aStartLine, SCH_SIGNAL& aSignal );
580 size_t parseGraphicPrimitive( const std::vector<std::string>& aLines, size_t aStartLine, SYMBOL_GRAPHIC& aGraphic );
581
582 void mergePartTypeData();
583
584 PIN_TYPE parsePinType( const std::string& aTypeStr );
585
586 bool isSectionMarker( const std::string& aLine ) const;
587 std::string extractSectionName( const std::string& aLine ) const;
588
592 std::vector<SYMBOL_DEF> m_symbolDefs;
593 std::vector<PART_PLACEMENT> m_partPlacements;
594 std::vector<SCH_SIGNAL> m_signals;
595 std::vector<OFF_PAGE_CONNECTOR> m_offPageConnectors;
596 std::vector<BUS_DEF> m_buses;
599 std::map<std::string, PARTTYPE_DEF> m_partTypes;
600 std::vector<TIED_DOT> m_tiedDots;
601 std::vector<SHEET_HEADER> m_sheetHeaders;
602 std::vector<TEXT_ITEM> m_textItems;
603 std::vector<LINES_ITEM> m_linesItems;
604 std::vector<NETNAME_LABEL> m_netNameLabels;
605};
606
607} // namespace PADS_SCH
size_t skipBraceDelimitedSection(const std::vector< std::string > &aLines, size_t aStartLine)
const std::vector< TEXT_ITEM > & GetTextItems() const
size_t parseSectionBUSSES(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSectionPARTTYPE(const std::vector< std::string > &aLines, size_t aStartLine)
const std::vector< TIED_DOT > & GetTiedDots() const
const std::vector< OFF_PAGE_CONNECTOR > & GetOffPageConnectors() const
bool isSectionMarker(const std::string &aLine) const
bool Parse(const std::string &aFileName)
const std::vector< SHEET_HEADER > & GetSheetHeaders() const
size_t parseSymbolDef(const std::vector< std::string > &aLines, size_t aStartLine, SYMBOL_DEF &aSymbol)
size_t parseSectionSCH(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSectionCAEDECAL(const std::vector< std::string > &aLines, size_t aStartLine)
std::vector< OFF_PAGE_CONNECTOR > m_offPageConnectors
size_t parseSectionTIEDOTS(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parsePartPlacement(const std::vector< std::string > &aLines, size_t aStartLine, PART_PLACEMENT &aPart)
const std::vector< NETNAME_LABEL > & GetNetNameLabels() const
const std::vector< BUS_DEF > & GetBuses() const
size_t parseSectionSHT(const std::vector< std::string > &aLines, size_t aStartLine)
std::vector< SCH_SIGNAL > m_signals
size_t parseSectionOFFPAGEREFS(const std::vector< std::string > &aLines, size_t aStartLine)
std::string extractSectionName(const std::string &aLine) const
size_t parseSectionCONNECTION(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSectionLINES(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseGraphicPrimitive(const std::vector< std::string > &aLines, size_t aStartLine, SYMBOL_GRAPHIC &aGraphic)
static PIN_TYPE ParsePinTypeChar(char aTypeChar)
bool parseHeader(const std::string &aLine)
std::vector< SHEET_HEADER > m_sheetHeaders
size_t parseSectionNETNAMES(const std::vector< std::string > &aLines, size_t aStartLine)
void SetReporter(REPORTER *aReporter)
const std::vector< SCH_SIGNAL > & GetSignals() const
std::vector< SYMBOL_DEF > m_symbolDefs
std::vector< PART_PLACEMENT > m_partPlacements
const FILE_HEADER & GetHeader() const
PIN_TYPE parsePinType(const std::string &aTypeStr)
const std::vector< LINES_ITEM > & GetLinesItems() const
std::vector< SCH_SIGNAL > GetSignalsOnSheet(int aSheetNumber) const
std::set< int > GetSheetNumbers() const
std::vector< TEXT_ITEM > m_textItems
static bool CheckFileHeader(const std::string &aFileName)
const std::vector< SYMBOL_DEF > & GetSymbolDefs() const
size_t parseSectionTEXT(const std::vector< std::string > &aLines, size_t aStartLine)
const std::vector< PART_PLACEMENT > & GetPartPlacements() const
size_t parseSignalDef(const std::vector< std::string > &aLines, size_t aStartLine, SCH_SIGNAL &aSignal)
const std::map< std::string, PARTTYPE_DEF > & GetPartTypes() const
std::vector< NETNAME_LABEL > m_netNameLabels
std::vector< PART_PLACEMENT > GetPartsOnSheet(int aSheetNumber) const
std::vector< LINES_ITEM > m_linesItems
const SCH_SIGNAL * GetSignal(const std::string &aName) const
std::vector< TIED_DOT > m_tiedDots
std::map< std::string, PARTTYPE_DEF > m_partTypes
std::vector< BUS_DEF > m_buses
const SYMBOL_DEF * GetSymbolDef(const std::string &aName) const
const PARAMETERS & GetParameters() const
const PART_PLACEMENT * GetPartPlacement(const std::string &aReference) const
size_t parseSectionCAE(const std::vector< std::string > &aLines, size_t aStartLine)
std::string GetVersion() const
size_t parseSectionFIELDS(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSectionPART(const std::vector< std::string > &aLines, size_t aStartLine)
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
VECTOR2I padsSchArcMidpoint(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter)
Midpoint of the arc through aStart and aEnd about aCenter, on the minor-arc side (the perpendicular b...
std::vector< BUS_ENTRY > entries
std::vector< POINT > path
std::vector< std::string > aliases
std::vector< std::string > member_nets
POINT position
std::string member_net
int rotation
std::vector< std::string > decal_names
std::vector< PARTTYPE_PIN > pins
std::optional< ARC_DATA > arc
std::vector< TEXT_ITEM > texts
std::vector< SYMBOL_GRAPHIC > primitives
std::map< std::string, std::string > fields
std::string border_template
std::vector< GATE_DEF > gates
std::vector< SPECIAL_VARIANT > special_variants
std::vector< std::string > swap_lines
std::vector< SIGPIN > sigpins
std::map< std::string, std::string > attr_overrides
std::string symbol_name
The part type, which is also the power symbol's net name.
std::string decal_name
CAEDECAL the placed gate draws, empty when unresolved.
std::vector< PART_ATTRIBUTE > attributes
std::vector< PIN_OVERRIDE > pin_overrides
std::vector< PIN_CONNECTION > connections
std::vector< WIRE_SEGMENT > wires
std::vector< SYMBOL_GRAPHIC > graphics
std::vector< SYMBOL_PIN > pins
std::vector< CAEDECAL_ATTR > attrs
std::vector< SYMBOL_TEXT > texts
std::vector< GRAPHIC_POINT > points
Wire segment connecting two endpoints through coordinate vertices.
std::vector< POINT > vertices
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683