36#include <wx/printdlg.h>
37#include <wx/artprov.h>
38#include <wx/stdpaths.h>
40#include <wx/listctrl.h>
41#include <wx/aui/aui.h>
43#include <wx/progdlg.h>
49#include "ocpn_frame.h"
59#include "model/track.h"
60#include "print_dialog.h"
61#include "printtable.h"
62#include "trackprintout.h"
64enum { PRINT_POSITION, PRINT_DISTANCE, PRINT_BEARING, PRINT_TIME, PRINT_SPEED };
66MyTrackPrintout::MyTrackPrintout(std::vector<bool> _toPrintOut,
Track* track,
70 toPrintOut(_toPrintOut) {
79 table.StartFillHeader();
82 table << (
const char*)wxString(_(
"Leg")).mb_str();
84 if (toPrintOut[PRINT_POSITION]) {
85 table << (
const char*)wxString(_(
"Position")).mb_str();
87 if (toPrintOut[PRINT_BEARING]) {
88 table << (
const char*)wxString(_(
"Course")).mb_str();
90 if (toPrintOut[PRINT_DISTANCE]) {
91 table << (
const char*)wxString(_(
"Distance")).mb_str();
93 if (toPrintOut[PRINT_TIME]) {
94 table << (
const char*)wxString(_(
"Time")).mb_str();
96 if (toPrintOut[PRINT_SPEED]) {
97 table << (
const char*)wxString(_(
"Speed")).mb_str();
100 table.StartFillWidths();
104 if (toPrintOut[PRINT_POSITION]) table << 80;
105 if (toPrintOut[PRINT_BEARING]) table << 40;
106 if (toPrintOut[PRINT_DISTANCE]) table << 40;
107 if (toPrintOut[PRINT_TIME]) table << 60;
108 if (toPrintOut[PRINT_SPEED]) table << 40;
110 table.StartFillData();
111 for (
int n = 0; n <= myTrack->GetnPoints(); n++) {
112 table << lcPoints->OnGetItemText(n, 0);
114 if (toPrintOut[PRINT_POSITION]) {
116 wxString pos = lcPoints->OnGetItemText(n, 3) + _T(
" ") +
117 lcPoints->OnGetItemText(n, 4);
120 if (toPrintOut[PRINT_BEARING])
121 table << lcPoints->OnGetItemText(n, 2);
122 if (toPrintOut[PRINT_DISTANCE])
123 table << lcPoints->OnGetItemText(n, 1);
124 if (toPrintOut[PRINT_TIME]) table << lcPoints->OnGetItemText(n, 5);
125 if (toPrintOut[PRINT_SPEED])
126 table << lcPoints->OnGetItemText(n, 6);
131void MyTrackPrintout::GetPageInfo(
int* minPage,
int* maxPage,
int* selPageFrom,
134 *maxPage = numberOfPages;
136 *selPageTo = numberOfPages;
139void MyTrackPrintout::OnPreparePrinting() {
142 wxFont trackPrintFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
143 wxFONTWEIGHT_NORMAL);
144 dc->SetFont(trackPrintFont);
154 int maxX = wxMin(w, 1000);
155 int maxY = wxMin(h, 1000);
158 double scaleX = (double)(w / maxX);
159 double scaleY = (double)(h / maxY);
162 double actualScale = wxMin(scaleX, scaleY);
165 dc->SetUserScale(actualScale, actualScale);
166 dc->SetDeviceOrigin((
long)marginX, (
long)marginY);
168 table.AdjustCells(dc, marginX, marginY);
169 numberOfPages = table.GetNumberPages();
172bool MyTrackPrintout::OnPrintPage(
int page) {
175 if (page <= numberOfPages) {
185void MyTrackPrintout::DrawPage(wxDC* dc) {
186 wxFont trackPrintFont_bold(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
188 dc->SetFont(trackPrintFont_bold);
189 wxBrush brush(wxColour(255, 255, 255), wxBRUSHSTYLE_TRANSPARENT);
192 int header_textOffsetX = 2;
193 int header_textOffsetY = 2;
195 dc->DrawText(myTrack->GetName(), 150, 20);
197 int currentX = marginX;
198 int currentY = marginY;
199 vector<PrintCell>& header_content = table.GetHeader();
200 for (
size_t j = 0; j < header_content.size(); j++) {
202 dc->DrawRectangle(currentX, currentY, cell.GetWidth(), cell.GetHeight());
203 dc->DrawText(cell.GetText(), currentX + header_textOffsetX,
204 currentY + header_textOffsetY);
205 currentX += cell.GetWidth();
208 wxFont trackPrintFont_normal(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
209 wxFONTWEIGHT_NORMAL);
210 dc->SetFont(trackPrintFont_normal);
212 vector<vector<PrintCell> >& cells = table.GetContent();
213 currentY = marginY + table.GetHeaderHeight();
214 int currentHeight = 0;
215 for (
size_t i = 0; i < cells.size(); i++) {
216 vector<PrintCell>& content_row = cells[i];
218 for (
size_t j = 0; j < content_row.size(); j++) {
220 if (cell.GetPage() == pageToPrint) {
221 wxRect r(currentX, currentY, cell.GetWidth(), cell.GetHeight());
222 dc->DrawRectangle(r);
223 r.Offset(textOffsetX, textOffsetY);
224 dc->DrawLabel(cell.GetText(), r);
225 currentX += cell.GetWidth();
226 currentHeight = cell.GetHeight();
229 currentY += currentHeight;
236EVT_BUTTON(ID_TRACKPRINT_SELECTION_CANCEL,
237 TrackPrintSelection::OnTrackpropCancelClick)
238EVT_BUTTON(ID_TRACKPRINT_SELECTION_OK, TrackPrintSelection::OnTrackpropOkClick)
242TrackPrintSelection::TrackPrintSelection(wxWindow* parent,
Track* _track,
244 wxWindowID
id,
const wxString& caption,
245 const wxPoint& pos,
const wxSize& size,
248 m_lcPoints = lcPoints;
252 Create(parent,
id, caption, pos, size, wstyle);
256TrackPrintSelection::~TrackPrintSelection() {}
263 const wxString& caption,
const wxPoint& pos,
264 const wxSize& size,
long style) {
265 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
268 style |= wxSTAY_ON_TOP;
271 wxDialog::Create(parent,
id, _(
"Print Track Selection"), pos, size, style);
284 wxStaticBox* itemStaticBoxSizer3Static =
285 new wxStaticBox(itemDialog1, wxID_ANY, _(
"Elements to print..."));
286 wxStaticBoxSizer* itemBoxSizer1 =
287 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
288 itemDialog1->SetSizer(itemBoxSizer1);
290 wxFlexGridSizer* fgSizer2;
291 fgSizer2 =
new wxFlexGridSizer(5, 2, 0, 0);
294 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Position"), wxDefaultPosition,
295 wxDefaultSize, wxALIGN_LEFT);
296 m_checkBoxPosition->SetValue(
true);
297 fgSizer2->Add(m_checkBoxPosition, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
298 wxStaticText* label2 =
299 new wxStaticText(itemDialog1, wxID_ANY, _(
"Show Waypoint position."),
300 wxDefaultPosition, wxDefaultSize);
301 fgSizer2->Add(label2, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
304 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Course"), wxDefaultPosition,
305 wxDefaultSize, wxALIGN_LEFT);
306 m_checkBoxCourse->SetValue(
true);
307 fgSizer2->Add(m_checkBoxCourse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
308 wxStaticText* label3 =
309 new wxStaticText(itemDialog1, wxID_ANY,
310 _(
"Show course from each Waypoint to the next one. "),
311 wxDefaultPosition, wxDefaultSize);
312 fgSizer2->Add(label3, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
315 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Distance"), wxDefaultPosition,
316 wxDefaultSize, wxALIGN_LEFT);
317 m_checkBoxDistance->SetValue(
true);
318 fgSizer2->Add(m_checkBoxDistance, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
319 wxStaticText* label4 =
320 new wxStaticText(itemDialog1, wxID_ANY,
321 _(
"Show Distance from each Waypoint to the next one."),
322 wxDefaultPosition, wxDefaultSize);
323 fgSizer2->Add(label4, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
326 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Time"), wxDefaultPosition,
327 wxDefaultSize, wxALIGN_LEFT);
328 m_checkBoxTime->SetValue(
true);
329 fgSizer2->Add(m_checkBoxTime, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
330 wxStaticText* label5 =
new wxStaticText(
331 itemDialog1, wxID_ANY, _(
"Show Time."), wxDefaultPosition, wxDefaultSize);
332 fgSizer2->Add(label5, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
335 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Speed"), wxDefaultPosition,
336 wxDefaultSize, wxALIGN_LEFT);
337 m_checkBoxSpeed->SetValue(
true);
338 fgSizer2->Add(m_checkBoxSpeed, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
339 wxStaticText* label6 =
340 new wxStaticText(itemDialog1, wxID_ANY, _(
"Show Speed."),
341 wxDefaultPosition, wxDefaultSize);
342 fgSizer2->Add(label6, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
344 itemBoxSizer1->Add(fgSizer2, 5, wxEXPAND, 5);
346 wxBoxSizer* itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
347 itemBoxSizer1->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
350 new wxButton(itemDialog1, ID_TRACKPRINT_SELECTION_CANCEL, _(
"Cancel"),
351 wxDefaultPosition, wxDefaultSize, 0);
352 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
354 m_OKButton =
new wxButton(itemDialog1, ID_TRACKPRINT_SELECTION_OK, _(
"OK"),
355 wxDefaultPosition, wxDefaultSize, 0);
356 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
357 m_OKButton->SetDefault();
359 SetColorScheme((ColorScheme)0);
362void TrackPrintSelection::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
368bool TrackPrintSelection::ShowToolTips() {
return TRUE; }
370void TrackPrintSelection::SetDialogTitle(
const wxString& title) {
374void TrackPrintSelection::OnTrackpropCancelClick(wxCommandEvent& event) {
379void TrackPrintSelection::OnTrackpropOkClick(wxCommandEvent& event) {
380 std::vector<bool> toPrintOut;
381 toPrintOut.push_back(m_checkBoxPosition->GetValue());
382 toPrintOut.push_back(m_checkBoxCourse->GetValue());
383 toPrintOut.push_back(m_checkBoxDistance->GetValue());
384 toPrintOut.push_back(m_checkBoxTime->GetValue());
385 toPrintOut.push_back(m_checkBoxSpeed->GetValue());
389 printer.Initialize(wxPORTRAIT);
390 printer.EnablePageNumbers(
true);
391 printer.Print(
this, &mytrackprintout1);
Application print support.
This class takes multilined string and modifies it to fit into given width for given device.
static PrintDialog & GetInstance()
Get instance to handle the print process,.
bool Create(wxWindow *parent, wxWindowID id=SYMBOL_TRACKPRINT_SELECTION_IDNAME, const wxString &caption=SYMBOL_TRACKPRINT_SELECTION_TITLE, const wxPoint &pos=SYMBOL_TRACKPRINT_SELECTION_POSITION, const wxSize &size=SYMBOL_TRACKPRINT_SELECTION_SIZE, long style=SYMBOL_TRACKPRINT_SELECTION_STYLE)
Represents a track, which is a series of connected track points.
General purpose GUI support.