From b8fa01b7272990b79dfd3f5dde7dfb1c8eec657e Mon Sep 17 00:00:00 2001 From: "U. Bruhin" Date: Fri, 26 Jan 2024 16:24:55 +0100 Subject: [PATCH] Wire: Add support for line style and line cap --- parseagle/board/board.cpp | 2 +- parseagle/board/signal.cpp | 2 +- parseagle/common/enums.h | 44 +++++++++++++++++++++++++++++++++ parseagle/common/wire.cpp | 8 +++++- parseagle/common/wire.h | 7 +++++- parseagle/package/package.cpp | 2 +- parseagle/schematic/segment.cpp | 2 +- parseagle/schematic/sheet.cpp | 2 +- parseagle/symbol/symbol.cpp | 2 +- 9 files changed, 63 insertions(+), 8 deletions(-) diff --git a/parseagle/board/board.cpp b/parseagle/board/board.cpp index 8b1ef64..20c4801 100644 --- a/parseagle/board/board.cpp +++ b/parseagle/board/board.cpp @@ -54,7 +54,7 @@ void Board::load(const QByteArray& content, QStringList* errors) if (board.hasChild("plain")) { foreach (const DomElement& child, board.getFirstChild("plain").getChilds()) { if (child.getTagName() == "wire") { - mWires.append(Wire(child)); + mWires.append(Wire(child, errors)); } else if (child.getTagName() == "rectangle") { mRectangles.append(Rectangle(child)); } else if (child.getTagName() == "circle") { diff --git a/parseagle/board/signal.cpp b/parseagle/board/signal.cpp index 14cadc2..e2e279e 100644 --- a/parseagle/board/signal.cpp +++ b/parseagle/board/signal.cpp @@ -16,7 +16,7 @@ Signal::Signal(const DomElement& root, QStringList* errors) } else if (child.getTagName() == "polygon") { mPolygons.append(Polygon(child, errors)); } else if (child.getTagName() == "wire") { - mWires.append(Wire(child)); + mWires.append(Wire(child, errors)); } else if (child.getTagName() == "via") { mVias.append(Via(child)); } else if (errors) { diff --git a/parseagle/common/enums.h b/parseagle/common/enums.h index 13fd478..26ecf30 100644 --- a/parseagle/common/enums.h +++ b/parseagle/common/enums.h @@ -351,6 +351,50 @@ inline ViaShape parseViaShape(const QString& s, QStringList* errors = nullptr) return ViaShape::Unknown; } +enum class WireCap +{ + Unknown, // Failed to parse XML attribute. + Flat, + Round, +}; + +inline WireCap parseWireCap(const QString& s, QStringList* errors = nullptr) +{ + if (s == "flat") { + return WireCap::Flat; + } else if (s == "round") { + return WireCap::Round; + } else if (errors) { + errors->append("Unknown wire cap: " + s); + } + return WireCap::Unknown; +} + +enum class WireStyle +{ + Unknown, // Failed to parse XML attribute. + Continuous, + LongDash, + ShortDash, + DashDot, +}; + +inline WireStyle parseWireStyle(const QString& s, QStringList* errors = nullptr) +{ + if (s == "continuous") { + return WireStyle::Continuous; + } else if (s == "longdash") { + return WireStyle::LongDash; + } else if (s == "shortdash") { + return WireStyle::ShortDash; + } else if (s == "dashdot") { + return WireStyle::DashDot; + } else if (errors) { + errors->append("Unknown wire style: " + s); + } + return WireStyle::Unknown; +} + } // namespace parseagle #endif // PARSEAGLE_ENUMS_H diff --git a/parseagle/common/wire.cpp b/parseagle/common/wire.cpp index 8fbe8cf..4a44497 100644 --- a/parseagle/common/wire.cpp +++ b/parseagle/common/wire.cpp @@ -4,7 +4,7 @@ namespace parseagle { -Wire::Wire(const DomElement& root) +Wire::Wire(const DomElement& root, QStringList* errors) { mLayer = root.getAttributeAsInt("layer"); mWidth = root.getAttributeAsDouble("width"); @@ -12,9 +12,15 @@ Wire::Wire(const DomElement& root) mP1.y = root.getAttributeAsDouble("y1"); mP2.x = root.getAttributeAsDouble("x2"); mP2.y = root.getAttributeAsDouble("y2"); + if (root.hasAttribute("style")) { + mWireStyle = parseWireStyle(root.getAttributeAsString("style"), errors); + } if (root.hasAttribute("curve")) { mCurve = root.getAttributeAsDouble("curve"); } + if (root.hasAttribute("cap")) { + mWireCap = parseWireCap(root.getAttributeAsString("cap"), errors); + } } Wire::~Wire() noexcept diff --git a/parseagle/common/wire.h b/parseagle/common/wire.h index f41467e..4de2d19 100644 --- a/parseagle/common/wire.h +++ b/parseagle/common/wire.h @@ -2,6 +2,7 @@ #define PARSEAGLE_WIRE_H #include +#include "../common/enums.h" #include "../common/point.h" namespace parseagle { @@ -14,7 +15,7 @@ class Wire final // Constructors / Destructor Wire() = delete; - explicit Wire(const DomElement& root); + explicit Wire(const DomElement& root, QStringList* errors = nullptr); ~Wire() noexcept; // Getters @@ -22,7 +23,9 @@ class Wire final double getWidth() const noexcept {return mWidth;} const Point& getP1() const noexcept {return mP1;} const Point& getP2() const noexcept {return mP2;} + WireStyle getWireStyle() const noexcept {return mWireStyle;} double getCurve() const noexcept {return mCurve;} + WireCap getWireCap() const noexcept {return mWireCap;} private: @@ -30,7 +33,9 @@ class Wire final double mWidth; Point mP1; Point mP2; + WireStyle mWireStyle = WireStyle::Continuous; double mCurve = 0; + WireCap mWireCap = WireCap::Round; }; } // namespace parseagle diff --git a/parseagle/package/package.cpp b/parseagle/package/package.cpp index 3428407..28b513c 100644 --- a/parseagle/package/package.cpp +++ b/parseagle/package/package.cpp @@ -11,7 +11,7 @@ Package::Package(const DomElement& root, QStringList* errors) if (child.getTagName() == "description") { mDescription = child.getText(); } else if (child.getTagName() == "wire") { - mWires.append(Wire(child)); + mWires.append(Wire(child, errors)); } else if (child.getTagName() == "rectangle") { mRectangles.append(Rectangle(child)); } else if (child.getTagName() == "circle") { diff --git a/parseagle/schematic/segment.cpp b/parseagle/schematic/segment.cpp index 42245f2..1b49756 100644 --- a/parseagle/schematic/segment.cpp +++ b/parseagle/schematic/segment.cpp @@ -10,7 +10,7 @@ Segment::Segment(const DomElement& root, QStringList* errors) if (child.getTagName() == "pinref") { mPinRefs.append(PinRef(child)); } else if (child.getTagName() == "wire") { - mWires.append(Wire(child)); + mWires.append(Wire(child, errors)); } else if (child.getTagName() == "junction") { mJunctions.append(Point{ child.getAttributeAsDouble("x"), diff --git a/parseagle/schematic/sheet.cpp b/parseagle/schematic/sheet.cpp index 58f3dff..42036a7 100644 --- a/parseagle/schematic/sheet.cpp +++ b/parseagle/schematic/sheet.cpp @@ -12,7 +12,7 @@ Sheet::Sheet(const DomElement& root, QStringList* errors) } else if (child.getTagName() == "plain") { foreach (const DomElement& plainChild, child.getChilds()) { if (plainChild.getTagName() == "wire") { - mWires.append(Wire(plainChild)); + mWires.append(Wire(plainChild, errors)); } else if (plainChild.getTagName() == "rectangle") { mRectangles.append(Rectangle(plainChild)); } else if (plainChild.getTagName() == "circle") { diff --git a/parseagle/symbol/symbol.cpp b/parseagle/symbol/symbol.cpp index 1bc54dd..fca3fa1 100644 --- a/parseagle/symbol/symbol.cpp +++ b/parseagle/symbol/symbol.cpp @@ -11,7 +11,7 @@ Symbol::Symbol(const DomElement& root, QStringList* errors) if (child.getTagName() == "description") { mDescription = child.getText(); } else if (child.getTagName() == "wire") { - mWires.append(Wire(child)); + mWires.append(Wire(child, errors)); } else if (child.getTagName() == "rectangle") { mRectangles.append(Rectangle(child)); } else if (child.getTagName() == "circle") {