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;
435 std::string font_name;
436 std::string content;
437};
438
439
444{
445 std::string name;
447 int param1 = 0;
448 int param2 = 0;
450 std::vector<SYMBOL_GRAPHIC> primitives;
451 std::vector<TEXT_ITEM> texts;
452};
453
454
459{
460 std::string net_name;
461 std::string anchor_ref;
462 int x_offset = 0;
463 int y_offset = 0;
464 int rotation = 0;
466 int f3 = 0;
467 int f4 = 0;
468 int f5 = 0;
469 int f6 = 0;
470 int f7 = 0;
471 int height = 0;
472 int width_pct = 0;
473 std::string font_name;
474};
475
476
481{
482 std::string pin_id;
483 int swap_group = 0;
484 char pin_type = 'U';
485 std::string pin_name;
486};
487
488
493{
495 int num_pins = 0;
496 int swap_flag = 0;
497 std::vector<std::string> decal_names;
498 std::vector<PARTTYPE_PIN> pins;
499};
500
501
506{
507 std::string name;
508 std::string category;
510 int num_sigpins = 0;
511 int unused = 0;
513 std::string timestamp;
514
515 std::vector<GATE_DEF> gates;
516
517 // For special symbols ($GND_SYMS, $PWR_SYMS, $OSR_SYMS)
518 std::string special_keyword;
520 {
521 std::string decal_name;
522 std::string pin_type;
523 std::string net_suffix;
524 };
525 std::vector<SPECIAL_VARIANT> special_variants;
526
527 // For CONN-based connectors
528 bool is_connector = false;
529
530 // SIGPIN entries (hidden power pins)
531 struct SIGPIN
532 {
533 std::string pin_number;
534 std::string net_name;
535 };
536 std::vector<SIGPIN> sigpins;
537
538 // Swap group lines
539 std::vector<std::string> swap_lines;
540};
541
542
550{
551public:
554
555 void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
556
557 bool Parse( const std::string& aFileName );
558
559 static bool CheckFileHeader( const std::string& aFileName );
560
561 static PIN_TYPE ParsePinTypeChar( char aTypeChar );
562
563 const FILE_HEADER& GetHeader() const { return m_header; }
564 const PARAMETERS& GetParameters() const { return m_parameters; }
565
566 const std::vector<SYMBOL_DEF>& GetSymbolDefs() const { return m_symbolDefs; }
567 const SYMBOL_DEF* GetSymbolDef( const std::string& aName ) const;
568
569 const std::vector<PART_PLACEMENT>& GetPartPlacements() const { return m_partPlacements; }
570 const PART_PLACEMENT* GetPartPlacement( const std::string& aReference ) const;
571
572 const std::vector<SCH_SIGNAL>& GetSignals() const { return m_signals; }
573 const SCH_SIGNAL* GetSignal( const std::string& aName ) const;
574
575 std::string GetVersion() const { return m_header.version; }
576 bool IsValid() const { return m_header.valid; }
577
578 int GetSheetCount() const;
579 std::set<int> GetSheetNumbers() const;
580
581 const std::vector<OFF_PAGE_CONNECTOR>& GetOffPageConnectors() const { return m_offPageConnectors; }
582
583 std::vector<SCH_SIGNAL> GetSignalsOnSheet( int aSheetNumber ) const;
584 std::vector<PART_PLACEMENT> GetPartsOnSheet( int aSheetNumber ) const;
585
586 const std::map<std::string, PARTTYPE_DEF>& GetPartTypes() const { return m_partTypes; }
587 const std::vector<TIED_DOT>& GetTiedDots() const { return m_tiedDots; }
588 const std::vector<SHEET_HEADER>& GetSheetHeaders() const { return m_sheetHeaders; }
589 const std::vector<TEXT_ITEM>& GetTextItems() const { return m_textItems; }
590 const std::vector<LINES_ITEM>& GetLinesItems() const { return m_linesItems; }
591 const std::vector<NETNAME_LABEL>& GetNetNameLabels() const { return m_netNameLabels; }
592
593private:
594 bool parseHeader( const std::string& aLine );
595
596 size_t parseSectionSCH( const std::vector<std::string>& aLines, size_t aStartLine );
597 size_t parseSectionFIELDS( const std::vector<std::string>& aLines, size_t aStartLine );
598 size_t parseSectionSHT( const std::vector<std::string>& aLines, size_t aStartLine );
599 size_t parseSectionCAE( const std::vector<std::string>& aLines, size_t aStartLine );
600 size_t parseSectionTEXT( const std::vector<std::string>& aLines, size_t aStartLine );
601 size_t parseSectionLINES( const std::vector<std::string>& aLines, size_t aStartLine );
602 size_t parseSectionCAEDECAL( const std::vector<std::string>& aLines, size_t aStartLine );
603 size_t parseSectionPARTTYPE( const std::vector<std::string>& aLines, size_t aStartLine );
604 size_t parseSectionPART( const std::vector<std::string>& aLines, size_t aStartLine );
605 size_t parseSectionOFFPAGEREFS( const std::vector<std::string>& aLines, size_t aStartLine );
606 size_t parseSectionTIEDOTS( const std::vector<std::string>& aLines, size_t aStartLine );
607 size_t parseSectionCONNECTION( const std::vector<std::string>& aLines, size_t aStartLine );
608 size_t parseSectionNETNAMES( const std::vector<std::string>& aLines, size_t aStartLine );
609
610 size_t skipBraceDelimitedSection( const std::vector<std::string>& aLines, size_t aStartLine );
611
612 size_t parseSymbolDef( const std::vector<std::string>& aLines, size_t aStartLine,
613 SYMBOL_DEF& aSymbol );
614
615 size_t parsePartPlacement( const std::vector<std::string>& aLines, size_t aStartLine,
616 PART_PLACEMENT& aPart );
617
618 size_t parseSignalDef( const std::vector<std::string>& aLines, size_t aStartLine,
619 SCH_SIGNAL& aSignal );
620
621 size_t parseGraphicPrimitive( const std::vector<std::string>& aLines, size_t aStartLine,
622 SYMBOL_GRAPHIC& aGraphic );
623
624 void mergePartTypeData();
625
626 PIN_TYPE parsePinType( const std::string& aTypeStr );
627
628 bool isSectionMarker( const std::string& aLine ) const;
629 std::string extractSectionName( const std::string& aLine ) const;
630
634 std::vector<SYMBOL_DEF> m_symbolDefs;
635 std::vector<PART_PLACEMENT> m_partPlacements;
636 std::vector<SCH_SIGNAL> m_signals;
637 std::vector<OFF_PAGE_CONNECTOR> m_offPageConnectors;
640 std::map<std::string, PARTTYPE_DEF> m_partTypes;
641 std::vector<TIED_DOT> m_tiedDots;
642 std::vector<SHEET_HEADER> m_sheetHeaders;
643 std::vector<TEXT_ITEM> m_textItems;
644 std::vector<LINES_ITEM> m_linesItems;
645 std::vector<NETNAME_LABEL> m_netNameLabels;
646};
647
648} // namespace PADS_SCH
649
650#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