KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_kicad_sexpr_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) 2020 CERN
5 * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Wayne Stambaugh <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
31#ifndef SCH_IO_KICAD_SEXPR_PARSER_H_
32#define SCH_IO_KICAD_SEXPR_PARSER_H_
33
34#include <symbol_library.h>
35#include <schematic_lexer.h>
36#include <sch_file_versions.h>
37#include <default_values.h> // For some default values
38
39
40class LIB_PIN;
41class PAGE_INFO;
42class SCH_BITMAP;
44class SCH_SYMBOL;
45class SCH_FIELD;
46class SCH_ITEM;
47class SCH_SHAPE;
48class SCH_JUNCTION;
49class SCH_LINE;
50class SCH_NO_CONNECT;
51class SCH_SCREEN;
52class SCH_SHEET;
53class SCH_SHEET_PIN;
54class SCH_TEXT;
55class SCH_TEXTBOX;
56class SCH_TABLE;
57class SCH_TABLECELL;
58class TITLE_BLOCK;
59
60
65{
66public:
68 COLOR4D m_Color;
69};
70
71
75class SCH_IO_KICAD_SEXPR_PARSER : public SCHEMATIC_LEXER
76{
77public:
78 SCH_IO_KICAD_SEXPR_PARSER( LINE_READER* aLineReader = nullptr,
79 PROGRESS_REPORTER* aProgressReporter = nullptr, unsigned aLineCount = 0,
80 SCH_SHEET* aRootSheet = nullptr, bool aIsAppending = false );
81
82 void ParseLib( LIB_SYMBOL_MAP& aSymbolLibMap );
83
87 LIB_SYMBOL* ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap,
88 int aFileVersion = SEXPR_SYMBOL_LIB_FILE_VERSION );
89
91
109 void ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyablyOnly = false,
110 int aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION );
111
113
114private:
115 void checkpoint();
116
117 KIID parseKIID();
118
119 void parseHeader( TSCHEMATIC_T::T aHeaderType, int aFileVersion );
120
121 inline long parseHex()
122 {
123 NextTok();
124 return strtol( CurText(), nullptr, 16 );
125 }
126
127 inline int parseInt()
128 {
129 return (int)strtol( CurText(), nullptr, 10 );
130 }
131
132 inline int parseInt( const char* aExpected )
133 {
134 NeedNUMBER( aExpected );
135 return parseInt();
136 }
137
138 int parseInternalUnits();
139
140 int parseInternalUnits( const char* aExpected );
141
142 inline int parseInternalUnits( TSCHEMATIC_T::T aToken )
143 {
144 return parseInternalUnits( GetTokenText( aToken ) );
145 }
146
148 {
149 VECTOR2I xy;
150
151 xy.x = parseInternalUnits( "X coordinate" );
152 xy.y = parseInternalUnits( "Y coordinate" );
153
154 return xy;
155 }
156
157 bool parseBool();
158
169 bool parseMaybeAbsentBool( bool aDefaultValue );
170
171 LIB_SYMBOL* parseLibSymbol( LIB_SYMBOL_MAP& aSymbolLibMap );
172
178 void parseStroke( STROKE_PARAMS& aStroke );
179
180 void parseFill( FILL_PARAMS& aFill );
181
182 void parseMargins( int& aLeft, int& aTop, int& aRight, int& aBottom )
183 {
184 aLeft = parseInternalUnits( "left margin" );
185 aTop = parseInternalUnits( "top margin" );
186 aRight = parseInternalUnits( "right margin" );
187 aBottom = parseInternalUnits( "bottom margin" );
188 }
189
190 void parseEDA_TEXT( EDA_TEXT* aText, bool aConvertOverbarSyntax,
191 bool aEnforceMinTextSize = true );
192 void parsePinNames( std::unique_ptr<LIB_SYMBOL>& aSymbol );
193
194 SCH_FIELD* parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol );
195
199 LIB_PIN* parsePin();
204
205 void parsePAGE_INFO( PAGE_INFO& aPageInfo );
206 void parseTITLE_BLOCK( TITLE_BLOCK& aTitleBlock );
207 void parseSchSymbolInstances( SCH_SCREEN* aScreen );
208 void parseSchSheetInstances( SCH_SHEET* aRootSheet, SCH_SCREEN* aScreen );
209
211 SCH_FIELD* parseSchField( SCH_ITEM* aParent );
226 void parseSchTextBoxContent( SCH_TEXTBOX* aTextBox );
229 void parseBusAlias( SCH_SCREEN* aScreen );
230
231private:
234 int m_unit;
236 wxString m_symbolName;
238
240 std::set<int> m_fieldIDsRead;
241
242 std::set<KIID> m_uuids;
243
244 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
245 const LINE_READER* m_lineReader; // for progress reporting
247 unsigned m_lineCount; // for progress reporting
248
249 KIID m_rootUuid; // The UUID of the root schematic.
250
253};
254
255#endif // SCH_IO_KICAD_SEXPR_PARSER_H_
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:83
Simple container to manage fill parameters.
Definition: kiid.h:49
Define a library symbol object.
Definition: lib_symbol.h:78
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
A progress reporter interface for use in multi-threaded environments.
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:41
Class for a wire to bus entry.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
Object to parser s-expression symbol library and schematic file formats.
bool m_appending
Appending load status.
SCH_FIELD * parseSchField(SCH_ITEM *aParent)
void parseSchSymbolInstances(SCH_SCREEN *aScreen)
LIB_SYMBOL * parseLibSymbol(LIB_SYMBOL_MAP &aSymbolLibMap)
int parseInternalUnits(TSCHEMATIC_T::T aToken)
void parseFill(FILL_PARAMS &aFill)
void parseBusAlias(SCH_SCREEN *aScreen)
std::set< int > m_fieldIDsRead
Field IDs that have been read so far for the current symbol.
void parseTITLE_BLOCK(TITLE_BLOCK &aTitleBlock)
void parseStroke(STROKE_PARAMS &aStroke)
Parse stroke definition aStroke.
int m_unit
The current unit being parsed.
void parseEDA_TEXT(EDA_TEXT *aText, bool aConvertOverbarSyntax, bool aEnforceMinTextSize=true)
SCH_SHEET * m_rootSheet
The rootsheet for full project loads or null for importing a schematic.
void ParseLib(LIB_SYMBOL_MAP &aSymbolLibMap)
void parseHeader(TSCHEMATIC_T::T aHeaderType, int aFileVersion)
void parseMargins(int &aLeft, int &aTop, int &aRight, int &aBottom)
wxString m_symbolName
The current symbol name.
void parsePinNames(std::unique_ptr< LIB_SYMBOL > &aSymbol)
void ParseSchematic(SCH_SHEET *aSheet, bool aIsCopyablyOnly=false, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
Parse the internal LINE_READER object into aSheet.
SCH_SHEET_PIN * parseSchSheetPin(SCH_SHEET *aSheet)
int m_bodyStyle
The current body style being parsed.
SCH_FIELD * parseProperty(std::unique_ptr< LIB_SYMBOL > &aSymbol)
void parseSchTextBoxContent(SCH_TEXTBOX *aTextBox)
bool parseMaybeAbsentBool(bool aDefaultValue)
Parses a boolean flag inside a list that existed before boolean normalization.
void parsePAGE_INFO(PAGE_INFO &aPageInfo)
int m_requiredVersion
Set to the symbol library file version required.
int parseInt(const char *aExpected)
LIB_SYMBOL * ParseSymbol(LIB_SYMBOL_MAP &aSymbolLibMap, int aFileVersion=SEXPR_SYMBOL_LIB_FILE_VERSION)
Parse internal LINE_READER object into symbols and return all found.
void parseSchSheetInstances(SCH_SHEET *aRootSheet, SCH_SCREEN *aScreen)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:172
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
Schematic symbol object.
Definition: sch_symbol.h:108
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:41
FILL_T
Definition: eda_shape.h:55
#define SEXPR_SYMBOL_LIB_FILE_VERSION
This file contains the file format version information for the s-expression schematic and symbol libr...
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
Definition for symbol library class.
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP