KiCad PCB EDA Suite
sch_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
32#ifndef __SCH_SEXPR_PARSER_H__
33#define __SCH_SEXPR_PARSER_H__
34
35#include <symbol_library.h>
36#include <schematic_lexer.h>
37#include <sch_file_versions.h>
38#include <default_values.h> // For some default values
39
40
41class LIB_SHAPE;
42class LIB_ITEM;
43class LIB_PIN;
44class LIB_TEXT;
45class PAGE_INFO;
46class SCH_BITMAP;
48class SCH_SYMBOL;
49class SCH_FIELD;
50class SCH_ITEM;
51class SCH_SHAPE;
52class SCH_JUNCTION;
53class SCH_LINE;
54class SCH_NO_CONNECT;
55class SCH_SCREEN;
56class SCH_SHEET;
57class SCH_SHEET_PIN;
58class SCH_TEXT;
59class SCH_TEXTBOX;
60class TITLE_BLOCK;
61
62
67{
68public:
70 COLOR4D m_Color;
71};
72
73
77class SCH_SEXPR_PARSER : public SCHEMATIC_LEXER
78{
79public:
80 SCH_SEXPR_PARSER( LINE_READER* aLineReader = nullptr,
81 PROGRESS_REPORTER* aProgressReporter = nullptr, unsigned aLineCount = 0,
82 SCH_SHEET* aRootSheet = nullptr, bool aIsAppending = false );
83
84 void ParseLib( LIB_SYMBOL_MAP& aSymbolLibMap );
85
86 LIB_SYMBOL* ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap,
87 int aFileVersion = SEXPR_SYMBOL_LIB_FILE_VERSION );
88
90
108 void ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyablyOnly = false,
109 int aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION );
110
112
113private:
114 void checkpoint();
115
116 KIID parseKIID();
117
118 void parseHeader( TSCHEMATIC_T::T aHeaderType, int aFileVersion );
119
120 inline long parseHex()
121 {
122 NextTok();
123 return strtol( CurText(), nullptr, 16 );
124 }
125
126 inline int parseInt()
127 {
128 return (int)strtol( CurText(), nullptr, 10 );
129 }
130
131 inline int parseInt( const char* aExpected )
132 {
133 NeedNUMBER( aExpected );
134 return parseInt();
135 }
136
137 int parseInternalUnits();
138
139 int parseInternalUnits( const char* aExpected );
140
141 inline int parseInternalUnits( TSCHEMATIC_T::T aToken )
142 {
143 return parseInternalUnits( GetTokenText( aToken ) );
144 }
145
146 inline wxPoint parseXY()
147 {
148 wxPoint xy;
149
150 xy.x = parseInternalUnits( "X coordinate" );
151 xy.y = parseInternalUnits( "Y coordinate" );
152
153 return xy;
154 }
155
156 bool parseBool();
157
163 void parseStroke( STROKE_PARAMS& aStroke );
164
165 void parseFill( FILL_PARAMS& aFill );
166
167 void parseEDA_TEXT( EDA_TEXT* aText, bool aConvertOverbarSyntax );
168 void parsePinNames( std::unique_ptr<LIB_SYMBOL>& aSymbol );
169
170 LIB_FIELD* parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol );
171
175 LIB_PIN* parsePin();
180
181 void parsePAGE_INFO( PAGE_INFO& aPageInfo );
182 void parseTITLE_BLOCK( TITLE_BLOCK& aTitleBlock );
183 void parseSchSymbolInstances( SCH_SCREEN* aScreen );
184 void parseSchSheetInstances( SCH_SHEET* aRootSheet, SCH_SCREEN* aScreen );
185
187 SCH_FIELD* parseSchField( SCH_ITEM* aParent );
202 void parseBusAlias( SCH_SCREEN* aScreen );
203
206 int m_unit;
208 wxString m_symbolName;
210
212 std::set<int> m_fieldIDsRead;
213
214 std::set<KIID> m_uuids;
215
216 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
217 const LINE_READER* m_lineReader; // for progress reporting
219 unsigned m_lineCount; // for progress reporting
220
221 KIID m_rootUuid; // The UUID of the root schematic.
222
225};
226
227#endif // __SCH_SEXPR_PARSER_H__
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:72
Simple container to manage fill parameters.
Definition: kiid.h:48
Field object used in symbol libraries.
Definition: lib_field.h:60
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
Define a library symbol object.
Definition: lib_symbol.h:98
Define a symbol library graphical text item.
Definition: lib_text.h:40
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:81
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
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:50
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
Object to parser s-expression symbol library and schematic file formats.
std::set< int > m_fieldIDsRead
Field IDs that have been read so far for the current symbol.
void parseBusAlias(SCH_SCREEN *aScreen)
int m_convert
The current body style being parsed.
SCH_SHEET_PIN * parseSchSheetPin(SCH_SHEET *aSheet)
void parseSchSheetInstances(SCH_SHEET *aRootSheet, SCH_SCREEN *aScreen)
SCH_BUS_WIRE_ENTRY * parseBusEntry()
void ParseLib(LIB_SYMBOL_MAP &aSymbolLibMap)
SCH_JUNCTION * parseJunction()
int m_fieldId
The current field ID.
void ParseSchematic(SCH_SHEET *aSheet, bool aIsCopyablyOnly=false, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
Parse the internal LINE_READER object into aSheet.
int parseInt(const char *aExpected)
LIB_ITEM * ParseDrawItem()
void parseHeader(TSCHEMATIC_T::T aHeaderType, int aFileVersion)
SCH_NO_CONNECT * parseNoConnect()
LIB_SHAPE * parseBezier()
SCH_SHAPE * parseSchCircle()
int m_unit
The current unit being parsed.
LIB_SHAPE * parseCircle()
SCH_SHAPE * parseSchRectangle()
SCH_SYMBOL * parseSchematicSymbol()
const LINE_READER * m_lineReader
int parseInternalUnits(TSCHEMATIC_T::T aToken)
SCH_BITMAP * parseImage()
SCH_SHAPE * parseSchBezier()
SCH_SHAPE * parseSchArc()
LIB_FIELD * parseProperty(std::unique_ptr< LIB_SYMBOL > &aSymbol)
void parseStroke(STROKE_PARAMS &aStroke)
Parse stroke definition aStroke.
LIB_SHAPE * parseRectangle()
SCH_SEXPR_PARSER(LINE_READER *aLineReader=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr, unsigned aLineCount=0, SCH_SHEET *aRootSheet=nullptr, bool aIsAppending=false)
SCH_SHEET * parseSheet()
LIB_SHAPE * parseArc()
void parseTITLE_BLOCK(TITLE_BLOCK &aTitleBlock)
LIB_SHAPE * parsePolyLine()
int m_requiredVersion
Set to the symbol library file version required.
SCH_TEXTBOX * parseSchTextBox()
SCH_TEXT * parseSchText()
LIB_TEXTBOX * parseTextBox()
wxString m_symbolName
The current symbol name.
SCH_FIELD * parseSchField(SCH_ITEM *aParent)
void parseEDA_TEXT(EDA_TEXT *aText, bool aConvertOverbarSyntax)
PROGRESS_REPORTER * m_progressReporter
void parseFill(FILL_PARAMS &aFill)
void parseSchSymbolInstances(SCH_SCREEN *aScreen)
void parsePinNames(std::unique_ptr< LIB_SYMBOL > &aSymbol)
unsigned m_lastProgressLine
std::set< KIID > m_uuids
void parsePAGE_INFO(PAGE_INFO &aPageInfo)
LIB_SYMBOL * ParseSymbol(LIB_SYMBOL_MAP &aSymbolLibMap, int aFileVersion=SEXPR_SYMBOL_LIB_FILE_VERSION)
SCH_SHEET * m_rootSheet
The rootsheet for full project loads or null for importing a schematic.
SCH_SHAPE * parseSchPolyLine()
bool m_appending
Appending load status.
int GetParsedRequiredVersion() const
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:55
Schematic symbol object.
Definition: sch_symbol.h:80
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
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:54
const char * GetTokenText(T aTok)
The DSN namespace and returns the C string representing a SPECCTRA_DB::keyword.
Definition: specctra.cpp:70
#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