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-2024 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 SCH_PIN;
41class PAGE_INFO;
42class SCH_BITMAP;
44class SCH_SYMBOL;
45class SCH_FIELD;
46class SCH_ITEM;
47class SCH_SHAPE;
48class SCH_RULE_AREA;
49class SCH_JUNCTION;
50class SCH_LINE;
51class SCH_NO_CONNECT;
52class SCH_SCREEN;
53class SCH_SHEET;
54class SCH_SHEET_PIN;
55class SCH_TEXT;
56class SCH_TEXTBOX;
57class SCH_TABLE;
58class SCH_TABLECELL;
59class TITLE_BLOCK;
60
61
66{
67public:
69 COLOR4D m_Color;
70};
71
72
76class SCH_IO_KICAD_SEXPR_PARSER : public SCHEMATIC_LEXER
77{
78public:
79 SCH_IO_KICAD_SEXPR_PARSER( LINE_READER* aLineReader = nullptr,
80 PROGRESS_REPORTER* aProgressReporter = nullptr, unsigned aLineCount = 0,
81 SCH_SHEET* aRootSheet = nullptr, bool aIsAppending = false );
82
83 void ParseLib( LIB_SYMBOL_MAP& aSymbolLibMap );
84
88 LIB_SYMBOL* ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap,
89 int aFileVersion = SEXPR_SYMBOL_LIB_FILE_VERSION );
90
92
110 void ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyablyOnly = false,
111 int aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION );
112
114
115private:
116 void checkpoint();
117
118 KIID parseKIID();
119
120 void parseHeader( TSCHEMATIC_T::T aHeaderType, int aFileVersion );
121
122 inline long parseHex()
123 {
124 NextTok();
125 return strtol( CurText(), nullptr, 16 );
126 }
127
128 inline int parseInt()
129 {
130 return (int)strtol( CurText(), nullptr, 10 );
131 }
132
133 inline int parseInt( const char* aExpected )
134 {
135 NeedNUMBER( aExpected );
136 return parseInt();
137 }
138
139 int parseInternalUnits();
140
141 int parseInternalUnits( const char* aExpected );
142
143 int parseInternalUnits( TSCHEMATIC_T::T aToken )
144 {
145 return parseInternalUnits( GetTokenText( aToken ) );
146 }
147
148 VECTOR2I parseXY( bool aInvertY = false )
149 {
150 VECTOR2I xy;
151
152 xy.x = parseInternalUnits( "X coordinate" );
153 xy.y = aInvertY ? -parseInternalUnits( "Y coordinate" )
154 : parseInternalUnits( "Y coordinate" );
155
156 return xy;
157 }
158
159 bool parseBool();
160
171 bool parseMaybeAbsentBool( bool aDefaultValue );
172
173 LIB_SYMBOL* parseLibSymbol( LIB_SYMBOL_MAP& aSymbolLibMap );
174
180 void parseStroke( STROKE_PARAMS& aStroke );
181
182 void parseFill( FILL_PARAMS& aFill );
183
184 void parseMargins( int& aLeft, int& aTop, int& aRight, int& aBottom )
185 {
186 aLeft = parseInternalUnits( "left margin" );
187 aTop = parseInternalUnits( "top margin" );
188 aRight = parseInternalUnits( "right margin" );
189 aBottom = parseInternalUnits( "bottom margin" );
190 }
191
192 void parseEDA_TEXT( EDA_TEXT* aText, bool aConvertOverbarSyntax,
193 bool aEnforceMinTextSize = true );
194 void parsePinNames( std::unique_ptr<LIB_SYMBOL>& aSymbol );
195 void parsePinNumbers( std::unique_ptr<LIB_SYMBOL>& aSymbol );
196
197 SCH_FIELD* parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol );
198
207
208 void parsePAGE_INFO( PAGE_INFO& aPageInfo );
209 void parseTITLE_BLOCK( TITLE_BLOCK& aTitleBlock );
210 void parseSchSymbolInstances( SCH_SCREEN* aScreen );
211 void parseSchSheetInstances( SCH_SHEET* aRootSheet, SCH_SCREEN* aScreen );
212
214 SCH_FIELD* parseSchField( SCH_ITEM* aParent );
230 void parseSchTextBoxContent( SCH_TEXTBOX* aTextBox );
233 void parseBusAlias( SCH_SCREEN* aScreen );
234
240 void removeEntryInFontTextMap( EDA_TEXT* aEntry, EDA_TEXT* aCandidate, bool aReplaceInList );
241
242private:
245 int m_unit;
247 wxString m_symbolName;
249
251 std::set<int> m_fieldIDsRead;
252
253 std::set<KIID> m_uuids;
254
255 std::map<EDA_TEXT*, std::tuple<wxString, bool, bool>> m_fontTextMap;
256
257 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
258 const LINE_READER* m_lineReader; // for progress reporting
260 unsigned m_lineCount; // for progress reporting
261
262 KIID m_rootUuid; // The UUID of the root schematic.
263
266};
267
268#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:80
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:40
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)
void parsePinNumbers(std::unique_ptr< LIB_SYMBOL > &aSymbol)
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)
std::map< EDA_TEXT *, std::tuple< wxString, bool, bool > > m_fontTextMap
void parseMargins(int &aLeft, int &aTop, int &aRight, int &aBottom)
wxString m_symbolName
The current symbol name.
VECTOR2I parseXY(bool aInvertY=false)
void parsePinNames(std::unique_ptr< LIB_SYMBOL > &aSymbol)
void removeEntryInFontTextMap(EDA_TEXT *aEntry, EDA_TEXT *aCandidate, bool aReplaceInList)
Remove aEntry from m_fontTextMap.
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:166
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
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:104
Simple container to manage line stroke parameters.
Definition: stroke_params.h:79
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:56
#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