KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
89 LIB_SYMBOL* ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap,
90 int aFileVersion = SEXPR_SYMBOL_LIB_FILE_VERSION );
91
93
111 void ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyablyOnly = false,
112 int aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION );
113
115
116private:
117 void checkpoint();
118
119 KIID parseKIID();
120
121 void parseHeader( TSCHEMATIC_T::T aHeaderType, int aFileVersion );
122
123 inline long parseHex()
124 {
125 NextTok();
126 return strtol( CurText(), nullptr, 16 );
127 }
128
129 inline int parseInt()
130 {
131 return (int)strtol( CurText(), nullptr, 10 );
132 }
133
134 inline int parseInt( const char* aExpected )
135 {
136 NeedNUMBER( aExpected );
137 return parseInt();
138 }
139
140 int parseInternalUnits();
141
142 int parseInternalUnits( const char* aExpected );
143
144 inline int parseInternalUnits( TSCHEMATIC_T::T aToken )
145 {
146 return parseInternalUnits( GetTokenText( aToken ) );
147 }
148
150 {
151 VECTOR2I xy;
152
153 xy.x = parseInternalUnits( "X coordinate" );
154 xy.y = parseInternalUnits( "Y coordinate" );
155
156 return xy;
157 }
158
159 bool parseBool();
160
161 LIB_SYMBOL* parseLibSymbol( LIB_SYMBOL_MAP& aSymbolLibMap );
162
168 void parseStroke( STROKE_PARAMS& aStroke );
169
170 void parseFill( FILL_PARAMS& aFill );
171
172 void parseEDA_TEXT( EDA_TEXT* aText, bool aConvertOverbarSyntax );
173 void parsePinNames( std::unique_ptr<LIB_SYMBOL>& aSymbol );
174
175 LIB_FIELD* parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol );
176
180 LIB_PIN* parsePin();
185
186 void parsePAGE_INFO( PAGE_INFO& aPageInfo );
187 void parseTITLE_BLOCK( TITLE_BLOCK& aTitleBlock );
188 void parseSchSymbolInstances( SCH_SCREEN* aScreen );
189 void parseSchSheetInstances( SCH_SHEET* aRootSheet, SCH_SCREEN* aScreen );
190
192 SCH_FIELD* parseSchField( SCH_ITEM* aParent );
207 void parseBusAlias( SCH_SCREEN* aScreen );
208
210 int m_unit;
212 wxString m_symbolName;
214
216 std::set<int> m_fieldIDsRead;
217
218 std::set<KIID> m_uuids;
219
220 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
221 const LINE_READER* m_lineReader; // for progress reporting
223 unsigned m_lineCount; // for progress reporting
224
225 KIID m_rootUuid; // The UUID of the root schematic.
226
229};
230
231#endif // __SCH_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
Field object used in symbol libraries.
Definition: lib_field.h:62
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
Define a library symbol object.
Definition: lib_symbol.h:99
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:93
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
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:52
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:150
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()
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()
LIB_SYMBOL * parseLibSymbol(LIB_SYMBOL_MAP &aSymbolLibMap)
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_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)
Parse internal LINE_READER object into symbols and return all found.
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:57
Schematic symbol object.
Definition: sch_symbol.h:81
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