Skip to content

Commit

Permalink
Wire: Add support for line style and line cap (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ubruhin authored Jan 26, 2024
1 parent 0b96168 commit e60f90b
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 8 deletions.
2 changes: 1 addition & 1 deletion parseagle/board/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion parseagle/board/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
44 changes: 44 additions & 0 deletions parseagle/common/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion parseagle/common/wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@

namespace parseagle {

Wire::Wire(const DomElement& root)
Wire::Wire(const DomElement& root, QStringList* errors)
{
mLayer = root.getAttributeAsInt("layer");
mWidth = root.getAttributeAsDouble("width");
mP1.x = root.getAttributeAsDouble("x1");
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
Expand Down
7 changes: 6 additions & 1 deletion parseagle/common/wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define PARSEAGLE_WIRE_H

#include <QtCore>
#include "../common/enums.h"
#include "../common/point.h"

namespace parseagle {
Expand All @@ -14,23 +15,27 @@ class Wire final

// Constructors / Destructor
Wire() = delete;
explicit Wire(const DomElement& root);
explicit Wire(const DomElement& root, QStringList* errors = nullptr);
~Wire() noexcept;

// Getters
int getLayer() const noexcept {return mLayer;}
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:
int mLayer;
double mWidth;
Point mP1;
Point mP2;
WireStyle mWireStyle = WireStyle::Continuous;
double mCurve = 0;
WireCap mWireCap = WireCap::Round;
};

} // namespace parseagle
Expand Down
2 changes: 1 addition & 1 deletion parseagle/package/package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion parseagle/schematic/segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion parseagle/schematic/sheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion parseagle/symbol/symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit e60f90b

Please sign in to comment.