From b78e171537fe8cc227521bb6b12bfb923a248f08 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 16 Sep 2021 10:56:37 +0200 Subject: replace txt export support with specific txyz export --- stftxtexport.cc | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'stftxtexport.cc') diff --git a/stftxtexport.cc b/stftxtexport.cc index 0163848..e6793b2 100644 --- a/stftxtexport.cc +++ b/stftxtexport.cc @@ -20,32 +20,42 @@ #include #include "stftxtexport.h" -class StfToTxtStrokeList : public StfReader::StrokeHandler { +class StfToTXYP : public StfReader::StrokeHandler { QTextStream _out; QPoint _lastP; - qint64 _lastTime; + int _lastForce; + qint64 _startTime; + bool _relativeTime; public: - StfToTxtStrokeList(QIODevice *out) - : _out(out) { + StfToTXYP(QIODevice *out, bool relativeTime) + : _out(out), _lastP(), _lastForce(0), _startTime(0), _relativeTime(relativeTime) { + _out << "T\tX\tY\tP\n"; } bool startStroke(const QPoint& p, int force, qint64 time) { - _out << time << " penDown " << p.x() << ' ' << p.y() << ' ' << force << '\n'; + if (_relativeTime && _startTime == 0) { + _startTime = time; + } + _out << (time - _startTime) << '\t' << p.x() << '\t' << p.y() << '\t' << force << '\n'; _lastP = p; - _lastTime = time; + _lastForce = force; return true; } bool strokePoint(const QPoint& p, int force, qint64 time) { - _out << time << " penMove " << p.x() << ' ' << p.y() << ' ' << force << '\n'; + _out << (time - _startTime) << '\t' << p.x() << '\t' << p.y() << '\t' << force << '\n'; _lastP = p; - _lastTime = time; + _lastForce = force; return true; } bool endStroke(qint64 time) { - _out << time << " penUp " << _lastP.x() << ' ' << _lastP.y() << ' ' << 0 << '\n'; + // Ensure there is a entry with force=0, in case the pen didn't provide it + if (_lastForce != 0) { + _out << (time - _startTime) << '\t' << _lastP.x() << '\t' << _lastP.y() << '\t' << 0 << '\n'; + _lastForce = 0; + } return true; } }; @@ -55,11 +65,15 @@ StfTxtExport::StfTxtExport(AfdNotebook *nb) { } -void StfTxtExport::exportStrokeList(QIODevice *out, int pageNum) +void StfTxtExport::exportToTXYP(QIODevice *out, int pageNum, bool relativeTime) { QStringList pens = _nb->penSerials(); if (pens.isEmpty()) return; + StfToTXYP h(out, relativeTime); + StfReader r; + r.setStrokeHandler(&h); + QStringList strokeFiles = _nb->strokeFiles(pens.first(), pageNum); foreach (const QString &strokeFile, strokeFiles) { QFile in(strokeFile); @@ -68,11 +82,8 @@ void StfTxtExport::exportStrokeList(QIODevice *out, int pageNum) continue; } - StfToTxtStrokeList h(out); - StfReader r; - r.setStrokeHandler(&h); if (!r.parse(&in)) { - qWarning() << "Could not open parse file:" << strokeFile; + qWarning() << "Could not parse stroke file:" << strokeFile; continue; } } -- cgit v1.2.3