LibrePCB Developers Documentation
Loading...
Searching...
No Matches
kicadtypeconverter.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_KICADTYPECONVERTER_H
21#define LIBREPCB_KICADIMPORT_KICADTYPECONVERTER_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "kicadtypes.h"
27
34
35#include <QtCore>
36
37#include <memory>
38#include <optional>
39
40/*******************************************************************************
41 * Namespace / Forward Declarations
42 ******************************************************************************/
43namespace librepcb {
44
45class Circle;
46class FootprintPad;
47class Hole;
48class Layer;
49class MessageLogger;
50class PackagePad;
51class Polygon;
52class StrokeText;
53class SymbolPin;
54class Text;
55class Zone;
56
57namespace kicadimport {
58
59/*******************************************************************************
60 * Class KiCadTypeConverter
61 ******************************************************************************/
62
66class KiCadTypeConverter final {
67 Q_DECLARE_TR_FUNCTIONS(KiCadTypeConverter)
68
69public:
70 // Types
71 struct Line {
72 const Layer* layer; // Not nullptr.
77 };
78 struct LineGroup {
79 const Layer* layer; // Not nullptr.
81 QVector<Path> paths;
82 };
83 struct Pad {
84 std::shared_ptr<FootprintPad> fptPad;
85 std::shared_ptr<Hole> hole;
86 QList<std::shared_ptr<Polygon>> polygons;
87 };
88
89 // Constructors / Destructor
91 KiCadTypeConverter(const KiCadTypeConverter& other) = delete;
93
94 // General Methods
95 static ElementName convertElementName(const QString& s);
96 static QString convertElementDescription(const FilePath& libFp,
97 const QString& elemName,
98 const QList<KiCadProperty>& props);
99 static QString convertElementKeywords(const QString& commonKeywords,
100 const QList<KiCadProperty>& props);
101 static ResourceList convertResources(const QList<KiCadProperty>& props);
102 static Point convertSymbolPoint(const QPointF& p);
103 static Point convertFootprintPoint(const QPointF& p);
104 static Angle convertArc(const Point& start, const Point& mid,
105 const Point& end);
106 static UnsignedLength convertSymbolStrokeWidth(qreal width);
107 static PositiveLength convertSymbolTextHeight(qreal height);
109 const Layer& layer);
110 static std::shared_ptr<Polygon> convertSymbolArc(const KiCadSymbolArc& a);
111 static std::shared_ptr<Circle> convertSymbolCircle(
112 const KiCadSymbolCircle& c);
113 static std::shared_ptr<Polygon> convertSymbolRectangle(
114 const KiCadSymbolRectangle& r);
115 static std::shared_ptr<Polygon> convertSymbolPolyline(
116 const KiCadSymbolPolyline& p);
117 static std::shared_ptr<Text> convertSymbolText(const KiCadSymbolText& t);
118 static std::shared_ptr<Text> convertSymbolPropertyToText(
119 const KiCadProperty& p);
120 static QList<std::pair<QString, QStringList>> convertSymbolPinNames(
121 const QList<KiCadSymbolPin>& pins);
122 static CircuitIdentifier convertSymbolPinName(const QString& name,
123 const QStringList& numbers);
124 static CircuitIdentifier convertCircuitIdentifier(const QString& text);
125 static std::shared_ptr<SymbolPin> convertSymbolPin(const KiCadSymbolPin& p,
126 const QString& name,
127 qreal pinNamesOffset);
128 static const Layer& convertFootprintGeometryLayer(const KiCadLayer& l);
131 static QList<LineGroup> groupLinesByLayerAndWidth(const QList<Line>& lines);
132 static std::shared_ptr<Circle> convertFootprintCircle(
133 const KiCadFootprintCircle& c);
134 static std::shared_ptr<Polygon> convertFootprintRectangle(
135 const KiCadFootprintRectangle& r);
136 static std::shared_ptr<Polygon> convertFootprintPolygon(
137 const KiCadFootprintPolygon& p);
138 static std::shared_ptr<Zone> convertFootprintZone(const KiCadZone& z,
139 MessageLogger& log);
140 static std::shared_ptr<StrokeText> convertFootprintText(
141 const KiCadFootprintText& t);
142 static std::shared_ptr<StrokeText> convertFootprintPropertyToText(
143 const KiCadProperty& p);
144 static Pad convertPad(const KiCadFootprintPad& p, qreal fptSolderMaskMargin,
145 qreal fptSolderPasteMargin, qreal fptSolderPasteRatio,
146 qreal fptClearance, MessageLogger& log);
147 static std::optional<KiCadProperty> findProperty(
148 const QList<KiCadProperty>& props, const QString& key);
149
150 // Operator Overloadings
152
153private:
157 static PositiveLength maxArcTolerance() noexcept {
158 return PositiveLength(5000);
159 }
160};
161
162/*******************************************************************************
163 * End of File
164 ******************************************************************************/
165
166} // namespace kicadimport
167} // namespace librepcb
168
169#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition angle.h:76
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
The Layer class provides all supported geometry layers.
Definition layer.h:42
Generic logger class to pass messages between objects.
Definition messagelogger.h:43
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
Helper class to convert KiCad types to LibrePCB types.
Definition kicadtypeconverter.h:66
static QString convertElementKeywords(const QString &commonKeywords, const QList< KiCadProperty > &props)
Definition kicadtypeconverter.cpp:71
static std::shared_ptr< Text > convertSymbolPropertyToText(const KiCadProperty &p)
Definition kicadtypeconverter.cpp:208
static std::optional< KiCadProperty > findProperty(const QList< KiCadProperty > &props, const QString &key)
Definition kicadtypeconverter.cpp:1068
static QList< std::pair< QString, QStringList > > convertSymbolPinNames(const QList< KiCadSymbolPin > &pins)
Definition kicadtypeconverter.cpp:241
static std::shared_ptr< Circle > convertSymbolCircle(const KiCadSymbolCircle &c)
Definition kicadtypeconverter.cpp:151
static std::shared_ptr< Polygon > convertFootprintRectangle(const KiCadFootprintRectangle &r)
Definition kicadtypeconverter.cpp:485
static std::shared_ptr< Polygon > convertSymbolArc(const KiCadSymbolArc &a)
Definition kicadtypeconverter.cpp:135
KiCadTypeConverter(const KiCadTypeConverter &other)=delete
static CircuitIdentifier convertCircuitIdentifier(const QString &text)
Definition kicadtypeconverter.cpp:312
static std::shared_ptr< SymbolPin > convertSymbolPin(const KiCadSymbolPin &p, const QString &name, qreal pinNamesOffset)
Definition kicadtypeconverter.cpp:364
static std::shared_ptr< StrokeText > convertFootprintPropertyToText(const KiCadProperty &p)
Definition kicadtypeconverter.cpp:587
static Point convertSymbolPoint(const QPointF &p)
Definition kicadtypeconverter.cpp:97
static PositiveLength maxArcTolerance() noexcept
Definition kicadtypeconverter.h:157
static CircuitIdentifier convertSymbolPinName(const QString &name, const QStringList &numbers)
Definition kicadtypeconverter.cpp:303
static std::shared_ptr< Circle > convertFootprintCircle(const KiCadFootprintCircle &c)
Definition kicadtypeconverter.cpp:467
static std::shared_ptr< Polygon > convertFootprintPolygon(const KiCadFootprintPolygon &p)
Definition kicadtypeconverter.cpp:497
static ElementName convertElementName(const QString &s)
Definition kicadtypeconverter.cpp:52
static UnsignedLength convertSymbolStrokeWidth(qreal width)
Definition kicadtypeconverter.cpp:114
static std::shared_ptr< Text > convertSymbolText(const KiCadSymbolText &t)
Definition kicadtypeconverter.cpp:192
static std::shared_ptr< Polygon > convertSymbolRectangle(const KiCadSymbolRectangle &r)
Definition kicadtypeconverter.cpp:161
static std::shared_ptr< Polygon > convertSymbolPolyline(const KiCadSymbolPolyline &p)
Definition kicadtypeconverter.cpp:172
KiCadTypeConverter & operator=(const KiCadTypeConverter &rhs)=delete
static std::shared_ptr< Zone > convertFootprintZone(const KiCadZone &z, MessageLogger &log)
Definition kicadtypeconverter.cpp:516
static Pad convertPad(const KiCadFootprintPad &p, qreal fptSolderMaskMargin, qreal fptSolderPasteMargin, qreal fptSolderPasteRatio, qreal fptClearance, MessageLogger &log)
Definition kicadtypeconverter.cpp:621
static QString convertElementDescription(const FilePath &libFp, const QString &elemName, const QList< KiCadProperty > &props)
Definition kicadtypeconverter.cpp:56
static UnsignedLength convertFootprintStrokeWidth(qreal width, const Layer &layer)
Definition kicadtypeconverter.cpp:126
static Line convertFootprintLine(const KiCadFootprintLine &l)
Definition kicadtypeconverter.cpp:423
static const Layer & convertFootprintGeometryLayer(const KiCadLayer &l)
Definition kicadtypeconverter.cpp:374
static PositiveLength convertSymbolTextHeight(qreal height)
Definition kicadtypeconverter.cpp:122
static ResourceList convertResources(const QList< KiCadProperty > &props)
Definition kicadtypeconverter.cpp:84
static Point convertFootprintPoint(const QPointF &p)
Definition kicadtypeconverter.cpp:101
static std::shared_ptr< StrokeText > convertFootprintText(const KiCadFootprintText &t)
Definition kicadtypeconverter.cpp:564
static Line convertFootprintArc(const KiCadFootprintArc &a)
Definition kicadtypeconverter.cpp:435
static QList< LineGroup > groupLinesByLayerAndWidth(const QList< Line > &lines)
Definition kicadtypeconverter.cpp:451
static Angle convertArc(const Point &start, const Point &mid, const Point &end)
Definition kicadtypeconverter.cpp:105
KiCadLayer
Definition kicadtypes.h:158
Definition occmodel.cpp:76
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition circuitidentifier.h:95
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84
Represents a KiCad footprint arc.
Definition kicadtypes.h:566
Represents a KiCad footprint circle.
Definition kicadtypes.h:587
Represents a KiCad footprint line.
Definition kicadtypes.h:546
Represents a KiCad footprint pad.
Definition kicadtypes.h:680
Represents a KiCad footprint polygon.
Definition kicadtypes.h:633
Represents a KiCad footprint rectangle.
Definition kicadtypes.h:610
Represents a KiCad footprint text.
Definition kicadtypes.h:655
Represents a KiCad property.
Definition kicadtypes.h:229
Represents a KiCad symbol arc.
Definition kicadtypes.h:353
Represents a KiCad symbol circle.
Definition kicadtypes.h:374
Represents a KiCad symbol pin.
Definition kicadtypes.h:455
Represents a KiCad symbol polyline.
Definition kicadtypes.h:415
Represents a KiCad symbol rectangle.
Definition kicadtypes.h:394
Represents a KiCad symbol text.
Definition kicadtypes.h:434
UnsignedLength width
Definition kicadtypeconverter.h:80
QVector< Path > paths
Definition kicadtypeconverter.h:81
const Layer * layer
Definition kicadtypeconverter.h:79
Definition kicadtypeconverter.h:71
UnsignedLength width
Definition kicadtypeconverter.h:73
Point start
Definition kicadtypeconverter.h:74
Point end
Definition kicadtypeconverter.h:75
Angle angle
Definition kicadtypeconverter.h:76
const Layer * layer
Definition kicadtypeconverter.h:72
Definition kicadtypeconverter.h:83
std::shared_ptr< FootprintPad > fptPad
Definition kicadtypeconverter.h:84
QList< std::shared_ptr< Polygon > > polygons
Definition kicadtypeconverter.h:86
std::shared_ptr< Hole > hole
Definition kicadtypeconverter.h:85
Represents a KiCad zone.
Definition kicadtypes.h:331