41#include <wx/aui/aui.h>
46#include <wx/listctrl.h>
47#include <wx/printdlg.h>
49#include <wx/statline.h>
50#include <wx/stdpaths.h>
54#include "libgui/button_switch.h"
63#if wxCHECK_VERSION(3, 2, 0)
64#define _(s) wxGetTranslation(wxASCII_STR(s)).ToStdString()
66#define _(s) wxGetTranslation((s)).ToStdString()
71static const std::unordered_map<TrackPrintOptions, std::string> kLabelByOption =
72 {{TrackPrintOptions::kTrackPosition, _(
"Print Track Position")},
73 {TrackPrintOptions::kTrackCourse, _(
"Print Track Course")},
74 {TrackPrintOptions::kTrackDistance, _(
"Print Track Distance")},
75 {TrackPrintOptions::kTrackTime, _(
"Print Track Time")},
76 {TrackPrintOptions::kTrackSpeed, _(
"Print Track Speed")}};
80class ButtonSizer :
public wxStdDialogButtonSizer {
82 explicit ButtonSizer(wxWindow* parent) : wxStdDialogButtonSizer() {
83 auto ok_btn =
new wxButton(parent, wxID_OK, _(
"Print..."));
85 AddButton(
new wxButton(parent, wxID_CANCEL));
86 SetAffirmativeButton(ok_btn);
93TrackPrintDlg::TrackPrintDlg(wxWindow* parent)
94 : wxDialog(parent, wxID_ANY, _(
"Print track")) {
95 auto grid =
new wxFlexGridSizer(2);
96 auto flags = wxSizerFlags().Border();
97 for (
auto& [option, label] : kLabelByOption) {
98 grid->Add(
new wxStaticText(
this, wxID_ANY, label), flags.Expand());
99 int id = wxWindow::NewControlId();
101 IdByOption[option] = id;
103 auto vbox =
new wxBoxSizer(wxVERTICAL);
104 vbox->Add(grid, wxSizerFlags(1));
105 vbox->Add(
new wxStaticLine(
this, wxID_ANY), wxSizerFlags().Expand());
106 vbox->Add(
new ButtonSizer(
this), flags);
110 Bind(wxEVT_CLOSE_WINDOW, [&](wxCloseEvent&) { Destroy(); });
113bool TrackPrintDlg::IsEnabled(TrackPrintOptions option)
const {
114 auto found = IdByOption.find(option);
115 assert(found != IdByOption.end() &&
"Illegal option");
118 id = IdByOption.at(option);
119 }
catch (std::out_of_range&) {
120 assert(
false &&
"No id for button");
122 auto* btn =
dynamic_cast<SwitchButton*
>(wxWindow::FindWindow(
id));
123 assert(btn &&
"Could not look up button");
124 return btn->GetValue();
135 m_table.StartFillHeader();
139 if (dlg.IsEnabled(TrackPrintOptions::kTrackPosition)) {
140 m_table << _(
"Position");
142 if (dlg.IsEnabled(TrackPrintOptions::kTrackCourse)) {
143 m_table << _(
"Course");
145 if (dlg.IsEnabled(TrackPrintOptions::kTrackDistance)) {
146 m_table << _(
"Distance");
148 if (dlg.IsEnabled(TrackPrintOptions::kTrackTime)) {
149 m_table << _(
"Time");
151 if (dlg.IsEnabled(TrackPrintOptions::kTrackSpeed)) {
152 m_table << _(
"Speed");
155 m_table.StartFillWidths();
159 if (dlg.IsEnabled(TrackPrintOptions::kTrackPosition)) m_table << 80;
160 if (dlg.IsEnabled(TrackPrintOptions::kTrackCourse)) m_table << 40;
161 if (dlg.IsEnabled(TrackPrintOptions::kTrackDistance)) m_table << 40;
162 if (dlg.IsEnabled(TrackPrintOptions::kTrackTime)) m_table << 60;
163 if (dlg.IsEnabled(TrackPrintOptions::kTrackSpeed)) m_table << 40;
165 m_table.StartFillData();
166 for (
int n = 0; n < m_track->GetnPoints(); n++) {
167 m_table << lcPoints->OnGetItemText(n, 0);
169 if (dlg.IsEnabled(TrackPrintOptions::kTrackPosition)) {
170 m_table << lcPoints->OnGetItemText(n, 3) + _(
" ") +
171 lcPoints->OnGetItemText(n, 4);
173 if (dlg.IsEnabled(TrackPrintOptions::kTrackCourse))
174 m_table << lcPoints->OnGetItemText(n, 2);
175 if (dlg.IsEnabled(TrackPrintOptions::kTrackDistance))
176 m_table << lcPoints->OnGetItemText(n, 1);
177 if (dlg.IsEnabled(TrackPrintOptions::kTrackTime))
178 m_table << lcPoints->OnGetItemText(n, 5);
179 if (dlg.IsEnabled(TrackPrintOptions::kTrackSpeed))
180 m_table << lcPoints->OnGetItemText(n, 6);
185void TrackPrintout::OnPreparePrinting() {
187 wxFont trackPrintFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
188 wxFONTWEIGHT_NORMAL);
189 dc->SetFont(trackPrintFont);
198 int max_x = wxMin(w, 1000);
199 int max_y = wxMin(h, 1000);
202 double scale_x = (double)(w / max_x);
203 double scale_y = (double)(h / max_y);
206 double actual_scale = wxMin(scale_x, scale_y);
209 dc->SetUserScale(actual_scale, actual_scale);
210 dc->SetDeviceOrigin((
long)m_margin_x, (
long)m_margin_y);
212 m_table.AdjustCells(dc, m_margin_x, m_margin_y);
213 m_pages = m_table.GetNumberPages();
217 wxFont trackPrintFont_bold(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
219 dc->SetFont(trackPrintFont_bold);
220 wxBrush brush(wxColour(255, 255, 255), wxBRUSHSTYLE_TRANSPARENT);
223 int header_text_offset_x = 2;
224 int header_text_offset_y = 2;
226 dc->DrawText(m_track->GetName(), 150, 20);
228 int current_x = m_margin_x;
229 int current_y = m_margin_y;
230 vector<PrintCell>& header_content = m_table.GetHeader();
231 for (
size_t j = 0; j < header_content.size(); j++) {
233 dc->DrawRectangle(current_x, current_y, cell.GetWidth(), cell.GetHeight());
234 dc->DrawText(cell.GetText(), current_x + header_text_offset_x,
235 current_y + header_text_offset_y);
236 current_x += cell.GetWidth();
239 wxFont trackPrintFont_normal(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
240 wxFONTWEIGHT_NORMAL);
241 dc->SetFont(trackPrintFont_normal);
243 vector<vector<PrintCell> >& cells = m_table.GetContent();
244 current_y = m_margin_y + m_table.GetHeaderHeight();
245 int current_height = 0;
246 for (
size_t i = 0; i < cells.size(); i++) {
247 vector<PrintCell>& content_row = cells[i];
248 current_x = m_margin_x;
249 for (
size_t j = 0; j < content_row.size(); j++) {
251 if (cell.GetPage() == page) {
252 wxRect r(current_x, current_y, cell.GetWidth(), cell.GetHeight());
253 dc->DrawRectangle(r);
254 r.Offset(m_text_offset_x, m_text_offset_y);
255 dc->DrawLabel(cell.GetText(), r);
256 current_x += cell.GetWidth();
257 current_height = cell.GetHeight();
260 current_y += current_height;
Application print support.
This class takes multilined string and modifies it to fit into given width for given device.
Input dialog with track print selection.
TrackPrintout(Track *track, OCPNTrackListCtrl *lcPoints, const TrackPrintDlg &dlg)
Create track printout.
void DrawPage(wxDC *dc, int page) override
Called by the print framework to draw the page.
Represents a track, which is a series of connected track points.
OpenCPN Route table printout.
Recorded track abstraction.