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
157 // T line groups place the pin number (pn) and the pin label (pl); sizes come from the decal header
159 int pn_angle = 0;
160 int pn_just = 0;
162 int pl_angle = 0;
163 int pl_just = 0;
164 std::string pin_decal_name;
165
166 // PADS draws nothing at the P line positions, so their meaning is unknown
168 int p_angle1 = 0;
169 int p_just1 = 0;
171 int p_angle2 = 0;
172 int p_just2 = 0;
173 int p_flags = 0;
174};
175
176
185
186
188{
190 double line_width = 0.0;
191 bool filled = false;
192 int line_style = 255;
193 std::vector<GRAPHIC_POINT> points;
195 double radius = 0.0;
196 double start_angle = 0.0;
197 double end_angle = 0.0;
198};
199
200
202{
203 std::string content;
205 double size = 60.0;
206 double rotation = 0.0;
207 bool visible = true;
210 int attr_flag = 0;
211 std::string font_name;
212};
213
214
216{
218 int angle = 0;
220 int height = 0;
221 int width = 0;
222 int visibility = 0;
223 std::string font_name;
224 std::string attr_name;
225};
226
227
229{
230 std::string name;
231 std::string timestamp;
232 int gate_count = 1;
234 std::vector<SYMBOL_PIN> pins;
235 std::vector<SYMBOL_GRAPHIC> graphics;
236 std::vector<SYMBOL_TEXT> texts;
237
238 int f1 = 0;
239 int f2 = 0;
240 int height = 0;
241 int width = 0;
242 int h2 = 0;
243 int w2 = 0;
244 int num_attrs = 0;
245 int num_pieces = 0;
247 int num_pins = 0;
250
251 std::string font1;
252 std::string font2;
253 std::vector<CAEDECAL_ATTR> attrs;
254};
255
256
258{
259 std::string name;
260 std::string value;
262 double rotation = 0.0;
263 double size = 60.0;
264 bool visible = true;
265
267 int height = 0;
268 int width = 0;
269 int visibility = 0;
270 std::string font_name;
271};
272
273
275{
276 std::string reference;
277 std::string symbol_name;
278 std::string decal_name;
279 std::string part_type;
281 double rotation = 0.0;
283 std::string power_net_name;
285 int gate_number = 1;
286 std::vector<PART_ATTRIBUTE> attributes;
287
288 int h1 = 0;
289 int w1 = 0;
290 int h2 = 0;
291 int w2 = 0;
292 int num_attrs = 0;
294 int num_pins = 0;
295 int gate_index = 0;
297 std::string font1;
298 std::string font2;
299
300 std::map<std::string, std::string> attr_overrides;
301
303 {
304 int height = 0;
305 int width = 0;
306 int angle = 0;
308 };
309
310 std::vector<PIN_OVERRIDE> pin_overrides;
311};
312
313
318{
322
323 std::string endpoint_a;
324 std::string endpoint_b;
326 int flags = 0;
327 std::vector<POINT> vertices;
328};
329
330
332{
333 std::string reference;
334 std::string pin_number;
336};
337
338
340{
341 std::string name;
342 std::vector<WIRE_SEGMENT> wires;
343 std::vector<PIN_CONNECTION> connections;
344
345 int flags1 = 0;
346 int flags2 = 0;
347 std::string function;
348};
349
350
352{
353 std::string signal_name;
357
358 int id = 0;
359 std::string symbol_lib;
360 int rotation = 0;
361 int flags1 = 0;
362 int flags2 = 0;
363};
364
365
367{
368 std::string member_net;
370 int rotation = 0;
371};
372
373
375{
376 std::string handle;
377 std::string name;
379 std::vector<POINT> path;
380 std::vector<BUS_ENTRY> entries;
381 std::vector<std::string> aliases;
382 std::vector<std::string> member_nets;
383};
384
385
387{
389 std::string name;
391};
392
393
395{
396 int sheet_num = 0;
397 std::string sheet_name;
398 int parent_num = -1;
399 std::string parent_name;
400};
401
402
404{
405 int id = 0;
408};
409
410
412{
414 int rotation = 0;
416 int height = 0;
418 int attr_flag = 0;
420 std::string font_name;
421 std::string content;
422};
423
424
426{
427 std::string name;
429 int param1 = 0;
430 int param2 = 0;
432 std::vector<SYMBOL_GRAPHIC> primitives;
433 std::vector<TEXT_ITEM> texts;
434};
435
436
438{
439 std::string net_name;
440 std::string anchor_ref;
441 int x_offset = 0;
442 int y_offset = 0;
443 int rotation = 0;
445 int f3 = 0;
446 int f4 = 0;
447 int f5 = 0;
448 int f6 = 0;
449 int f7 = 0;
450 int height = 0;
451 int width_pct = 0;
452 std::string font_name;
453};
454
455
457{
458 std::string pin_id;
459 int swap_group = 0;
460 char pin_type = 'U';
461 std::string pin_name;
462};
463
464
466{
468 int num_pins = 0;
469 int swap_flag = 0;
470 std::vector<std::string> decal_names;
471 std::vector<PARTTYPE_PIN> pins;
472};
473
474
476{
477 std::string name;
478 std::string category;
480 int num_sigpins = 0;
481 int unused = 0;
483 std::string timestamp;
484
485 std::vector<GATE_DEF> gates;
486
487 std::string special_keyword;
489 {
490 std::string decal_name;
491 std::string pin_type;
492 std::string net_suffix;
493 };
494
495 std::vector<SPECIAL_VARIANT> special_variants;
496
497 bool is_connector = false;
498
499 struct SIGPIN
500 {
501 std::string pin_number;
502 std::string net_name;
503 };
504 std::vector<SIGPIN> sigpins;
505
506 std::vector<std::string> swap_lines;
507};
508
509
514{
515public:
518
519 void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
520
521 bool Parse( const std::string& aFileName );
522
523 static bool CheckFileHeader( const std::string& aFileName );
524
525 static PIN_TYPE ParsePinTypeChar( char aTypeChar );
526
527 const FILE_HEADER& GetHeader() const { return m_header; }
528 const PARAMETERS& GetParameters() const { return m_parameters; }
529
530 const std::vector<SYMBOL_DEF>& GetSymbolDefs() const { return m_symbolDefs; }
531 const SYMBOL_DEF* GetSymbolDef( const std::string& aName ) const;
532
533 const std::vector<PART_PLACEMENT>& GetPartPlacements() const { return m_partPlacements; }
534 const PART_PLACEMENT* GetPartPlacement( const std::string& aReference ) const;
535
536 const std::vector<SCH_SIGNAL>& GetSignals() const { return m_signals; }
537 const SCH_SIGNAL* GetSignal( const std::string& aName ) const;
538
539 std::string GetVersion() const { return m_header.version; }
540 bool IsValid() const { return m_header.valid; }
541
542 int GetSheetCount() const;
543 std::set<int> GetSheetNumbers() const;
544
545 const std::vector<OFF_PAGE_CONNECTOR>& GetOffPageConnectors() const { return m_offPageConnectors; }
546 const std::vector<BUS_DEF>& GetBuses() const { return m_buses; }
547
548 std::vector<SCH_SIGNAL> GetSignalsOnSheet( int aSheetNumber ) const;
549 std::vector<PART_PLACEMENT> GetPartsOnSheet( int aSheetNumber ) const;
550
551 const std::map<std::string, PARTTYPE_DEF>& GetPartTypes() const { return m_partTypes; }
552 const std::vector<TIED_DOT>& GetTiedDots() const { return m_tiedDots; }
553 const std::vector<SHEET_HEADER>& GetSheetHeaders() const { return m_sheetHeaders; }
554 const std::vector<TEXT_ITEM>& GetTextItems() const { return m_textItems; }
555 const std::vector<LINES_ITEM>& GetLinesItems() const { return m_linesItems; }
556 const std::vector<NETNAME_LABEL>& GetNetNameLabels() const { return m_netNameLabels; }
557
558private:
559 bool parseHeader( const std::string& aLine );
560
561 size_t parseSectionSCH( const std::vector<std::string>& aLines, size_t aStartLine );
562 size_t parseSectionFIELDS( const std::vector<std::string>& aLines, size_t aStartLine );
563 size_t parseSectionSHT( const std::vector<std::string>& aLines, size_t aStartLine );
564 size_t parseSectionCAE( const std::vector<std::string>& aLines, size_t aStartLine );
565 size_t parseSectionTEXT( const std::vector<std::string>& aLines, size_t aStartLine );
566 size_t parseSectionLINES( const std::vector<std::string>& aLines, size_t aStartLine );
567 size_t parseSectionCAEDECAL( const std::vector<std::string>& aLines, size_t aStartLine );
568 size_t parseSectionPARTTYPE( const std::vector<std::string>& aLines, size_t aStartLine );
569 size_t parseSectionPART( const std::vector<std::string>& aLines, size_t aStartLine );
570 size_t parseSectionBUSSES( const std::vector<std::string>& aLines, size_t aStartLine );
571 size_t parseSectionOFFPAGEREFS( const std::vector<std::string>& aLines, size_t aStartLine );
572 size_t parseSectionTIEDOTS( const std::vector<std::string>& aLines, size_t aStartLine );
573 size_t parseSectionCONNECTION( const std::vector<std::string>& aLines, size_t aStartLine );
574 size_t parseSectionNETNAMES( const std::vector<std::string>& aLines, size_t aStartLine );
575
576 size_t skipBraceDelimitedSection( const std::vector<std::string>& aLines, size_t aStartLine );
577
578 size_t parseSymbolDef( const std::vector<std::string>& aLines, size_t aStartLine, SYMBOL_DEF& aSymbol );
579 size_t parsePartPlacement( const std::vector<std::string>& aLines, size_t aStartLine, PART_PLACEMENT& aPart );
580 size_t parseSignalDef( const std::vector<std::string>& aLines, size_t aStartLine, SCH_SIGNAL& aSignal );
581 size_t parseGraphicPrimitive( const std::vector<std::string>& aLines, size_t aStartLine, SYMBOL_GRAPHIC& aGraphic );
582
583 void mergePartTypeData();
584
585 PIN_TYPE parsePinType( const std::string& aTypeStr );
586
587 bool isSectionMarker( const std::string& aLine ) const;
588 std::string extractSectionName( const std::string& aLine ) const;
589
593 std::vector<SYMBOL_DEF> m_symbolDefs;
594 std::vector<PART_PLACEMENT> m_partPlacements;
595 std::vector<SCH_SIGNAL> m_signals;
596 std::vector<OFF_PAGE_CONNECTOR> m_offPageConnectors;
597 std::vector<BUS_DEF> m_buses;
600 std::map<std::string, PARTTYPE_DEF> m_partTypes;
601 std::vector<TIED_DOT> m_tiedDots;
602 std::vector<SHEET_HEADER> m_sheetHeaders;
603 std::vector<TEXT_ITEM> m_textItems;
604 std::vector<LINES_ITEM> m_linesItems;
605 std::vector<NETNAME_LABEL> m_netNameLabels;
606};
607
608} // 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:708