38#include <wx/printdlg.h>
39#include <wx/artprov.h>
40#include <wx/stdpaths.h>
42#include <wx/listctrl.h>
43#include <wx/aui/aui.h>
45#include <wx/progdlg.h>
65#include "routeprintout.h"
67#include "printtable.h"
68#include "model/wx28compat.h"
69#include "model/track.h"
70#include "model/route.h"
72#include "model/navutil_base.h"
74#define PRINT_WP_NAME 0
75#define PRINT_WP_POSITION 1
76#define PRINT_WP_COURSE 2
77#define PRINT_WP_DISTANCE 3
78#define PRINT_WP_DESCRIPTION 4
83extern wxPrintData* g_printData;
85extern wxPageSetupData* g_pageSetupData;
87MyRoutePrintout::MyRoutePrintout(std::vector<bool> _toPrintOut,
Route* route,
88 const wxString& title)
89 :
MyPrintout(title), myRoute(route), toPrintOut(_toPrintOut) {
98 table.StartFillHeader();
103 if (toPrintOut[PRINT_WP_NAME]) {
104 table << _(
"To Waypoint");
106 if (toPrintOut[PRINT_WP_POSITION]) {
107 table << _(
"Position");
109 if (toPrintOut[PRINT_WP_COURSE]) {
110 table << _(
"Course");
112 if (toPrintOut[PRINT_WP_DISTANCE]) {
113 table << _(
"Distance");
115 if (toPrintOut[PRINT_WP_DESCRIPTION]) {
116 table << _(
"Description");
119 table.StartFillWidths();
124 if (toPrintOut[PRINT_WP_NAME]) {
127 if (toPrintOut[PRINT_WP_POSITION]) {
130 if (toPrintOut[PRINT_WP_COURSE]) {
133 if (toPrintOut[PRINT_WP_DISTANCE]) {
136 if (toPrintOut[PRINT_WP_DESCRIPTION]) {
140 table.StartFillData();
142 for (
int n = 1; n <= myRoute->GetnPoints(); n++) {
146 if (n - 1 >= 0) pointm1 = myRoute->GetPoint(n - 1);
148 if (NULL == point)
continue;
150 wxString leg = _T(
"---");
151 if (n > 1) leg.Printf(_T(
"%d"), n - 1);
153 string cell(leg.mb_str());
157 if (toPrintOut[PRINT_WP_NAME]) {
158 string cell(point->GetName().mb_str());
161 if (toPrintOut[PRINT_WP_POSITION]) {
162 wxString point_position = toSDMM(1, point->m_lat,
false) + _T(
"\n" ) +
163 toSDMM(2, point->m_lon,
false);
164 string cell(point_position.mb_str());
167 if (toPrintOut[PRINT_WP_COURSE]) {
168 wxString point_course =
"---";
170 point_course = formatAngle(point->GetCourse());
172 table << point_course;
174 if (toPrintOut[PRINT_WP_DISTANCE]) {
175 wxString point_distance = _T(
"---");
177 point_distance.Printf(_T(
"%6.2f" + getUsrDistanceUnit()),
178 toUsrDistance(point->GetDistance()));
179 table << point_distance;
181 if (toPrintOut[PRINT_WP_DESCRIPTION]) {
182 table << point->GetDescription();
188void MyRoutePrintout::GetPageInfo(
int* minPage,
int* maxPage,
int* selPageFrom,
191 *maxPage = numberOfPages;
193 *selPageTo = numberOfPages;
196void MyRoutePrintout::OnPreparePrinting() {
199 wxFont routePrintFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
200 wxFONTWEIGHT_NORMAL);
201 dc->SetFont(routePrintFont);
211 int maxX = wxMin(w, 1000);
212 int maxY = wxMin(h, 1000);
215 double scaleX = (double)(w / maxX);
216 double scaleY = (double)(h / maxY);
219 double actualScale = wxMin(scaleX, scaleY);
222 dc->SetUserScale(actualScale, actualScale);
223 dc->SetDeviceOrigin((
long)marginX, (
long)marginY);
225 table.AdjustCells(dc, marginX, marginY);
226 numberOfPages = table.GetNumberPages();
229bool MyRoutePrintout::OnPrintPage(
int page) {
232 if (page <= numberOfPages) {
242void MyRoutePrintout::DrawPage(wxDC* dc) {
243 wxFont routePrintFont_bold(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
245 dc->SetFont(routePrintFont_bold);
246 wxBrush brush(wxColour(255, 255, 255), wxBRUSHSTYLE_TRANSPARENT);
249 int header_textOffsetX = 2;
250 int header_textOffsetY = 2;
252 dc->DrawText(myRoute->m_RouteNameString, 150, 20);
254 int currentX = marginX;
255 int currentY = marginY;
256 vector<PrintCell>& header_content = table.GetHeader();
257 for (
size_t j = 0; j < header_content.size(); j++) {
259 dc->DrawRectangle(currentX, currentY, cell.GetWidth(), cell.GetHeight());
260 dc->DrawText(cell.GetText(), currentX + header_textOffsetX,
261 currentY + header_textOffsetY);
262 currentX += cell.GetWidth();
265 wxFont routePrintFont_normal(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
266 wxFONTWEIGHT_NORMAL);
267 dc->SetFont(routePrintFont_normal);
269 vector<vector<PrintCell> >& cells = table.GetContent();
270 currentY = marginY + table.GetHeaderHeight();
271 int currentHeight = 0;
272 for (
size_t i = 0; i < cells.size(); i++) {
273 vector<PrintCell>& content_row = cells[i];
275 for (
size_t j = 0; j < content_row.size(); j++) {
277 if (cell.GetPage() == pageToPrint) {
278 wxRect r(currentX, currentY, cell.GetWidth(), cell.GetHeight());
279 dc->DrawRectangle(r);
280 r.Offset(textOffsetX, textOffsetY);
281 dc->DrawLabel(cell.GetText(), r);
282 currentX += cell.GetWidth();
283 currentHeight = cell.GetHeight();
286 currentY += currentHeight;
301EVT_BUTTON(ID_ROUTEPRINT_SELECTION_CANCEL,
302 RoutePrintSelection::OnRoutepropCancelClick)
303EVT_BUTTON(ID_ROUTEPRINT_SELECTION_OK, RoutePrintSelection::OnRoutepropOkClick)
312RoutePrintSelection::RoutePrintSelection(wxWindow* parent,
Route* _route,
313 wxWindowID
id,
const wxString& caption,
314 const wxPoint& pos,
const wxSize& size,
320 Create(parent,
id, caption, pos, size, wstyle);
324RoutePrintSelection::~RoutePrintSelection() {}
331 const wxString& caption,
const wxPoint& pos,
332 const wxSize& size,
long style) {
333 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
336 style |= wxSTAY_ON_TOP;
339 wxDialog::Create(parent,
id, _(
"Print Route Selection"), pos, size, style);
353 wxStaticBox* itemStaticBoxSizer3Static =
354 new wxStaticBox(itemDialog1, wxID_ANY, _(
"Elements to print..."));
356 wxStaticBoxSizer* itemBoxSizer1 =
357 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
358 itemDialog1->SetSizer(itemBoxSizer1);
360 wxFlexGridSizer* fgSizer2;
361 fgSizer2 =
new wxFlexGridSizer(5, 2, 0, 0);
364 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Name"), wxDefaultPosition,
365 wxDefaultSize, wxALIGN_LEFT);
366 m_checkBoxWPName->SetValue(
true);
367 fgSizer2->Add(m_checkBoxWPName, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
369 wxStaticText* label1 =
370 new wxStaticText(itemDialog1, wxID_ANY, _(
"Show Waypoint name."),
371 wxDefaultPosition, wxDefaultSize);
372 fgSizer2->Add(label1, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
374 m_checkBoxWPPosition =
375 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Position"), wxDefaultPosition,
376 wxDefaultSize, wxALIGN_LEFT);
377 m_checkBoxWPPosition->SetValue(
true);
378 fgSizer2->Add(m_checkBoxWPPosition, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
379 wxStaticText* label2 =
380 new wxStaticText(itemDialog1, wxID_ANY, _(
"Show Waypoint position."),
381 wxDefaultPosition, wxDefaultSize);
382 fgSizer2->Add(label2, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
385 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Course"), wxDefaultPosition,
386 wxDefaultSize, wxALIGN_LEFT);
387 m_checkBoxWPCourse->SetValue(
true);
388 fgSizer2->Add(m_checkBoxWPCourse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
389 wxStaticText* label3 =
390 new wxStaticText(itemDialog1, wxID_ANY,
391 _(
"Show course from each Waypoint to the next one. "),
392 wxDefaultPosition, wxDefaultSize);
393 fgSizer2->Add(label3, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
395 m_checkBoxWPDistanceToNext =
396 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Distance"), wxDefaultPosition,
397 wxDefaultSize, wxALIGN_LEFT);
398 m_checkBoxWPDistanceToNext->SetValue(
true);
399 fgSizer2->Add(m_checkBoxWPDistanceToNext, 0, wxALL | wxALIGN_CENTER_VERTICAL,
401 wxStaticText* label4 =
402 new wxStaticText(itemDialog1, wxID_ANY,
403 _(
"Show Distance from each Waypoint to the next one."),
404 wxDefaultPosition, wxDefaultSize);
405 fgSizer2->Add(label4, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
407 m_checkBoxWPDescription =
408 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Description"), wxDefaultPosition,
409 wxDefaultSize, wxALIGN_LEFT);
410 m_checkBoxWPDescription->SetValue(
true);
411 fgSizer2->Add(m_checkBoxWPDescription, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
412 wxStaticText* label5 =
413 new wxStaticText(itemDialog1, wxID_ANY, _(
"Show Waypoint description."),
414 wxDefaultPosition, wxDefaultSize);
415 fgSizer2->Add(label5, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
417 itemBoxSizer1->Add(fgSizer2, 5, wxEXPAND, 5);
419 wxBoxSizer* itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
420 itemBoxSizer1->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
423 new wxButton(itemDialog1, ID_ROUTEPRINT_SELECTION_CANCEL, _(
"Cancel"),
424 wxDefaultPosition, wxDefaultSize, 0);
425 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
427 m_OKButton =
new wxButton(itemDialog1, ID_ROUTEPRINT_SELECTION_OK, _(
"OK"),
428 wxDefaultPosition, wxDefaultSize, 0);
429 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
430 m_OKButton->SetDefault();
432 SetColorScheme((ColorScheme)0);
435void RoutePrintSelection::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
441bool RoutePrintSelection::ShowToolTips() {
return TRUE; }
443void RoutePrintSelection::SetDialogTitle(
const wxString& title) {
447void RoutePrintSelection::OnRoutepropCancelClick(wxCommandEvent& event) {
452void RoutePrintSelection::OnRoutepropOkClick(wxCommandEvent& event) {
453 std::vector<bool> toPrintOut;
454 toPrintOut.push_back(m_checkBoxWPName->GetValue());
455 toPrintOut.push_back(m_checkBoxWPPosition->GetValue());
456 toPrintOut.push_back(m_checkBoxWPCourse->GetValue());
457 toPrintOut.push_back(m_checkBoxWPDistanceToNext->GetValue());
458 toPrintOut.push_back(m_checkBoxWPDescription->GetValue());
460 if (NULL == g_printData) {
461 g_printData =
new wxPrintData;
462 g_printData->SetOrientation(wxPORTRAIT);
463 g_pageSetupData =
new wxPageSetupDialogData;
469 wxPrintDialogData printDialogData(*g_printData);
470 printDialogData.EnablePageNumbers(
true);
472 wxPrinter printer(&printDialogData);
473 if (!printer.Print(
this, myrouteprintout1,
true)) {
474 if (wxPrinter::GetLastError() == wxPRINTER_ERROR) {
476 _(
"There was a problem printing.\nPerhaps your current "
477 "printer is not set correctly?"),
478 _T(
"OpenCPN" ), wxOK);
This class takes multilined string and modifies it to fit into given width for given device.
bool Create(wxWindow *parent, wxWindowID id=SYMBOL_ROUTEPRINT_SELECTION_IDNAME, const wxString &caption=SYMBOL_ROUTEPRINT_SELECTION_TITLE, const wxPoint &pos=SYMBOL_ROUTEPRINT_SELECTION_POSITION, const wxSize &size=SYMBOL_ROUTEPRINT_SELECTION_SIZE, long style=SYMBOL_ROUTEPRINT_SELECTION_STYLE)
General purpose GUI support.