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 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Wayne Stambaugh <stambaughw@gmail.com>
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 <convert_to_biu.h> // IU_PER_MM
36 
37 #include <symbol_library.h>
38 #include <schematic_lexer.h>
39 #include <sch_file_versions.h>
40 #include <default_values.h> // For some default values
41 
42 
43 class LIB_ARC;
44 class LIB_BEZIER;
45 class LIB_CIRCLE;
46 class LIB_ITEM;
47 class LIB_PIN;
48 class LIB_POLYLINE;
49 class LIB_TEXT;
50 class PAGE_INFO;
51 class SCH_BITMAP;
52 class SCH_BUS_WIRE_ENTRY;
53 class SCH_SYMBOL;
54 class SCH_FIELD;
55 class SCH_JUNCTION;
56 class SCH_LINE;
57 class SCH_NO_CONNECT;
58 class SCH_SCREEN;
59 class SCH_SHEET;
60 class SCH_SHEET_PIN;
61 class SCH_TEXT;
62 class TITLE_BLOCK;
63 
64 
69 {
70 public:
72  COLOR4D m_Color;
73 };
74 
75 
79 class SCH_SEXPR_PARSER : public SCHEMATIC_LEXER
80 {
82  int m_fieldId;
83  int m_unit;
84  int m_convert;
85  wxString m_symbolName;
86 
87  PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
88  const LINE_READER* m_lineReader; // for progress reporting
90  unsigned m_lineCount; // for progress reporting
91 
92  void checkpoint();
93 
94  void parseHeader( TSCHEMATIC_T::T aHeaderType, int aFileVersion );
95 
96  inline long parseHex()
97  {
98  NextTok();
99  return strtol( CurText(), nullptr, 16 );
100  }
101 
102  inline int parseInt()
103  {
104  return (int)strtol( CurText(), nullptr, 10 );
105  }
106 
107  inline int parseInt( const char* aExpected )
108  {
109  NeedNUMBER( aExpected );
110  return parseInt();
111  }
112 
120  double parseDouble();
121 
122  inline double parseDouble( const char* aExpected )
123  {
124  NeedNUMBER( aExpected );
125  return parseDouble();
126  }
127 
128  inline double parseDouble( TSCHEMATIC_T::T aToken )
129  {
130  return parseDouble( GetTokenText( aToken ) );
131  }
132 
133  int parseInternalUnits();
134 
135  int parseInternalUnits( const char* aExpected );
136 
137  inline int parseInternalUnits( TSCHEMATIC_T::T aToken )
138  {
139  return parseInternalUnits( GetTokenText( aToken ) );
140  }
141 
142  inline wxPoint parseXY()
143  {
144  wxPoint xy;
145 
146  xy.x = parseInternalUnits( "X coordinate" );
147  xy.y = parseInternalUnits( "Y coordinate" );
148 
149  return xy;
150  }
151 
152  bool parseBool();
153 
159  void parseStroke( STROKE_PARAMS& aStroke );
160 
161  void parseFill( FILL_PARAMS& aFill );
162 
163  void parseEDA_TEXT( EDA_TEXT* aText, bool aConvertOverbarSyntax );
164  void parsePinNames( std::unique_ptr<LIB_SYMBOL>& aSymbol );
165 
166  LIB_FIELD* parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol );
167 
168  LIB_ARC* parseArc();
171  LIB_PIN* parsePin();
174  LIB_TEXT* parseText();
175 
176  void parsePAGE_INFO( PAGE_INFO& aPageInfo );
177  void parseTITLE_BLOCK( TITLE_BLOCK& aTitleBlock );
178  void parseSchSymbolInstances( SCH_SCREEN* aScreen );
179  void parseSchSheetInstances( SCH_SHEET* aRootSheet, SCH_SCREEN* aScreen );
180 
182  SCH_FIELD* parseSchField( SCH_ITEM* aParent );
189  SCH_LINE* parseLine();
191  void parseBusAlias( SCH_SCREEN* aScreen );
192 
193 public:
194  SCH_SEXPR_PARSER( LINE_READER* aLineReader = nullptr,
195  PROGRESS_REPORTER* aProgressReporter = nullptr, unsigned aLineCount = 0 );
196 
197  void ParseLib( LIB_SYMBOL_MAP& aSymbolLibMap );
198 
199  LIB_SYMBOL* ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap,
200  int aFileVersion = SEXPR_SYMBOL_LIB_FILE_VERSION );
201 
203 
221  void ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyablyOnly = false,
222  int aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION );
223 };
224 
225 #endif // __SCH_SEXPR_PARSER_H__
int m_fieldId
The current field ID.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
LIB_FIELD * parseProperty(std::unique_ptr< LIB_SYMBOL > &aSymbol)
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
Symbol map used by symbol library object.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:80
FILL_TYPE
The set of fill types used in plotting or drawing enclosed areas.
Definition: fill_type.h:28
Define a symbol library graphical text item.
Definition: lib_text.h:39
SCH_SHEET_PIN * parseSchSheetPin(SCH_SHEET *aSheet)
A progress reporter interface for use in multi-threaded environments.
void parseBusAlias(SCH_SCREEN *aScreen)
void parseEDA_TEXT(EDA_TEXT *aText, bool aConvertOverbarSyntax)
LIB_POLYLINE * parsePolyLine()
Field object used in symbol libraries.
Definition: lib_field.h:59
unsigned m_lastProgressLine
LIB_SYMBOL * ParseSymbol(LIB_SYMBOL_MAP &aSymbolLibMap, int aFileVersion=SEXPR_SYMBOL_LIB_FILE_VERSION)
int m_unit
The current unit being parsed.
void parseTITLE_BLOCK(TITLE_BLOCK &aTitleBlock)
#define SEXPR_SYMBOL_LIB_FILE_VERSION
This file contains the file format version information for the s-expression schematic and symbol libr...
SCH_SYMBOL * parseSchematicSymbol()
Define a library symbol object.
Definition: lib_symbol.h:96
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
void parseSchSheetInstances(SCH_SHEET *aRootSheet, SCH_SCREEN *aScreen)
void parseSchSymbolInstances(SCH_SCREEN *aScreen)
SCH_BUS_WIRE_ENTRY * parseBusEntry()
LIB_RECTANGLE * parseRectangle()
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
FILL_TYPE m_FillType
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
Simple container to manage fill parameters.
void parseHeader(TSCHEMATIC_T::T aHeaderType, int aFileVersion)
void ParseLib(LIB_SYMBOL_MAP &aSymbolLibMap)
wxString m_symbolName
The current symbol name.
SCH_JUNCTION * parseJunction()
int m_convert
The current body style being parsed.
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
SCH_NO_CONNECT * parseNoConnect()
LIB_BEZIER * parseBezier()
Definition for symbol library class.
int parseInternalUnits(TSCHEMATIC_T::T aToken)
double parseDouble(const char *aExpected)
const LINE_READER * m_lineReader
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
Object to parser s-expression symbol library and schematic file formats.
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:40
SCH_SEXPR_PARSER(LINE_READER *aLineReader=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr, unsigned aLineCount=0)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
LIB_ITEM * ParseDrawItem()
void parsePAGE_INFO(PAGE_INFO &aPageInfo)
Schematic symbol object.
Definition: sch_symbol.h:78
int m_requiredVersion
Set to the symbol library file version required.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
SCH_BITMAP * parseImage()
void parsePinNames(std::unique_ptr< LIB_SYMBOL > &aSymbol)
Simple container to manage line stroke parameters.
Definition: sch_item.h:151
double parseDouble(TSCHEMATIC_T::T aToken)
SCH_FIELD * parseSchField(SCH_ITEM *aParent)
LIB_CIRCLE * parseCircle()
void parseFill(FILL_PARAMS &aFill)
const char * GetTokenText(T aTok)
The DSN namespace and returns the C string representing a SPECCTRA_DB::keyword.
Definition: specctra.cpp:70
void ParseSchematic(SCH_SHEET *aSheet, bool aIsCopyablyOnly=false, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
Parse the internal LINE_READER object into aSheet.
Class for a wire to bus entry.
SCH_TEXT * parseSchText()
double parseDouble()
Parse the current token as an ASCII numeric string with possible leading whitespace into a double pre...
int parseInt(const char *aExpected)
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:193
void parseStroke(STROKE_PARAMS &aStroke)
Parse stroke definition aStroke.
PROGRESS_REPORTER * m_progressReporter
Define a bezier curve graphic body item.
Definition: lib_bezier.h:34
SCH_SHEET * parseSheet()