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 "wx28compat.h"
72#include "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;
302EVT_BUTTON(ID_ROUTEPRINT_SELECTION_CANCEL,
303 RoutePrintSelection::OnRoutepropCancelClick)
304EVT_BUTTON(ID_ROUTEPRINT_SELECTION_OK, RoutePrintSelection::OnRoutepropOkClick)
313RoutePrintSelection::RoutePrintSelection(wxWindow* parent,
Route* _route,
314 wxWindowID
id,
const wxString& caption,
315 const wxPoint& pos,
const wxSize& size,
321 Create(parent,
id, caption, pos, size, wstyle);
325RoutePrintSelection::~RoutePrintSelection() {}
332 const wxString& caption,
const wxPoint& pos,
333 const wxSize& size,
long style) {
334 SetExtraStyle(GetExtraStyle() | wxWS_EX_BLOCK_EVENTS);
337 style |= wxSTAY_ON_TOP;
340 wxDialog::Create(parent,
id, _(
"Print Route Selection"), pos, size, style);
354 wxStaticBox* itemStaticBoxSizer3Static =
355 new wxStaticBox(itemDialog1, wxID_ANY, _(
"Elements to print..."));
357 wxStaticBoxSizer* itemBoxSizer1 =
358 new wxStaticBoxSizer(itemStaticBoxSizer3Static, wxVERTICAL);
359 itemDialog1->SetSizer(itemBoxSizer1);
361 wxFlexGridSizer* fgSizer2;
362 fgSizer2 =
new wxFlexGridSizer(5, 2, 0, 0);
365 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Name"), wxDefaultPosition,
366 wxDefaultSize, wxALIGN_LEFT);
367 m_checkBoxWPName->SetValue(
true);
368 fgSizer2->Add(m_checkBoxWPName, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
370 wxStaticText* label1 =
371 new wxStaticText(itemDialog1, wxID_ANY, _(
"Show Waypoint name."),
372 wxDefaultPosition, wxDefaultSize);
373 fgSizer2->Add(label1, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
375 m_checkBoxWPPosition =
376 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Position"), wxDefaultPosition,
377 wxDefaultSize, wxALIGN_LEFT);
378 m_checkBoxWPPosition->SetValue(
true);
379 fgSizer2->Add(m_checkBoxWPPosition, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
380 wxStaticText* label2 =
381 new wxStaticText(itemDialog1, wxID_ANY, _(
"Show Waypoint position."),
382 wxDefaultPosition, wxDefaultSize);
383 fgSizer2->Add(label2, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
386 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Course"), wxDefaultPosition,
387 wxDefaultSize, wxALIGN_LEFT);
388 m_checkBoxWPCourse->SetValue(
true);
389 fgSizer2->Add(m_checkBoxWPCourse, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
390 wxStaticText* label3 =
391 new wxStaticText(itemDialog1, wxID_ANY,
392 _(
"Show course from each Waypoint to the next one. "),
393 wxDefaultPosition, wxDefaultSize);
394 fgSizer2->Add(label3, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
396 m_checkBoxWPDistanceToNext =
397 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Distance"), wxDefaultPosition,
398 wxDefaultSize, wxALIGN_LEFT);
399 m_checkBoxWPDistanceToNext->SetValue(
true);
400 fgSizer2->Add(m_checkBoxWPDistanceToNext, 0, wxALL | wxALIGN_CENTER_VERTICAL,
402 wxStaticText* label4 =
403 new wxStaticText(itemDialog1, wxID_ANY,
404 _(
"Show Distance from each Waypoint to the next one."),
405 wxDefaultPosition, wxDefaultSize);
406 fgSizer2->Add(label4, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
408 m_checkBoxWPDescription =
409 new wxCheckBox(itemDialog1, wxID_ANY, _(
"Description"), wxDefaultPosition,
410 wxDefaultSize, wxALIGN_LEFT);
411 m_checkBoxWPDescription->SetValue(
true);
412 fgSizer2->Add(m_checkBoxWPDescription, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
413 wxStaticText* label5 =
414 new wxStaticText(itemDialog1, wxID_ANY, _(
"Show Waypoint description."),
415 wxDefaultPosition, wxDefaultSize);
416 fgSizer2->Add(label5, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5);
418 itemBoxSizer1->Add(fgSizer2, 5, wxEXPAND, 5);
420 wxBoxSizer* itemBoxSizer16 =
new wxBoxSizer(wxHORIZONTAL);
421 itemBoxSizer1->Add(itemBoxSizer16, 0, wxALIGN_RIGHT | wxALL, 5);
424 new wxButton(itemDialog1, ID_ROUTEPRINT_SELECTION_CANCEL, _(
"Cancel"),
425 wxDefaultPosition, wxDefaultSize, 0);
426 itemBoxSizer16->Add(m_CancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
428 m_OKButton =
new wxButton(itemDialog1, ID_ROUTEPRINT_SELECTION_OK, _(
"OK"),
429 wxDefaultPosition, wxDefaultSize, 0);
430 itemBoxSizer16->Add(m_OKButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
431 m_OKButton->SetDefault();
433 SetColorScheme((ColorScheme)0);
436void RoutePrintSelection::SetColorScheme(ColorScheme cs) { DimeControl(
this); }
442bool RoutePrintSelection::ShowToolTips() {
return TRUE; }
444void RoutePrintSelection::SetDialogTitle(
const wxString& title) {
448void RoutePrintSelection::OnRoutepropCancelClick(wxCommandEvent& event) {
453void RoutePrintSelection::OnRoutepropOkClick(wxCommandEvent& event) {
454 std::vector<bool> toPrintOut;
455 toPrintOut.push_back(m_checkBoxWPName->GetValue());
456 toPrintOut.push_back(m_checkBoxWPPosition->GetValue());
457 toPrintOut.push_back(m_checkBoxWPCourse->GetValue());
458 toPrintOut.push_back(m_checkBoxWPDistanceToNext->GetValue());
459 toPrintOut.push_back(m_checkBoxWPDescription->GetValue());
461 if (NULL == g_printData) {
462 g_printData =
new wxPrintData;
463 g_printData->SetOrientation(wxPORTRAIT);
464 g_pageSetupData =
new wxPageSetupDialogData;
470 wxPrintDialogData printDialogData(*g_printData);
471 printDialogData.EnablePageNumbers(
true);
473 wxPrinter printer(&printDialogData);
474 if (!printer.Print(
this, myrouteprintout1,
true)) {
475 if (wxPrinter::GetLastError() == wxPRINTER_ERROR) {
477 _(
"There was a problem printing.\nPerhaps your current "
478 "printer is not set correctly?"),
479 _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)