File indexing completed on 2024-05-12 04:41:09
0001 /* AtCore KDE Libary for 3D Printers 0002 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0003 SPDX-FileCopyrightText: 2019 Chris Rizzitello <rizzitello@kde.org> 0004 */ 0005 0006 #include "beddeform.h" 0007 #include <QRegularExpressionMatch> 0008 0009 struct BedDeform::BedDeformPrivate { 0010 /** bedData Beddeform data*/ 0011 QVariantList bedData; 0012 /** Regex to capture lines containing valid data */ 0013 static const QRegularExpression lineRegEx; 0014 /** Regex to capture Data from in lines*/ 0015 static const QRegularExpression valueRegEx; 0016 }; 0017 /** 0018 * @brief Line with the pattern of digit(s) a single space then '+' or '-'. 0019 * Examples: 0020 * 0 -0.155 +5.123 -4.567 0021 * 10 +8.901 -2.345 +6.789 0022 */ 0023 const QRegularExpression BedDeform::BedDeformPrivate::lineRegEx = QRegularExpression(QStringLiteral(R"((?:\d+\s(\+|\-)))")); 0024 /** 0025 * @brief Numeric value with a decimal (maybe negative) 0026 * example Input : 0 +0.005 -1.110, +1.040 0027 * captured values from above line: 0.005, -1.110, 1.04 0028 */ 0029 const QRegularExpression BedDeform::BedDeformPrivate::valueRegEx = QRegularExpression(QStringLiteral(R"((?<value>\-?\d+\.?\d+))")); 0030 0031 BedDeform::BedDeform(QObject *parent) 0032 : QObject(parent) 0033 , d(new BedDeformPrivate) 0034 { 0035 } 0036 0037 BedDeform::~BedDeform() 0038 { 0039 delete d; 0040 QObject::~QObject(); 0041 } 0042 void BedDeform::decodeDeform(const QStringList &rawData) 0043 { 0044 d->bedData.clear(); 0045 QVariantList coreList; 0046 for (const QString &line : rawData) { 0047 QRegularExpressionMatch lineCheck = d->lineRegEx.match(line); 0048 if (lineCheck.hasMatch()) { 0049 QRegularExpressionMatchIterator valueCheck = d->valueRegEx.globalMatch(line); 0050 while (valueCheck.hasNext()) { 0051 coreList.append(valueCheck.next().captured(QStringLiteral("value")).toDouble()); 0052 } 0053 d->bedData.push_back(coreList); 0054 coreList.clear(); 0055 } 0056 } 0057 Q_EMIT dataChanged(d->bedData); 0058 } 0059 0060 QVariantList BedDeform::bedDeformationGrid() 0061 { 0062 return d->bedData; 0063 }