LibrePCB Developers Documentation
kicadlibraryconverter.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_KICADLIBRARYCONVERTER_H
21#define LIBREPCB_KICADIMPORT_KICADLIBRARYCONVERTER_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "kicadtypes.h"
27
30#include <optional/tl/optional.hpp>
31
32#include <QtCore>
33
34#include <memory>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40
41class Component;
42class Device;
43class FilePath;
44class Package;
45class Symbol;
46class WorkspaceLibraryDb;
47
48namespace kicadimport {
49
50/*******************************************************************************
51 * Struct KiCadLibraryConverterSettings
52 ******************************************************************************/
53
59
60 QString namePrefix;
62 QString author;
63 QString keywords;
64 QSet<Uuid> symbolCategories;
67 QSet<Uuid> deviceCategories;
68};
69
70/*******************************************************************************
71 * Class KiCadLibraryConverter
72 ******************************************************************************/
73
77class KiCadLibraryConverter final : public QObject {
78 Q_OBJECT
79
80public:
81 // Constructors / Destructor
84 const KiCadLibraryConverterSettings& settings,
85 QObject* parent = nullptr) noexcept;
86 ~KiCadLibraryConverter() noexcept;
87
88 // General Methods
89 void reset() noexcept;
90 std::unique_ptr<Package> createPackage(const FilePath& libFp,
91 const KiCadFootprint& kiFpt,
92 const QString& generatedBy,
93 const QMap<QString, FilePath>& models,
94 MessageLogger& log);
95 std::unique_ptr<Symbol> createSymbol(const FilePath& libFp,
96 const KiCadSymbol& kiSym,
97 const KiCadSymbolGate& kiGate,
98 const QString& generatedBy,
99 MessageLogger& log);
100 std::unique_ptr<Component> createComponent(
101 const FilePath& libFp, const KiCadSymbol& kiSym,
102 const QList<KiCadSymbolGate>& kiGates, const QString& generatedBy,
103 const QStringList& symGeneratedBy, MessageLogger& log);
104 std::unique_ptr<Device> createDevice(const FilePath& libFp,
105 const KiCadSymbol& kiSym,
106 const QList<KiCadSymbolGate>& kiGates,
107 const QString& generatedBy,
108 const QString& cmpGeneratedBy,
109 const QString& pkgGeneratedBy,
110 MessageLogger& log);
111
112 // Operator Overloadings
113 KiCadLibraryConverter& operator=(const KiCadLibraryConverter& rhs) = delete;
114
115private: // Methods
116 void loadAlreadyImportedSymbol(const QString& generatedBy);
117 void loadAlreadyImportedPackage(const QString& generatedBy);
118 void loadAlreadyImportedComponent(const QString& generatedBy);
119 template <typename T>
120 FilePath getAlreadyImportedFp(const QString& generatedBy) const;
121 void tryOrLogError(std::function<void()> func, MessageLogger& log);
122
123private: // Data
126
129 QHash<QString, tl::optional<Uuid>> mPackageMap;
130
133 QHash<QString, QMap<QString, tl::optional<Uuid>>> mPackagePadMap;
134
137 QHash<QString, tl::optional<Uuid>> mSymbolMap;
138
141 QHash<std::pair<QString, QString>, tl::optional<Uuid>> mSymbolPinMap;
142
145 QHash<QString, tl::optional<Uuid>> mComponentMap;
146
149 QHash<std::pair<QString, QString>, tl::optional<Uuid>> mComponentSignalMap;
150};
151
152/*******************************************************************************
153 * End of File
154 ******************************************************************************/
155
156} // namespace kicadimport
157} // namespace librepcb
158
159#endif
The Component class represents a "generic" device in the library.
Definition: component.h:73
The Device class represents an instance of a component (a "real" component)
Definition: device.h:55
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 Package class represents a package of a component (including footprint and 3D model)
Definition: package.h:59
The Symbol class represents the part of a component which is added to schematics.
Definition: symbol.h:55
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
The WorkspaceLibraryDb class.
Definition: workspacelibrarydb.h:58
Converts KiCad library elements to LibrePCB.
Definition: kicadlibraryconverter.h:77
QHash< QString, tl::optional< Uuid > > mPackageMap
Definition: kicadlibraryconverter.h:129
void loadAlreadyImportedComponent(const QString &generatedBy)
Definition: kicadlibraryconverter.cpp:540
void loadAlreadyImportedPackage(const QString &generatedBy)
Definition: kicadlibraryconverter.cpp:528
std::unique_ptr< Device > createDevice(const FilePath &libFp, const KiCadSymbol &kiSym, const QList< KiCadSymbolGate > &kiGates, const QString &generatedBy, const QString &cmpGeneratedBy, const QString &pkgGeneratedBy, MessageLogger &log)
Definition: kicadlibraryconverter.cpp:444
void reset() noexcept
Definition: kicadlibraryconverter.cpp:78
QHash< QString, tl::optional< Uuid > > mComponentMap
Definition: kicadlibraryconverter.h:145
std::unique_ptr< Package > createPackage(const FilePath &libFp, const KiCadFootprint &kiFpt, const QString &generatedBy, const QMap< QString, FilePath > &models, MessageLogger &log)
Definition: kicadlibraryconverter.cpp:81
WorkspaceLibraryDb & mLibraryDb
Definition: kicadlibraryconverter.h:124
QHash< QString, tl::optional< Uuid > > mSymbolMap
Definition: kicadlibraryconverter.h:137
std::unique_ptr< Component > createComponent(const FilePath &libFp, const KiCadSymbol &kiSym, const QList< KiCadSymbolGate > &kiGates, const QString &generatedBy, const QStringList &symGeneratedBy, MessageLogger &log)
Definition: kicadlibraryconverter.cpp:345
KiCadLibraryConverter(const KiCadLibraryConverter &other)=delete
QHash< QString, QMap< QString, tl::optional< Uuid > > > mPackagePadMap
Definition: kicadlibraryconverter.h:133
void tryOrLogError(std::function< void()> func, MessageLogger &log)
Definition: kicadlibraryconverter.cpp:570
QHash< std::pair< QString, QString >, tl::optional< Uuid > > mComponentSignalMap
Definition: kicadlibraryconverter.h:149
KiCadLibraryConverterSettings mSettings
Definition: kicadlibraryconverter.h:125
FilePath getAlreadyImportedFp(const QString &generatedBy) const
Definition: kicadlibraryconverter.cpp:555
void loadAlreadyImportedSymbol(const QString &generatedBy)
Definition: kicadlibraryconverter.cpp:515
std::unique_ptr< Symbol > createSymbol(const FilePath &libFp, const KiCadSymbol &kiSym, const KiCadSymbolGate &kiGate, const QString &generatedBy, MessageLogger &log)
Definition: kicadlibraryconverter.cpp:266
QHash< std::pair< QString, QString >, tl::optional< Uuid > > mSymbolPinMap
Definition: kicadlibraryconverter.h:141
static QString generatedBy(QString libName, QStringList keys)
Definition: kicadlibraryimport.cpp:48
Definition: occmodel.cpp:77
Definition: uuid.h:183
Represents a KiCad footprint.
Definition: kicadtypes.h:741
Settings for librepcb::kicadimport::KiCadLibraryConverter.
Definition: kicadlibraryconverter.h:57
QString namePrefix
Definition: kicadlibraryconverter.h:60
QString author
Definition: kicadlibraryconverter.h:62
QSet< Uuid > packageCategories
Definition: kicadlibraryconverter.h:65
QString keywords
Definition: kicadlibraryconverter.h:63
QSet< Uuid > symbolCategories
Definition: kicadlibraryconverter.h:64
QSet< Uuid > deviceCategories
Definition: kicadlibraryconverter.h:67
Version version
Definition: kicadlibraryconverter.h:61
KiCadLibraryConverterSettings() noexcept
Definition: kicadlibraryconverter.cpp:54
QSet< Uuid > componentCategories
Definition: kicadlibraryconverter.h:66
Represents a KiCad symbol gate.
Definition: kicadtypes.h:477
Represents a KiCad symbol.
Definition: kicadtypes.h:503