Changeset 9b8a040 in subsurface


Ignore:
Timestamp:
Oct 11, 2016, 10:00:08 PM (8 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
1801a68
Parents:
0d20344
git-author:
Robert C. Helling <helling@…> (10/03/16 08:08:02)
git-committer:
Dirk Hohndel <dirk@…> (10/11/16 22:00:08)
Message:

Export to TeX file initialized

This does the basic export as a TeX file including a template.

It still lacks proper location parsing.

Signed-off-by: Robert C. Helling <helling@…>
Signed-off-by: Dirk Hohndel <dirk@…>

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • desktop-widgets/divelogexportdialog.cpp

    r7be962b r9b8a040  
    1212#include "core/save-html.h"
    1313#include "desktop-widgets/mainwindow.h"
     14#include "profile-widget/profilewidget2.h"
     15
    1416
    1517#define GET_UNIT(name, field, f, t)                   \
     
    8789        } else if (ui->exportImageDepths->isChecked()) {
    8890                ui->description->setText(tr("Write depths of images to file."));
     91        } else if (ui->exportTeX->isChecked()) {
     92                ui->description->setText(tr("Write dive as TeX macros to file."));
    8993        }
    9094}
     
    163167                        if (!filename.isNull() && !filename.isEmpty())
    164168                                export_depths(filename.toUtf8().data(), ui->exportSelected->isChecked());
     169                } else if (ui->exportTeX->isChecked()) {
     170                        filename = QFileDialog::getSaveFileName(this, tr("Export to TeX file"), lastDir, tr("TeX files (*.tex)"));
     171                        if (!filename.isNull() && !filename.isEmpty())
     172                                export_TeX(filename.toUtf8().data(), ui->exportSelected->isChecked());
    165173                }
    166174                break;
     
    224232        free_buffer(&buf);
    225233}
     234
     235void DiveLogExportDialog::export_TeX(const char *filename, const bool selected_only)
     236{
     237        FILE *f;
     238        struct dive *dive;
     239        depth_t depth;
     240        int i;
     241        const char *unit = NULL;
     242        bool need_pagebreak = false;
     243
     244        struct membuffer buf = {};
     245
     246        put_format(&buf, "\\input subsurfacetemplate\n");
     247        put_format(&buf, "%% This is a plain TeX file. Compile with pdftex, not pdflatex!\n");
     248        put_format(&buf, "%% You will also need a subsurfacetemplate.tex in the current directory.\n");
     249        put_format(&buf, "%% You can downlaod an example from http://www.atdotde.de/~robert/subsurfacetemplate\n%%\n");
     250        for_each_dive (i, dive) {
     251                if (selected_only && !dive->selected)
     252                        continue;
     253
     254                QString filename = "profile%1.png";
     255                ProfileWidget2 *profile = MainWindow::instance()->graphics();
     256                profile->plotDive(dive, true);
     257                profile->setToolTipVisibile(false);
     258                QPixmap pix = QPixmap::grabWidget(profile);
     259                profile->setToolTipVisibile(true);
     260                pix.save(filename.arg(dive->number));
     261
     262
     263
     264                struct tm tm;
     265                utc_mkdate(dive->when, &tm);
     266
     267                dive_site *site = get_dive_site_by_uuid(dive->dive_site_uuid);;
     268
     269                pressure_t delta_p = {.mbar = 0};
     270
     271                QString star = "*";
     272                QString viz = star.repeated(dive->visibility);
     273                int i;
     274
     275                for (i = 0; i < MAX_CYLINDERS; i++)
     276                        if (is_cylinder_used(dive, i))
     277                                delta_p.mbar += dive->cylinder[i].start.mbar - dive->cylinder[i].end.mbar;
     278
     279                if (need_pagebreak)
     280                        put_format(&buf, "\\vfill\\eject\n");
     281                need_pagebreak = true;
     282                put_format(&buf, "\\def\\date{%04u-%02u-%02u}\n",
     283                      tm.tm_year, tm.tm_mon+1, tm.tm_mday);
     284                put_format(&buf, "\\def\\number{%d}\n", dive->number);
     285                put_format(&buf, "\\def\\place{%s}\n", site->name);
     286                put_format(&buf, "\\def\\spot{}\n");
     287                put_format(&buf, "\\def\\country{}\n");
     288                put_format(&buf, "\\def\\entrance{}\n");
     289                put_format(&buf, "\\def\\time{%u:%02u}\n", FRACTION(dive->duration.seconds, 60));
     290                put_format(&buf, "\\def\\depth{%u.%01um}\n", FRACTION(dive->maxdepth.mm / 100, 10));
     291                put_format(&buf, "\\def\\gasuse{%u.%01ubar}\n", FRACTION(delta_p.mbar / 100, 10));
     292                put_format(&buf, "\\def\\sac{%u.%01u l/min}\n", FRACTION(dive->sac/100,10));
     293                put_format(&buf, "\\def\\type{%s}\n", dive->tag_list ? dive->tag_list->tag->name : "");
     294                put_format(&buf, "\\def\\viz{%s}\n", viz.toUtf8().data());
     295                put_format(&buf, "\\def\\plot{\\includegraphics[width=9cm,height=4cm]{profile%d}}\n", dive->number);
     296                put_format(&buf, "\\def\\comment{%s}\n", dive->notes);
     297                put_format(&buf, "\\def\\buddy{%s}\n", dive->buddy);
     298                put_format(&buf, "\\page\n");
     299        }
     300
     301        put_format(&buf, "\\bye\n");
     302
     303        f = subsurface_fopen(filename, "w+");
     304        if (!f) {
     305                report_error(tr("Can't open file %s").toUtf8().data(), filename);
     306        } else {
     307                flush_buffer(&buf, f); /*check for writing errors? */
     308                fclose(f);
     309        }
     310        free_buffer(&buf);
     311}
  • desktop-widgets/divelogexportdialog.h

    r7be962b r9b8a040  
    3434        void exportHtmlInit(const QString &filename);
    3535        void export_depths(const char *filename, const bool selected_only);
     36        void export_TeX(const char *filename, const bool selected_only);
    3637};
    3738
  • desktop-widgets/divelogexportdialog.ui

    r49cbb830 r9b8a040  
    193193          </item>
    194194          <item>
     195           <widget class="QRadioButton" name="exportTeX">
     196            <property name="text">
     197             <string>TeX</string>
     198            </property>
     199            <attribute name="buttonGroup">
     200             <string notr="true">exportGroup</string>
     201            </attribute>
     202           </widget>
     203          </item>
     204          <item>
    195205           <widget class="QRadioButton" name="exportImageDepths">
    196206            <property name="text">
     
    601611 </connections>
    602612 <buttongroups>
     613  <buttongroup name="exportGroup"/>
    603614  <buttongroup name="buttonGroup"/>
    604   <buttongroup name="exportGroup"/>
    605615 </buttongroups>
    606616</ui>
Note: See TracChangeset for help on using the changeset viewer.