2019-11-20 17:09:44 +00:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2021-04-07 06:35:35 +00:00
|
|
|
|
#include "exportfuncs.h"
|
2019-11-20 17:09:44 +00:00
|
|
|
|
#include "core/membuffer.h"
|
2020-05-01 11:43:52 +00:00
|
|
|
|
#include "core/dive.h"
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
|
#include "core/divelog.h"
|
2019-11-20 17:09:44 +00:00
|
|
|
|
#include "core/divesite.h"
|
2020-02-06 21:38:29 +00:00
|
|
|
|
#include "core/gettextfromc.h"
|
2019-11-20 17:09:44 +00:00
|
|
|
|
#include "core/tag.h"
|
2020-05-01 12:07:59 +00:00
|
|
|
|
#include "core/subsurface-time.h"
|
2019-11-20 17:09:44 +00:00
|
|
|
|
#include "core/file.h"
|
|
|
|
|
#include "core/errorhelper.h"
|
|
|
|
|
#include "core/divefilter.h"
|
2019-11-28 15:04:00 +00:00
|
|
|
|
#include "core/divesite.h"
|
2020-04-10 07:42:14 +00:00
|
|
|
|
#include "core/picture.h"
|
2020-10-25 18:13:42 +00:00
|
|
|
|
#include "core/pref.h"
|
2024-05-29 05:03:03 +00:00
|
|
|
|
#include "core/range.h"
|
2020-10-25 12:28:55 +00:00
|
|
|
|
#include "core/sample.h"
|
2021-04-30 13:51:13 +00:00
|
|
|
|
#include "core/selection.h"
|
2021-10-25 23:04:54 +00:00
|
|
|
|
#include "core/taxonomy.h"
|
2021-04-07 06:35:35 +00:00
|
|
|
|
#include "core/sample.h"
|
2021-08-04 05:27:41 +00:00
|
|
|
|
#include "profile-widget/profilescene.h"
|
2021-04-07 06:35:35 +00:00
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QtConcurrent>
|
2021-04-07 12:02:55 +00:00
|
|
|
|
#include <memory>
|
2019-11-20 17:09:44 +00:00
|
|
|
|
|
2021-04-30 13:51:13 +00:00
|
|
|
|
// Default implementation of the export callback: do nothing / never cancel
|
|
|
|
|
void ExportCallback::setProgress(int)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ExportCallback::canceled() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-15 19:44:14 +00:00
|
|
|
|
#if !defined(SUBSURFACE_MOBILE)
|
2021-04-07 06:35:35 +00:00
|
|
|
|
|
2021-05-06 12:45:09 +00:00
|
|
|
|
// Let's say that 800x600 is a "reasonable" profile size. Use four times that for printing.
|
|
|
|
|
static constexpr int profileScale = 4;
|
|
|
|
|
static constexpr int profileWidth = 800 * profileScale;
|
|
|
|
|
static constexpr int profileHeight = 600 * profileScale;
|
2021-04-07 06:35:35 +00:00
|
|
|
|
|
2024-06-07 08:25:09 +00:00
|
|
|
|
static void exportProfile(ProfileScene &profile, const struct dive &dive, const QString &filename)
|
2021-04-07 06:35:35 +00:00
|
|
|
|
{
|
2021-05-06 12:45:09 +00:00
|
|
|
|
QImage image = QImage(QSize(profileWidth, profileHeight), QImage::Format_RGB32);
|
2021-04-07 06:35:35 +00:00
|
|
|
|
QPainter paint;
|
|
|
|
|
paint.begin(&image);
|
2024-06-07 08:25:09 +00:00
|
|
|
|
profile.draw(&paint, QRect(0, 0, profileWidth, profileHeight), &dive, 0, nullptr, false);
|
2021-04-07 06:35:35 +00:00
|
|
|
|
image.save(filename);
|
2021-04-07 11:49:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-04 05:27:41 +00:00
|
|
|
|
static std::unique_ptr<ProfileScene> getPrintProfile()
|
2021-04-07 11:49:19 +00:00
|
|
|
|
{
|
2021-08-04 05:27:41 +00:00
|
|
|
|
return std::make_unique<ProfileScene>((double)profileScale, true, false);
|
2021-04-07 11:49:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-01 19:21:50 +00:00
|
|
|
|
void exportProfile(QString filename, bool selected_only, ExportCallback &cb)
|
2019-11-20 17:09:44 +00:00
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
if (!filename.endsWith(".png", Qt::CaseInsensitive))
|
|
|
|
|
filename = filename.append(".png");
|
|
|
|
|
QFileInfo fi(filename);
|
|
|
|
|
|
2024-06-07 08:25:09 +00:00
|
|
|
|
int todo = selected_only ? amount_selected : static_cast<int>(divelog.dives.size());
|
2021-05-01 19:21:50 +00:00
|
|
|
|
int done = 0;
|
2021-04-07 12:02:55 +00:00
|
|
|
|
auto profile = getPrintProfile();
|
2024-06-07 08:25:09 +00:00
|
|
|
|
for (auto &dive: divelog.dives) {
|
2021-05-01 19:21:50 +00:00
|
|
|
|
if (cb.canceled())
|
|
|
|
|
return;
|
2019-11-20 17:09:44 +00:00
|
|
|
|
if (selected_only && !dive->selected)
|
|
|
|
|
continue;
|
2021-05-01 19:21:50 +00:00
|
|
|
|
cb.setProgress(done++ * 1000 / todo);
|
2021-04-07 11:49:19 +00:00
|
|
|
|
QString fn = count ? fi.path() + QDir::separator() + fi.completeBaseName().append(QString("-%1.").arg(count)) + fi.suffix()
|
|
|
|
|
: filename;
|
2024-06-07 08:25:09 +00:00
|
|
|
|
exportProfile(*profile, *dive, fn);
|
2019-11-20 17:09:44 +00:00
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-30 13:51:13 +00:00
|
|
|
|
void export_TeX(const char *filename, bool selected_only, bool plain, ExportCallback &cb)
|
2019-11-20 17:09:44 +00:00
|
|
|
|
{
|
|
|
|
|
FILE *f;
|
|
|
|
|
QDir texdir = QFileInfo(filename).dir();
|
|
|
|
|
const struct units *units = get_units();
|
|
|
|
|
const char *unit;
|
|
|
|
|
const char *ssrf;
|
|
|
|
|
bool need_pagebreak = false;
|
|
|
|
|
|
2024-05-05 04:47:28 +00:00
|
|
|
|
membuffer buf;
|
2019-11-20 17:09:44 +00:00
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
2024-06-07 08:25:09 +00:00
|
|
|
|
int todo = selected_only ? amount_selected : static_cast<int>(divelog.dives.size());
|
2021-04-30 13:51:13 +00:00
|
|
|
|
int done = 0;
|
2021-04-07 12:02:55 +00:00
|
|
|
|
auto profile = getPrintProfile();
|
2024-06-07 08:25:09 +00:00
|
|
|
|
for (auto &dive: divelog.dives) {
|
2021-04-30 13:51:13 +00:00
|
|
|
|
if (cb.canceled())
|
|
|
|
|
return;
|
2019-11-20 17:09:44 +00:00
|
|
|
|
if (selected_only && !dive->selected)
|
|
|
|
|
continue;
|
2021-04-30 13:51:13 +00:00
|
|
|
|
cb.setProgress(done++ * 1000 / todo);
|
2024-06-07 08:25:09 +00:00
|
|
|
|
exportProfile(*profile, *dive, texdir.filePath(QString("profile%1.png").arg(dive->number)));
|
2019-11-20 17:09:44 +00:00
|
|
|
|
struct tm tm;
|
|
|
|
|
utc_mkdate(dive->when, &tm);
|
|
|
|
|
|
2024-05-04 11:39:04 +00:00
|
|
|
|
std::string country;
|
2019-11-20 17:09:44 +00:00
|
|
|
|
dive_site *site = dive->dive_site;
|
2021-10-25 23:04:54 +00:00
|
|
|
|
if (site)
|
2024-05-04 11:39:04 +00:00
|
|
|
|
country = taxonomy_get_country(site->taxonomy);
|
2024-06-07 08:25:09 +00:00
|
|
|
|
pressure_t delta_p;
|
2019-11-20 17:09:44 +00:00
|
|
|
|
|
|
|
|
|
QString star = "*";
|
|
|
|
|
QString viz = star.repeated(dive->visibility);
|
|
|
|
|
QString rating = star.repeated(dive->rating);
|
|
|
|
|
|
|
|
|
|
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);
|
2024-05-04 15:18:08 +00:00
|
|
|
|
put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name.c_str() : "");
|
2019-11-20 17:09:44 +00:00
|
|
|
|
put_format(&buf, "\\def\\%sspot{}\n", ssrf);
|
2024-05-04 15:18:08 +00:00
|
|
|
|
put_format(&buf, "\\def\\%ssitename{%s}\n", ssrf, site ? site->name.c_str() : "");
|
2019-11-20 17:09:44 +00:00
|
|
|
|
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");
|
2024-05-27 15:09:48 +00:00
|
|
|
|
put_format(&buf, "\\def\\%scomputer{%s}\n", ssrf, dive->dcs[0].model.c_str());
|
2024-05-04 11:39:04 +00:00
|
|
|
|
put_format(&buf, "\\def\\%scountry{%s}\n", ssrf, country.c_str());
|
2024-05-01 09:01:06 +00:00
|
|
|
|
put_format(&buf, "\\def\\%stime{%u:%02u}\n", ssrf, FRACTION_TUPLE(dive->duration.seconds, 60));
|
2019-11-20 17:09:44 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2024-05-29 15:57:48 +00:00
|
|
|
|
std::string tags = taglist_get_tagstring(dive->tags);
|
2024-03-26 20:06:13 +00:00
|
|
|
|
put_format(&buf, "\\def\\%stype{%s}\n", ssrf, tags.c_str());
|
2019-11-20 17:09:44 +00:00
|
|
|
|
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);
|
2024-05-29 18:40:18 +00:00
|
|
|
|
put_format(&buf, "\\def\\%scomment{%s}\n", ssrf, dive->notes.c_str());
|
|
|
|
|
put_format(&buf, "\\def\\%sbuddy{%s}\n", ssrf, dive->buddy.c_str());
|
|
|
|
|
put_format(&buf, "\\def\\%sdivemaster{%s}\n", ssrf, dive->diveguide.c_str());
|
|
|
|
|
put_format(&buf, "\\def\\%ssuit{%s}\n", ssrf, dive->suit.c_str());
|
2019-11-20 17:09:44 +00:00
|
|
|
|
|
|
|
|
|
// Print cylinder data
|
|
|
|
|
put_format(&buf, "\n%% Gas use information:\n");
|
2024-05-29 05:03:03 +00:00
|
|
|
|
int qty_cyl = 0;
|
2024-06-07 08:25:09 +00:00
|
|
|
|
for (auto [i, cyl]: enumerated_range(dive->cylinders)) {
|
|
|
|
|
if (is_cylinder_used(dive.get(), i) || (prefs.include_unused_tanks && !cyl.type.description.empty())){
|
2024-05-28 19:31:11 +00:00
|
|
|
|
put_format(&buf, "\\def\\%scyl%cdescription{%s}\n", ssrf, 'a' + i, cyl.type.description.c_str());
|
2019-11-20 17:09:44 +00:00
|
|
|
|
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");
|
2024-05-29 05:03:03 +00:00
|
|
|
|
int qty_weight = 0;
|
|
|
|
|
double total_weight = 0;
|
|
|
|
|
for (auto [i, w]: enumerated_range(dive->weightsystems)) {
|
|
|
|
|
put_format(&buf, "\\def\\%sweight%ctype{%s}\n", ssrf, 'a' + i, w.description.c_str());
|
2019-11-20 17:09:44 +00:00
|
|
|
|
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);
|
2024-05-04 15:18:08 +00:00
|
|
|
|
put_format(&buf, "\\def\\%splace{%s}\n", ssrf, site ? site->name.c_str() : "");
|
2019-11-20 17:09:44 +00:00
|
|
|
|
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) {
|
2020-02-06 21:38:29 +00:00
|
|
|
|
report_error(qPrintable(gettextFromC::tr("Can't open file %s")), filename);
|
2019-11-20 17:09:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
flush_buffer(&buf, f); /*check for writing errors? */
|
|
|
|
|
fclose(f);
|
|
|
|
|
}
|
2021-04-30 13:51:13 +00:00
|
|
|
|
cb.setProgress(1000);
|
2019-11-20 17:09:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 21:56:10 +00:00
|
|
|
|
void export_depths(const char *filename, bool selected_only)
|
2019-11-20 17:09:44 +00:00
|
|
|
|
{
|
|
|
|
|
FILE *f;
|
|
|
|
|
const char *unit = NULL;
|
|
|
|
|
|
2024-05-05 04:47:28 +00:00
|
|
|
|
membuffer buf;
|
2019-11-20 17:09:44 +00:00
|
|
|
|
|
2024-06-07 08:25:09 +00:00
|
|
|
|
for (auto &dive: divelog.dives) {
|
2019-11-20 17:09:44 +00:00
|
|
|
|
if (selected_only && !dive->selected)
|
|
|
|
|
continue;
|
|
|
|
|
|
2024-05-30 13:00:28 +00:00
|
|
|
|
for (auto &picture: dive->pictures) {
|
2024-05-19 10:38:38 +00:00
|
|
|
|
depth_t depth;
|
2024-05-27 15:09:48 +00:00
|
|
|
|
for (auto &s: dive->dcs[0].samples) {
|
2024-05-30 13:00:28 +00:00
|
|
|
|
if ((int32_t)s.time.seconds > picture.offset.seconds)
|
2024-05-19 10:38:38 +00:00
|
|
|
|
break;
|
|
|
|
|
depth = s.depth;
|
2019-11-20 17:09:44 +00:00
|
|
|
|
}
|
2024-05-30 13:00:28 +00:00
|
|
|
|
put_format(&buf, "%s\t%.1f", picture.filename.c_str(), get_depth_units(depth.mm, NULL, &unit));
|
2019-11-20 17:09:44 +00:00
|
|
|
|
put_format(&buf, "%s\n", unit);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
f = subsurface_fopen(filename, "w+");
|
|
|
|
|
if (!f) {
|
2020-02-06 21:38:29 +00:00
|
|
|
|
report_error(qPrintable(gettextFromC::tr("Can't open file %s")), filename);
|
2019-11-20 17:09:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
flush_buffer(&buf, f); /*check for writing errors? */
|
|
|
|
|
fclose(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-15 19:44:14 +00:00
|
|
|
|
#endif /* ! SUBSURFACE_MOBILE */
|
2019-11-20 17:09:44 +00:00
|
|
|
|
|
2020-02-06 21:38:29 +00:00
|
|
|
|
std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly)
|
2019-11-20 17:09:44 +00:00
|
|
|
|
{
|
|
|
|
|
std::vector<const dive_site *> 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.
|
2024-05-11 11:21:53 +00:00
|
|
|
|
for (auto ds: DiveFilter::instance()->filteredDiveSites())
|
2019-11-20 17:09:44 +00:00
|
|
|
|
res.push_back(ds);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-08 14:30:24 +00:00
|
|
|
|
res.reserve(divelog.sites.size());
|
|
|
|
|
for (const auto &ds: divelog.sites) {
|
2024-05-11 13:01:37 +00:00
|
|
|
|
if (ds->is_empty())
|
2019-11-20 17:09:44 +00:00
|
|
|
|
continue;
|
2024-05-11 13:01:37 +00:00
|
|
|
|
if (selectedOnly && !ds->is_selected())
|
2019-11-20 17:09:44 +00:00
|
|
|
|
continue;
|
2024-05-11 09:47:45 +00:00
|
|
|
|
res.push_back(ds.get());
|
2019-11-20 17:09:44 +00:00
|
|
|
|
}
|
2019-11-28 15:04:00 +00:00
|
|
|
|
#else
|
|
|
|
|
/* walk the dive site list */
|
2024-06-08 14:30:24 +00:00
|
|
|
|
for (const auto &ds: divelog.sites)
|
2024-05-11 09:47:45 +00:00
|
|
|
|
res.push_back(ds.get());
|
2019-11-20 17:09:44 +00:00
|
|
|
|
#endif
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-16 16:39:19 +00:00
|
|
|
|
QFuture<int> exportUsingStyleSheet(const QString &filename, bool doExport, int units,
|
|
|
|
|
const QString &stylesheet, bool anonymize)
|
2019-11-20 17:09:44 +00:00
|
|
|
|
{
|
2020-02-06 21:18:42 +00:00
|
|
|
|
return QtConcurrent::run(export_dives_xslt, filename.toUtf8(), doExport, units, stylesheet.toUtf8(), anonymize);
|
2019-11-20 17:09:44 +00:00
|
|
|
|
}
|