40#include <wx/filename.h>
41#include <wx/textfile.h>
95 const std::map<std::string, UTF8>* aProperties =
nullptr )
override;
169 std::vector<GEDA_ATTR>
parseAttributes( wxTextFile& aFile,
size_t& aLineIdx );
172 wxString
findAttr(
const std::vector<GEDA_ATTR>& aAttrs,
const wxString& aName )
const;
176 const wxString& aName )
const;
185 void parseComponent(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
186 void parseNet(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
187 void parseBus(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
188 void parseText(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
189 void parseLine(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
190 void parseBox(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
191 void parseCircle(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
192 void parseArc(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
193 void parsePath(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
194 void parsePicture(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
195 void parsePin(
const wxString& aLine, wxTextFile& aFile,
size_t& aLineIdx );
216 std::unique_ptr<LIB_SYMBOL>
loadSymbolFile(
const wxString& aPath,
217 wxString* aSymversion =
nullptr,
218 wxString* aNetAttr =
nullptr );
226 int aWhichEnd,
const std::vector<GEDA_ATTR>& aAttrs );
230 size_t& aLineIdx, wxChar aType );
Define a library symbol object.
Holds all the data relating to one schematic.
std::unique_ptr< PENDING_COMPONENT > m_pendingComp
Pending component awaiting symbol resolution.
void addBusEntries()
Create SCH_BUS_WIRE_ENTRY objects where net endpoints touch bus segments.
void importHierarchicalSheet(const wxString &aSourceFile)
Import a gEDA hierarchical sub-schematic as a KiCad SCH_SHEET.
int toKiCadDist(int aMils) const
Convert a gEDA distance in mils to KiCad IU.
void addSymbolGraphic(LIB_SYMBOL &aSymbol, const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx, wxChar aType)
Add a graphical item (line/box/circle/arc/path) to a LIB_SYMBOL.
void parseBus(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
void fitPageToContent()
Enlarge the page if needed and center all content on the sheet.
std::vector< GEDA_ATTR > maybeParseAttributes(wxTextFile &aFile, size_t &aLineIdx)
Check for and consume a { } attribute block at the current line position.
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
bool m_symLibraryInitialized
const GEDA_ATTR * findAttrStruct(const std::vector< GEDA_ATTR > &aAttrs, const wxString &aName) const
Find a GEDA_ATTR struct by name, returns nullptr if not found.
void parseEmbeddedComponent(wxTextFile &aFile, size_t &aLineIdx)
void addJunctions()
Place junctions where 3+ net/pin endpoints coincide.
void parseNet(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
void postProcess()
Run the full post-processing pipeline after parsing is complete:
std::map< std::pair< int, int >, int > m_netEndpoints
Net endpoint positions in raw gEDA coordinates for junction detection.
int m_powerCounter
Sequential counter for auto-generated #PWR references.
static constexpr int MILS_TO_IU
gEDA coordinates are mils with Y-up.
int m_maxY
The maximum Y coordinate seen during parsing (gEDA coords, before flip).
std::vector< DEFERRED_SHEET > m_deferredSheets
std::unique_ptr< LIB_SYMBOL > loadBuiltinSymbol(const wxString &aBasename)
Try loading a symbol from the built-in standard library embedded in the importer.
LIB_SYMBOL * getOrLoadSymbol(const wxString &aBasename)
Get or load a cached symbol by gEDA basename.
void parseText(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
void parseComponent(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
void parsePin(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
void parseSymbolObjects(wxTextFile &aFile, size_t &aLineIdx, LIB_SYMBOL &aSymbol, size_t aEndLine)
Parse objects from a .sym file or [] block into a LIB_SYMBOL.
int toKiCadOrientation(int aAngle, int aMirror) const
Map gEDA angle (0/90/180/270) + mirror to KiCad symbol orientation.
void parseLine(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
void parseCircle(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > m_libSymbols
Loaded symbols for this import session, keyed by basename.
void parsePath(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
void scanSymbolDir(const wxString &aDir, int aDepth=0)
Recursively scan a directory for .sym files and populate m_symLibrary.
std::set< wxString > m_importStack
Set of fully-resolved file paths currently in the import call stack, used to detect and prevent circu...
wxString getLibName() const
Derive the KiCad import library name from the schematic file.
void flushPendingComponent()
Instantiate the pending component: look up or load the symbol, create SCH_SYMBOL, apply transforms an...
std::unique_ptr< LIB_SYMBOL > createFallbackSymbol(const wxString &aBasename)
Create a fallback rectangular symbol when the .sym file is not found.
static const std::map< wxString, wxString > & getBuiltinSymbols()
Return the map of built-in gEDA symbol definitions (symbol name -> .sym content).
VECTOR2I toKiCad(int aGedaX, int aGedaY) const
Apply the Y-flip and scale to transform gEDA coords to KiCad.
static LINE_STYLE toLineStyle(int aDashStyle)
Map gEDA dashstyle (0-4) to KiCad LINE_STYLE.
void parseBox(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
std::vector< NET_ATTR_RECORD > m_netAttrRecords
wxString findAttr(const std::vector< GEDA_ATTR > &aAttrs, const wxString &aName) const
Find an attribute by name, returns empty string if not found.
std::vector< BUS_SEGMENT > m_busSegments
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_IO.
void parseArc(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
int GetModifyHash() const override
Return the modification hash from the library cache.
std::unique_ptr< LIB_SYMBOL > loadSymbolFile(const wxString &aPath, wxString *aSymversion=nullptr, wxString *aNetAttr=nullptr)
Load a .sym file and return a LIB_SYMBOL.
void processNetAttributes()
For each component with net= attributes, create global labels at pin positions.
void initSymbolLibrary()
Ensure the symbol library hash is built by scanning gEDA library dirs.
std::map< wxString, SYM_CACHE_ENTRY > m_symLibrary
Symbol library cache: gEDA basename -> cache entry.
long m_releaseVersion
gEDA file version fields from the "v YYYYMMDD N" header line.
void parsePicture(const wxString &aLine, wxTextFile &aFile, size_t &aLineIdx)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void parseRcFileForLibraries(const wxString &aPath, const wxString &aBaseDir)
Parse an RC file (gafrc or gschemrc) for component-library directives.
void trackEndpoint(int aGedaX, int aGedaY)
Track a point as a net or pin endpoint for junction detection.
bool parseVersionLine(const wxString &aLine)
Parse the "v YYYYMMDD N" version line and validate.
std::vector< GEDA_ATTR > parseAttributes(wxTextFile &aFile, size_t &aLineIdx)
Read a { } attribute block starting after the '{' line.
const std::map< std::string, UTF8 > * m_properties
Properties passed from the import framework (search paths, etc.)
void addSymbolPin(LIB_SYMBOL &aSymbol, int aX1, int aY1, int aX2, int aY2, int aWhichEnd, const std::vector< GEDA_ATTR > &aAttrs)
Create a pin on a LIB_SYMBOL from gEDA P line data and its attributes.
void loadDeferredSheets()
Load sub-schematics for any SCH_SHEET objects created during parsing.
static FILL_T toFillType(int aFillType)
Map gEDA filltype (0-4) to KiCad FILL_T.
SCH_IO(const wxString &aName)
Segment description base class to describe items which have 2 end points (track, wire,...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
LINE_STYLE
Dashed line types.
Container that describes file type info.
Parsed bus segment in KiCad coordinates with gEDA ripper direction.
int ripperDir
-1, 0, or 1 from gEDA U line
Deferred hierarchical sheet loads.
wxString sourceFile
Resolved full path to the sub-schematic.
Parsed attribute from a gEDA T line inside a { } block.
int showNV
0=name+value, 1=value, 2=name
Components with net= attributes that need post-processing.
Pending component waiting for symbol resolution.
std::vector< GEDA_ATTR > attrs
std::unique_ptr< LIB_SYMBOL > embeddedSym
Entry in the symbol library search cache.
wxString symversion
symversion from the .sym file (if any)
wxString netAttr
net= attribute (e.g. "GND:1") identifying power symbols
std::unique_ptr< LIB_SYMBOL > symbol
Loaded symbol (null if not yet loaded)
wxString path
Full path to .sym file.
VECTOR2< int32_t > VECTOR2I