KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_pcad.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) 2025 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef SCH_IO_PCAD_H
21#define SCH_IO_PCAD_H
22
23#include <sch_io/sch_io.h>
24#include <sch_io/sch_io_mgr.h>
25
26#include <map>
27#include <memory>
28
29class SCH_SCREEN;
30class SCH_SHEET;
31class SCHEMATIC;
32class LIB_SYMBOL;
33
34namespace PCAD_SCH
35{
36struct SHEET;
37struct SCHEMATIC;
38}
39
40struct LIB_SYMBOL_STORE;
41
48class SCH_IO_PCAD : public SCH_IO
49{
50public:
53
55 {
56 return IO_BASE::IO_FILE_DESC( _HKI( "P-CAD schematic files" ), { "SCH", "sch" } );
57 }
58
60 {
61 return IO_BASE::IO_FILE_DESC( _HKI( "P-CAD schematic and library files" ),
62 { "SCH", "sch", "LIA", "lia" } );
63 }
64
65 bool CanReadSchematicFile( const wxString& aFileName ) const override;
66
67 bool CanReadLibrary( const wxString& aFileName ) const override;
68
69 int GetModifyHash() const override { return m_modifyHash; }
70
71 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
72 SCH_SHEET* aAppendToMe = nullptr,
73 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
74
75 // Library interface — P-CAD .SCH files embed symbol definitions, so we
76 // can expose them as a read-only symbol library.
77 void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
78 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
79
80 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
81 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
82
83 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aPartName,
84 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
85
86 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
87
88private:
89 static wxString getLibName( const ::SCHEMATIC* aSchematic, const wxString& aFileName );
90
93 void ensureLoadedLibrary( const wxString& aLibraryPath );
94
95 void populateScreen( SCH_SCREEN* aScreen, const PCAD_SCH::SHEET& aSheet,
96 const PCAD_SCH::SCHEMATIC& aPcad, double aPageH,
97 const LIB_SYMBOL_STORE& aLibSymbols, const wxString& aLibName );
98
99 wxString m_cachePath;
100 long long m_cacheTimestamp = 0;
102
103 std::map<wxString, std::unique_ptr<LIB_SYMBOL>> m_libCache;
104};
105
106#endif // SCH_IO_PCAD_H
Define a library symbol object.
Definition lib_symbol.h:80
Holds all the data relating to one schematic.
Definition schematic.h:90
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
Definition sch_io_pcad.h:59
wxString m_cachePath
Definition sch_io_pcad.h:99
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
int GetModifyHash() const override
Return the modification hash from the library cache.
Definition sch_io_pcad.h:69
static wxString getLibName(const ::SCHEMATIC *aSchematic, const wxString &aFileName)
long long m_cacheTimestamp
void ensureLoadedLibrary(const wxString &aLibraryPath)
Parse the library file once and serve cache-owned symbols, invalidated by path or file timestamp chan...
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
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,...
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
Definition sch_io_pcad.h:86
void populateScreen(SCH_SCREEN *aScreen, const PCAD_SCH::SHEET &aSheet, const PCAD_SCH::SCHEMATIC &aPcad, double aPageH, const LIB_SYMBOL_STORE &aLibSymbols, const wxString &aLibName)
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > m_libCache
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_IO.
Definition sch_io_pcad.h:54
SCH_IO(const wxString &aName)
Definition sch_io.h:375
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
#define _HKI(x)
Definition page_info.cpp:40
Container that describes file type info.
Definition io_base.h:43