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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PADS_SCH_PARSER_H_
21#define PADS_SCH_PARSER_H_
22
23#include <string>
24#include <vector>
25#include <map>
26#include <set>
27#include <optional>
28
29class REPORTER;
30
31
32namespace PADS_SCH
33{
34
35enum class UNIT_TYPE
36{
40};
41
42
44{
45 std::string product;
46 std::string version;
47 std::string codepage;
48 std::string description;
49 bool valid = false;
50};
51
52
54{
55 double width = 11000.0;
56 double height = 8500.0;
57 std::string name;
58};
59
60
65{
67 double grid_x = 100.0;
68 double grid_y = 100.0;
69 std::string border_template;
70 std::string job_name;
72 double text_size = 60.0;
73 double line_width = 1.0;
74
75 // Additional *SCH* parameters
76 int cur_sheet = 0;
77 int conn_width = 0;
78 int bus_width = 0;
79 int bus_angle = 0;
80 int pin_name_h = 0;
81 int pin_name_w = 0;
82 int ref_name_h = 0;
83 int ref_name_w = 0;
84 int part_name_h = 0;
85 int part_name_w = 0;
86 int pin_no_h = 0;
87 int pin_no_w = 0;
88 int net_name_h = 0;
89 int net_name_w = 0;
90 int text_h = 0;
91 int text_w = 0;
92 int dot_grid = 0;
94 int real_width = 0;
95 std::string font_mode;
96 std::string default_font;
97
98 // All user fields from *FIELDS*, keyed by field name
99 std::map<std::string, std::string> fields;
100};
101
102
103struct POINT
104{
105 double x = 0.0;
106 double y = 0.0;
107};
108
109
111{
112 double bulge = 0.0;
113 double angle = 0.0;
114 double bbox_x1 = 0.0;
115 double bbox_y1 = 0.0;
116 double bbox_x2 = 0.0;
117 double bbox_y2 = 0.0;
118};
119
120
122{
124 std::optional<ARC_DATA> arc;
125};
126
127
140
141
146{
147 std::string name;
148 std::string number;
151 double length = 200.0;
152 double rotation = 0.0;
153 bool inverted = false;
154 bool clock = false;
155
156 // T-line fields
157 int side = 0;
158 int pn_h = 0;
159 int pn_w = 0;
160 int pn_angle = 0;
161 int pn_just = 0;
162 int pl_h = 0;
163 int pl_w = 0;
164 int pl_angle = 0;
165 int pl_just = 0;
166 std::string pin_decal_name;
167
168 // P-line fields
171 int pn_off_just = 0;
174 int pl_off_just = 0;
175 int p_flags = 0;
176};
177
178
187
188
193{
195 double line_width = 0.0;
196 bool filled = false;
197 int line_style = 255;
198 std::vector<GRAPHIC_POINT> points;
200 double radius = 0.0;
201 double start_angle = 0.0;
202 double end_angle = 0.0;
203};
204
205
207{
208 std::string content;
210 double size = 60.0;
211 double rotation = 0.0;
212 bool visible = true;
215 int attr_flag = 0;
216 std::string font_name;
217};
218
219
224{
226 int angle = 0;
228 int height = 0;
229 int width = 0;
230 int visibility = 0;
231 std::string font_name;
232 std::string attr_name;
233};
234
235
242{
243 std::string name;
244 std::string timestamp;
245 int gate_count = 1;
247 std::vector<SYMBOL_PIN> pins;
248 std::vector<SYMBOL_GRAPHIC> graphics;
249 std::vector<SYMBOL_TEXT> texts;
250
251 // Full CAEDECAL header fields
252 int f1 = 0;
253 int f2 = 0;
254 int height = 0;
255 int width = 0;
256 int h2 = 0;
257 int w2 = 0;
258 int num_attrs = 0;
259 int num_pieces = 0;
261 int num_pins = 0;
264
265 std::string font1;
266 std::string font2;
267 std::vector<CAEDECAL_ATTR> attrs;
268};
269
270
272{
273 std::string name;
274 std::string value;
276 double rotation = 0.0;
277 double size = 60.0;
278 bool visible = true;
279
281 int height = 0;
282 int width = 0;
283 int visibility = 0;
284 std::string font_name;
285};
286
287
292{
293 std::string reference;
294 std::string symbol_name;
295 std::string part_type;
297 double rotation = 0.0;
299 std::string power_net_name;
301 int gate_number = 1;
302 std::vector<PART_ATTRIBUTE> attributes;
303
304 // Full *PART* header fields
305 int h1 = 0;
306 int w1 = 0;
307 int h2 = 0;
308 int w2 = 0;
309 int num_attrs = 0;
311 int num_pins = 0;
312 int gate_index = 0;
314 std::string font1;
315 std::string font2;
316
317 // Attribute value overrides parsed from "name" value lines
318 std::map<std::string, std::string> attr_overrides;
319
320 // Pin override lines (zero-based index -> formatting)
322 {
323 int height = 0;
324 int width = 0;
325 int angle = 0;
327 };
328
329 std::vector<PIN_OVERRIDE> pin_overrides;
330};
331
332
337{
341
342 // Real format fields
343 std::string endpoint_a;
344 std::string endpoint_b;
346 int flags = 0;
347 std::vector<POINT> vertices;
348};
349
350
352{
353 std::string reference;
354 std::string pin_number;
356};
357
358
363{
364 std::string name;
365 std::vector<WIRE_SEGMENT> wires;
366 std::vector<PIN_CONNECTION> connections;
367
368 int flags1 = 0;
369 int flags2 = 0;
370 std::string function;
371};
372
373
378{
379 std::string signal_name;
383
384 int id = 0;
385 std::string symbol_lib;
386 int rotation = 0;
387 int flags1 = 0;
388 int flags2 = 0;
389};
390
391
393{
395 std::string name;
397};
398
399
404{
405 int sheet_num = 0;
406 std::string sheet_name;
407 int parent_num = -1;
408 std::string parent_name;
409};
410
411
416{
417 int id = 0;
420};
421
422
427{
429 int rotation = 0;
431 int height = 0;
433 int attr_flag = 0;
434 std::string font_name;
435 std::string content;
436};
437
438
443{
444 std::string name;
446 int param1 = 0;
447 int param2 = 0;
448 std::vector<SYMBOL_GRAPHIC> primitives;
449 std::vector<TEXT_ITEM> texts;
450};
451
452
457{
458 std::string net_name;
459 std::string anchor_ref;
460 int x_offset = 0;
461 int y_offset = 0;
462 int rotation = 0;
464 int f3 = 0;
465 int f4 = 0;
466 int f5 = 0;
467 int f6 = 0;
468 int f7 = 0;
469 int height = 0;
470 int width_pct = 0;
471 std::string font_name;
472};
473
474
479{
480 std::string pin_id;
481 int swap_group = 0;
482 char pin_type = 'U';
483 std::string pin_name;
484};
485
486
491{
493 int num_pins = 0;
494 int swap_flag = 0;
495 std::vector<std::string> decal_names;
496 std::vector<PARTTYPE_PIN> pins;
497};
498
499
504{
505 std::string name;
506 std::string category;
508 int num_sigpins = 0;
509 int unused = 0;
511 std::string timestamp;
512
513 std::vector<GATE_DEF> gates;
514
515 // For special symbols ($GND_SYMS, $PWR_SYMS, $OSR_SYMS)
516 std::string special_keyword;
518 {
519 std::string decal_name;
520 std::string pin_type;
521 std::string net_suffix;
522 };
523 std::vector<SPECIAL_VARIANT> special_variants;
524
525 // For CONN-based connectors
526 bool is_connector = false;
527
528 // SIGPIN entries (hidden power pins)
529 struct SIGPIN
530 {
531 std::string pin_number;
532 std::string net_name;
533 };
534 std::vector<SIGPIN> sigpins;
535
536 // Swap group lines
537 std::vector<std::string> swap_lines;
538};
539
540
548{
549public:
552
553 void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
554
555 bool Parse( const std::string& aFileName );
556
557 static bool CheckFileHeader( const std::string& aFileName );
558
559 static PIN_TYPE ParsePinTypeChar( char aTypeChar );
560
561 const FILE_HEADER& GetHeader() const { return m_header; }
562 const PARAMETERS& GetParameters() const { return m_parameters; }
563
564 const std::vector<SYMBOL_DEF>& GetSymbolDefs() const { return m_symbolDefs; }
565 const SYMBOL_DEF* GetSymbolDef( const std::string& aName ) const;
566
567 const std::vector<PART_PLACEMENT>& GetPartPlacements() const { return m_partPlacements; }
568 const PART_PLACEMENT* GetPartPlacement( const std::string& aReference ) const;
569
570 const std::vector<SCH_SIGNAL>& GetSignals() const { return m_signals; }
571 const SCH_SIGNAL* GetSignal( const std::string& aName ) const;
572
573 std::string GetVersion() const { return m_header.version; }
574 bool IsValid() const { return m_header.valid; }
575
576 int GetSheetCount() const;
577 std::set<int> GetSheetNumbers() const;
578
579 const std::vector<OFF_PAGE_CONNECTOR>& GetOffPageConnectors() const { return m_offPageConnectors; }
580
581 std::vector<SCH_SIGNAL> GetSignalsOnSheet( int aSheetNumber ) const;
582 std::vector<PART_PLACEMENT> GetPartsOnSheet( int aSheetNumber ) const;
583
584 const std::map<std::string, PARTTYPE_DEF>& GetPartTypes() const { return m_partTypes; }
585 const std::vector<TIED_DOT>& GetTiedDots() const { return m_tiedDots; }
586 const std::vector<SHEET_HEADER>& GetSheetHeaders() const { return m_sheetHeaders; }
587 const std::vector<TEXT_ITEM>& GetTextItems() const { return m_textItems; }
588 const std::vector<LINES_ITEM>& GetLinesItems() const { return m_linesItems; }
589 const std::vector<NETNAME_LABEL>& GetNetNameLabels() const { return m_netNameLabels; }
590
591private:
592 bool parseHeader( const std::string& aLine );
593
594 size_t parseSectionSCH( const std::vector<std::string>& aLines, size_t aStartLine );
595 size_t parseSectionFIELDS( const std::vector<std::string>& aLines, size_t aStartLine );
596 size_t parseSectionSHT( const std::vector<std::string>& aLines, size_t aStartLine );
597 size_t parseSectionCAE( const std::vector<std::string>& aLines, size_t aStartLine );
598 size_t parseSectionTEXT( const std::vector<std::string>& aLines, size_t aStartLine );
599 size_t parseSectionLINES( const std::vector<std::string>& aLines, size_t aStartLine );
600 size_t parseSectionCAEDECAL( const std::vector<std::string>& aLines, size_t aStartLine );
601 size_t parseSectionPARTTYPE( const std::vector<std::string>& aLines, size_t aStartLine );
602 size_t parseSectionPART( const std::vector<std::string>& aLines, size_t aStartLine );
603 size_t parseSectionOFFPAGEREFS( const std::vector<std::string>& aLines, size_t aStartLine );
604 size_t parseSectionTIEDOTS( const std::vector<std::string>& aLines, size_t aStartLine );
605 size_t parseSectionCONNECTION( const std::vector<std::string>& aLines, size_t aStartLine );
606 size_t parseSectionNETNAMES( const std::vector<std::string>& aLines, size_t aStartLine );
607
608 size_t skipBraceDelimitedSection( const std::vector<std::string>& aLines, size_t aStartLine );
609
610 size_t parseSymbolDef( const std::vector<std::string>& aLines, size_t aStartLine,
611 SYMBOL_DEF& aSymbol );
612
613 size_t parsePartPlacement( const std::vector<std::string>& aLines, size_t aStartLine,
614 PART_PLACEMENT& aPart );
615
616 size_t parseSignalDef( const std::vector<std::string>& aLines, size_t aStartLine,
617 SCH_SIGNAL& aSignal );
618
619 size_t parseGraphicPrimitive( const std::vector<std::string>& aLines, size_t aStartLine,
620 SYMBOL_GRAPHIC& aGraphic );
621
622 void mergePartTypeData();
623
624 PIN_TYPE parsePinType( const std::string& aTypeStr );
625
626 bool isSectionMarker( const std::string& aLine ) const;
627 std::string extractSectionName( const std::string& aLine ) const;
628
632 std::vector<SYMBOL_DEF> m_symbolDefs;
633 std::vector<PART_PLACEMENT> m_partPlacements;
634 std::vector<SCH_SIGNAL> m_signals;
635 std::vector<OFF_PAGE_CONNECTOR> m_offPageConnectors;
638 std::map<std::string, PARTTYPE_DEF> m_partTypes;
639 std::vector<TIED_DOT> m_tiedDots;
640 std::vector<SHEET_HEADER> m_sheetHeaders;
641 std::vector<TEXT_ITEM> m_textItems;
642 std::vector<LINES_ITEM> m_linesItems;
643 std::vector<NETNAME_LABEL> m_netNameLabels;
644};
645
646} // namespace PADS_SCH
647
648#endif // PADS_SCH_PARSER_H_
size_t skipBraceDelimitedSection(const std::vector< std::string > &aLines, size_t aStartLine)
const std::vector< TEXT_ITEM > & GetTextItems() const
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
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
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:75
Attribute label pair from CAEDECAL or PART entries.
Gate definition within a PARTTYPE.
std::vector< std::string > decal_names
std::vector< PARTTYPE_PIN > pins
std::optional< ARC_DATA > arc
Graphical line/shape item from LINES section.
std::vector< TEXT_ITEM > texts
std::vector< SYMBOL_GRAPHIC > primitives
Net name label from NETNAMES section.
Off-page reference from OFFPAGE REFS section.
General schematic parameters from SCH and FIELDS sections.
std::map< std::string, std::string > fields
std::string border_template
Part type definition from PARTTYPE section.
std::vector< GATE_DEF > gates
std::vector< SPECIAL_VARIANT > special_variants
std::vector< std::string > swap_lines
std::vector< SIGPIN > sigpins
Pin definition within a PARTTYPE GATE.
Part instance from PART section.
std::map< std::string, std::string > attr_overrides
std::vector< PART_ATTRIBUTE > attributes
std::vector< PIN_OVERRIDE > pin_overrides
Signal (net) definition from CONNECTION and SIGNAL sections.
std::vector< PIN_CONNECTION > connections
std::vector< WIRE_SEGMENT > wires
Sheet header from SHT section.
Symbol definition from CAEDECAL section.
std::vector< SYMBOL_GRAPHIC > graphics
std::vector< SYMBOL_PIN > pins
std::vector< CAEDECAL_ATTR > attrs
std::vector< SYMBOL_TEXT > texts
Graphic primitive from CAEDECAL or LINES sections (OPEN, CLOSED, CIRCLE, COPCLS).
std::vector< GRAPHIC_POINT > points
Pin T/P line pair from CAEDECAL.
Free text item from TEXT section.
Junction dot from TIEDOTS section.
Wire segment connecting two endpoints through coordinate vertices.
std::vector< POINT > vertices