LibrePCB Developers Documentation
kicadlibraryimport.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (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
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_KICADIMPORT_KICADLIBRARYIMPORT_H
21#define LIBREPCB_KICADIMPORT_KICADLIBRARYIMPORT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
28
29#include <QtCore>
30
31#include <memory>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37
38class MessageLogger;
39class WorkspaceLibraryDb;
40
41namespace kicadimport {
42
43class KiCadLibraryConverterSettings;
44
45/*******************************************************************************
46 * Class KiCadLibraryImport
47 ******************************************************************************/
48
52class KiCadLibraryImport final : public QObject {
53 Q_OBJECT
54
55public:
56 enum class State {
57 Reset,
58 Scanning,
59 Scanned,
60 Parsing,
61 Parsed,
62 Importing,
63 Imported,
64 };
65
66 struct Gate {
67 int index; // As specified in KiCad symbol.
68 QString symGeneratedBy; // Symbol "generated_by" property.
70 };
71
72 struct Symbol {
73 QString name;
74 QString cmpGeneratedBy; // Component "generated_by" property.
75 QString devGeneratedBy; // Device "generated_by" property.
76 QString pkgGeneratedBy; // Package "generated_by" property (optional).
80 QString extends;
81 QList<Gate> gates;
82 Qt::CheckState symChecked;
83 Qt::CheckState cmpChecked;
84 Qt::CheckState devChecked;
85 };
86
89 QList<Symbol> symbols;
90 };
91
92 struct Footprint {
94 QString name;
95 QString generatedBy; // To be set as "generated_by" property.
97 Qt::CheckState checked;
98 };
99
102 QList<FilePath> files;
103 QList<Footprint> footprints;
104 };
105
108 QList<FilePath> stepFiles;
109 };
110
111 struct Result {
112 QList<SymbolLibrary> symbolLibs;
113 QList<FootprintLibrary> footprintLibs;
114 QList<Package3DLibrary> package3dLibs;
115 int fileCount = 0;
116 };
117
118 // Constructors / Destructor
121 QObject* parent = nullptr) noexcept;
122 ~KiCadLibraryImport() noexcept;
123
124 // Getters
125 State getState() const noexcept { return mState; }
126 const FilePath& getLoadedLibsPath() const noexcept { return mLoadedLibsFp; }
127 const FilePath& getLoadedShapes3dPath() const noexcept {
128 return mLoadedShapes3dFp;
129 }
130 bool canStartParsing() const noexcept;
131 bool canStartSelecting() const noexcept;
132 bool canStartImport() const noexcept;
133
134 // Setters
135 void setNamePrefix(const QString& prefix) noexcept;
136 void setSymbolCategories(const QSet<Uuid>& uuids) noexcept;
137 void setPackageCategories(const QSet<Uuid>& uuids) noexcept;
138 void setComponentCategories(const QSet<Uuid>& uuids) noexcept;
139 void setDeviceCategories(const QSet<Uuid>& uuids) noexcept;
140 void setSymbolChecked(const QString& libName, const QString& symName,
141 bool checked) noexcept;
142 void setPackageChecked(const QString& libName, const QString& fptName,
143 bool checked) noexcept;
144 void setComponentChecked(const QString& libName, const QString& symName,
145 bool checked) noexcept;
146 void setDeviceChecked(const QString& libName, const QString& symName,
147 bool checked) noexcept;
148
149 // General Methods
150 void reset() noexcept;
151 bool startScan(const FilePath& libsFp, const FilePath& shapes3dFp,
152 std::shared_ptr<MessageLogger> log) noexcept;
153 bool startParse(std::shared_ptr<MessageLogger> log) noexcept;
154 bool startImport(std::shared_ptr<MessageLogger> log) noexcept;
155 bool isRunning() const noexcept;
156 std::shared_ptr<Result> getResult() noexcept;
157 void cancel() noexcept;
158
159 // Operator Overloadings
160 KiCadLibraryImport& operator=(const KiCadLibraryImport& rhs) = delete;
161
162signals:
163 void symbolCheckStateChanged(const QString& libName, const QString& symName,
164 Qt::CheckState state);
165 void packageCheckStateChanged(const QString& libName, const QString& fptName,
166 Qt::CheckState state);
167 void componentCheckStateChanged(const QString& libName,
168 const QString& symName, Qt::CheckState state);
169 void progressPercent(int percent);
170 void progressStatus(QString status);
174
175private:
176 std::shared_ptr<Result> scan(FilePath libsFp, const FilePath& shapes3dFp,
177 std::shared_ptr<MessageLogger> log) noexcept;
178 std::shared_ptr<Result> parse(std::shared_ptr<Result> result,
179 std::shared_ptr<MessageLogger> log) noexcept;
180 std::shared_ptr<Result> import(std::shared_ptr<Result> result,
181 std::shared_ptr<MessageLogger> log) noexcept;
182 template <typename T>
183 bool isAlreadyImported(const QString& generatedBy) const noexcept;
184 void updateDependencies(std::shared_ptr<Result> result) noexcept;
185
191 QFuture<std::shared_ptr<Result>> mFuture;
193 bool mAbort;
194};
195
196/*******************************************************************************
197 * End of File
198 ******************************************************************************/
199
200} // namespace kicadimport
201} // namespace librepcb
202
203#endif
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:129
Generic logger class to pass messages between objects.
Definition: messagelogger.h:43
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:58
KiCad library import.
Definition: kicadlibraryimport.h:52
bool canStartSelecting() const noexcept
Definition: kicadlibraryimport.cpp:139
void setComponentChecked(const QString &libName, const QString &symName, bool checked) noexcept
Definition: kicadlibraryimport.cpp:273
void setPackageChecked(const QString &libName, const QString &fptName, bool checked) noexcept
Definition: kicadlibraryimport.cpp:250
const FilePath & getLoadedShapes3dPath() const noexcept
Definition: kicadlibraryimport.h:127
void reset() noexcept
Definition: kicadlibraryimport.cpp:323
void packageCheckStateChanged(const QString &libName, const QString &fptName, Qt::CheckState state)
void cancel() noexcept
Definition: kicadlibraryimport.cpp:404
void setPackageCategories(const QSet< Uuid > &uuids) noexcept
Definition: kicadlibraryimport.cpp:213
bool mAbort
Definition: kicadlibraryimport.h:193
WorkspaceLibraryDb & mLibraryDb
Definition: kicadlibraryimport.h:187
bool startParse(std::shared_ptr< MessageLogger > log) noexcept
Definition: kicadlibraryimport.cpp:353
void updateDependencies(std::shared_ptr< Result > result) noexcept
Definition: kicadlibraryimport.cpp:1000
bool canStartParsing() const noexcept
Definition: kicadlibraryimport.cpp:129
std::shared_ptr< Result > parse(std::shared_ptr< Result > result, std::shared_ptr< MessageLogger > log) noexcept
Definition: kicadlibraryimport.cpp:540
State mState
Definition: kicadlibraryimport.h:192
QScopedPointer< KiCadLibraryConverterSettings > mSettings
Definition: kicadlibraryimport.h:188
FilePath mLoadedLibsFp
Definition: kicadlibraryimport.h:189
std::shared_ptr< Result > getResult() noexcept
Definition: kicadlibraryimport.cpp:399
State
Definition: kicadlibraryimport.h:56
bool isAlreadyImported(const QString &generatedBy) const noexcept
Definition: kicadlibraryimport.cpp:976
std::shared_ptr< Result > import(std::shared_ptr< Result > result, std::shared_ptr< MessageLogger > log) noexcept
Definition: kicadlibraryimport.cpp:695
void setNamePrefix(const QString &prefix) noexcept
Definition: kicadlibraryimport.cpp:205
void setSymbolCategories(const QSet< Uuid > &uuids) noexcept
Definition: kicadlibraryimport.cpp:209
bool canStartImport() const noexcept
Definition: kicadlibraryimport.cpp:162
void symbolCheckStateChanged(const QString &libName, const QString &symName, Qt::CheckState state)
bool isRunning() const noexcept
Definition: kicadlibraryimport.cpp:393
FilePath mLoadedShapes3dFp
Definition: kicadlibraryimport.h:190
bool startScan(const FilePath &libsFp, const FilePath &shapes3dFp, std::shared_ptr< MessageLogger > log) noexcept
Definition: kicadlibraryimport.cpp:330
void setComponentCategories(const QSet< Uuid > &uuids) noexcept
Definition: kicadlibraryimport.cpp:218
const FilePath & getLoadedLibsPath() const noexcept
Definition: kicadlibraryimport.h:126
State getState() const noexcept
Definition: kicadlibraryimport.h:125
KiCadLibraryImport(const KiCadLibraryImport &other)=delete
void componentCheckStateChanged(const QString &libName, const QString &symName, Qt::CheckState state)
void setDeviceChecked(const QString &libName, const QString &symName, bool checked) noexcept
Definition: kicadlibraryimport.cpp:296
void setDeviceCategories(const QSet< Uuid > &uuids) noexcept
Definition: kicadlibraryimport.cpp:223
const FilePath mDestinationLibraryFp
Definition: kicadlibraryimport.h:186
std::shared_ptr< Result > scan(FilePath libsFp, const FilePath &shapes3dFp, std::shared_ptr< MessageLogger > log) noexcept
Definition: kicadlibraryimport.cpp:413
void setSymbolChecked(const QString &libName, const QString &symName, bool checked) noexcept
Definition: kicadlibraryimport.cpp:227
bool startImport(std::shared_ptr< MessageLogger > log) noexcept
Definition: kicadlibraryimport.cpp:373
QFuture< std::shared_ptr< Result > > mFuture
Definition: kicadlibraryimport.h:191
static QString generatedBy(QString libName, QStringList keys)
Definition: kicadlibraryimport.cpp:48
Definition: occmodel.cpp:77
Settings for librepcb::kicadimport::KiCadLibraryConverter.
Definition: kicadlibraryconverter.h:57
Definition: kicadlibraryimport.h:92
QString generatedBy
Definition: kicadlibraryimport.h:95
FilePath file
Definition: kicadlibraryimport.h:93
bool alreadyImported
Definition: kicadlibraryimport.h:96
Qt::CheckState checked
Definition: kicadlibraryimport.h:97
QString name
Definition: kicadlibraryimport.h:94
QList< FilePath > files
Definition: kicadlibraryimport.h:102
FilePath dir
Definition: kicadlibraryimport.h:101
QList< Footprint > footprints
Definition: kicadlibraryimport.h:103
Definition: kicadlibraryimport.h:66
QString symGeneratedBy
Definition: kicadlibraryimport.h:68
bool alreadyImported
Definition: kicadlibraryimport.h:69
int index
Definition: kicadlibraryimport.h:67
QList< FilePath > stepFiles
Definition: kicadlibraryimport.h:108
FilePath dir
Definition: kicadlibraryimport.h:107
Definition: kicadlibraryimport.h:111
QList< FootprintLibrary > footprintLibs
Definition: kicadlibraryimport.h:113
QList< Package3DLibrary > package3dLibs
Definition: kicadlibraryimport.h:114
QList< SymbolLibrary > symbolLibs
Definition: kicadlibraryimport.h:112
int fileCount
Definition: kicadlibraryimport.h:115
Definition: kicadlibraryimport.h:72
QString pkgGeneratedBy
Definition: kicadlibraryimport.h:76
Qt::CheckState devChecked
Definition: kicadlibraryimport.h:84
QString extends
Definition: kicadlibraryimport.h:80
bool devAlreadyImported
Definition: kicadlibraryimport.h:79
QString cmpGeneratedBy
Definition: kicadlibraryimport.h:74
bool symAlreadyImported
Definition: kicadlibraryimport.h:77
Qt::CheckState cmpChecked
Definition: kicadlibraryimport.h:83
QList< Gate > gates
Definition: kicadlibraryimport.h:81
bool cmpAlreadyImported
Definition: kicadlibraryimport.h:78
QString name
Definition: kicadlibraryimport.h:73
Qt::CheckState symChecked
Definition: kicadlibraryimport.h:82
QString devGeneratedBy
Definition: kicadlibraryimport.h:75
FilePath file
Definition: kicadlibraryimport.h:88
QList< Symbol > symbols
Definition: kicadlibraryimport.h:89