Skip to content

Commit

Permalink
Refactored getting of pin identifier into function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kjell Morgenstern authored and KjellMorgenstern committed Sep 4, 2023
1 parent 4772aa0 commit 8d480a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
43 changes: 25 additions & 18 deletions src/ipc/ipc_d_356.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ class IPCD356A {
};
};

QString getPinNumberOrIdentifier(const QString & connectorId, const QString & connectorName) {
QString pin;

QRegularExpression matcher("\\d+"); // Matches one or more digits
QRegularExpressionMatch match = matcher.match(connectorId);

if(connectorId.length() <= 4) {
pin = connectorId;
} else if(match.hasMatch()) {
QString numberStr = match.captured(0);
pin = numberStr.length() > 4 ? numberStr.left(4) : numberStr;
} else {
pin = connectorId.left(4);
}

if (connectorName.contains("anode", Qt::CaseInsensitive)) pin = "A";
if (connectorName.contains("catho", Qt::CaseInsensitive)) pin = "C";
// Use the connector number instead of "GND" to avoid duplicate naming
// if (connectorName.contains("gnd", Qt::CaseInsensitive)) pin = "GND";
if (connectorName == "-") pin = "-";
if (connectorName == "+") pin = "+";
return pin;
}

// Forward declaration, currently unused
// QString electricalTestRecord(QString netLabel, QString partLabel, QString connectorName, QString pin, bool isTHT, bool isMiddle, bool isPlated, bool isDrilled, int r, int x, int y, int w, int h, int layer, int ccw_angle);
QString electricalTestRecord(int cmd, QString netLabel, QString partLabel, QString connectorName, QString connectorId, bool isTHT, bool isMiddle, bool isPlated, bool isDrilled, int r, int x, int y, int w, int h, int layer, int ccw_angle) {
Expand Down Expand Up @@ -70,24 +94,7 @@ QString electricalTestRecord(int cmd, QString netLabel, QString partLabel, QStri

int soldermask = 0;

QList<uint> numbers = TextUtils::getPositiveIntegers(connectorId);
QString pin;

if(connectorId.length() <= 4) {
pin = connectorId;
} else if(!numbers.isEmpty()) {
QString numberStr = QString::number(numbers.constFirst());
pin = numberStr.length() > 4 ? numberStr.left(4) : numberStr;
} else {
pin = connectorId.left(4);
}

if (connectorName.contains("anode", Qt::CaseInsensitive)) pin = "A";
if (connectorName.contains("catho", Qt::CaseInsensitive)) pin = "C";
// Use the connector number instead of "GND" to avoid duplicate naming
// if (connectorName.contains("gnd", Qt::CaseInsensitive)) pin = "GND";
if (connectorName == "-") pin = "-";
if (connectorName == "+") pin = "+";
QString pin = getPinNumberOrIdentifier(connectorId, connectorName);

int angle = (ccw_angle % 360 + 360) % 360;

Expand Down
13 changes: 0 additions & 13 deletions src/utils/textutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,19 +980,6 @@ QList<double> TextUtils::getTransformFloats(const QString & transform) {

return list;
}
QList<uint> TextUtils::getPositiveIntegers(const QString & str) {
QList<uint> list;
int pos = 0;

QRegularExpressionMatch match;
while ((pos = str.indexOf(TextUtils::positiveIntegerMatcher, pos, &match)) != -1) {
list << str.mid(pos, match.capturedLength()).toDouble();
pos += match.capturedLength();
match = QRegularExpressionMatch();
}

return list;
}

void TextUtils::gWrap(QDomDocument & domDocument, const QHash<QString, QString> & attributes)
{
Expand Down
1 change: 0 additions & 1 deletion src/utils/textutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class TextUtils
static const QString AdobeIllustratorIdentifier;

static QMap<QString, QString> parseFileForViewImages(const QString &fzpPath);
static QList<uint> getPositiveIntegers(const QString &str);
protected:
static bool pxToInches(QDomElement &elem, const QString &attrName, bool isIllustrator);
static void squashNotElement(QDomElement & element, const QString & elementName, const QString & attName, const QRegularExpression & matchContent, bool & result);
Expand Down

0 comments on commit 8d480a1

Please sign in to comment.