LibrePCB Developers Documentation
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 <optional/tl/optional.hpp>
45#include <parseagle/common/enums.h>
46
47#include <QtCore>
48
49#include <memory>
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 tl::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:78
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:40
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:83
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:58
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition: point.h:79
The Vertex class.
Definition: vertex.h:44
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:988
static UnsignedLength convertLineWidth(double w, int layerId)
Convert a line width for a given layer.
Definition: eagletypeconverter.cpp:380
static void convertGrid(const parseagle::Grid &g, PositiveLength &interval, LengthUnit &unit)
Convert grid settings.
Definition: eagletypeconverter.cpp:449
static void tryConvertAttributes(const QList< parseagle::Attribute > &in, AttributeList &out, MessageLogger &log)
Try converting a list of attributes.
Definition: eagletypeconverter.cpp:155
EagleTypeConverter(const EagleTypeConverter &other)=delete
static Geometry convertPolygon(const parseagle::Polygon &p, bool isGrabArea)
Convert a polygon.
Definition: eagletypeconverter.cpp:553
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:122
static std::shared_ptr< Text > tryConvertSchematicAttribute(const parseagle::Attribute &t)
Try to convert a schematic/symbol attribute text.
Definition: eagletypeconverter.cpp:648
static ElementName convertDeviceName(const QString &deviceSetName, const QString &deviceName)
Convert a device name.
Definition: eagletypeconverter.cpp:86
static std::shared_ptr< Text > tryConvertSchematicText(const parseagle::Text &t)
Try to convert a schematic/symbol text.
Definition: eagletypeconverter.cpp:628
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:810
static ComponentSymbolVariantItemSuffix convertGateName(const QString &n)
Convert a component gate name.
Definition: eagletypeconverter.cpp:105
static const Layer * tryConvertBoardLayer(int id) noexcept
Try to convert a layer ID to a board layer.
Definition: eagletypeconverter.cpp:219
static Vertex convertVertex(const parseagle::Vertex &v)
Convert a vertex.
Definition: eagletypeconverter.cpp:469
static Geometry convertFrame(const parseagle::Frame &f)
Convert a frame.
Definition: eagletypeconverter.cpp:591
static Geometry convertRectangle(const parseagle::Rectangle &r, bool isGrabArea)
Convert a rectangle.
Definition: eagletypeconverter.cpp:536
static Angle convertAngle(double a)
Convert an angle.
Definition: eagletypeconverter.cpp:445
static ComponentPrefix convertComponentPrefix(const QString &p)
Convert a component prefix.
Definition: eagletypeconverter.cpp:100
static QHash< const Layer *, const Layer * > convertLayerSetup(const QString &s)
Convert a layer setup string.
Definition: eagletypeconverter.cpp:321
static std::shared_ptr< StrokeText > tryConvertBoardText(const parseagle::Text &t)
Try to cnvert a board/footprint text.
Definition: eagletypeconverter.cpp:712
static Pin convertSymbolPin(const parseagle::Pin &p)
Convert a symbol pin.
Definition: eagletypeconverter.cpp:762
static Point convertPoint(const parseagle::Point &p)
Convert a point.
Definition: eagletypeconverter.cpp:441
static PositiveLength convertSchematicTextSize(double s)
Convert the size (height) of a schematic text.
Definition: eagletypeconverter.cpp:624
static CircuitIdentifier convertPinOrPadName(const QString &n)
Convert a pin or pad name.
Definition: eagletypeconverter.cpp:111
static std::shared_ptr< Attribute > tryConvertAttribute(const parseagle::Attribute &a, MessageLogger &log)
Try converting an attribute.
Definition: eagletypeconverter.cpp:143
static std::pair< std::shared_ptr< PackagePad >, std::shared_ptr< FootprintPad > > convertSmtPad(const parseagle::SmtPad &p)
Convert an SMT pad.
Definition: eagletypeconverter.cpp:881
static std::shared_ptr< Circle > tryConvertToSchematicCircle(const Geometry &g)
Try to convert an intermediate geometry to a schematic circle.
Definition: eagletypeconverter.cpp:918
static Path convertVertices(const QList< parseagle::Vertex > &v, bool close)
Convert vertices.
Definition: eagletypeconverter.cpp:473
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:485
static Length convertLength(double l)
Convert a length.
Definition: eagletypeconverter.cpp:376
static Alignment convertAlignment(parseagle::Alignment a)
Convert an alignment.
Definition: eagletypeconverter.cpp:351
static BoundedUnsignedRatio getDefaultAutoThtAnnularWidth() noexcept
Get the default annular width of THT pads with 'auto' size.
Definition: eagletypeconverter.cpp:1129
static QString getLayerName(int id, const QString &fallback="unknown") noexcept
Get the EAGLE layer name for a given layer ID.
Definition: eagletypeconverter.cpp:1009
static UnsignedLength convertBoardTextStrokeWidth(int layerId, double size, int ratio)
Convert the stroke width of a board text.
Definition: eagletypeconverter.cpp:688
static Geometry convertCircle(const parseagle::Circle &c, bool isGrabArea)
Convert a circle.
Definition: eagletypeconverter.cpp:565
static ElementName convertComponentName(QString n)
Convert a component name.
Definition: eagletypeconverter.cpp:79
static QString convertTextValue(const QString &v)
Convert a text value.
Definition: eagletypeconverter.cpp:610
static std::shared_ptr< Polygon > tryConvertToSchematicPolygon(const Geometry &g)
Try to convert an intermediate geometry to a schematic polygon.
Definition: eagletypeconverter.cpp:930
static std::shared_ptr< StrokeText > tryConvertBoardAttribute(const parseagle::Attribute &t)
Try to convert a board/footprint attribute text.
Definition: eagletypeconverter.cpp:737
static std::shared_ptr< Polygon > tryConvertToBoardPolygon(const Geometry &g)
Try to convert an intermediate geometry to a board polygon.
Definition: eagletypeconverter.cpp:1000
static QVector< std::shared_ptr< Zone > > tryConvertToBoardZones(const Geometry &g)
Try to convert an intermediate geometry to board keepout zones.
Definition: eagletypeconverter.cpp:952
static const Layer * tryConvertSchematicLayer(int id) noexcept
Try to convert a layer ID to a schematic layer.
Definition: eagletypeconverter.cpp:188
static std::shared_ptr< Hole > convertHole(const parseagle::Hole &h)
Convert a hole.
Definition: eagletypeconverter.cpp:581
static ElementName convertElementName(const QString &n)
Convert an element (e.g. symbol) name.
Definition: eagletypeconverter.cpp:62
static QString convertElementDescription(const QString &d)
Convert an element (e.g. symbol) description.
Definition: eagletypeconverter.cpp:70
static PositiveLength convertBoardTextSize(int layerId, double size)
Convert the size (height) of a board text.
Definition: eagletypeconverter.cpp:668
static QVector< Path > convertBoardZoneOutline(const Path &outline, const Length &lineWidth)
Convert the outline of a board zone.
Definition: eagletypeconverter.cpp:939
static void tryExtractMpnAndManufacturer(AttributeList &attributes, SimpleString &mpn, SimpleString &manufacturer) noexcept
Try extracting MPN and manufacturer from a list of attributes.
Definition: eagletypeconverter.cpp:167
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:96
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
type_safe::constrained_type< QString, ComponentPrefixConstraint, ComponentPrefixVerifier > ComponentPrefix
Definition: componentprefix.h:85
type_safe::constrained_type< QString, SimpleStringConstraint, SimpleStringVerifier > SimpleString
Definition: simplestring.h:80
type_safe::constrained_type< QString, ComponentSymbolVariantItemSuffixConstraint, ComponentSymbolVariantItemSuffixVerifier > ComponentSymbolVariantItemSuffix
Definition: componentsymbolvariantitemsuffix.h:89
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
bool filled
Definition: eagletypeconverter.h:105
tl::optional< std::pair< Point, PositiveLength > > circle
Definition: eagletypeconverter.h:108
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