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 <[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 <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_SHAPE;
44 class LIB_ITEM;
45 class LIB_PIN;
46 class LIB_TEXT;
47 class PAGE_INFO;
48 class SCH_BITMAP;
49 class SCH_BUS_WIRE_ENTRY;
50 class SCH_SYMBOL;
51 class SCH_FIELD;
52 class SCH_JUNCTION;
53 class SCH_LINE;
54 class SCH_NO_CONNECT;
55 class SCH_SCREEN;
56 class SCH_SHEET;
57 class SCH_SHEET_PIN;
58 class SCH_TEXT;
59 class TITLE_BLOCK;
60 
61 
66 {
67 public:
69  COLOR4D m_Color;
70 };
71 
72 
76 class SCH_SEXPR_PARSER : public SCHEMATIC_LEXER
77 {
79  int m_fieldId;
80  int m_unit;
81  int m_convert;
82  wxString m_symbolName;
83 
85  std::set<int> m_fieldIDsRead;
86 
87  std::set<KIID> m_uuids;
88 
89  PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
90  const LINE_READER* m_lineReader; // for progress reporting
92  unsigned m_lineCount; // for progress reporting
93 
94  void checkpoint();
95 
96  KIID parseKIID();
97 
98  void parseHeader( TSCHEMATIC_T::T aHeaderType, int aFileVersion );
99 
100  inline long parseHex()
101  {
102  NextTok();
103  return strtol( CurText(), nullptr, 16 );
104  }
105 
106  inline int parseInt()
107  {
108  return (int)strtol( CurText(), nullptr, 10 );
109  }
110 
111  inline int parseInt( const char* aExpected )
112  {
113  NeedNUMBER( aExpected );
114  return parseInt();
115  }
116 
124  double parseDouble();
125 
126  inline double parseDouble( const char* aExpected )
127  {
128  NeedNUMBER( aExpected );
129  return parseDouble();
130  }
131 
132  inline double parseDouble( TSCHEMATIC_T::T aToken )
133  {
134  return parseDouble( GetTokenText( aToken ) );
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 
172  LIB_SHAPE* parseArc();
175  LIB_PIN* parsePin();
178  LIB_TEXT* parseText();
179 
180  void parsePAGE_INFO( PAGE_INFO& aPageInfo );
181  void parseTITLE_BLOCK( TITLE_BLOCK& aTitleBlock );
182  void parseSchSymbolInstances( SCH_SCREEN* aScreen );
183  void parseSchSheetInstances( SCH_SHEET* aRootSheet, SCH_SCREEN* aScreen );
184 
186  SCH_FIELD* parseSchField( SCH_ITEM* aParent );
193  SCH_LINE* parseLine();
195  void parseBusAlias( SCH_SCREEN* aScreen );
196 
197 public:
198  SCH_SEXPR_PARSER( LINE_READER* aLineReader = nullptr,
199  PROGRESS_REPORTER* aProgressReporter = nullptr, unsigned aLineCount = 0 );
200 
201  void ParseLib( LIB_SYMBOL_MAP& aSymbolLibMap );
202 
203  LIB_SYMBOL* ParseSymbol( LIB_SYMBOL_MAP& aSymbolLibMap,
204  int aFileVersion = SEXPR_SYMBOL_LIB_FILE_VERSION );
205 
207 
225  void ParseSchematic( SCH_SHEET* aSheet, bool aIsCopyablyOnly = false,
226  int aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION );
227 };
228 
229 #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
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)
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)
FILL_T
Definition: eda_shape.h:53
SCH_BUS_WIRE_ENTRY * parseBusEntry()
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:140
LIB_SHAPE * parsePolyLine()
Definition: kiid.h:44
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
LIB_SHAPE * parseCircle()
SCH_NO_CONNECT * parseNoConnect()
Definition for symbol library class.
int parseInternalUnits(TSCHEMATIC_T::T aToken)
double parseDouble(const char *aExpected)
LIB_SHAPE * parseArc()
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.
std::set< KIID > m_uuids
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)
std::set< int > m_fieldIDsRead
Field IDs that have been read so far for the current symbol.
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:140
double parseDouble(TSCHEMATIC_T::T aToken)
SCH_FIELD * parseSchField(SCH_ITEM *aParent)
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.
LIB_SHAPE * parseRectangle()
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
void parseStroke(STROKE_PARAMS &aStroke)
Parse stroke definition aStroke.
LIB_SHAPE * parseBezier()
PROGRESS_REPORTER * m_progressReporter
SCH_SHEET * parseSheet()