LibrePCB Developers Documentation
Loading...
Searching...
No Matches
eagletypeconverter.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_EAGLEIMPORT_EAGLETYPECONVERTER_H
21#define LIBREPCB_EAGLEIMPORT_EAGLETYPECONVERTER_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
44#include <parseagle/common/enums.h>
45
46#include <QtCore>
47
48#include <memory>
49#include <optional>
50
51/*******************************************************************************
52 * Namespace / Forward Declarations
53 ******************************************************************************/
54namespace parseagle {
55class Attribute;
56class Circle;
57class DeviceSet;
58class Frame;
59class Gate;
60class Grid;
61class Hole;
62class Library;
63class Package;
64class Param;
65class Pin;
66class Polygon;
67class Rectangle;
68class SmtPad;
69class Symbol;
70class Text;
71class ThtPad;
72class Vertex;
73class Wire;
74struct Point;
75} // namespace parseagle
76
77namespace librepcb {
78
79class Layer;
80class LengthUnit;
81class MessageLogger;
82
83namespace eagleimport {
84
85/*******************************************************************************
86 * Class EagleTypeConverter
87 ******************************************************************************/
88
92class EagleTypeConverter final {
93 Q_DECLARE_TR_FUNCTIONS(EagleTypeConverter)
94
95public:
96 // Types
97
102 struct Geometry {
105 bool filled;
108 std::optional<std::pair<Point, PositiveLength>> circle;
109 };
110
114 struct Pin {
115 std::shared_ptr<SymbolPin> pin;
116 std::shared_ptr<Circle> circle;
117 std::shared_ptr<Polygon> polygon;
118 };
119
120 // Constructors / Destructor
124
136 static ElementName convertElementName(const QString& n);
137
147 static QString convertElementDescription(const QString& d);
148
159 static ElementName convertComponentName(QString n);
160
172 static ElementName convertDeviceName(const QString& deviceSetName,
173 const QString& deviceName);
174
185 static ComponentPrefix convertComponentPrefix(const QString& p);
186
197 static ComponentSymbolVariantItemSuffix convertGateName(const QString& n);
198
209 static CircuitIdentifier convertPinOrPadName(const QString& n);
210
218 static QString convertInversionSyntax(const QString& s) noexcept;
219
228 static std::shared_ptr<Attribute> tryConvertAttribute(
229 const parseagle::Attribute& a, MessageLogger& log);
230
244 static void tryConvertAttributes(const QList<parseagle::Attribute>& in,
245 AttributeList& out, MessageLogger& log);
246
255 static void tryExtractMpnAndManufacturer(AttributeList& attributes,
256 SimpleString& mpn,
257 SimpleString& manufacturer) noexcept;
258
266 static const Layer* tryConvertSchematicLayer(int id) noexcept;
267
275 static const Layer* tryConvertBoardLayer(int id) noexcept;
276
284 static QHash<const Layer*, const Layer*> convertLayerSetup(const QString& s);
285
293 static Alignment convertAlignment(parseagle::Alignment a);
294
302 static Length convertLength(double l);
303
315 static UnsignedLength convertLineWidth(double w, int layerId);
316
328 template <typename T>
329 static T convertParamTo(const parseagle::Param& p);
330
338 static Point convertPoint(const parseagle::Point& p);
339
347 static Angle convertAngle(double a);
348
359 static void convertGrid(const parseagle::Grid& g, PositiveLength& interval,
360 LengthUnit& unit);
361
369 static Vertex convertVertex(const parseagle::Vertex& v);
370
379 static Path convertVertices(const QList<parseagle::Vertex>& v, bool close);
380
391 static QList<Geometry> convertAndJoinWires(
392 const QList<parseagle::Wire>& wires, bool isGrabAreaIfClosed,
393 MessageLogger& log);
394
403 static Geometry convertRectangle(const parseagle::Rectangle& r,
404 bool isGrabArea);
405
414 static Geometry convertPolygon(const parseagle::Polygon& p, bool isGrabArea);
415
424 static Geometry convertCircle(const parseagle::Circle& c, bool isGrabArea);
425
433 static std::shared_ptr<Hole> convertHole(const parseagle::Hole& h);
434
442 static Geometry convertFrame(const parseagle::Frame& f);
443
451 static QString convertTextValue(const QString& v);
452
461
469 static std::shared_ptr<Text> tryConvertSchematicText(
470 const parseagle::Text& t);
471
479 static std::shared_ptr<Text> tryConvertSchematicAttribute(
480 const parseagle::Attribute& t);
481
490 static PositiveLength convertBoardTextSize(int layerId, double size);
491
501 static UnsignedLength convertBoardTextStrokeWidth(int layerId, double size,
502 int ratio);
503
511 static std::shared_ptr<StrokeText> tryConvertBoardText(
512 const parseagle::Text& t);
513
521 static std::shared_ptr<StrokeText> tryConvertBoardAttribute(
522 const parseagle::Attribute& t);
523
531 static Pin convertSymbolPin(const parseagle::Pin& p);
532
543 static std::pair<std::shared_ptr<PackagePad>, std::shared_ptr<FootprintPad>>
544 convertThtPad(const parseagle::ThtPad& p,
545 const BoundedUnsignedRatio& autoAnnularWidth);
546
554 static std::pair<std::shared_ptr<PackagePad>, std::shared_ptr<FootprintPad>>
555 convertSmtPad(const parseagle::SmtPad& p);
556
565 static std::shared_ptr<Circle> tryConvertToSchematicCircle(const Geometry& g);
566
574 static std::shared_ptr<Polygon> tryConvertToSchematicPolygon(
575 const Geometry& g);
576
588 static QVector<Path> convertBoardZoneOutline(const Path& outline,
589 const Length& lineWidth);
590
599 static QVector<std::shared_ptr<Zone>> tryConvertToBoardZones(
600 const Geometry& g);
601
610 static std::shared_ptr<Circle> tryConvertToBoardCircle(const Geometry& g);
611
619 static std::shared_ptr<Polygon> tryConvertToBoardPolygon(const Geometry& g);
620
629 static QString getLayerName(int id,
630 const QString& fallback = "unknown") noexcept;
631
640
641 // Operator Overloadings
642 EagleTypeConverter& operator=(const EagleTypeConverter& rhs) = delete;
643};
644
645/*******************************************************************************
646 * End of File
647 ******************************************************************************/
648
649} // namespace eagleimport
650} // namespace librepcb
651
652#endif
The Alignment class.
Definition alignment.h:115
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition angle.h:76
The BoundedUnsignedRatio class represents a ratio limited to a range specified by min/max values.
Definition boundedunsignedratio.h:46
The Layer class provides all supported geometry layers.
Definition layer.h:42
The Length class is used to represent a length (for example 12.75 millimeters)
Definition length.h:82
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition lengthunit.h:60
Generic logger class to pass messages between objects.
Definition messagelogger.h:43
The Path class represents a list of vertices connected by straight lines or circular arc segments.
Definition path.h:57
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
The Vertex class.
Definition vertex.h:43
Helper class to convert EAGLE types to LibrePCB types.
Definition eagletypeconverter.h:92
static std::shared_ptr< Circle > tryConvertToBoardCircle(const Geometry &g)
Try to convert an intermediate geometry to a board circle.
Definition eagletypeconverter.cpp:983
static UnsignedLength convertLineWidth(double w, int layerId)
Convert a line width for a given layer.
Definition eagletypeconverter.cpp:375
static void convertGrid(const parseagle::Grid &g, PositiveLength &interval, LengthUnit &unit)
Convert grid settings.
Definition eagletypeconverter.cpp:444
static void tryConvertAttributes(const QList< parseagle::Attribute > &in, AttributeList &out, MessageLogger &log)
Try converting a list of attributes.
Definition eagletypeconverter.cpp:151
EagleTypeConverter(const EagleTypeConverter &other)=delete
static Geometry convertPolygon(const parseagle::Polygon &p, bool isGrabArea)
Convert a polygon.
Definition eagletypeconverter.cpp:548
static T convertParamTo(const parseagle::Param &p)
Convert a parameter value to a LibrePCB type.
static QString convertInversionSyntax(const QString &s) noexcept
Convert the inversion syntax of a text.
Definition eagletypeconverter.cpp:118
static std::shared_ptr< Text > tryConvertSchematicAttribute(const parseagle::Attribute &t)
Try to convert a schematic/symbol attribute text.
Definition eagletypeconverter.cpp:643
static ElementName convertDeviceName(const QString &deviceSetName, const QString &deviceName)
Convert a device name.
Definition eagletypeconverter.cpp:82
static std::shared_ptr< Text > tryConvertSchematicText(const parseagle::Text &t)
Try to convert a schematic/symbol text.
Definition eagletypeconverter.cpp:623
static std::pair< std::shared_ptr< PackagePad >, std::shared_ptr< FootprintPad > > convertThtPad(const parseagle::ThtPad &p, const BoundedUnsignedRatio &autoAnnularWidth)
Convert a THT pad.
Definition eagletypeconverter.cpp:805
static ComponentSymbolVariantItemSuffix convertGateName(const QString &n)
Convert a component gate name.
Definition eagletypeconverter.cpp:101
static const Layer * tryConvertBoardLayer(int id) noexcept
Try to convert a layer ID to a board layer.
Definition eagletypeconverter.cpp:215
static Vertex convertVertex(const parseagle::Vertex &v)
Convert a vertex.
Definition eagletypeconverter.cpp:464
static Geometry convertFrame(const parseagle::Frame &f)
Convert a frame.
Definition eagletypeconverter.cpp:586
static Geometry convertRectangle(const parseagle::Rectangle &r, bool isGrabArea)
Convert a rectangle.
Definition eagletypeconverter.cpp:531
static Angle convertAngle(double a)
Convert an angle.
Definition eagletypeconverter.cpp:440
static ComponentPrefix convertComponentPrefix(const QString &p)
Convert a component prefix.
Definition eagletypeconverter.cpp:96
static QHash< const Layer *, const Layer * > convertLayerSetup(const QString &s)
Convert a layer setup string.
Definition eagletypeconverter.cpp:317
static std::shared_ptr< StrokeText > tryConvertBoardText(const parseagle::Text &t)
Try to cnvert a board/footprint text.
Definition eagletypeconverter.cpp:707
static Pin convertSymbolPin(const parseagle::Pin &p)
Convert a symbol pin.
Definition eagletypeconverter.cpp:757
static Point convertPoint(const parseagle::Point &p)
Convert a point.
Definition eagletypeconverter.cpp:436
static PositiveLength convertSchematicTextSize(double s)
Convert the size (height) of a schematic text.
Definition eagletypeconverter.cpp:619
static CircuitIdentifier convertPinOrPadName(const QString &n)
Convert a pin or pad name.
Definition eagletypeconverter.cpp:107
static std::shared_ptr< Attribute > tryConvertAttribute(const parseagle::Attribute &a, MessageLogger &log)
Try converting an attribute.
Definition eagletypeconverter.cpp:139
static std::pair< std::shared_ptr< PackagePad >, std::shared_ptr< FootprintPad > > convertSmtPad(const parseagle::SmtPad &p)
Convert an SMT pad.
Definition eagletypeconverter.cpp:876
static std::shared_ptr< Circle > tryConvertToSchematicCircle(const Geometry &g)
Try to convert an intermediate geometry to a schematic circle.
Definition eagletypeconverter.cpp:913
static Path convertVertices(const QList< parseagle::Vertex > &v, bool close)
Convert vertices.
Definition eagletypeconverter.cpp:468
static QList< Geometry > convertAndJoinWires(const QList< parseagle::Wire > &wires, bool isGrabAreaIfClosed, MessageLogger &log)
Try to join and convert multiple wires to polygons.
Definition eagletypeconverter.cpp:480
static Length convertLength(double l)
Convert a length.
Definition eagletypeconverter.cpp:371
static Alignment convertAlignment(parseagle::Alignment a)
Convert an alignment.
Definition eagletypeconverter.cpp:346
static BoundedUnsignedRatio getDefaultAutoThtAnnularWidth() noexcept
Get the default annular width of THT pads with 'auto' size.
Definition eagletypeconverter.cpp:1124
static QString getLayerName(int id, const QString &fallback="unknown") noexcept
Get the EAGLE layer name for a given layer ID.
Definition eagletypeconverter.cpp:1004
static UnsignedLength convertBoardTextStrokeWidth(int layerId, double size, int ratio)
Convert the stroke width of a board text.
Definition eagletypeconverter.cpp:683
static Geometry convertCircle(const parseagle::Circle &c, bool isGrabArea)
Convert a circle.
Definition eagletypeconverter.cpp:560
static ElementName convertComponentName(QString n)
Convert a component name.
Definition eagletypeconverter.cpp:75
static QString convertTextValue(const QString &v)
Convert a text value.
Definition eagletypeconverter.cpp:605
static std::shared_ptr< Polygon > tryConvertToSchematicPolygon(const Geometry &g)
Try to convert an intermediate geometry to a schematic polygon.
Definition eagletypeconverter.cpp:925
static std::shared_ptr< StrokeText > tryConvertBoardAttribute(const parseagle::Attribute &t)
Try to convert a board/footprint attribute text.
Definition eagletypeconverter.cpp:732
static std::shared_ptr< Polygon > tryConvertToBoardPolygon(const Geometry &g)
Try to convert an intermediate geometry to a board polygon.
Definition eagletypeconverter.cpp:995
static QVector< std::shared_ptr< Zone > > tryConvertToBoardZones(const Geometry &g)
Try to convert an intermediate geometry to board keepout zones.
Definition eagletypeconverter.cpp:947
static const Layer * tryConvertSchematicLayer(int id) noexcept
Try to convert a layer ID to a schematic layer.
Definition eagletypeconverter.cpp:184
static std::shared_ptr< Hole > convertHole(const parseagle::Hole &h)
Convert a hole.
Definition eagletypeconverter.cpp:576
static ElementName convertElementName(const QString &n)
Convert an element (e.g. symbol) name.
Definition eagletypeconverter.cpp:61
static QString convertElementDescription(const QString &d)
Convert an element (e.g. symbol) description.
Definition eagletypeconverter.cpp:69
static PositiveLength convertBoardTextSize(int layerId, double size)
Convert the size (height) of a board text.
Definition eagletypeconverter.cpp:663
static QVector< Path > convertBoardZoneOutline(const Path &outline, const Length &lineWidth)
Convert the outline of a board zone.
Definition eagletypeconverter.cpp:934
static void tryExtractMpnAndManufacturer(AttributeList &attributes, SimpleString &mpn, SimpleString &manufacturer) noexcept
Try extracting MPN and manufacturer from a list of attributes.
Definition eagletypeconverter.cpp:163
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, ComponentPrefixConstraint, ComponentPrefixVerifier > ComponentPrefix
Definition componentprefix.h:84
type_safe::constrained_type< QString, SimpleStringConstraint, SimpleStringVerifier > SimpleString
Definition simplestring.h:79
type_safe::constrained_type< QString, ComponentSymbolVariantItemSuffixConstraint, ComponentSymbolVariantItemSuffixVerifier > ComponentSymbolVariantItemSuffix
Definition componentsymbolvariantitemsuffix.h:88
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84
Definition eaglelibraryconverter.h:38
Intermediate geometry type used for converting polygon-like EAGLE elements.
Definition eagletypeconverter.h:102
UnsignedLength lineWidth
Definition eagletypeconverter.h:104
bool grabArea
Definition eagletypeconverter.h:106
int layerId
Definition eagletypeconverter.h:103
std::optional< std::pair< Point, PositiveLength > > circle
Definition eagletypeconverter.h:108
bool filled
Definition eagletypeconverter.h:105
Path path
Definition eagletypeconverter.h:107
LibrePCB data structure to represent an EAGLE symbol pin.
Definition eagletypeconverter.h:114
std::shared_ptr< Circle > circle
Definition eagletypeconverter.h:116
std::shared_ptr< Polygon > polygon
Definition eagletypeconverter.h:117
std::shared_ptr< SymbolPin > pin
Definition eagletypeconverter.h:115