KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SCH_IO_KICAD_SEXPR_PARSER Class Reference

Object to parser s-expression symbol library and schematic file formats. More...

#include <sch_io_kicad_sexpr_parser.h>

Inheritance diagram for SCH_IO_KICAD_SEXPR_PARSER:

Public Member Functions

 SCH_IO_KICAD_SEXPR_PARSER (LINE_READER *aLineReader=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr, unsigned aLineCount=0, SCH_SHEET *aRootSheet=nullptr, bool aIsAppending=false)
 
void ParseLib (LIB_SYMBOL_MAP &aSymbolLibMap)
 
LIB_SYMBOLParseSymbol (LIB_SYMBOL_MAP &aSymbolLibMap, int aFileVersion=SEXPR_SYMBOL_LIB_FILE_VERSION)
 Parse internal LINE_READER object into symbols and return all found.
 
SCH_ITEMParseSymbolDrawItem ()
 
void ParseSchematic (SCH_SHEET *aSheet, bool aIsCopyablyOnly=false, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
 Parse the internal LINE_READER object into aSheet.
 
int GetParsedRequiredVersion () const
 

Private Member Functions

void checkpoint ()
 
KIID parseKIID ()
 
void parseHeader (TSCHEMATIC_T::T aHeaderType, int aFileVersion)
 
long parseHex ()
 
int parseInt ()
 
int parseInt (const char *aExpected)
 
int parseInternalUnits ()
 
int parseInternalUnits (const char *aExpected)
 
int parseInternalUnits (TSCHEMATIC_T::T aToken)
 
VECTOR2I parseXY (bool aInvertY=false)
 
bool parseBool ()
 
bool parseMaybeAbsentBool (bool aDefaultValue)
 Parses a boolean flag inside a list that existed before boolean normalization.
 
LIB_SYMBOLparseLibSymbol (LIB_SYMBOL_MAP &aSymbolLibMap)
 
void parseStroke (STROKE_PARAMS &aStroke)
 Parse stroke definition aStroke.
 
void parseFill (FILL_PARAMS &aFill)
 
void parseMargins (int &aLeft, int &aTop, int &aRight, int &aBottom)
 
void parseEDA_TEXT (EDA_TEXT *aText, bool aConvertOverbarSyntax, bool aEnforceMinTextSize=true)
 
void parsePinNames (std::unique_ptr< LIB_SYMBOL > &aSymbol)
 
void parsePinNumbers (std::unique_ptr< LIB_SYMBOL > &aSymbol)
 
SCH_FIELDparseProperty (std::unique_ptr< LIB_SYMBOL > &aSymbol)
 
SCH_SHAPEparseSymbolArc ()
 
SCH_SHAPEparseSymbolBezier ()
 
SCH_SHAPEparseSymbolCircle ()
 
SCH_PINparseSymbolPin ()
 
SCH_SHAPEparseSymbolPolyLine ()
 
SCH_SHAPEparseSymbolRectangle ()
 
SCH_TEXTparseSymbolText ()
 
SCH_TEXTBOXparseSymbolTextBox ()
 
void parsePAGE_INFO (PAGE_INFO &aPageInfo)
 
void parseTITLE_BLOCK (TITLE_BLOCK &aTitleBlock)
 
void parseSchSymbolInstances (SCH_SCREEN *aScreen)
 
void parseSchSheetInstances (SCH_SHEET *aRootSheet, SCH_SCREEN *aScreen)
 
SCH_SHEET_PINparseSchSheetPin (SCH_SHEET *aSheet)
 
SCH_FIELDparseSchField (SCH_ITEM *aParent)
 
SCH_SYMBOLparseSchematicSymbol ()
 
SCH_BITMAPparseImage ()
 
SCH_SHEETparseSheet ()
 
SCH_JUNCTIONparseJunction ()
 
SCH_NO_CONNECTparseNoConnect ()
 
SCH_BUS_WIRE_ENTRYparseBusEntry ()
 
SCH_LINEparseLine ()
 
SCH_SHAPEparseSchPolyLine ()
 
SCH_SHAPEparseSchArc ()
 
SCH_SHAPEparseSchCircle ()
 
SCH_SHAPEparseSchRectangle ()
 
SCH_SHAPEparseSchBezier ()
 
SCH_RULE_AREAparseSchRuleArea ()
 
SCH_TEXTparseSchText ()
 
SCH_TEXTBOXparseSchTextBox ()
 
void parseSchTextBoxContent (SCH_TEXTBOX *aTextBox)
 
SCH_TABLECELLparseSchTableCell ()
 
SCH_TABLEparseSchTable ()
 
void parseBusAlias (SCH_SCREEN *aScreen)
 
void removeEntryInFontTextMap (EDA_TEXT *aEntry, EDA_TEXT *aCandidate, bool aReplaceInList)
 Remove aEntry from m_fontTextMap.
 

Private Attributes

int m_requiredVersion
 Set to the symbol library file version required.
 
wxString m_generatorVersion
 
int m_unit
 The current unit being parsed.
 
int m_bodyStyle
 The current body style being parsed.
 
wxString m_symbolName
 The current symbol name.
 
bool m_appending
 Appending load status.
 
std::set< int > m_fieldIDsRead
 Field IDs that have been read so far for the current symbol.
 
std::set< KIIDm_uuids
 
std::map< EDA_TEXT *, std::tuple< wxString, bool, bool > > m_fontTextMap
 
PROGRESS_REPORTERm_progressReporter
 
const LINE_READERm_lineReader
 
unsigned m_lastProgressLine
 
unsigned m_lineCount
 
KIID m_rootUuid
 
SCH_SHEETm_rootSheet
 The rootsheet for full project loads or null for importing a schematic.
 

Detailed Description

Object to parser s-expression symbol library and schematic file formats.

Definition at line 76 of file sch_io_kicad_sexpr_parser.h.

Constructor & Destructor Documentation

◆ SCH_IO_KICAD_SEXPR_PARSER()

SCH_IO_KICAD_SEXPR_PARSER::SCH_IO_KICAD_SEXPR_PARSER ( LINE_READER aLineReader = nullptr,
PROGRESS_REPORTER aProgressReporter = nullptr,
unsigned  aLineCount = 0,
SCH_SHEET aRootSheet = nullptr,
bool  aIsAppending = false 
)

Definition at line 75 of file sch_io_kicad_sexpr_parser.cpp.

Member Function Documentation

◆ checkpoint()

◆ GetParsedRequiredVersion()

int SCH_IO_KICAD_SEXPR_PARSER::GetParsedRequiredVersion ( ) const
inline

Definition at line 113 of file sch_io_kicad_sexpr_parser.h.

References m_requiredVersion.

Referenced by SCH_IO_KICAD_SEXPR_LIB_CACHE::Load().

◆ parseBool()

◆ parseBusAlias()

void SCH_IO_KICAD_SEXPR_PARSER::parseBusAlias ( SCH_SCREEN aScreen)
private

◆ parseBusEntry()

◆ parseEDA_TEXT()

◆ parseFill()

◆ parseHeader()

void SCH_IO_KICAD_SEXPR_PARSER::parseHeader ( TSCHEMATIC_T::T  aHeaderType,
int  aFileVersion 
)
private

Definition at line 831 of file sch_io_kicad_sexpr_parser.cpp.

References m_requiredVersion, and parseInt().

Referenced by ParseLib(), and ParseSchematic().

◆ parseHex()

long SCH_IO_KICAD_SEXPR_PARSER::parseHex ( )
inlineprivate

Definition at line 122 of file sch_io_kicad_sexpr_parser.h.

◆ parseImage()

◆ parseInt() [1/2]

◆ parseInt() [2/2]

int SCH_IO_KICAD_SEXPR_PARSER::parseInt ( const char *  aExpected)
inlineprivate

Definition at line 133 of file sch_io_kicad_sexpr_parser.h.

References parseInt().

◆ parseInternalUnits() [1/3]

◆ parseInternalUnits() [2/3]

int SCH_IO_KICAD_SEXPR_PARSER::parseInternalUnits ( const char *  aExpected)
private

◆ parseInternalUnits() [3/3]

int SCH_IO_KICAD_SEXPR_PARSER::parseInternalUnits ( TSCHEMATIC_T::T  aToken)
inlineprivate

Definition at line 143 of file sch_io_kicad_sexpr_parser.h.

References parseInternalUnits().

◆ parseJunction()

SCH_JUNCTION * SCH_IO_KICAD_SEXPR_PARSER::parseJunction ( )
private

◆ parseKIID()

◆ ParseLib()

◆ parseLibSymbol()

◆ parseLine()

SCH_LINE * SCH_IO_KICAD_SEXPR_PARSER::parseLine ( )
private

◆ parseMargins()

void SCH_IO_KICAD_SEXPR_PARSER::parseMargins ( int &  aLeft,
int &  aTop,
int &  aRight,
int &  aBottom 
)
inlineprivate

Definition at line 184 of file sch_io_kicad_sexpr_parser.h.

References parseInternalUnits().

Referenced by parseSchTextBoxContent(), and parseSymbolTextBox().

◆ parseMaybeAbsentBool()

bool SCH_IO_KICAD_SEXPR_PARSER::parseMaybeAbsentBool ( bool  aDefaultValue)
private

Parses a boolean flag inside a list that existed before boolean normalization.

For example, this will handle both (legacy_teardrops) and (legacy_teardrops yes). Call this after parsing the T_legacy_teardrops, and aDefaultValue will be returned for the first case, or true will be returned for the second case.

Parameters
aDefaultValuewill be returned if the end of the list is encountered as the next token
Returns
the parsed boolean

Definition at line 146 of file sch_io_kicad_sexpr_parser.cpp.

References DSN_RIGHT.

Referenced by parseEDA_TEXT(), parseProperty(), parseSchematicSymbol(), parseSchField(), parseSchText(), and parseSheet().

◆ parseNoConnect()

SCH_NO_CONNECT * SCH_IO_KICAD_SEXPR_PARSER::parseNoConnect ( )
private

Definition at line 3702 of file sch_io_kicad_sexpr_parser.cpp.

References parseKIID(), and parseXY().

Referenced by ParseSchematic().

◆ parsePAGE_INFO()

◆ parsePinNames()

void SCH_IO_KICAD_SEXPR_PARSER::parsePinNames ( std::unique_ptr< LIB_SYMBOL > &  aSymbol)
private

(pin_names (offset 123) ; optional (hide yes/no) ; optional hide ; optional, pre-20241004 )

Definition at line 852 of file sch_io_kicad_sexpr_parser.cpp.

References parseBool(), and parseInternalUnits().

Referenced by parseLibSymbol().

◆ parsePinNumbers()

void SCH_IO_KICAD_SEXPR_PARSER::parsePinNumbers ( std::unique_ptr< LIB_SYMBOL > &  aSymbol)
private

(pin_numbers (hide yes/no) ; optional hide ; optional (pre-20241004) )

Definition at line 900 of file sch_io_kicad_sexpr_parser.cpp.

References parseBool().

Referenced by parseLibSymbol().

◆ parseProperty()

◆ parseSchArc()

SCH_SHAPE * SCH_IO_KICAD_SEXPR_PARSER::parseSchArc ( )
private

◆ parseSchBezier()

SCH_SHAPE * SCH_IO_KICAD_SEXPR_PARSER::parseSchBezier ( )
private

◆ parseSchCircle()

◆ ParseSchematic()

void SCH_IO_KICAD_SEXPR_PARSER::ParseSchematic ( SCH_SHEET aSheet,
bool  aIsCopyablyOnly = false,
int  aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION 
)

Parse the internal LINE_READER object into aSheet.

When aIsCopyableOnly is true, only schematic objects that are viewable on the canvas for copy and paste purposes are parsed. Other schematic content such as bus definitions or instance data will throw an IO_ERROR exception.

When aIsCopyableOnly is false, full schematic file parsing is performed.

Note
This does not load any sub-sheets or decent complex sheet hierarchies.
Parameters
aSheetThe SCH_SHEET object to store the parsed schematic file.
aIsCopyableOnlyLoad only the schematic objects that can be copied into aSheet if true. Otherwise, load the full schematic file format.
aFileVersionThe schematic file version to parser. Defaults to the schematic file being parsed when aIsCopyableOnly is false.

Definition at line 2571 of file sch_io_kicad_sexpr_parser.cpp.

References _, SCH_SCREEN::AddLibSymbol(), SCH_SCREEN::Append(), checkpoint(), SHAPE_LINE_CHAIN::CPoint(), SCH_SCREEN::FixupEmbeddedData(), Fontconfig(), SCHEMATIC::GetEmbeddedFiles(), KIFONT::FONT::GetFont(), EMBEDDED_FILES::GetFontFiles(), EDA_SHAPE::GetPointCount(), EDA_SHAPE::GetPolyShape(), SCH_SHEET::GetScreen(), SCH_SHAPE::GetStroke(), SCH_SCREEN::GetUuid(), KI_FALLTHROUGH, LAYER_NOTES, m_fontTextMap, m_generatorVersion, m_requiredVersion, m_rootSheet, m_rootUuid, SCH_SCREEN::m_uuid, EDA_ITEM::m_Uuid, SHAPE_POLY_SET::Outline(), parseBool(), parseBusAlias(), parseBusEntry(), EMBEDDED_FILES_PARSER::ParseEmbedded(), parseHeader(), parseImage(), parseJunction(), parseKIID(), parseLibSymbol(), parseLine(), parseNoConnect(), parsePAGE_INFO(), parseSchArc(), parseSchBezier(), parseSchCircle(), parseSchematicSymbol(), parseSchPolyLine(), parseSchRectangle(), parseSchRuleArea(), parseSchSheetInstances(), parseSchSymbolInstances(), parseSchTable(), parseSchText(), parseSchTextBox(), parseSheet(), parseTITLE_BLOCK(), Pgm(), SCH_SCREEN::Schematic(), EMBEDDED_FILES::SetAreFontsEmbedded(), SCH_LINE::SetEndPoint(), SCH_SCREEN::SetFileFormatVersionAtLoad(), SCH_SCREEN::SetLegacySymbolInstanceData(), SCH_SCREEN::SetPageSettings(), EDA_ITEM::SetParent(), SCH_LINE::SetStartPoint(), SCH_LINE::SetStroke(), SCH_SCREEN::SetTitleBlock(), SEXPR_SCHEMATIC_FILE_VERSION, text, THROW_PARSE_ERROR, LIB_SYMBOL::UpdateFieldOrdinals(), EMBEDDED_FILES::UpdateFontFiles(), SCH_SCREEN::UpdateLocalLibSymbolLinks(), and IO_ERROR::What().

Referenced by SCH_IO_KICAD_SEXPR::LoadContent(), SCH_IO_KICAD_SEXPR::loadFile(), and KI_TEST::LoadSheetSchematicContents().

◆ parseSchematicSymbol()

◆ parseSchField()

◆ parseSchPolyLine()

◆ parseSchRectangle()

SCH_SHAPE * SCH_IO_KICAD_SEXPR_PARSER::parseSchRectangle ( )
private

◆ parseSchRuleArea()

SCH_RULE_AREA * SCH_IO_KICAD_SEXPR_PARSER::parseSchRuleArea ( )
private

◆ parseSchSheetInstances()

◆ parseSchSheetPin()

SCH_SHEET_PIN * SCH_IO_KICAD_SEXPR_PARSER::parseSchSheetPin ( SCH_SHEET aSheet)
private

◆ parseSchSymbolInstances()

◆ parseSchTable()

SCH_TABLE * SCH_IO_KICAD_SEXPR_PARSER::parseSchTable ( )
private

◆ parseSchTableCell()

SCH_TABLECELL * SCH_IO_KICAD_SEXPR_PARSER::parseSchTableCell ( )
private

Definition at line 4411 of file sch_io_kicad_sexpr_parser.cpp.

References parseSchTextBoxContent().

Referenced by parseSchTable().

◆ parseSchText()

◆ parseSchTextBox()

SCH_TEXTBOX * SCH_IO_KICAD_SEXPR_PARSER::parseSchTextBox ( )
private

Definition at line 4398 of file sch_io_kicad_sexpr_parser.cpp.

References parseSchTextBoxContent().

Referenced by ParseSchematic().

◆ parseSchTextBoxContent()

◆ parseSheet()

◆ parseStroke()

◆ ParseSymbol()

LIB_SYMBOL * SCH_IO_KICAD_SEXPR_PARSER::ParseSymbol ( LIB_SYMBOL_MAP aSymbolLibMap,
int  aFileVersion = SEXPR_SYMBOL_LIB_FILE_VERSION 
)

◆ parseSymbolArc()

◆ parseSymbolBezier()

◆ parseSymbolCircle()

◆ ParseSymbolDrawItem()

◆ parseSymbolPin()

◆ parseSymbolPolyLine()

◆ parseSymbolRectangle()

◆ parseSymbolText()

SCH_TEXT * SCH_IO_KICAD_SEXPR_PARSER::parseSymbolText ( )
private

◆ parseSymbolTextBox()

◆ parseTITLE_BLOCK()

void SCH_IO_KICAD_SEXPR_PARSER::parseTITLE_BLOCK ( TITLE_BLOCK aTitleBlock)
private

◆ parseXY()

◆ removeEntryInFontTextMap()

void SCH_IO_KICAD_SEXPR_PARSER::removeEntryInFontTextMap ( EDA_TEXT aEntry,
EDA_TEXT aCandidate,
bool  aReplaceInList 
)
private

Remove aEntry from m_fontTextMap.

If aCandidate is not null, set the aCandidate font from the font of aEntry if aReplaceInList is true, aCandidate will replace aEntry in m_fontTextMap

Definition at line 4739 of file sch_io_kicad_sexpr_parser.cpp.

References KIFONT::FONT::GetFont(), m_fontTextMap, and EDA_TEXT::SetFont().

Referenced by parseSchematicSymbol(), parseSchText(), and parseSheet().

Member Data Documentation

◆ m_appending

bool SCH_IO_KICAD_SEXPR_PARSER::m_appending
private

Appending load status.

Definition at line 248 of file sch_io_kicad_sexpr_parser.h.

Referenced by parseSchSheetInstances(), and parseSchSymbolInstances().

◆ m_bodyStyle

int SCH_IO_KICAD_SEXPR_PARSER::m_bodyStyle
private

◆ m_fieldIDsRead

std::set<int> SCH_IO_KICAD_SEXPR_PARSER::m_fieldIDsRead
private

Field IDs that have been read so far for the current symbol.

Definition at line 251 of file sch_io_kicad_sexpr_parser.h.

Referenced by parseLibSymbol(), parseProperty(), and parseSchematicSymbol().

◆ m_fontTextMap

std::map<EDA_TEXT*, std::tuple<wxString, bool, bool> > SCH_IO_KICAD_SEXPR_PARSER::m_fontTextMap
private

◆ m_generatorVersion

wxString SCH_IO_KICAD_SEXPR_PARSER::m_generatorVersion
private

Definition at line 244 of file sch_io_kicad_sexpr_parser.h.

Referenced by ParseLib(), and ParseSchematic().

◆ m_lastProgressLine

unsigned SCH_IO_KICAD_SEXPR_PARSER::m_lastProgressLine
private

Definition at line 259 of file sch_io_kicad_sexpr_parser.h.

Referenced by checkpoint().

◆ m_lineCount

unsigned SCH_IO_KICAD_SEXPR_PARSER::m_lineCount
private

Definition at line 260 of file sch_io_kicad_sexpr_parser.h.

Referenced by checkpoint().

◆ m_lineReader

const LINE_READER* SCH_IO_KICAD_SEXPR_PARSER::m_lineReader
private

Definition at line 258 of file sch_io_kicad_sexpr_parser.h.

Referenced by checkpoint().

◆ m_progressReporter

PROGRESS_REPORTER* SCH_IO_KICAD_SEXPR_PARSER::m_progressReporter
private

Definition at line 257 of file sch_io_kicad_sexpr_parser.h.

Referenced by checkpoint().

◆ m_requiredVersion

int SCH_IO_KICAD_SEXPR_PARSER::m_requiredVersion
private

◆ m_rootSheet

SCH_SHEET* SCH_IO_KICAD_SEXPR_PARSER::m_rootSheet
private

The rootsheet for full project loads or null for importing a schematic.

Definition at line 265 of file sch_io_kicad_sexpr_parser.h.

Referenced by ParseSchematic().

◆ m_rootUuid

KIID SCH_IO_KICAD_SEXPR_PARSER::m_rootUuid
private

◆ m_symbolName

wxString SCH_IO_KICAD_SEXPR_PARSER::m_symbolName
private

The current symbol name.

Definition at line 247 of file sch_io_kicad_sexpr_parser.h.

Referenced by parseLibSymbol().

◆ m_unit

int SCH_IO_KICAD_SEXPR_PARSER::m_unit
private

◆ m_uuids

std::set<KIID> SCH_IO_KICAD_SEXPR_PARSER::m_uuids
private

Definition at line 253 of file sch_io_kicad_sexpr_parser.h.

Referenced by parseKIID().


The documentation for this class was generated from the following files: