From 9c52aaf043753dbb594c7420f776c836215dd6d2 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Sat, 14 Dec 2019 21:56:31 +0100 Subject: build-system: move exportfuncs to backend-shared WARNING: multi directory commit, needed to secure it builds. move the core/exportfuncs.* to backend-shared. update backend-shared/CMakeLists.txt to generate backend-shared lib update CMakeLists.txt to include backend-shared lib in link process. update ios project to reflect new directory Signed-off-by: Jan Iversen --- CMakeLists.txt | 2 + backend-shared/CMakeLists.txt | 7 + backend-shared/exportfuncs.cpp | 318 ++++++++++++++++++++++++++++++++ backend-shared/exportfuncs.h | 39 ++++ core/CMakeLists.txt | 2 - core/exportfuncs.cpp | 318 -------------------------------- core/exportfuncs.h | 39 ---- desktop-widgets/divelogexportdialog.cpp | 2 +- mobile-widgets/qmlmanager.cpp | 2 +- packaging/ios/Subsurface-mobile.pro | 4 +- 10 files changed, 370 insertions(+), 363 deletions(-) create mode 100644 backend-shared/exportfuncs.cpp create mode 100644 backend-shared/exportfuncs.h delete mode 100644 core/exportfuncs.cpp delete mode 100644 core/exportfuncs.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 55589f830..f032c6c45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -312,6 +312,7 @@ if (SUBSURFACE_TARGET_EXECUTABLE MATCHES "MobileExecutable") subsurface_mobile subsurface_profile subsurface_mapwidget + subsurface_backend_shared subsurface_models_mobile subsurface_corelib ${SUBSURFACE_LINK_LIBRARIES} @@ -335,6 +336,7 @@ elseif (SUBSURFACE_TARGET_EXECUTABLE MATCHES "DesktopExecutable") subsurface_profile subsurface_statistics subsurface_mapwidget + subsurface_backend_shared subsurface_models_desktop subsurface_commands_desktop subsurface_corelib diff --git a/backend-shared/CMakeLists.txt b/backend-shared/CMakeLists.txt index 750d22a98..b6502bfdf 100644 --- a/backend-shared/CMakeLists.txt +++ b/backend-shared/CMakeLists.txt @@ -1,2 +1,9 @@ # backend functionality shared between Desktop (UI) and Mobile (QML) +set(BACKEND_SRCS + exportfuncs.cpp + exportfuncs.h +) + +add_library(subsurface_backend_shared STATIC ${BACKEND_SRCS}) +target_link_libraries(subsurface_backend_shared ${QT_LIBRARIES}) diff --git a/backend-shared/exportfuncs.cpp b/backend-shared/exportfuncs.cpp new file mode 100644 index 000000000..839c0bf1d --- /dev/null +++ b/backend-shared/exportfuncs.cpp @@ -0,0 +1,318 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include "core/membuffer.h" +#include "core/divesite.h" +#include "core/tag.h" +#include "core/file.h" +#include "core/errorhelper.h" +#include "core/divefilter.h" +#include "core/divesite.h" +#include "exportfuncs.h" + + +exportFuncs *exportFuncs::instance() +{ + static exportFuncs *self = new exportFuncs; + return self; +} + +void exportFuncs::exportProfile(QString filename, const bool selected_only) +{ + struct dive *dive; + int i; + int count = 0; + if (!filename.endsWith(".png", Qt::CaseInsensitive)) + filename = filename.append(".png"); + QFileInfo fi(filename); + + for_each_dive (i, dive) { + if (selected_only && !dive->selected) + continue; + if (count) + saveProfile(dive, fi.path() + QDir::separator() + fi.completeBaseName().append(QString("-%1.").arg(count)) + fi.suffix()); + else + saveProfile(dive, filename); + ++count; + } +} + + +void exportFuncs::export_TeX(const char *filename, const bool selected_only, bool plain) +{ + FILE *f; + QDir texdir = QFileInfo(filename).dir(); + struct dive *dive; + const struct units *units = get_units(); + const char *unit; + const char *ssrf; + int i; + bool need_pagebreak = false; + + struct membuffer buf = {}; + + if (plain) { + ssrf = ""; + put_format(&buf, "\\input subsurfacetemplate\n"); + put_format(&buf, "%% This is a plain TeX file. Compile with pdftex, not pdflatex!\n"); + put_format(&buf, "%% You will also need a subsurfacetemplate.tex in the current directory.\n"); + } else { + ssrf = "ssrf"; + put_format(&buf, "\\input subsurfacelatextemplate\n"); + put_format(&buf, "%% This is a plain LaTeX file. Compile with pdflatex, not pdftex!\n"); + put_format(&buf, "%% You will also need a subsurfacelatextemplate.tex in the current directory.\n"); + } + put_format(&buf, "%% You can download an example from http://www.atdotde.de/~robert/subsurfacetemplate\n%%\n"); + put_format(&buf, "%%\n"); + put_format(&buf, "%% Notes: TeX/LaTex will not render the degree symbol correctly by default. In LaTeX, you may\n"); + put_format(&buf, "%% add the following line to the end of the preamble of your template to ensure correct output:\n"); + put_format(&buf, "%% \\usepackage[utf8]{inputenc}\n"); + put_format(&buf, "%% \\usepackage{gensymb}\n"); + put_format(&buf, "%% \\DeclareUnicodeCharacter{00B0}{\\degree}\n"); //replaces ° with \degree + put_format(&buf, "%%\n"); + + /* Define text fields with the units used for export. These values are set in the Subsurface Preferences + * and the text fields created here are included in the data fields below. + */ + put_format(&buf, "\n%% These fields contain the units used in other fields below. They may be\n"); + put_format(&buf, "%% referenced as needed in TeX templates.\n"); + put_format(&buf, "%% \n"); + put_format(&buf, "%% By default, Subsurface exports units of volume as \"ℓ\" and \"cuft\", which do\n"); + put_format(&buf, "%% not render well in TeX/LaTeX. The code below substitutes \"L\" and \"ft$^{3}$\",\n"); + put_format(&buf, "%% respectively. If you wish to display the original values, you may edit this\n"); + put_format(&buf, "%% list and all calls to those units will be updated in your document.\n"); + + put_format(&buf, "\\def\\%sdepthunit{\\%sunit%s}", ssrf, ssrf, units->length == units::METERS ? "meter" : "ft"); + put_format(&buf, "\\def\\%sweightunit{\\%sunit%s}",ssrf, ssrf, units->weight == units::KG ? "kg" : "lb"); + put_format(&buf, "\\def\\%spressureunit{\\%sunit%s}", ssrf, ssrf, units->pressure == units::BAR ? "bar" : "psi"); + put_format(&buf, "\\def\\%stemperatureunit{\\%sunit%s}", ssrf, ssrf, units->temperature == units::CELSIUS ? "centigrade" : "fahrenheit"); + put_format(&buf, "\\def\\%svolumeunit{\\%sunit%s}", ssrf, ssrf, units->volume == units::LITER ? "liter" : "cuft"); + put_format(&buf, "\\def\\%sverticalspeedunit{\\%sunit%s}", ssrf, ssrf, units->length == units::METERS ? "meterpermin" : "ftpermin"); + + put_format(&buf, "\n%%%%%%%%%% Begin Dive Data: %%%%%%%%%%\n"); + + for_each_dive (i, dive) { + if (selected_only && !dive->selected) + continue; + + saveProfile(dive, texdir.filePath(QString("profile%1.png").arg(dive->number))); + struct tm tm; + utc_mkdate(dive->when, &tm); + + dive_site *site = dive->dive_site; + QRegExp ct("countrytag: (\\w+)"); + QString country; + if (site && ct.indexIn(site->notes) >= 0) + country = ct.cap(1); + else + country = ""; + + pressure_t delta_p = {.mbar = 0}; + + QString star = "*"; + QString viz = star.repeated(dive->visibility); + QString rating = star.repeated(dive->rating); + + int i; + int qty_cyl; + int qty_weight; + double total_weight; + + if (need_pagebreak) { + if (plain) + put_format(&buf, "\\vfill\\eject\n"); + + else + put_format(&buf, "\\newpage\n"); + } + need_pagebreak = true; + put_format(&buf, "\n%% Time, Date, and location:\n"); + put_format(&buf, "\\def\\%sdate{%04u-%02u-%02u}\n", ssrf, + tm.tm_year, tm.tm_mon+1, tm.tm_mday); + put_format(&buf, "\\def\\%shour{%02u}\n", ssrf, tm.tm_hour); + put_format(&buf, "\\def\\%sminute{%02u}\n", ssrf, tm.tm_min); + put_format(&buf, "\\def\\%snumber{%d}\n", ssrf, dive->number); + put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name : ""); + put_format(&buf, "\\def\\%sspot{}\n", ssrf); + put_format(&buf, "\\def\\%ssitename{%s}\n", ssrf, site ? site->name : ""); + site ? put_format(&buf, "\\def\\%sgpslat{%f}\n", ssrf, site->location.lat.udeg / 1000000.0) : put_format(&buf, "\\def\\%sgpslat{}\n", ssrf); + site ? put_format(&buf, "\\def\\%sgpslon{%f}\n", ssrf, site->location.lon.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslon{}\n"); + put_format(&buf, "\\def\\%scomputer{%s}\n", ssrf, dive->dc.model); + put_format(&buf, "\\def\\%scountry{%s}\n", ssrf, qPrintable(country)); + put_format(&buf, "\\def\\%stime{%u:%02u}\n", ssrf, FRACTION(dive->duration.seconds, 60)); + + put_format(&buf, "\n%% Dive Profile Details:\n"); + dive->maxtemp.mkelvin ? put_format(&buf, "\\def\\%smaxtemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->maxtemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%smaxtemp{}\n", ssrf); + dive->mintemp.mkelvin ? put_format(&buf, "\\def\\%smintemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->mintemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%ssrfmintemp{}\n", ssrf); + dive->watertemp.mkelvin ? put_format(&buf, "\\def\\%swatertemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->watertemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%swatertemp{}\n", ssrf); + dive->airtemp.mkelvin ? put_format(&buf, "\\def\\%sairtemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->airtemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%sairtemp{}\n", ssrf); + dive->maxdepth.mm ? put_format(&buf, "\\def\\%smaximumdepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->maxdepth.mm, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%smaximumdepth{}\n", ssrf); + dive->meandepth.mm ? put_format(&buf, "\\def\\%smeandepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->meandepth.mm, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%smeandepth{}\n", ssrf); + + struct tag_entry *tag = dive->tag_list; + QString tags; + if (tag) { + tags = tag->tag->name; + while ((tag = tag->next)) + tags += QString(", ") + QString(tag->tag->name); + } + put_format(&buf, "\\def\\%stype{%s}\n", ssrf, qPrintable(tags)); + put_format(&buf, "\\def\\%sviz{%s}\n", ssrf, qPrintable(viz)); + put_format(&buf, "\\def\\%srating{%s}\n", ssrf, qPrintable(rating)); + put_format(&buf, "\\def\\%splot{\\includegraphics[width=9cm,height=4cm]{profile%d}}\n", ssrf, dive->number); + put_format(&buf, "\\def\\%sprofilename{profile%d}\n", ssrf, dive->number); + put_format(&buf, "\\def\\%scomment{%s}\n", ssrf, dive->notes ? dive->notes : ""); + put_format(&buf, "\\def\\%sbuddy{%s}\n", ssrf, dive->buddy ? dive->buddy : ""); + put_format(&buf, "\\def\\%sdivemaster{%s}\n", ssrf, dive->divemaster ? dive->divemaster : ""); + put_format(&buf, "\\def\\%ssuit{%s}\n", ssrf, dive->suit ? dive->suit : ""); + + // Print cylinder data + put_format(&buf, "\n%% Gas use information:\n"); + qty_cyl = 0; + for (i = 0; i < dive->cylinders.nr; i++){ + const cylinder_t &cyl = *get_cylinder(dive, i); + if (is_cylinder_used(dive, i) || (prefs.display_unused_tanks && cyl.type.description)){ + put_format(&buf, "\\def\\%scyl%cdescription{%s}\n", ssrf, 'a' + i, cyl.type.description); + put_format(&buf, "\\def\\%scyl%cgasname{%s}\n", ssrf, 'a' + i, gasname(cyl.gasmix)); + put_format(&buf, "\\def\\%scyl%cmixO2{%.1f\\%%}\n", ssrf, 'a' + i, get_o2(cyl.gasmix)/10.0); + put_format(&buf, "\\def\\%scyl%cmixHe{%.1f\\%%}\n", ssrf, 'a' + i, get_he(cyl.gasmix)/10.0); + put_format(&buf, "\\def\\%scyl%cmixN2{%.1f\\%%}\n", ssrf, 'a' + i, (100.0 - (get_o2(cyl.gasmix)/10.0) - (get_he(cyl.gasmix)/10.0))); + delta_p.mbar += cyl.start.mbar - cyl.end.mbar; + put_format(&buf, "\\def\\%scyl%cstartpress{%.1f\\%spressureunit}\n", ssrf, 'a' + i, get_pressure_units(cyl.start.mbar, &unit)/1.0, ssrf); + put_format(&buf, "\\def\\%scyl%cendpress{%.1f\\%spressureunit}\n", ssrf, 'a' + i, get_pressure_units(cyl.end.mbar, &unit)/1.0, ssrf); + qty_cyl += 1; + } else { + put_format(&buf, "\\def\\%scyl%cdescription{}\n", ssrf, 'a' + i); + put_format(&buf, "\\def\\%scyl%cgasname{}\n", ssrf, 'a' + i); + put_format(&buf, "\\def\\%scyl%cmixO2{}\n", ssrf, 'a' + i); + put_format(&buf, "\\def\\%scyl%cmixHe{}\n", ssrf, 'a' + i); + put_format(&buf, "\\def\\%scyl%cmixN2{}\n", ssrf, 'a' + i); + delta_p.mbar += cyl.start.mbar - cyl.end.mbar; + put_format(&buf, "\\def\\%scyl%cstartpress{}\n", ssrf, 'a' + i); + put_format(&buf, "\\def\\%scyl%cendpress{}\n", ssrf, 'a' + i); + qty_cyl += 1; + } + } + put_format(&buf, "\\def\\%sqtycyl{%d}\n", ssrf, qty_cyl); + put_format(&buf, "\\def\\%sgasuse{%.1f\\%spressureunit}\n", ssrf, get_pressure_units(delta_p.mbar, &unit)/1.0, ssrf); + put_format(&buf, "\\def\\%ssac{%.2f\\%svolumeunit/min}\n", ssrf, get_volume_units(dive->sac, NULL, &unit), ssrf); + + //Code block prints all weights listed in dive. + put_format(&buf, "\n%% Weighting information:\n"); + qty_weight = 0; + total_weight = 0; + for (i = 0; i < dive->weightsystems.nr; i++) { + weightsystem_t w = dive->weightsystems.weightsystems[i]; + put_format(&buf, "\\def\\%sweight%ctype{%s}\n", ssrf, 'a' + i, w.description); + put_format(&buf, "\\def\\%sweight%camt{%.3f\\%sweightunit}\n", ssrf, 'a' + i, get_weight_units(w.weight.grams, NULL, &unit), ssrf); + qty_weight += 1; + total_weight += get_weight_units(w.weight.grams, NULL, &unit); + } + put_format(&buf, "\\def\\%sqtyweights{%d}\n", ssrf, qty_weight); + put_format(&buf, "\\def\\%stotalweight{%.2f\\%sweightunit}\n", ssrf, total_weight, ssrf); + unit = ""; + + // Legacy fields + put_format(&buf, "\\def\\%sspot{}\n", ssrf); + put_format(&buf, "\\def\\%sentrance{}\n", ssrf); + put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name : ""); + dive->maxdepth.mm ? put_format(&buf, "\\def\\%sdepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->maxdepth.mm, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%sdepth{}\n", ssrf); + + put_format(&buf, "\\%spage\n", ssrf); + + } + + if (plain) + put_format(&buf, "\\bye\n"); + else + put_format(&buf, "\\end{document}\n"); + + f = subsurface_fopen(filename, "w+"); + if (!f) { + report_error(qPrintable(tr("Can't open file %s")), filename); + } else { + flush_buffer(&buf, f); /*check for writing errors? */ + fclose(f); + } + free_buffer(&buf); + +} + +void exportFuncs::export_depths(const char *filename, const bool selected_only) +{ + FILE *f; + struct dive *dive; + depth_t depth; + int i; + const char *unit = NULL; + + struct membuffer buf = {}; + + for_each_dive (i, dive) { + if (selected_only && !dive->selected) + continue; + + FOR_EACH_PICTURE (dive) { + int n = dive->dc.samples; + struct sample *s = dive->dc.sample; + depth.mm = 0; + while (--n >= 0 && (int32_t)s->time.seconds <= picture->offset.seconds) { + depth.mm = s->depth.mm; + s++; + } + put_format(&buf, "%s\t%.1f", picture->filename, get_depth_units(depth.mm, NULL, &unit)); + put_format(&buf, "%s\n", unit); + } + } + + f = subsurface_fopen(filename, "w+"); + if (!f) { + report_error(qPrintable(tr("Can't open file %s")), filename); + } else { + flush_buffer(&buf, f); /*check for writing errors? */ + fclose(f); + } + free_buffer(&buf); +} + +std::vector exportFuncs::getDiveSitesToExport(bool selectedOnly) +{ + std::vector res; +#ifndef SUBSURFACE_MOBILE + // Waiting for DiveFilter to be combined for both mobile and desktop + + if (selectedOnly && DiveFilter::instance()->diveSiteMode()) { + // Special case in dive site mode: export all selected dive sites, + // not the dive sites of selected dives. + QVector sites = DiveFilter::instance()->filteredDiveSites(); + res.reserve(sites.size()); + for (const dive_site *ds: sites) + res.push_back(ds); + return res; + } + + res.reserve(dive_site_table.nr); + for (int i = 0; i < dive_site_table.nr; i++) { + struct dive_site *ds = get_dive_site(i, &dive_site_table); + if (dive_site_is_empty(ds)) + continue; + if (selectedOnly && !is_dive_site_selected(ds)) + continue; + res.push_back(ds); + } +#else + /* walk the dive site list */ + int i; + const struct dive_site *ds; + for_each_dive_site (i, ds, &dive_site_table) + res.push_back(get_dive_site(i, &dive_site_table)); +#endif + return res; +} + +void exportFuncs::exportUsingStyleSheet(QString filename, bool doExport, int units, + QString stylesheet, bool anonymize) +{ + future = QtConcurrent::run(export_dives_xslt, filename.toUtf8(), doExport, units, stylesheet.toUtf8(), anonymize); +} diff --git a/backend-shared/exportfuncs.h b/backend-shared/exportfuncs.h new file mode 100644 index 000000000..a378e152d --- /dev/null +++ b/backend-shared/exportfuncs.h @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef EXPORTFUNCS_H +#define EXPORTFUNCS_H + +#include +#include +#include "core/dive.h" + +class exportFuncs: public QObject { + Q_OBJECT + +public: + static exportFuncs *instance(); + + void exportProfile(QString filename, const bool selected_only); + void export_TeX(const char *filename, const bool selected_only, bool plain); + void export_depths(const char *filename, const bool selected_only); + std::vector getDiveSitesToExport(bool selectedOnly); + void exportUsingStyleSheet(QString filename, bool doExport, int units, + QString stylesheet, bool anonymize); + QFuture future; + + // prepareDivesForUploadDiveLog + // prepareDivesForUploadDiveShare + +private: + exportFuncs() {} + + // WARNING + // saveProfile uses the UI and are therefore different between + // Desktop (UI) and Mobile (QML) + // In order to solve this difference, the actual implementations + // are done in + // desktop-widgets/divelogexportdialog.cpp and + // mobile-widgets/qmlmanager.cpp + void saveProfile(const struct dive *dive, const QString filename); +}; + +#endif // EXPORT_FUNCS_H diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 376cfda4f..017fbdeea 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -86,8 +86,6 @@ set(SUBSURFACE_CORE_LIB_SRCS errorhelper.c exif.cpp exif.h - exportfuncs.cpp - exportfuncs.h file.c file.h format.cpp diff --git a/core/exportfuncs.cpp b/core/exportfuncs.cpp deleted file mode 100644 index 839c0bf1d..000000000 --- a/core/exportfuncs.cpp +++ /dev/null @@ -1,318 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include -#include "core/membuffer.h" -#include "core/divesite.h" -#include "core/tag.h" -#include "core/file.h" -#include "core/errorhelper.h" -#include "core/divefilter.h" -#include "core/divesite.h" -#include "exportfuncs.h" - - -exportFuncs *exportFuncs::instance() -{ - static exportFuncs *self = new exportFuncs; - return self; -} - -void exportFuncs::exportProfile(QString filename, const bool selected_only) -{ - struct dive *dive; - int i; - int count = 0; - if (!filename.endsWith(".png", Qt::CaseInsensitive)) - filename = filename.append(".png"); - QFileInfo fi(filename); - - for_each_dive (i, dive) { - if (selected_only && !dive->selected) - continue; - if (count) - saveProfile(dive, fi.path() + QDir::separator() + fi.completeBaseName().append(QString("-%1.").arg(count)) + fi.suffix()); - else - saveProfile(dive, filename); - ++count; - } -} - - -void exportFuncs::export_TeX(const char *filename, const bool selected_only, bool plain) -{ - FILE *f; - QDir texdir = QFileInfo(filename).dir(); - struct dive *dive; - const struct units *units = get_units(); - const char *unit; - const char *ssrf; - int i; - bool need_pagebreak = false; - - struct membuffer buf = {}; - - if (plain) { - ssrf = ""; - put_format(&buf, "\\input subsurfacetemplate\n"); - put_format(&buf, "%% This is a plain TeX file. Compile with pdftex, not pdflatex!\n"); - put_format(&buf, "%% You will also need a subsurfacetemplate.tex in the current directory.\n"); - } else { - ssrf = "ssrf"; - put_format(&buf, "\\input subsurfacelatextemplate\n"); - put_format(&buf, "%% This is a plain LaTeX file. Compile with pdflatex, not pdftex!\n"); - put_format(&buf, "%% You will also need a subsurfacelatextemplate.tex in the current directory.\n"); - } - put_format(&buf, "%% You can download an example from http://www.atdotde.de/~robert/subsurfacetemplate\n%%\n"); - put_format(&buf, "%%\n"); - put_format(&buf, "%% Notes: TeX/LaTex will not render the degree symbol correctly by default. In LaTeX, you may\n"); - put_format(&buf, "%% add the following line to the end of the preamble of your template to ensure correct output:\n"); - put_format(&buf, "%% \\usepackage[utf8]{inputenc}\n"); - put_format(&buf, "%% \\usepackage{gensymb}\n"); - put_format(&buf, "%% \\DeclareUnicodeCharacter{00B0}{\\degree}\n"); //replaces ° with \degree - put_format(&buf, "%%\n"); - - /* Define text fields with the units used for export. These values are set in the Subsurface Preferences - * and the text fields created here are included in the data fields below. - */ - put_format(&buf, "\n%% These fields contain the units used in other fields below. They may be\n"); - put_format(&buf, "%% referenced as needed in TeX templates.\n"); - put_format(&buf, "%% \n"); - put_format(&buf, "%% By default, Subsurface exports units of volume as \"ℓ\" and \"cuft\", which do\n"); - put_format(&buf, "%% not render well in TeX/LaTeX. The code below substitutes \"L\" and \"ft$^{3}$\",\n"); - put_format(&buf, "%% respectively. If you wish to display the original values, you may edit this\n"); - put_format(&buf, "%% list and all calls to those units will be updated in your document.\n"); - - put_format(&buf, "\\def\\%sdepthunit{\\%sunit%s}", ssrf, ssrf, units->length == units::METERS ? "meter" : "ft"); - put_format(&buf, "\\def\\%sweightunit{\\%sunit%s}",ssrf, ssrf, units->weight == units::KG ? "kg" : "lb"); - put_format(&buf, "\\def\\%spressureunit{\\%sunit%s}", ssrf, ssrf, units->pressure == units::BAR ? "bar" : "psi"); - put_format(&buf, "\\def\\%stemperatureunit{\\%sunit%s}", ssrf, ssrf, units->temperature == units::CELSIUS ? "centigrade" : "fahrenheit"); - put_format(&buf, "\\def\\%svolumeunit{\\%sunit%s}", ssrf, ssrf, units->volume == units::LITER ? "liter" : "cuft"); - put_format(&buf, "\\def\\%sverticalspeedunit{\\%sunit%s}", ssrf, ssrf, units->length == units::METERS ? "meterpermin" : "ftpermin"); - - put_format(&buf, "\n%%%%%%%%%% Begin Dive Data: %%%%%%%%%%\n"); - - for_each_dive (i, dive) { - if (selected_only && !dive->selected) - continue; - - saveProfile(dive, texdir.filePath(QString("profile%1.png").arg(dive->number))); - struct tm tm; - utc_mkdate(dive->when, &tm); - - dive_site *site = dive->dive_site; - QRegExp ct("countrytag: (\\w+)"); - QString country; - if (site && ct.indexIn(site->notes) >= 0) - country = ct.cap(1); - else - country = ""; - - pressure_t delta_p = {.mbar = 0}; - - QString star = "*"; - QString viz = star.repeated(dive->visibility); - QString rating = star.repeated(dive->rating); - - int i; - int qty_cyl; - int qty_weight; - double total_weight; - - if (need_pagebreak) { - if (plain) - put_format(&buf, "\\vfill\\eject\n"); - - else - put_format(&buf, "\\newpage\n"); - } - need_pagebreak = true; - put_format(&buf, "\n%% Time, Date, and location:\n"); - put_format(&buf, "\\def\\%sdate{%04u-%02u-%02u}\n", ssrf, - tm.tm_year, tm.tm_mon+1, tm.tm_mday); - put_format(&buf, "\\def\\%shour{%02u}\n", ssrf, tm.tm_hour); - put_format(&buf, "\\def\\%sminute{%02u}\n", ssrf, tm.tm_min); - put_format(&buf, "\\def\\%snumber{%d}\n", ssrf, dive->number); - put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name : ""); - put_format(&buf, "\\def\\%sspot{}\n", ssrf); - put_format(&buf, "\\def\\%ssitename{%s}\n", ssrf, site ? site->name : ""); - site ? put_format(&buf, "\\def\\%sgpslat{%f}\n", ssrf, site->location.lat.udeg / 1000000.0) : put_format(&buf, "\\def\\%sgpslat{}\n", ssrf); - site ? put_format(&buf, "\\def\\%sgpslon{%f}\n", ssrf, site->location.lon.udeg / 1000000.0) : put_format(&buf, "\\def\\gpslon{}\n"); - put_format(&buf, "\\def\\%scomputer{%s}\n", ssrf, dive->dc.model); - put_format(&buf, "\\def\\%scountry{%s}\n", ssrf, qPrintable(country)); - put_format(&buf, "\\def\\%stime{%u:%02u}\n", ssrf, FRACTION(dive->duration.seconds, 60)); - - put_format(&buf, "\n%% Dive Profile Details:\n"); - dive->maxtemp.mkelvin ? put_format(&buf, "\\def\\%smaxtemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->maxtemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%smaxtemp{}\n", ssrf); - dive->mintemp.mkelvin ? put_format(&buf, "\\def\\%smintemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->mintemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%ssrfmintemp{}\n", ssrf); - dive->watertemp.mkelvin ? put_format(&buf, "\\def\\%swatertemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->watertemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%swatertemp{}\n", ssrf); - dive->airtemp.mkelvin ? put_format(&buf, "\\def\\%sairtemp{%.1f\\%stemperatureunit}\n", ssrf, get_temp_units(dive->airtemp.mkelvin, &unit), ssrf) : put_format(&buf, "\\def\\%sairtemp{}\n", ssrf); - dive->maxdepth.mm ? put_format(&buf, "\\def\\%smaximumdepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->maxdepth.mm, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%smaximumdepth{}\n", ssrf); - dive->meandepth.mm ? put_format(&buf, "\\def\\%smeandepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->meandepth.mm, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%smeandepth{}\n", ssrf); - - struct tag_entry *tag = dive->tag_list; - QString tags; - if (tag) { - tags = tag->tag->name; - while ((tag = tag->next)) - tags += QString(", ") + QString(tag->tag->name); - } - put_format(&buf, "\\def\\%stype{%s}\n", ssrf, qPrintable(tags)); - put_format(&buf, "\\def\\%sviz{%s}\n", ssrf, qPrintable(viz)); - put_format(&buf, "\\def\\%srating{%s}\n", ssrf, qPrintable(rating)); - put_format(&buf, "\\def\\%splot{\\includegraphics[width=9cm,height=4cm]{profile%d}}\n", ssrf, dive->number); - put_format(&buf, "\\def\\%sprofilename{profile%d}\n", ssrf, dive->number); - put_format(&buf, "\\def\\%scomment{%s}\n", ssrf, dive->notes ? dive->notes : ""); - put_format(&buf, "\\def\\%sbuddy{%s}\n", ssrf, dive->buddy ? dive->buddy : ""); - put_format(&buf, "\\def\\%sdivemaster{%s}\n", ssrf, dive->divemaster ? dive->divemaster : ""); - put_format(&buf, "\\def\\%ssuit{%s}\n", ssrf, dive->suit ? dive->suit : ""); - - // Print cylinder data - put_format(&buf, "\n%% Gas use information:\n"); - qty_cyl = 0; - for (i = 0; i < dive->cylinders.nr; i++){ - const cylinder_t &cyl = *get_cylinder(dive, i); - if (is_cylinder_used(dive, i) || (prefs.display_unused_tanks && cyl.type.description)){ - put_format(&buf, "\\def\\%scyl%cdescription{%s}\n", ssrf, 'a' + i, cyl.type.description); - put_format(&buf, "\\def\\%scyl%cgasname{%s}\n", ssrf, 'a' + i, gasname(cyl.gasmix)); - put_format(&buf, "\\def\\%scyl%cmixO2{%.1f\\%%}\n", ssrf, 'a' + i, get_o2(cyl.gasmix)/10.0); - put_format(&buf, "\\def\\%scyl%cmixHe{%.1f\\%%}\n", ssrf, 'a' + i, get_he(cyl.gasmix)/10.0); - put_format(&buf, "\\def\\%scyl%cmixN2{%.1f\\%%}\n", ssrf, 'a' + i, (100.0 - (get_o2(cyl.gasmix)/10.0) - (get_he(cyl.gasmix)/10.0))); - delta_p.mbar += cyl.start.mbar - cyl.end.mbar; - put_format(&buf, "\\def\\%scyl%cstartpress{%.1f\\%spressureunit}\n", ssrf, 'a' + i, get_pressure_units(cyl.start.mbar, &unit)/1.0, ssrf); - put_format(&buf, "\\def\\%scyl%cendpress{%.1f\\%spressureunit}\n", ssrf, 'a' + i, get_pressure_units(cyl.end.mbar, &unit)/1.0, ssrf); - qty_cyl += 1; - } else { - put_format(&buf, "\\def\\%scyl%cdescription{}\n", ssrf, 'a' + i); - put_format(&buf, "\\def\\%scyl%cgasname{}\n", ssrf, 'a' + i); - put_format(&buf, "\\def\\%scyl%cmixO2{}\n", ssrf, 'a' + i); - put_format(&buf, "\\def\\%scyl%cmixHe{}\n", ssrf, 'a' + i); - put_format(&buf, "\\def\\%scyl%cmixN2{}\n", ssrf, 'a' + i); - delta_p.mbar += cyl.start.mbar - cyl.end.mbar; - put_format(&buf, "\\def\\%scyl%cstartpress{}\n", ssrf, 'a' + i); - put_format(&buf, "\\def\\%scyl%cendpress{}\n", ssrf, 'a' + i); - qty_cyl += 1; - } - } - put_format(&buf, "\\def\\%sqtycyl{%d}\n", ssrf, qty_cyl); - put_format(&buf, "\\def\\%sgasuse{%.1f\\%spressureunit}\n", ssrf, get_pressure_units(delta_p.mbar, &unit)/1.0, ssrf); - put_format(&buf, "\\def\\%ssac{%.2f\\%svolumeunit/min}\n", ssrf, get_volume_units(dive->sac, NULL, &unit), ssrf); - - //Code block prints all weights listed in dive. - put_format(&buf, "\n%% Weighting information:\n"); - qty_weight = 0; - total_weight = 0; - for (i = 0; i < dive->weightsystems.nr; i++) { - weightsystem_t w = dive->weightsystems.weightsystems[i]; - put_format(&buf, "\\def\\%sweight%ctype{%s}\n", ssrf, 'a' + i, w.description); - put_format(&buf, "\\def\\%sweight%camt{%.3f\\%sweightunit}\n", ssrf, 'a' + i, get_weight_units(w.weight.grams, NULL, &unit), ssrf); - qty_weight += 1; - total_weight += get_weight_units(w.weight.grams, NULL, &unit); - } - put_format(&buf, "\\def\\%sqtyweights{%d}\n", ssrf, qty_weight); - put_format(&buf, "\\def\\%stotalweight{%.2f\\%sweightunit}\n", ssrf, total_weight, ssrf); - unit = ""; - - // Legacy fields - put_format(&buf, "\\def\\%sspot{}\n", ssrf); - put_format(&buf, "\\def\\%sentrance{}\n", ssrf); - put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name : ""); - dive->maxdepth.mm ? put_format(&buf, "\\def\\%sdepth{%.1f\\%sdepthunit}\n", ssrf, get_depth_units(dive->maxdepth.mm, NULL, &unit), ssrf) : put_format(&buf, "\\def\\%sdepth{}\n", ssrf); - - put_format(&buf, "\\%spage\n", ssrf); - - } - - if (plain) - put_format(&buf, "\\bye\n"); - else - put_format(&buf, "\\end{document}\n"); - - f = subsurface_fopen(filename, "w+"); - if (!f) { - report_error(qPrintable(tr("Can't open file %s")), filename); - } else { - flush_buffer(&buf, f); /*check for writing errors? */ - fclose(f); - } - free_buffer(&buf); - -} - -void exportFuncs::export_depths(const char *filename, const bool selected_only) -{ - FILE *f; - struct dive *dive; - depth_t depth; - int i; - const char *unit = NULL; - - struct membuffer buf = {}; - - for_each_dive (i, dive) { - if (selected_only && !dive->selected) - continue; - - FOR_EACH_PICTURE (dive) { - int n = dive->dc.samples; - struct sample *s = dive->dc.sample; - depth.mm = 0; - while (--n >= 0 && (int32_t)s->time.seconds <= picture->offset.seconds) { - depth.mm = s->depth.mm; - s++; - } - put_format(&buf, "%s\t%.1f", picture->filename, get_depth_units(depth.mm, NULL, &unit)); - put_format(&buf, "%s\n", unit); - } - } - - f = subsurface_fopen(filename, "w+"); - if (!f) { - report_error(qPrintable(tr("Can't open file %s")), filename); - } else { - flush_buffer(&buf, f); /*check for writing errors? */ - fclose(f); - } - free_buffer(&buf); -} - -std::vector exportFuncs::getDiveSitesToExport(bool selectedOnly) -{ - std::vector res; -#ifndef SUBSURFACE_MOBILE - // Waiting for DiveFilter to be combined for both mobile and desktop - - if (selectedOnly && DiveFilter::instance()->diveSiteMode()) { - // Special case in dive site mode: export all selected dive sites, - // not the dive sites of selected dives. - QVector sites = DiveFilter::instance()->filteredDiveSites(); - res.reserve(sites.size()); - for (const dive_site *ds: sites) - res.push_back(ds); - return res; - } - - res.reserve(dive_site_table.nr); - for (int i = 0; i < dive_site_table.nr; i++) { - struct dive_site *ds = get_dive_site(i, &dive_site_table); - if (dive_site_is_empty(ds)) - continue; - if (selectedOnly && !is_dive_site_selected(ds)) - continue; - res.push_back(ds); - } -#else - /* walk the dive site list */ - int i; - const struct dive_site *ds; - for_each_dive_site (i, ds, &dive_site_table) - res.push_back(get_dive_site(i, &dive_site_table)); -#endif - return res; -} - -void exportFuncs::exportUsingStyleSheet(QString filename, bool doExport, int units, - QString stylesheet, bool anonymize) -{ - future = QtConcurrent::run(export_dives_xslt, filename.toUtf8(), doExport, units, stylesheet.toUtf8(), anonymize); -} diff --git a/core/exportfuncs.h b/core/exportfuncs.h deleted file mode 100644 index a378e152d..000000000 --- a/core/exportfuncs.h +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#ifndef EXPORTFUNCS_H -#define EXPORTFUNCS_H - -#include -#include -#include "core/dive.h" - -class exportFuncs: public QObject { - Q_OBJECT - -public: - static exportFuncs *instance(); - - void exportProfile(QString filename, const bool selected_only); - void export_TeX(const char *filename, const bool selected_only, bool plain); - void export_depths(const char *filename, const bool selected_only); - std::vector getDiveSitesToExport(bool selectedOnly); - void exportUsingStyleSheet(QString filename, bool doExport, int units, - QString stylesheet, bool anonymize); - QFuture future; - - // prepareDivesForUploadDiveLog - // prepareDivesForUploadDiveShare - -private: - exportFuncs() {} - - // WARNING - // saveProfile uses the UI and are therefore different between - // Desktop (UI) and Mobile (QML) - // In order to solve this difference, the actual implementations - // are done in - // desktop-widgets/divelogexportdialog.cpp and - // mobile-widgets/qmlmanager.cpp - void saveProfile(const struct dive *dive, const QString filename); -}; - -#endif // EXPORT_FUNCS_H diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp index 2ba837de9..dc0928e8f 100644 --- a/desktop-widgets/divelogexportdialog.cpp +++ b/desktop-widgets/divelogexportdialog.cpp @@ -15,7 +15,7 @@ #include "core/errorhelper.h" #include "core/file.h" #include "core/tag.h" -#include "core/exportfuncs.h" +#include "backend-shared/exportfuncs.h" #include "desktop-widgets/mainwindow.h" #include "desktop-widgets/divelogexportdialog.h" #include "desktop-widgets/diveshareexportdialog.h" diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index ca8d82f13..f58fa7d83 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -45,7 +45,7 @@ #include "core/settings/qPrefPartialPressureGas.h" #include "core/settings/qPrefUnit.h" #include "core/trip.h" -#include "core/exportfuncs.h" +#include "backend-shared/exportfuncs.h" #include "core/worldmap-save.h" #include "core/uploadDiveLogsDE.h" #include "core/uploadDiveShare.h" diff --git a/packaging/ios/Subsurface-mobile.pro b/packaging/ios/Subsurface-mobile.pro index af265488d..97c939275 100644 --- a/packaging/ios/Subsurface-mobile.pro +++ b/packaging/ios/Subsurface-mobile.pro @@ -31,7 +31,6 @@ SOURCES += ../../subsurface-mobile-main.cpp \ ../../core/divesitehelpers.cpp \ ../../core/errorhelper.c \ ../../core/exif.cpp \ - ../../core/exportfuncs.cpp \ ../../core/format.cpp \ ../../core/gettextfromc.cpp \ ../../core/metrics.cpp \ @@ -107,6 +106,7 @@ SOURCES += ../../subsurface-mobile-main.cpp \ ../../core/subsurface-qt/CylinderObjectHelper.cpp \ ../../core/subsurface-qt/DiveObjectHelper.cpp \ ../../core/subsurface-qt/DiveListNotifier.cpp \ + ../../backend-shared/exportfuncs.cpp \ ../../mobile-widgets/qmlmanager.cpp \ ../../mobile-widgets/qmlprefs.cpp \ ../../qt-models/divelistmodel.cpp \ @@ -186,7 +186,6 @@ HEADERS += \ ../../core/divelogexportlogic.h \ ../../core/divesitehelpers.h \ ../../core/exif.h \ - ../../core/exportfuncs.h \ ../../core/file.h \ ../../core/gaspressures.h \ ../../core/gettext.h \ @@ -232,6 +231,7 @@ HEADERS += \ ../../core/subsurface-qt/CylinderObjectHelper.h \ ../../core/subsurface-qt/DiveObjectHelper.h \ ../../core/subsurface-qt/DiveListNotifier.h \ + ../../backend-shared/exportfuncs.h \ ../../mobile-widgets/qmlmanager.h \ ../../mobile-widgets/qmlprefs.h \ ../../map-widget/qmlmapwidgethelper.h \ -- cgit v1.2.3-70-g09d2