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 description;
48 bool valid = false;
49};
50
51
53{
54 double width = 11000.0;
55 double height = 8500.0;
56 std::string name;
57};
58
59
64{
66 double grid_x = 100.0;
67 double grid_y = 100.0;
68 std::string border_template;
69 std::string job_name;
71 double text_size = 60.0;
72 double line_width = 1.0;
73
74 // Additional *SCH* parameters
75 int cur_sheet = 0;
76 int conn_width = 0;
77 int bus_width = 0;
78 int bus_angle = 0;
79 int pin_name_h = 0;
80 int pin_name_w = 0;
81 int ref_name_h = 0;
82 int ref_name_w = 0;
83 int part_name_h = 0;
84 int part_name_w = 0;
85 int pin_no_h = 0;
86 int pin_no_w = 0;
87 int net_name_h = 0;
88 int net_name_w = 0;
89 int text_h = 0;
90 int text_w = 0;
91 int dot_grid = 0;
93 int real_width = 0;
94 std::string font_mode;
95 std::string default_font;
96
97 // All user fields from *FIELDS*, keyed by field name
98 std::map<std::string, std::string> fields;
99};
100
101
102struct POINT
103{
104 double x = 0.0;
105 double y = 0.0;
106};
107
108
110{
111 double bulge = 0.0;
112 double angle = 0.0;
113 double bbox_x1 = 0.0;
114 double bbox_y1 = 0.0;
115 double bbox_x2 = 0.0;
116 double bbox_y2 = 0.0;
117};
118
119
121{
123 std::optional<ARC_DATA> arc;
124};
125
126
139
140
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 // T-line fields
156 int side = 0;
157 int pn_h = 0;
158 int pn_w = 0;
159 int pn_angle = 0;
160 int pn_just = 0;
161 int pl_h = 0;
162 int pl_w = 0;
163 int pl_angle = 0;
164 int pl_just = 0;
165 std::string pin_decal_name;
166
167 // P-line fields
170 int pn_off_just = 0;
173 int pl_off_just = 0;
174 int p_flags = 0;
175};
176
177
186
187
192{
194 double line_width = 0.0;
195 bool filled = false;
196 int line_style = 255;
197 std::vector<GRAPHIC_POINT> points;
199 double radius = 0.0;
200 double start_angle = 0.0;
201 double end_angle = 0.0;
202};
203
204
206{
207 std::string content;
209 double size = 60.0;
210 double rotation = 0.0;
211 bool visible = true;
214 int attr_flag = 0;
215 std::string font_name;
216};
217
218
223{
225 int angle = 0;
227 int height = 0;
228 int width = 0;
229 int visibility = 0;
230 std::string font_name;
231 std::string attr_name;
232};
233
234
241{
242 std::string name;
243 std::string timestamp;
244 int gate_count = 1;
246 std::vector<SYMBOL_PIN> pins;
247 std::vector<SYMBOL_GRAPHIC> graphics;
248 std::vector<SYMBOL_TEXT> texts;
249
250 // Full CAEDECAL header fields
251 int f1 = 0;
252 int f2 = 0;
253 int height = 0;
254 int width = 0;
255 int h2 = 0;
256 int w2 = 0;
257 int num_attrs = 0;
258 int num_pieces = 0;
260 int num_pins = 0;
263
264 std::string font1;
265 std::string font2;
266 std::vector<CAEDECAL_ATTR> attrs;
267};
268
269
271{
272 std::string name;
273 std::string value;
275 double rotation = 0.0;
276 double size = 60.0;
277 bool visible = true;
278
280 int height = 0;
281 int width = 0;
282 int visibility = 0;
283 std::string font_name;
284};
285
286
291{
292 std::string reference;
293 std::string symbol_name;
294 std::string part_type;
296 double rotation = 0.0;
298 std::string power_net_name;
300 int gate_number = 1;
301 std::vector<PART_ATTRIBUTE> attributes;
302
303 // Full *PART* header fields
304 int h1 = 0;
305 int w1 = 0;
306 int h2 = 0;
307 int w2 = 0;
308 int num_attrs = 0;
310 int num_pins = 0;
311 int gate_index = 0;
313 std::string font1;
314 std::string font2;
315
316 // Attribute value overrides parsed from "name" value lines
317 std::map<std::string, std::string> attr_overrides;
318
319 // Pin override lines (zero-based index -> formatting)
321 {
322 int height = 0;
323 int width = 0;
324 int angle = 0;
326 };
327
328 std::vector<PIN_OVERRIDE> pin_overrides;
329};
330
331
336{
340
341 // Real format fields
342 std::string endpoint_a;
343 std::string endpoint_b;
345 int flags = 0;
346 std::vector<POINT> vertices;
347};
348
349
351{
352 std::string reference;
353 std::string pin_number;
355};
356
357
362{
363 std::string name;
364 std::vector<WIRE_SEGMENT> wires;
365 std::vector<PIN_CONNECTION> connections;
366
367 int flags1 = 0;
368 int flags2 = 0;
369 std::string function;
370};
371
372
377{
378 std::string signal_name;
382
383 int id = 0;
384 std::string symbol_lib;
385 int rotation = 0;
386 int flags1 = 0;
387 int flags2 = 0;
388};
389
390
392{
394 std::string name;
396};
397
398
403{
404 int sheet_num = 0;
405 std::string sheet_name;
406 int parent_num = -1;
407 std::string parent_name;
408};
409
410
415{
416 int id = 0;
419};
420
421
426{
428 int rotation = 0;
430 int height = 0;
432 int attr_flag = 0;
433 std::string font_name;
434 std::string content;
435};
436
437
442{
443 std::string name;
445 int param1 = 0;
446 int param2 = 0;
447 std::vector<SYMBOL_GRAPHIC> primitives;
448 std::vector<TEXT_ITEM> texts;
449};
450
451
456{
457 std::string net_name;
458 std::string anchor_ref;
459 int x_offset = 0;
460 int y_offset = 0;
461 int rotation = 0;
463 int f3 = 0;
464 int f4 = 0;
465 int f5 = 0;
466 int f6 = 0;
467 int f7 = 0;
468 int height = 0;
469 int width_pct = 0;
470 std::string font_name;
471};
472
473
478{
479 std::string pin_id;
480 int swap_group = 0;
481 char pin_type = 'U';
482 std::string pin_name;
483};
484
485
490{
492 int num_pins = 0;
493 int swap_flag = 0;
494 std::vector<std::string> decal_names;
495 std::vector<PARTTYPE_PIN> pins;
496};
497
498
503{
504 std::string name;
505 std::string category;
507 int num_sigpins = 0;
508 int unused = 0;
510 std::string timestamp;
511
512 std::vector<GATE_DEF> gates;
513
514 // For special symbols ($GND_SYMS, $PWR_SYMS, $OSR_SYMS)
515 std::string special_keyword;
517 {
518 std::string decal_name;
519 std::string pin_type;
520 std::string net_suffix;
521 };
522 std::vector<SPECIAL_VARIANT> special_variants;
523
524 // For CONN-based connectors
525 bool is_connector = false;
526
527 // SIGPIN entries (hidden power pins)
528 struct SIGPIN
529 {
530 std::string pin_number;
531 std::string net_name;
532 };
533 std::vector<SIGPIN> sigpins;
534
535 // Swap group lines
536 std::vector<std::string> swap_lines;
537};
538
539
547{
548public:
551
552 void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
553
554 bool Parse( const std::string& aFileName );
555
556 static bool CheckFileHeader( const std::string& aFileName );
557
558 static PIN_TYPE ParsePinTypeChar( char aTypeChar );
559
560 const FILE_HEADER& GetHeader() const { return m_header; }
561 const PARAMETERS& GetParameters() const { return m_parameters; }
562
563 const std::vector<SYMBOL_DEF>& GetSymbolDefs() const { return m_symbolDefs; }
564 const SYMBOL_DEF* GetSymbolDef( const std::string& aName ) const;
565
566 const std::vector<PART_PLACEMENT>& GetPartPlacements() const { return m_partPlacements; }
567 const PART_PLACEMENT* GetPartPlacement( const std::string& aReference ) const;
568
569 const std::vector<SCH_SIGNAL>& GetSignals() const { return m_signals; }
570 const SCH_SIGNAL* GetSignal( const std::string& aName ) const;
571
572 std::string GetVersion() const { return m_header.version; }
573 bool IsValid() const { return m_header.valid; }
574
575 int GetSheetCount() const;
576 std::set<int> GetSheetNumbers() const;
577
578 const std::vector<OFF_PAGE_CONNECTOR>& GetOffPageConnectors() const { return m_offPageConnectors; }
579
580 std::vector<SCH_SIGNAL> GetSignalsOnSheet( int aSheetNumber ) const;
581 std::vector<PART_PLACEMENT> GetPartsOnSheet( int aSheetNumber ) const;
582
583 const std::map<std::string, PARTTYPE_DEF>& GetPartTypes() const { return m_partTypes; }
584 const std::vector<TIED_DOT>& GetTiedDots() const { return m_tiedDots; }
585 const std::vector<SHEET_HEADER>& GetSheetHeaders() const { return m_sheetHeaders; }
586 const std::vector<TEXT_ITEM>& GetTextItems() const { return m_textItems; }
587 const std::vector<LINES_ITEM>& GetLinesItems() const { return m_linesItems; }
588 const std::vector<NETNAME_LABEL>& GetNetNameLabels() const { return m_netNameLabels; }
589
590private:
591 bool parseHeader( const std::string& aLine );
592
593 size_t parseSectionSCH( const std::vector<std::string>& aLines, size_t aStartLine );
594 size_t parseSectionFIELDS( const std::vector<std::string>& aLines, size_t aStartLine );
595 size_t parseSectionSHT( const std::vector<std::string>& aLines, size_t aStartLine );
596 size_t parseSectionCAE( const std::vector<std::string>& aLines, size_t aStartLine );
597 size_t parseSectionTEXT( const std::vector<std::string>& aLines, size_t aStartLine );
598 size_t parseSectionLINES( const std::vector<std::string>& aLines, size_t aStartLine );
599 size_t parseSectionCAEDECAL( const std::vector<std::string>& aLines, size_t aStartLine );
600 size_t parseSectionPARTTYPE( const std::vector<std::string>& aLines, size_t aStartLine );
601 size_t parseSectionPART( const std::vector<std::string>& aLines, size_t aStartLine );
602 size_t parseSectionOFFPAGEREFS( const std::vector<std::string>& aLines, size_t aStartLine );
603 size_t parseSectionTIEDOTS( const std::vector<std::string>& aLines, size_t aStartLine );
604 size_t parseSectionCONNECTION( const std::vector<std::string>& aLines, size_t aStartLine );
605 size_t parseSectionNETNAMES( const std::vector<std::string>& aLines, size_t aStartLine );
606
607 size_t skipBraceDelimitedSection( const std::vector<std::string>& aLines, size_t aStartLine );
608
609 size_t parseSymbolDef( const std::vector<std::string>& aLines, size_t aStartLine,
610 SYMBOL_DEF& aSymbol );
611
612 size_t parsePartPlacement( const std::vector<std::string>& aLines, size_t aStartLine,
613 PART_PLACEMENT& aPart );
614
615 size_t parseSignalDef( const std::vector<std::string>& aLines, size_t aStartLine,
616 SCH_SIGNAL& aSignal );
617
618 size_t parseGraphicPrimitive( const std::vector<std::string>& aLines, size_t aStartLine,
619 SYMBOL_GRAPHIC& aGraphic );
620
621 void mergePartTypeData();
622
623 PIN_TYPE parsePinType( const std::string& aTypeStr );
624
625 bool isSectionMarker( const std::string& aLine ) const;
626 std::string extractSectionName( const std::string& aLine ) const;
627
631 std::vector<SYMBOL_DEF> m_symbolDefs;
632 std::vector<PART_PLACEMENT> m_partPlacements;
633 std::vector<SCH_SIGNAL> m_signals;
634 std::vector<OFF_PAGE_CONNECTOR> m_offPageConnectors;
637 std::map<std::string, PARTTYPE_DEF> m_partTypes;
638 std::vector<TIED_DOT> m_tiedDots;
639 std::vector<SHEET_HEADER> m_sheetHeaders;
640 std::vector<TEXT_ITEM> m_textItems;
641 std::vector<LINES_ITEM> m_linesItems;
642 std::vector<NETNAME_LABEL> m_netNameLabels;
643};
644
645} // namespace PADS_SCH
646
647#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:73
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