Omit hidden splays from page bounds calculations
[survex.git] / src / printing.cc
blob71b5dfc74d7b929715ef63a2f15144b61d7c7d9e
1 /* printing.cc */
2 /* Aven printing code */
3 /* Copyright (C) 1993-2003,2004,2005,2006,2010,2011,2012,2013,2014,2015,2016 Olly Betts
4 * Copyright (C) 2001,2004 Philip Underwood
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #include <wx/confbase.h>
26 #include <wx/filename.h>
27 #include <wx/print.h>
28 #include <wx/printdlg.h>
29 #include <wx/spinctrl.h>
30 #include <wx/radiobox.h>
31 #include <wx/statbox.h>
32 #include <wx/valgen.h>
34 #include <vector>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <math.h>
39 #include <string.h>
40 #include <ctype.h>
41 #include <float.h>
42 #include <limits.h>
44 #include "debug.h" /* for SVX_ASSERT */
45 #include "export.h"
46 #include "filelist.h"
47 #include "filename.h"
48 #include "message.h"
49 #include "useful.h"
51 #include "aven.h"
52 #include "avenprcore.h"
53 #include "mainfrm.h"
54 #include "printing.h"
56 using namespace std;
58 // How many decimal points to show on angles:
59 #define ANGLE_DP 1
61 #if ANGLE_DP == 0
62 # define ANGLE_FMT wxT("%03.f")
63 # define ANGLE2_FMT wxT("%.f")
64 #elif ANGLE_DP == 1
65 # define ANGLE_FMT wxT("%05.1f")
66 # define ANGLE2_FMT wxT("%.1f")
67 #elif ANGLE_DP == 2
68 # define ANGLE_FMT wxT("%06.2f")
69 # define ANGLE2_FMT wxT("%.2f")
70 #else
71 # error Need to add ANGLE_FMT and ANGLE2_FMT for the currently set ANGLE_DP
72 #endif
74 static wxString
75 format_angle(const wxChar * fmt, double angle)
77 wxString s;
78 s.Printf(fmt, angle);
79 size_t dot = s.find('.');
80 size_t i = s.size();
81 while (i > dot) {
82 --i;
83 if (s[i] != '0') {
84 if (i != dot) ++i;
85 s.resize(i);
86 break;
89 s += wmsg(/*°*/344);
90 return s;
93 enum {
94 svx_EXPORT = 1200,
95 svx_FORMAT,
96 svx_SCALE,
97 svx_BEARING,
98 svx_TILT,
99 svx_LEGS,
100 svx_STATIONS,
101 svx_NAMES,
102 svx_XSECT,
103 svx_WALLS,
104 svx_PASSAGES,
105 svx_BORDERS,
106 svx_BLANKS,
107 svx_LEGEND,
108 svx_SURFACE,
109 svx_SPLAYS,
110 svx_PLAN,
111 svx_ELEV,
112 svx_ENTS,
113 svx_FIXES,
114 svx_EXPORTS,
115 svx_PROJ_LABEL,
116 svx_PROJ,
117 svx_GRID,
118 svx_TEXT_HEIGHT,
119 svx_MARKER_SIZE,
120 svx_CENTRED,
121 svx_FULLCOORDS
124 class BitValidator : public wxValidator {
125 // Disallow assignment.
126 BitValidator & operator=(const BitValidator&);
128 protected:
129 int * val;
131 int mask;
133 public:
134 BitValidator(int * val_, int mask_)
135 : val(val_), mask(mask_) { }
137 BitValidator(const BitValidator &o) : wxValidator() {
138 Copy(o);
141 ~BitValidator() { }
143 wxObject *Clone() const { return new BitValidator(val, mask); }
145 bool Copy(const BitValidator& o) {
146 wxValidator::Copy(o);
147 val = o.val;
148 mask = o.mask;
149 return true;
152 bool Validate(wxWindow *) { return true; }
154 bool TransferToWindow() {
155 if (!m_validatorWindow->IsKindOf(CLASSINFO(wxCheckBox)))
156 return false;
157 ((wxCheckBox*)m_validatorWindow)->SetValue(*val & mask);
158 return true;
161 bool TransferFromWindow() {
162 if (!m_validatorWindow->IsKindOf(CLASSINFO(wxCheckBox)))
163 return false;
164 if (((wxCheckBox*)m_validatorWindow)->IsChecked())
165 *val |= mask;
166 else
167 *val &= ~mask;
168 return true;
172 class svxPrintout : public wxPrintout {
173 MainFrm *mainfrm;
174 layout *m_layout;
175 wxPageSetupDialogData* m_data;
176 wxDC* pdc;
177 wxFont *font_labels, *font_default;
178 // Currently unused, but "skip blank pages" would use it.
179 bool scan_for_blank_pages;
181 wxPen *pen_frame, *pen_cross, *pen_leg, *pen_surface_leg, *pen_splay;
182 wxColour colour_text, colour_labels;
184 long x_t, y_t;
185 double font_scaling_x, font_scaling_y;
187 struct {
188 long x_min, y_min, x_max, y_max;
189 } clip;
191 bool fBlankPage;
193 int check_intersection(long x_p, long y_p);
194 void draw_info_box();
195 void draw_scale_bar(double x, double y, double MaxLength);
196 int next_page(int *pstate, char **q, int pageLim);
197 void drawticks(int tsize, int x, int y);
199 void MOVEMM(double X, double Y) {
200 MoveTo((long)(X * m_layout->scX), (long)(Y * m_layout->scY));
202 void DRAWMM(double X, double Y) {
203 DrawTo((long)(X * m_layout->scX), (long)(Y * m_layout->scY));
205 void MoveTo(long x, long y);
206 void DrawTo(long x, long y);
207 void DrawCross(long x, long y);
208 void SetFont(wxFont * font) {
209 pdc->SetFont(*font);
211 void WriteString(const wxString & s);
212 void DrawEllipse(long x, long y, long r, long R);
213 void SolidRectangle(long x, long y, long w, long h);
214 void NewPage(int pg, int pagesX, int pagesY);
215 void PlotLR(const vector<XSect> & centreline);
216 void PlotUD(const vector<XSect> & centreline);
217 public:
218 svxPrintout(MainFrm *mainfrm, layout *l, wxPageSetupDialogData *data, const wxString & title);
219 bool OnPrintPage(int pageNum);
220 void GetPageInfo(int *minPage, int *maxPage,
221 int *pageFrom, int *pageTo);
222 bool HasPage(int pageNum);
223 void OnBeginPrinting();
224 void OnEndPrinting();
227 BEGIN_EVENT_TABLE(svxPrintDlg, wxDialog)
228 EVT_CHOICE(svx_FORMAT, svxPrintDlg::OnChange)
229 EVT_TEXT(svx_SCALE, svxPrintDlg::OnChange)
230 EVT_COMBOBOX(svx_SCALE, svxPrintDlg::OnChange)
231 EVT_SPINCTRL(svx_BEARING, svxPrintDlg::OnChangeSpin)
232 EVT_SPINCTRL(svx_TILT, svxPrintDlg::OnChangeSpin)
233 EVT_BUTTON(wxID_PRINT, svxPrintDlg::OnPrint)
234 EVT_BUTTON(svx_EXPORT, svxPrintDlg::OnExport)
235 EVT_BUTTON(wxID_CANCEL, svxPrintDlg::OnCancel)
236 #ifdef AVEN_PRINT_PREVIEW
237 EVT_BUTTON(wxID_PREVIEW, svxPrintDlg::OnPreview)
238 #endif
239 EVT_BUTTON(svx_PLAN, svxPrintDlg::OnPlan)
240 EVT_BUTTON(svx_ELEV, svxPrintDlg::OnElevation)
241 EVT_UPDATE_UI(svx_PLAN, svxPrintDlg::OnPlanUpdate)
242 EVT_UPDATE_UI(svx_ELEV, svxPrintDlg::OnElevationUpdate)
243 EVT_CHECKBOX(svx_LEGS, svxPrintDlg::OnChange)
244 EVT_CHECKBOX(svx_STATIONS, svxPrintDlg::OnChange)
245 EVT_CHECKBOX(svx_NAMES, svxPrintDlg::OnChange)
246 EVT_CHECKBOX(svx_SURFACE, svxPrintDlg::OnChange)
247 EVT_CHECKBOX(svx_SPLAYS, svxPrintDlg::OnChange)
248 EVT_CHECKBOX(svx_ENTS, svxPrintDlg::OnChange)
249 EVT_CHECKBOX(svx_FIXES, svxPrintDlg::OnChange)
250 EVT_CHECKBOX(svx_EXPORTS, svxPrintDlg::OnChange)
251 END_EVENT_TABLE()
253 static wxString scales[] = {
254 wxT(""),
255 wxT("25"),
256 wxT("50"),
257 wxT("100"),
258 wxT("250"),
259 wxT("500"),
260 wxT("1000"),
261 wxT("2500"),
262 wxT("5000"),
263 wxT("10000"),
264 wxT("25000"),
265 wxT("50000"),
266 wxT("100000")
269 static wxString formats[] = {
270 wxT("DXF"),
271 wxT("EPS"),
272 wxT("GPX"),
273 wxT("HPGL"),
274 wxT("JSON"),
275 wxT("KML"),
276 wxT("Plot"),
277 wxT("Skencil"),
278 wxT("Survex pos"),
279 wxT("SVG")
282 #if 0
283 static wxString projs[] = {
284 /* CUCC Austria: */
285 wxT("+proj=tmerc +lat_0=0 +lon_0=13d20 +k=1 +x_0=0 +y_0=-5200000 +ellps=bessel +towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232"),
286 /* British grid SD (Yorkshire): */
287 wxT("+proj=tmerc +lat_0=49d +lon_0=-2d +k=0.999601 +x_0=100000 +y_0=-500000 +ellps=airy +towgs84=375,-111,431,0,0,0,0"),
288 /* British full grid reference: */
289 wxT("+proj=tmerc +lat_0=49d +lon_0=-2d +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=375,-111,431,0,0,0,0")
291 #endif
293 static const unsigned format_info[] = {
294 LABELS|LEGS|SURF|SPLAYS|STNS|PASG|XSECT|WALLS|MARKER_SIZE|TEXT_HEIGHT|GRID|FULL_COORDS,
295 LABELS|LEGS|SURF|SPLAYS|STNS|PASG|XSECT|WALLS,
296 LABELS|LEGS|SURF|SPLAYS|ENTS|FIXES|EXPORTS|PROJ|EXPORT_3D,
297 LABELS|LEGS|SURF|SPLAYS|STNS|CENTRED,
298 LEGS|SPLAYS|CENTRED|EXPORT_3D,
299 LABELS|LEGS|SPLAYS|ENTS|FIXES|EXPORTS|PROJ|EXPORT_3D,
300 LABELS|LEGS|SURF|SPLAYS,
301 LABELS|LEGS|SURF|SPLAYS|STNS|MARKER_SIZE|GRID|SCALE,
302 LABELS|ENTS|FIXES|EXPORTS|EXPORT_3D,
303 LABELS|LEGS|SURF|SPLAYS|STNS|PASG|XSECT|WALLS|MARKER_SIZE|TEXT_HEIGHT|SCALE
306 static const char * extension[] = {
307 ".dxf",
308 ".eps",
309 ".gpx",
310 ".hpgl",
311 ".json",
312 ".kml",
313 ".plt",
314 ".sk",
315 ".pos",
316 ".svg"
319 static const int msg_filetype[] = {
320 /*DXF files*/411,
321 /*EPS files*/412,
322 /*GPX files*/413,
323 /* TRANSLATORS: Here "plotter" refers to a machine which draws a printout
324 * on a (usually large) sheet of paper using a pen mounted in a motorised
325 * mechanism. */
326 /*HPGL for plotters*/414,
327 /*JSON files*/445,
328 /*KML files*/444,
329 /* TRANSLATORS: "Compass" and "Carto" are the names of software packages,
330 * so should not be translated:
331 * http://www.fountainware.com/compass/
332 * http://www.psc-cavers.org/carto/ */
333 /*Compass PLT for use with Carto*/415,
334 /* TRANSLATORS: "Skencil" is the name of a software package, so should not be
335 * translated: http://www.skencil.org/ */
336 /*Skencil files*/416,
337 /* TRANSLATORS: Survex is the name of the software, and "pos" refers to a
338 * file extension, so neither should be translated. */
339 /*Survex pos files*/166,
340 /*SVG files*/417
343 svxPrintDlg::svxPrintDlg(MainFrm* mainfrm_, const wxString & filename,
344 const wxString & title, const wxString & cs_proj,
345 const wxString & datestamp, time_t datestamp_numeric,
346 double angle, double tilt_angle,
347 bool labels, bool crosses, bool legs, bool surf,
348 bool splays, bool tubes, bool ents, bool fixes,
349 bool exports, bool printing, bool close_after_)
350 : wxDialog(mainfrm_, -1, wxString(printing ?
351 /* TRANSLATORS: Title of the print
352 * dialog */
353 wmsg(/*Print*/399) :
354 /* TRANSLATORS: Title of the export
355 * dialog */
356 wmsg(/*Export*/383))),
357 m_layout(printing ? wxGetApp().GetPageSetupDialogData() : NULL),
358 m_File(filename), mainfrm(mainfrm_), close_after(close_after_)
360 m_scale = NULL;
361 m_printSize = NULL;
362 m_bearing = NULL;
363 m_tilt = NULL;
364 m_format = NULL;
365 int show_mask = 0;
366 if (labels)
367 show_mask |= LABELS;
368 if (crosses)
369 show_mask |= STNS;
370 if (legs)
371 show_mask |= LEGS;
372 if (surf)
373 show_mask |= SURF;
374 if (splays)
375 show_mask |= SPLAYS;
376 if (tubes)
377 show_mask |= XSECT|WALLS|PASG;
378 if (ents)
379 show_mask |= ENTS;
380 if (fixes)
381 show_mask |= FIXES;
382 if (exports)
383 show_mask |= EXPORTS;
384 m_layout.show_mask = show_mask;
385 m_layout.datestamp = datestamp;
386 m_layout.datestamp_numeric = datestamp_numeric;
387 m_layout.rot = angle;
388 m_layout.title = title;
389 m_layout.cs_proj = cs_proj;
390 if (mainfrm->IsExtendedElevation()) {
391 m_layout.view = layout::EXTELEV;
392 if (m_layout.rot != 0.0 && m_layout.rot != 180.0) m_layout.rot = 0;
393 m_layout.tilt = 0;
394 } else {
395 m_layout.tilt = tilt_angle;
396 if (m_layout.tilt == -90.0) {
397 m_layout.view = layout::PLAN;
398 } else if (m_layout.tilt == 0.0) {
399 m_layout.view = layout::ELEV;
400 } else {
401 m_layout.view = layout::TILT;
405 /* setup our print dialog*/
406 wxBoxSizer* v1 = new wxBoxSizer(wxVERTICAL);
407 wxBoxSizer* h1 = new wxBoxSizer(wxHORIZONTAL); // holds controls
408 /* TRANSLATORS: Used as a label for the surrounding box for the "Bearing"
409 * and "Tilt angle" fields, and the "Plan view" and "Elevation" buttons in
410 * the "what to print/export" dialog. */
411 m_viewbox = new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*View*/283)), wxVERTICAL);
412 /* TRANSLATORS: Used as a label for the surrounding box for the "survey
413 * legs" "stations" "names" etc checkboxes in the "what to print" dialog.
414 * "Elements" isn’t a good name for this but nothing better has yet come to
415 * mind! */
416 wxBoxSizer* v3 = new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*Elements*/256)), wxVERTICAL);
417 wxBoxSizer* h2 = new wxBoxSizer(wxHORIZONTAL);
418 wxBoxSizer* h3 = new wxBoxSizer(wxHORIZONTAL); // holds buttons
420 if (!printing) {
421 wxStaticText* label;
422 label = new wxStaticText(this, -1, wxString(wmsg(/*Export format*/410)));
423 const size_t n_formats = sizeof(formats) / sizeof(formats[0]);
424 m_format = new wxChoice(this, svx_FORMAT,
425 wxDefaultPosition, wxDefaultSize,
426 n_formats, formats);
427 unsigned current_format = 0;
428 wxConfigBase * cfg = wxConfigBase::Get();
429 wxString s;
430 if (cfg->Read(wxT("export_format"), &s, wxString())) {
431 for (unsigned i = 0; i != n_formats; ++i) {
432 if (s == formats[i]) {
433 current_format = i;
434 break;
438 m_format->SetSelection(current_format);
439 wxBoxSizer* formatbox = new wxBoxSizer(wxHORIZONTAL);
440 formatbox->Add(label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
441 formatbox->Add(m_format, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
443 v1->Add(formatbox, 0, wxALIGN_LEFT|wxALL, 0);
446 wxStaticText* label;
447 label = new wxStaticText(this, -1, wxString(wmsg(/*Scale*/154)) + wxT(" 1:"));
448 if (scales[0].empty()) {
449 if (printing) {
450 /* TRANSLATORS: used in the scale drop down selector in the print
451 * dialog the implicit meaning is "choose a suitable scale to fit
452 * the plot on a single page", but we need something shorter */
453 scales[0].assign(wmsg(/*One page*/258));
454 } else {
455 scales[0].assign(wxT("1000"));
458 m_scale = new wxComboBox(this, svx_SCALE, scales[0], wxDefaultPosition,
459 wxDefaultSize, sizeof(scales) / sizeof(scales[0]),
460 scales);
461 m_scalebox = new wxBoxSizer(wxHORIZONTAL);
462 m_scalebox->Add(label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
463 m_scalebox->Add(m_scale, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
465 m_viewbox->Add(m_scalebox, 0, wxALIGN_LEFT|wxALL, 0);
467 if (printing) {
468 // Make the dummy string wider than any sane value and use that to
469 // fix the width of the control so the sizers allow space for bigger
470 // page layouts.
471 m_printSize = new wxStaticText(this, -1, wxString::Format(wmsg(/*%d pages (%dx%d)*/257), 9604, 98, 98));
472 m_viewbox->Add(m_printSize, 0, wxALIGN_LEFT|wxALL, 5);
475 /* FIXME:
476 * svx_GRID, // double - spacing, default: 100m
477 * svx_TEXT_HEIGHT, // default 0.6
478 * svx_MARKER_SIZE // default 0.8
481 if (m_layout.view != layout::EXTELEV) {
482 wxFlexGridSizer* anglebox = new wxFlexGridSizer(2);
483 wxStaticText * brg_label, * tilt_label;
484 brg_label = new wxStaticText(this, -1, wmsg(/*Bearing*/259));
485 anglebox->Add(brg_label, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALL, 5);
486 m_bearing = new wxSpinCtrlDouble(this, svx_BEARING);
487 m_bearing->SetRange(0.0, 360.0);
488 m_bearing->SetDigits(ANGLE_DP);
489 anglebox->Add(m_bearing, 0, wxALIGN_CENTER|wxALL, 5);
490 /* TRANSLATORS: Used in the print dialog: */
491 tilt_label = new wxStaticText(this, -1, wmsg(/*Tilt angle*/263));
492 anglebox->Add(tilt_label, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALL, 5);
493 m_tilt = new wxSpinCtrlDouble(this, svx_TILT);
494 m_tilt->SetRange(-90.0, 90.0);
495 m_tilt->SetDigits(ANGLE_DP);
496 anglebox->Add(m_tilt, 0, wxALIGN_CENTER|wxALL, 5);
498 m_viewbox->Add(anglebox, 0, wxALIGN_LEFT|wxALL, 0);
500 wxBoxSizer * planelevsizer = new wxBoxSizer(wxHORIZONTAL);
501 planelevsizer->Add(new wxButton(this, svx_PLAN, wmsg(/*P&lan view*/117)),
502 0, wxALIGN_CENTRE_VERTICAL|wxALL, 5);
503 planelevsizer->Add(new wxButton(this, svx_ELEV, wmsg(/*&Elevation*/285)),
504 0, wxALIGN_CENTRE_VERTICAL|wxALL, 5);
506 m_viewbox->Add(planelevsizer, 0, wxALIGN_LEFT|wxALL, 5);
509 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
510 * "survey stations". */
511 v3->Add(new wxCheckBox(this, svx_LEGS, wmsg(/*Underground Survey Legs*/262),
512 wxDefaultPosition, wxDefaultSize, 0,
513 BitValidator(&m_layout.show_mask, LEGS)),
514 0, wxALIGN_LEFT|wxALL, 2);
515 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
516 * "survey stations". */
517 v3->Add(new wxCheckBox(this, svx_SURFACE, wmsg(/*Sur&face Survey Legs*/403),
518 wxDefaultPosition, wxDefaultSize, 0,
519 BitValidator(&m_layout.show_mask, SURF)),
520 0, wxALIGN_LEFT|wxALL, 2);
521 v3->Add(new wxCheckBox(this, svx_SPLAYS, wmsg(/*Spla&y Legs*/406),
522 wxDefaultPosition, wxDefaultSize, 0,
523 BitValidator(&m_layout.show_mask, SPLAYS)),
524 0, wxALIGN_LEFT|wxALL, 2);
525 v3->Add(new wxCheckBox(this, svx_STATIONS, wmsg(/*Crosses*/261),
526 wxDefaultPosition, wxDefaultSize, 0,
527 BitValidator(&m_layout.show_mask, STNS)),
528 0, wxALIGN_LEFT|wxALL, 2);
529 v3->Add(new wxCheckBox(this, svx_NAMES, wmsg(/*Station Names*/260),
530 wxDefaultPosition, wxDefaultSize, 0,
531 BitValidator(&m_layout.show_mask, LABELS)),
532 0, wxALIGN_LEFT|wxALL, 2);
533 v3->Add(new wxCheckBox(this, svx_ENTS, wmsg(/*Entrances*/418),
534 wxDefaultPosition, wxDefaultSize, 0,
535 BitValidator(&m_layout.show_mask, ENTS)),
536 0, wxALIGN_LEFT|wxALL, 2);
537 v3->Add(new wxCheckBox(this, svx_FIXES, wmsg(/*Fixed Points*/419),
538 wxDefaultPosition, wxDefaultSize, 0,
539 BitValidator(&m_layout.show_mask, FIXES)),
540 0, wxALIGN_LEFT|wxALL, 2);
541 v3->Add(new wxCheckBox(this, svx_EXPORTS, wmsg(/*Exported Stations*/420),
542 wxDefaultPosition, wxDefaultSize, 0,
543 BitValidator(&m_layout.show_mask, EXPORTS)),
544 0, wxALIGN_LEFT|wxALL, 2);
545 v3->Add(new wxCheckBox(this, svx_XSECT, wmsg(/*Cross-sections*/393),
546 wxDefaultPosition, wxDefaultSize, 0,
547 BitValidator(&m_layout.show_mask, XSECT)),
548 0, wxALIGN_LEFT|wxALL, 2);
549 if (!printing) {
550 v3->Add(new wxCheckBox(this, svx_WALLS, wmsg(/*Walls*/394),
551 wxDefaultPosition, wxDefaultSize, 0,
552 BitValidator(&m_layout.show_mask, WALLS)),
553 0, wxALIGN_LEFT|wxALL, 2);
554 // TRANSLATORS: Label for checkbox which controls whether there's a
555 // layer in the exported file (for formats such as DXF and SVG)
556 // containing polygons for the inside of cave passages).
557 v3->Add(new wxCheckBox(this, svx_PASSAGES, wmsg(/*Passages*/395),
558 wxDefaultPosition, wxDefaultSize, 0,
559 BitValidator(&m_layout.show_mask, PASG)),
560 0, wxALIGN_LEFT|wxALL, 2);
561 v3->Add(new wxCheckBox(this, svx_CENTRED, wmsg(/*Origin in centre*/421),
562 wxDefaultPosition, wxDefaultSize, 0,
563 BitValidator(&m_layout.show_mask, CENTRED)),
564 0, wxALIGN_LEFT|wxALL, 2);
565 v3->Add(new wxCheckBox(this, svx_FULLCOORDS, wmsg(/*Full coordinates*/422),
566 wxDefaultPosition, wxDefaultSize, 0,
567 BitValidator(&m_layout.show_mask, FULL_COORDS)),
568 0, wxALIGN_LEFT|wxALL, 2);
570 if (printing) {
571 /* TRANSLATORS: used in the print dialog - controls drawing lines
572 * around each page */
573 v3->Add(new wxCheckBox(this, svx_BORDERS, wmsg(/*Page Borders*/264),
574 wxDefaultPosition, wxDefaultSize, 0,
575 wxGenericValidator(&m_layout.Border)),
576 0, wxALIGN_LEFT|wxALL, 2);
577 /* TRANSLATORS: will be used in the print dialog - check this to print
578 * blank pages (otherwise they’ll be skipped to save paper) */
579 // m_blanks = new wxCheckBox(this, svx_BLANKS, wmsg(/*Blank Pages*/266));
580 // v3->Add(m_blanks, 0, wxALIGN_LEFT|wxALL, 2);
581 /* TRANSLATORS: As in the legend on a map. Used in the print dialog -
582 * controls drawing the box at the lower left with survey name, view
583 * angles, etc */
584 v3->Add(new wxCheckBox(this, svx_LEGEND, wmsg(/*Legend*/265),
585 wxDefaultPosition, wxDefaultSize, 0,
586 wxGenericValidator(&m_layout.Legend)),
587 0, wxALIGN_LEFT|wxALL, 2);
590 h1->Add(v3, 0, wxALIGN_LEFT|wxALL, 5);
591 h1->Add(m_viewbox, 0, wxALIGN_LEFT|wxLEFT, 5);
593 if (!printing) {
594 /* TRANSLATORS: The PROJ library is used to do coordinate
595 * transformations (https://trac.osgeo.org/proj/) - if the .3d file
596 * doesn't contain details of the coordinate projection in use, the
597 * user must specify it here for export formats which need to know it
598 * (e.g. GPX).
600 h2->Add(new wxStaticText(this, svx_PROJ_LABEL, wmsg(/*Coordinate projection*/440)),
601 0, wxLEFT|wxALIGN_CENTRE_VERTICAL, 5);
602 long style = 0;
603 if (!m_layout.cs_proj.empty()) {
604 // If the input file specified the coordinate system, don't let the
605 // user mess with it.
606 style = wxTE_READONLY;
607 } else {
608 #if 0 // FIXME: Is it a good idea to save this?
609 wxConfigBase * cfg = wxConfigBase::Get();
610 wxString input_projection;
611 cfg->Read(wxT("input_projection"), &input_projection);
612 if (!input_projection.empty())
613 proj_edit.SetValue(input_projection);
614 #endif
616 wxTextCtrl * proj_edit = new wxTextCtrl(this, svx_PROJ, m_layout.cs_proj,
617 wxDefaultPosition, wxDefaultSize,
618 style);
619 h2->Add(proj_edit, 1, wxALL|wxEXPAND|wxALIGN_CENTRE_VERTICAL, 5);
620 v1->Add(h2, 0, wxALIGN_LEFT|wxEXPAND, 5);
623 v1->Add(h1, 0, wxALIGN_LEFT|wxALL, 5);
625 // When we enable/disable checkboxes in the export dialog, ideally we'd
626 // like the dialog to resize, but not sure how to achieve that, so we
627 // add a stretchable spacer here so at least the buttons stay in the
628 // lower right corner.
629 v1->AddStretchSpacer();
631 wxButton * but;
632 but = new wxButton(this, wxID_CANCEL);
633 h3->Add(but, 0, wxALIGN_RIGHT|wxALL, 5);
634 if (printing) {
635 #ifdef AVEN_PRINT_PREVIEW
636 but = new wxButton(this, wxID_PREVIEW);
637 h3->Add(but, 0, wxALIGN_RIGHT|wxALL, 5);
638 but = new wxButton(this, wxID_PRINT);
639 #else
640 but = new wxButton(this, wxID_PRINT, wmsg(/*&Print...*/400));
641 #endif
642 } else {
643 /* TRANSLATORS: The text on the action button in the "Export" settings
644 * dialog */
645 but = new wxButton(this, svx_EXPORT, wmsg(/*&Export...*/230));
647 but->SetDefault();
648 h3->Add(but, 0, wxALIGN_RIGHT|wxALL, 5);
649 v1->Add(h3, 0, wxALIGN_RIGHT|wxALL, 5);
651 SetAutoLayout(true);
652 SetSizer(v1);
653 v1->SetSizeHints(this);
655 LayoutToUI();
656 SomethingChanged(0);
659 void
660 svxPrintDlg::OnPrint(wxCommandEvent&) {
661 SomethingChanged(0);
662 TransferDataFromWindow();
663 wxPageSetupDialogData * psdd = wxGetApp().GetPageSetupDialogData();
664 wxPrintDialogData pd(psdd->GetPrintData());
665 wxPrinter pr(&pd);
666 svxPrintout po(mainfrm, &m_layout, psdd, m_File);
667 if (m_layout.SkipBlank) {
668 // FIXME: wx's printing requires a contiguous range of valid page
669 // numbers. To achieve that, we need to run a scan for blank pages
670 // here, so that GetPageInfo() knows what range to return, and so
671 // that OnPrintPage() can map a page number back to where in the
672 // MxN multi-page layout.
673 #if 0
674 po.scan_for_blank_pages = true;
675 for (int page = 1; page <= m_layout->pages; ++page) {
676 po.fBlankPage = fTrue;
677 po.OnPrintPage(page);
678 // FIXME: Do something with po.fBlankPage
680 po.scan_for_blank_pages = false;
681 #endif
683 if (pr.Print(this, &po, true)) {
684 // Close the print dialog if printing succeeded.
685 Destroy();
689 void
690 svxPrintDlg::OnExport(wxCommandEvent&) {
691 UIToLayout();
692 TransferDataFromWindow();
693 wxString leaf;
694 wxFileName::SplitPath(m_File, NULL, NULL, &leaf, NULL, wxPATH_NATIVE);
695 unsigned format_idx = ((wxChoice*)FindWindow(svx_FORMAT))->GetSelection();
696 leaf += wxString::FromUTF8(extension[format_idx]);
698 wxString filespec = wmsg(msg_filetype[format_idx]);
699 filespec += wxT("|*");
700 filespec += wxString::FromUTF8(extension[format_idx]);
701 filespec += wxT("|");
702 filespec += wmsg(/*All files*/208);
703 filespec += wxT("|");
704 filespec += wxFileSelectorDefaultWildcardStr;
706 /* TRANSLATORS: Title of file dialog to choose name and type of exported
707 * file. */
708 wxFileDialog dlg(this, wmsg(/*Export as:*/401), wxString(), leaf,
709 filespec, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
710 if (dlg.ShowModal() == wxID_OK) {
711 wxString input_projection = ((wxTextCtrl*)FindWindow(svx_PROJ))->GetValue();
712 double grid = 100; // metres
713 double text_height = 0.6;
714 double marker_size = 0.8;
716 try {
717 if (!Export(dlg.GetPath(), m_layout.title,
718 m_layout.datestamp, m_layout.datestamp_numeric, mainfrm,
719 m_layout.rot, m_layout.tilt, m_layout.show_mask,
720 export_format(format_idx), input_projection.utf8_str(),
721 grid, text_height, marker_size, m_layout.Scale)) {
722 wxString m = wxString::Format(wmsg(/*Couldn’t write file “%s”*/402).c_str(),
723 m_File.c_str());
724 wxGetApp().ReportError(m);
726 } catch (const wxString & m) {
727 wxGetApp().ReportError(m);
730 Destroy();
733 #ifdef AVEN_PRINT_PREVIEW
734 void
735 svxPrintDlg::OnPreview(wxCommandEvent&) {
736 SomethingChanged(0);
737 TransferDataFromWindow();
738 wxPageSetupDialogData * psdd = wxGetApp().GetPageSetupDialogData();
739 wxPrintDialogData pd(psdd->GetPrintData());
740 wxPrintPreview* pv;
741 pv = new wxPrintPreview(new svxPrintout(mainfrm, &m_layout, psdd, m_File),
742 new svxPrintout(mainfrm, &m_layout, psdd, m_File),
743 &pd);
744 // TRANSLATORS: Title of the print preview dialog
745 wxPreviewFrame *frame = new wxPreviewFrame(pv, mainfrm, wmsg(/*Print Preview*/398));
746 frame->Initialize();
748 // Size preview frame so that all of the controlbar and canvas can be seen
749 // if possible.
750 int w, h;
751 // GetBestSize gives us the width needed to show the whole controlbar.
752 frame->GetBestSize(&w, &h);
753 if (h < w) {
754 // On wxGTK at least, GetBestSize() returns much too small a height.
755 h = w * 6 / 5;
757 // Ensure that we don't make the window bigger than the screen.
758 // Use wxGetClientDisplayRect() so we don't cover the MS Windows
759 // task bar either.
760 wxRect disp = wxGetClientDisplayRect();
761 if (w > disp.GetWidth()) w = disp.GetWidth();
762 if (h > disp.GetHeight()) h = disp.GetHeight();
763 // Centre the window within the "ClientDisplayRect".
764 int x = disp.GetLeft() + (disp.GetWidth() - w) / 2;
765 int y = disp.GetTop() + (disp.GetHeight() - h) / 2;
766 frame->SetSize(x, y, w, h);
768 frame->Show();
770 #endif
772 void
773 svxPrintDlg::OnPlan(wxCommandEvent&) {
774 m_tilt->SetValue(-90.0);
775 SomethingChanged(svx_TILT);
778 void
779 svxPrintDlg::OnElevation(wxCommandEvent&) {
780 m_tilt->SetValue(0.0);
781 SomethingChanged(svx_TILT);
784 void
785 svxPrintDlg::OnPlanUpdate(wxUpdateUIEvent& e) {
786 e.Enable(m_tilt->GetValue() != -90.0);
789 void
790 svxPrintDlg::OnElevationUpdate(wxUpdateUIEvent& e) {
791 e.Enable(m_tilt->GetValue() != 0.0);
794 void
795 svxPrintDlg::OnChangeSpin(wxSpinEvent& e) {
796 SomethingChanged(e.GetId());
799 void
800 svxPrintDlg::OnChange(wxCommandEvent& e) {
801 SomethingChanged(e.GetId());
804 void
805 svxPrintDlg::OnCancel(wxCommandEvent&) {
806 if (close_after)
807 mainfrm->Close();
808 Destroy();
811 void
812 svxPrintDlg::SomethingChanged(int control_id) {
813 if ((control_id == 0 || control_id == svx_FORMAT) && m_format) {
814 // Update the shown/hidden fields for the newly selected export filter.
815 int new_filter_idx = m_format->GetSelection();
816 if (new_filter_idx != wxNOT_FOUND) {
817 unsigned mask = format_info[new_filter_idx];
818 static const struct { int id; unsigned mask; } controls[] = {
819 { svx_LEGS, LEGS },
820 { svx_SURFACE, SURF },
821 { svx_SPLAYS, SPLAYS },
822 { svx_STATIONS, STNS },
823 { svx_NAMES, LABELS },
824 { svx_XSECT, XSECT },
825 { svx_WALLS, WALLS },
826 { svx_PASSAGES, PASG },
827 { svx_ENTS, ENTS },
828 { svx_FIXES, FIXES },
829 { svx_EXPORTS, EXPORTS },
830 { svx_CENTRED, CENTRED },
831 { svx_FULLCOORDS, FULL_COORDS },
832 { svx_PROJ_LABEL, PROJ },
833 { svx_PROJ, PROJ },
835 static unsigned n_controls = sizeof(controls) / sizeof(controls[0]);
836 for (unsigned i = 0; i != n_controls; ++i) {
837 wxWindow * control = FindWindow(controls[i].id);
838 if (control) control->Show(mask & controls[i].mask);
840 m_scalebox->Show(bool(mask & SCALE));
841 m_viewbox->Show(!bool(mask & EXPORT_3D));
842 GetSizer()->Layout();
843 if (control_id == svx_FORMAT) {
844 wxConfigBase * cfg = wxConfigBase::Get();
845 cfg->Write(wxT("export_format"), formats[new_filter_idx]);
850 UIToLayout();
852 if (m_printSize || m_scale) {
853 // Update the bounding box.
854 RecalcBounds();
856 if (m_scale) {
857 (m_scale->GetValue()).ToDouble(&(m_layout.Scale));
858 if (m_layout.Scale == 0.0) {
859 m_layout.pick_scale(1, 1);
864 if (m_printSize && m_layout.xMax >= m_layout.xMin) {
865 m_layout.pages_required();
866 m_printSize->SetLabel(wxString::Format(wmsg(/*%d pages (%dx%d)*/257), m_layout.pages, m_layout.pagesX, m_layout.pagesY));
870 void
871 svxPrintDlg::LayoutToUI(){
872 // m_blanks->SetValue(m_layout.SkipBlank);
873 if (m_layout.view != layout::EXTELEV) {
874 m_tilt->SetValue(m_layout.tilt);
875 m_bearing->SetValue(m_layout.rot);
878 // Do this last as it causes an OnChange message which calls UIToLayout
879 if (m_scale) {
880 if (m_layout.Scale != 0) {
881 wxString temp;
882 temp << m_layout.Scale;
883 m_scale->SetValue(temp);
884 } else {
885 if (scales[0].empty()) scales[0].assign(wmsg(/*One page*/258));
886 m_scale->SetValue(scales[0]);
891 void
892 svxPrintDlg::UIToLayout(){
893 // m_layout.SkipBlank = m_blanks->IsChecked();
895 if (m_layout.view != layout::EXTELEV && m_tilt) {
896 m_layout.tilt = m_tilt->GetValue();
897 if (m_layout.tilt == -90.0) {
898 m_layout.view = layout::PLAN;
899 } else if (m_layout.tilt == 0.0) {
900 m_layout.view = layout::ELEV;
901 } else {
902 m_layout.view = layout::TILT;
905 bool enable_passage_opts = (m_layout.view != layout::TILT);
906 wxWindow * win;
907 win = FindWindow(svx_XSECT);
908 if (win) win->Enable(enable_passage_opts);
909 win = FindWindow(svx_WALLS);
910 if (win) win->Enable(enable_passage_opts);
911 win = FindWindow(svx_PASSAGES);
912 if (win) win->Enable(enable_passage_opts);
914 m_layout.rot = m_bearing->GetValue();
918 void
919 svxPrintDlg::RecalcBounds()
921 m_layout.yMax = m_layout.xMax = -DBL_MAX;
922 m_layout.yMin = m_layout.xMin = DBL_MAX;
924 double SIN = sin(rad(m_layout.rot));
925 double COS = cos(rad(m_layout.rot));
926 double SINT = sin(rad(m_layout.tilt));
927 double COST = cos(rad(m_layout.tilt));
929 if (m_layout.show_mask & LEGS) {
930 list<traverse>::const_iterator trav = mainfrm->traverses_begin();
931 list<traverse>::const_iterator tend = mainfrm->traverses_end();
932 for ( ; trav != tend; ++trav) {
933 if (trav->isSplay && !(m_layout.show_mask & SPLAYS))
934 continue;
935 vector<PointInfo>::const_iterator pos = trav->begin();
936 vector<PointInfo>::const_iterator end = trav->end();
937 for ( ; pos != end; ++pos) {
938 double x = pos->GetX();
939 double y = pos->GetY();
940 double z = pos->GetZ();
941 double X = x * COS - y * SIN;
942 if (X > m_layout.xMax) m_layout.xMax = X;
943 if (X < m_layout.xMin) m_layout.xMin = X;
944 double Y = z * COST - (x * SIN + y * COS) * SINT;
945 if (Y > m_layout.yMax) m_layout.yMax = Y;
946 if (Y < m_layout.yMin) m_layout.yMin = Y;
950 if (m_layout.show_mask & SURF) {
951 list<traverse>::const_iterator trav = mainfrm->surface_traverses_begin();
952 list<traverse>::const_iterator tend = mainfrm->surface_traverses_end();
953 for ( ; trav != tend; ++trav) {
954 if (trav->isSplay && !(m_layout.show_mask & SPLAYS))
955 continue;
956 vector<PointInfo>::const_iterator pos = trav->begin();
957 vector<PointInfo>::const_iterator end = trav->end();
958 for ( ; pos != end; ++pos) {
959 double x = pos->GetX();
960 double y = pos->GetY();
961 double z = pos->GetZ();
962 double X = x * COS - y * SIN;
963 if (X > m_layout.xMax) m_layout.xMax = X;
964 if (X < m_layout.xMin) m_layout.xMin = X;
965 double Y = z * COST - (x * SIN + y * COS) * SINT;
966 if (Y > m_layout.yMax) m_layout.yMax = Y;
967 if (Y < m_layout.yMin) m_layout.yMin = Y;
971 if (m_layout.show_mask & (LABELS|STNS)) {
972 list<LabelInfo*>::const_iterator label = mainfrm->GetLabels();
973 while (label != mainfrm->GetLabelsEnd()) {
974 double x = (*label)->GetX();
975 double y = (*label)->GetY();
976 double z = (*label)->GetZ();
977 if ((m_layout.show_mask & SURF) || (*label)->IsUnderground()) {
978 double X = x * COS - y * SIN;
979 if (X > m_layout.xMax) m_layout.xMax = X;
980 if (X < m_layout.xMin) m_layout.xMin = X;
981 double Y = z * COST - (x * SIN + y * COS) * SINT;
982 if (Y > m_layout.yMax) m_layout.yMax = Y;
983 if (Y < m_layout.yMin) m_layout.yMin = Y;
985 ++label;
990 static int xpPageWidth, ypPageDepth;
991 static long x_offset, y_offset;
992 static int fontsize, fontsize_labels;
994 /* FIXME: allow the font to be set */
996 static const char *fontname = "Arial", *fontname_labels = "Arial";
998 svxPrintout::svxPrintout(MainFrm *mainfrm_, layout *l,
999 wxPageSetupDialogData *data, const wxString & title)
1000 : wxPrintout(title), font_labels(NULL), font_default(NULL),
1001 scan_for_blank_pages(false)
1003 mainfrm = mainfrm_;
1004 m_layout = l;
1005 m_data = data;
1008 void
1009 svxPrintout::draw_info_box()
1011 layout *l = m_layout;
1012 int boxwidth = 70;
1013 int boxheight = 30;
1015 pdc->SetPen(*pen_frame);
1017 int div = boxwidth;
1018 if (l->view != layout::EXTELEV) {
1019 boxwidth += boxheight;
1020 MOVEMM(div, boxheight);
1021 DRAWMM(div, 0);
1022 MOVEMM(0, 30); DRAWMM(div, 30);
1025 MOVEMM(0, boxheight);
1026 DRAWMM(boxwidth, boxheight);
1027 DRAWMM(boxwidth, 0);
1028 if (!l->Border) {
1029 DRAWMM(0, 0);
1030 DRAWMM(0, boxheight);
1033 MOVEMM(0, 20); DRAWMM(div, 20);
1034 MOVEMM(0, 10); DRAWMM(div, 10);
1036 switch (l->view) {
1037 case layout::PLAN: {
1038 long ax, ay, bx, by, cx, cy, dx, dy;
1040 long xc = boxwidth - boxheight / 2;
1041 long yc = boxheight / 2;
1042 const double RADIUS = boxheight / 3;
1043 DrawEllipse(long(xc * l->scX), long(yc * l->scY),
1044 long(RADIUS * l->scX), long(RADIUS * l->scY));
1046 ax = (long)((xc - (RADIUS - 1) * sin(rad(000.0 + l->rot))) * l->scX);
1047 ay = (long)((yc + (RADIUS - 1) * cos(rad(000.0 + l->rot))) * l->scY);
1048 bx = (long)((xc - RADIUS * 0.5 * sin(rad(180.0 + l->rot))) * l->scX);
1049 by = (long)((yc + RADIUS * 0.5 * cos(rad(180.0 + l->rot))) * l->scY);
1050 cx = (long)((xc - (RADIUS - 1) * sin(rad(160.0 + l->rot))) * l->scX);
1051 cy = (long)((yc + (RADIUS - 1) * cos(rad(160.0 + l->rot))) * l->scY);
1052 dx = (long)((xc - (RADIUS - 1) * sin(rad(200.0 + l->rot))) * l->scX);
1053 dy = (long)((yc + (RADIUS - 1) * cos(rad(200.0 + l->rot))) * l->scY);
1055 MoveTo(ax, ay);
1056 DrawTo(bx, by);
1057 DrawTo(cx, cy);
1058 DrawTo(ax, ay);
1059 DrawTo(dx, dy);
1060 DrawTo(bx, by);
1062 pdc->SetTextForeground(colour_text);
1063 MOVEMM(div + 0.5, boxheight - 5.5);
1064 WriteString(wmsg(/*North*/115));
1066 wxString angle = format_angle(ANGLE_FMT, l->rot);
1067 wxString s;
1068 /* TRANSLATORS: This is used on printouts of plans, with %s replaced by
1069 * something like "123°". The bearing is up the page. */
1070 s.Printf(wmsg(/*Plan view, %s up page*/168), angle.c_str());
1071 MOVEMM(2, 12); WriteString(s);
1072 break;
1074 case layout::ELEV: case layout::TILT: {
1075 const int L = div + 2;
1076 const int R = boxwidth - 2;
1077 const int H = boxheight / 2;
1078 MOVEMM(L, H); DRAWMM(L + 5, H - 3); DRAWMM(L + 3, H); DRAWMM(L + 5, H + 3);
1080 DRAWMM(L, H); DRAWMM(R, H);
1082 DRAWMM(R - 5, H + 3); DRAWMM(R - 3, H); DRAWMM(R - 5, H - 3); DRAWMM(R, H);
1084 MOVEMM((L + R) / 2, H - 2); DRAWMM((L + R) / 2, H + 2);
1086 pdc->SetTextForeground(colour_text);
1087 MOVEMM(div + 2, boxheight - 8);
1088 /* TRANSLATORS: "Elevation on" 020 <-> 200 degrees */
1089 WriteString(wmsg(/*Elevation on*/116));
1091 MOVEMM(L, 2);
1092 WriteString(format_angle(ANGLE_FMT, fmod(l->rot + 270.0, 360.0)));
1093 MOVEMM(R - 10, 2);
1094 WriteString(format_angle(ANGLE_FMT, fmod(l->rot + 90.0, 360.0)));
1096 wxString angle = format_angle(ANGLE_FMT, l->rot);
1097 wxString s;
1098 if (l->view == layout::ELEV) {
1099 /* TRANSLATORS: This is used on printouts of elevations, with %s
1100 * replaced by something like "123°". The bearing is the direction
1101 * we’re looking. */
1102 s.Printf(wmsg(/*Elevation facing %s*/169), angle.c_str());
1103 } else {
1104 wxString a2 = format_angle(ANGLE2_FMT, l->tilt);
1105 /* TRANSLATORS: This is used on printouts of tilted elevations, with
1106 * the first %s replaced by something like "123°", and the second by
1107 * something like "-45°". The bearing is the direction we’re
1108 * looking. */
1109 s.Printf(wmsg(/*Elevation facing %s, tilted %s*/284), angle.c_str(), a2.c_str());
1111 MOVEMM(2, 12); WriteString(s);
1112 break;
1114 case layout::EXTELEV:
1115 pdc->SetTextForeground(colour_text);
1116 MOVEMM(2, 12);
1117 /* TRANSLATORS: This is used on printouts of extended elevations. */
1118 WriteString(wmsg(/*Extended elevation*/191));
1119 break;
1122 MOVEMM(2, boxheight - 8); WriteString(l->title);
1124 MOVEMM(2, 2);
1125 // FIXME: "Original Scale" better?
1126 WriteString(wxString::Format(wmsg(/*Scale*/154) + wxT(" 1:%.0f"),
1127 l->Scale));
1129 /* This used to be a copyright line, but it was occasionally
1130 * mis-interpreted as us claiming copyright on the survey, so let's
1131 * give the website URL instead */
1132 MOVEMM(boxwidth + 2, 2);
1133 WriteString(wxT("Survex " VERSION " - https://survex.com/"));
1135 draw_scale_bar(boxwidth + 10.0, 17.0, l->PaperWidth - boxwidth - 18.0);
1138 /* Draw fancy scale bar with bottom left at (x,y) (both in mm) and at most */
1139 /* MaxLength mm long. The scaling in use is 1:scale */
1140 void
1141 svxPrintout::draw_scale_bar(double x, double y, double MaxLength)
1143 double StepEst, d;
1144 int E, Step, n, c;
1145 wxString buf;
1146 /* Limit scalebar to 20cm to stop people with A0 plotters complaining */
1147 if (MaxLength > 200.0) MaxLength = 200.0;
1149 #define dmin 10.0 /* each division >= dmin mm long */
1150 #define StepMax 5 /* number in steps of at most StepMax (x 10^N) */
1151 #define epsilon (1e-4) /* fudge factor to prevent rounding problems */
1153 E = (int)ceil(log10((dmin * 0.001 * m_layout->Scale) / StepMax));
1154 StepEst = pow(10.0, -(double)E) * (dmin * 0.001) * m_layout->Scale - epsilon;
1156 /* Force labelling to be in multiples of 1, 2, or 5 */
1157 Step = (StepEst <= 1.0 ? 1 : (StepEst <= 2.0 ? 2 : 5));
1159 /* Work out actual length of each scale bar division */
1160 d = Step * pow(10.0, (double)E) / m_layout->Scale * 1000.0;
1162 /* FIXME: Non-metric units here... */
1163 /* Choose appropriate units, s.t. if possible E is >=0 and minimized */
1164 int units;
1165 if (E >= 3) {
1166 E -= 3;
1167 units = /*km*/423;
1168 } else if (E >= 0) {
1169 units = /*m*/424;
1170 } else {
1171 E += 2;
1172 units = /*cm*/425;
1175 buf = wmsg(/*Scale*/154);
1177 /* Add units used - eg. "Scale (10m)" */
1178 double pow10_E = pow(10.0, (double)E);
1179 if (E >= 0) {
1180 buf += wxString::Format(wxT(" (%.f%s)"), pow10_E, wmsg(units).c_str());
1181 } else {
1182 int sf = -(int)floor(E);
1183 buf += wxString::Format(wxT(" (%.*f%s)"), sf, pow10_E, wmsg(units).c_str());
1185 pdc->SetTextForeground(colour_text);
1186 MOVEMM(x, y + 4); WriteString(buf);
1188 /* Work out how many divisions there will be */
1189 n = (int)(MaxLength / d);
1191 pdc->SetPen(*pen_frame);
1193 long Y = long(y * m_layout->scY);
1194 long Y2 = long((y + 3) * m_layout->scY);
1195 long X = long(x * m_layout->scX);
1196 long X2 = long((x + n * d) * m_layout->scX);
1198 /* Draw top of scale bar */
1199 MoveTo(X2, Y2);
1200 DrawTo(X, Y2);
1201 #if 0
1202 DrawTo(X2, Y);
1203 DrawTo(X, Y);
1204 MOVEMM(x + n * d, y); DRAWMM(x, y);
1205 #endif
1206 /* Draw divisions and label them */
1207 for (c = 0; c <= n; c++) {
1208 pdc->SetPen(*pen_frame);
1209 X = long((x + c * d) * m_layout->scX);
1210 MoveTo(X, Y);
1211 DrawTo(X, Y2);
1212 #if 0 // Don't waste toner!
1213 /* Draw a "zebra crossing" scale bar. */
1214 if (c < n && (c & 1) == 0) {
1215 X2 = long((x + (c + 1) * d) * m_layout->scX);
1216 SolidRectangle(X, Y, X2 - X, Y2 - Y);
1218 #endif
1219 buf.Printf(wxT("%d"), c * Step);
1220 pdc->SetTextForeground(colour_text);
1221 MOVEMM(x + c * d - buf.length(), y - 5);
1222 WriteString(buf);
1226 #if 0
1227 void
1228 make_calibration(layout *l) {
1229 img_point pt = { 0.0, 0.0, 0.0 };
1230 l->xMax = l->yMax = 0.1;
1231 l->xMin = l->yMin = 0;
1233 stack(l,img_MOVE, NULL, &pt);
1234 pt.x = 0.1;
1235 stack(l,img_LINE, NULL, &pt);
1236 pt.y = 0.1;
1237 stack(l,img_LINE, NULL, &pt);
1238 pt.x = 0.0;
1239 stack(l,img_LINE, NULL, &pt);
1240 pt.y = 0.0;
1241 stack(l,img_LINE, NULL, &pt);
1242 pt.x = 0.05;
1243 pt.y = 0.001;
1244 stack(l,img_LABEL, "10cm", &pt);
1245 pt.x = 0.001;
1246 pt.y = 0.05;
1247 stack(l,img_LABEL, "10cm", &pt);
1248 l->Scale = 1.0;
1250 #endif
1253 svxPrintout::next_page(int *pstate, char **q, int pageLim)
1255 char *p;
1256 int page;
1257 int c;
1258 p = *q;
1259 if (*pstate > 0) {
1260 /* doing a range */
1261 (*pstate)++;
1262 SVX_ASSERT(*p == '-');
1263 p++;
1264 while (isspace((unsigned char)*p)) p++;
1265 if (sscanf(p, "%u%n", &page, &c) > 0) {
1266 p += c;
1267 } else {
1268 page = pageLim;
1270 if (*pstate > page) goto err;
1271 if (*pstate < page) return *pstate;
1272 *q = p;
1273 *pstate = 0;
1274 return page;
1277 while (isspace((unsigned char)*p) || *p == ',') p++;
1279 if (!*p) return 0; /* done */
1281 if (*p == '-') {
1282 *q = p;
1283 *pstate = 1;
1284 return 1; /* range with initial parameter omitted */
1286 if (sscanf(p, "%u%n", &page, &c) > 0) {
1287 p += c;
1288 while (isspace((unsigned char)*p)) p++;
1289 *q = p;
1290 if (0 < page && page <= pageLim) {
1291 if (*p == '-') *pstate = page; /* range with start */
1292 return page;
1295 err:
1296 *pstate = -1;
1297 return 0;
1300 /* Draws in alignment marks on each page or borders on edge pages */
1301 void
1302 svxPrintout::drawticks(int tsize, int x, int y)
1304 long i;
1305 int s = tsize * 4;
1306 int o = s / 8;
1307 bool fAtCorner = fFalse;
1308 pdc->SetPen(*pen_frame);
1309 if (x == 0 && m_layout->Border) {
1310 /* solid left border */
1311 MoveTo(clip.x_min, clip.y_min);
1312 DrawTo(clip.x_min, clip.y_max);
1313 fAtCorner = fTrue;
1314 } else {
1315 if (x > 0 || y > 0) {
1316 MoveTo(clip.x_min, clip.y_min);
1317 DrawTo(clip.x_min, clip.y_min + tsize);
1319 if (s && x > 0 && m_layout->Cutlines) {
1320 /* dashed left border */
1321 i = (clip.y_max - clip.y_min) -
1322 (tsize + ((clip.y_max - clip.y_min - tsize * 2L) % s) / 2);
1323 for ( ; i > tsize; i -= s) {
1324 MoveTo(clip.x_min, clip.y_max - (i + o));
1325 DrawTo(clip.x_min, clip.y_max - (i - o));
1328 if (x > 0 || y < m_layout->pagesY - 1) {
1329 MoveTo(clip.x_min, clip.y_max - tsize);
1330 DrawTo(clip.x_min, clip.y_max);
1331 fAtCorner = fTrue;
1335 if (y == m_layout->pagesY - 1 && m_layout->Border) {
1336 /* solid top border */
1337 if (!fAtCorner) MoveTo(clip.x_min, clip.y_max);
1338 DrawTo(clip.x_max, clip.y_max);
1339 fAtCorner = fTrue;
1340 } else {
1341 if (y < m_layout->pagesY - 1 || x > 0) {
1342 if (!fAtCorner) MoveTo(clip.x_min, clip.y_max);
1343 DrawTo(clip.x_min + tsize, clip.y_max);
1345 if (s && y < m_layout->pagesY - 1 && m_layout->Cutlines) {
1346 /* dashed top border */
1347 i = (clip.x_max - clip.x_min) -
1348 (tsize + ((clip.x_max - clip.x_min - tsize * 2L) % s) / 2);
1349 for ( ; i > tsize; i -= s) {
1350 MoveTo(clip.x_max - (i + o), clip.y_max);
1351 DrawTo(clip.x_max - (i - o), clip.y_max);
1354 if (y < m_layout->pagesY - 1 || x < m_layout->pagesX - 1) {
1355 MoveTo(clip.x_max - tsize, clip.y_max);
1356 DrawTo(clip.x_max, clip.y_max);
1357 fAtCorner = fTrue;
1358 } else {
1359 fAtCorner = fFalse;
1363 if (x == m_layout->pagesX - 1 && m_layout->Border) {
1364 /* solid right border */
1365 if (!fAtCorner) MoveTo(clip.x_max, clip.y_max);
1366 DrawTo(clip.x_max, clip.y_min);
1367 fAtCorner = fTrue;
1368 } else {
1369 if (x < m_layout->pagesX - 1 || y < m_layout->pagesY - 1) {
1370 if (!fAtCorner) MoveTo(clip.x_max, clip.y_max);
1371 DrawTo(clip.x_max, clip.y_max - tsize);
1373 if (s && x < m_layout->pagesX - 1 && m_layout->Cutlines) {
1374 /* dashed right border */
1375 i = (clip.y_max - clip.y_min) -
1376 (tsize + ((clip.y_max - clip.y_min - tsize * 2L) % s) / 2);
1377 for ( ; i > tsize; i -= s) {
1378 MoveTo(clip.x_max, clip.y_min + (i + o));
1379 DrawTo(clip.x_max, clip.y_min + (i - o));
1382 if (x < m_layout->pagesX - 1 || y > 0) {
1383 MoveTo(clip.x_max, clip.y_min + tsize);
1384 DrawTo(clip.x_max, clip.y_min);
1385 fAtCorner = fTrue;
1386 } else {
1387 fAtCorner = fFalse;
1391 if (y == 0 && m_layout->Border) {
1392 /* solid bottom border */
1393 if (!fAtCorner) MoveTo(clip.x_max, clip.y_min);
1394 DrawTo(clip.x_min, clip.y_min);
1395 } else {
1396 if (y > 0 || x < m_layout->pagesX - 1) {
1397 if (!fAtCorner) MoveTo(clip.x_max, clip.y_min);
1398 DrawTo(clip.x_max - tsize, clip.y_min);
1400 if (s && y > 0 && m_layout->Cutlines) {
1401 /* dashed bottom border */
1402 i = (clip.x_max - clip.x_min) -
1403 (tsize + ((clip.x_max - clip.x_min - tsize * 2L) % s) / 2);
1404 for ( ; i > tsize; i -= s) {
1405 MoveTo(clip.x_min + (i + o), clip.y_min);
1406 DrawTo(clip.x_min + (i - o), clip.y_min);
1409 if (y > 0 || x > 0) {
1410 MoveTo(clip.x_min + tsize, clip.y_min);
1411 DrawTo(clip.x_min, clip.y_min);
1416 bool
1417 svxPrintout::OnPrintPage(int pageNum) {
1418 GetPageSizePixels(&xpPageWidth, &ypPageDepth);
1419 pdc = GetDC();
1420 pdc->SetBackgroundMode(wxTRANSPARENT);
1421 #ifdef AVEN_PRINT_PREVIEW
1422 if (IsPreview()) {
1423 int dcx, dcy;
1424 pdc->GetSize(&dcx, &dcy);
1425 pdc->SetUserScale((double)dcx / xpPageWidth, (double)dcy / ypPageDepth);
1427 #endif
1429 layout * l = m_layout;
1431 int pwidth, pdepth;
1432 GetPageSizeMM(&pwidth, &pdepth);
1433 l->scX = (double)xpPageWidth / pwidth;
1434 l->scY = (double)ypPageDepth / pdepth;
1435 font_scaling_x = l->scX * (25.4 / 72.0);
1436 font_scaling_y = l->scY * (25.4 / 72.0);
1437 long MarginLeft = m_data->GetMarginTopLeft().x;
1438 long MarginTop = m_data->GetMarginTopLeft().y;
1439 long MarginBottom = m_data->GetMarginBottomRight().y;
1440 long MarginRight = m_data->GetMarginBottomRight().x;
1441 xpPageWidth -= (int)(l->scX * (MarginLeft + MarginRight));
1442 ypPageDepth -= (int)(l->scY * (FOOTER_HEIGHT_MM + MarginBottom + MarginTop));
1443 // xpPageWidth -= 1;
1444 pdepth -= FOOTER_HEIGHT_MM;
1445 x_offset = (long)(l->scX * MarginLeft);
1446 y_offset = (long)(l->scY * MarginTop);
1447 l->PaperWidth = pwidth -= MarginLeft + MarginRight;
1448 l->PaperDepth = pdepth -= MarginTop + MarginBottom;
1451 double SIN = sin(rad(l->rot));
1452 double COS = cos(rad(l->rot));
1453 double SINT = sin(rad(l->tilt));
1454 double COST = cos(rad(l->tilt));
1456 NewPage(pageNum, l->pagesX, l->pagesY);
1458 if (l->Legend && pageNum == (l->pagesY - 1) * l->pagesX + 1) {
1459 SetFont(font_default);
1460 draw_info_box();
1463 pdc->SetClippingRegion(x_offset, y_offset,xpPageWidth+1, ypPageDepth+1);
1465 const double Sc = 1000 / l->Scale;
1467 if (l->show_mask & LEGS) {
1468 list<traverse>::const_iterator trav = mainfrm->traverses_begin();
1469 list<traverse>::const_iterator tend = mainfrm->traverses_end();
1470 for ( ; trav != tend; ++trav) {
1471 if (trav->isSplay) {
1472 if (!(l->show_mask & SPLAYS))
1473 continue;
1474 pdc->SetPen(*pen_splay);
1475 } else {
1476 pdc->SetPen(*pen_leg);
1478 vector<PointInfo>::const_iterator pos = trav->begin();
1479 vector<PointInfo>::const_iterator end = trav->end();
1480 for ( ; pos != end; ++pos) {
1481 double x = pos->GetX();
1482 double y = pos->GetY();
1483 double z = pos->GetZ();
1484 double X = x * COS - y * SIN;
1485 double Y = z * COST - (x * SIN + y * COS) * SINT;
1486 long px = (long)((X * Sc + l->xOrg) * l->scX);
1487 long py = (long)((Y * Sc + l->yOrg) * l->scY);
1488 if (pos == trav->begin()) {
1489 MoveTo(px, py);
1490 } else {
1491 DrawTo(px, py);
1497 if ((l->show_mask & XSECT) &&
1498 (l->tilt == 0.0 || l->tilt == 90.0 || l->tilt == -90.0)) {
1499 pdc->SetPen(*pen_splay);
1500 list<vector<XSect> >::const_iterator trav = mainfrm->tubes_begin();
1501 list<vector<XSect> >::const_iterator tend = mainfrm->tubes_end();
1502 for ( ; trav != tend; ++trav) {
1503 if (l->tilt == 90.0 || l->tilt == -90.0) PlotLR(*trav);
1504 if (l->tilt == 0.0) PlotUD(*trav);
1508 if (l->show_mask & SURF) {
1509 list<traverse>::const_iterator trav = mainfrm->surface_traverses_begin();
1510 list<traverse>::const_iterator tend = mainfrm->surface_traverses_end();
1511 for ( ; trav != tend; ++trav) {
1512 if (trav->isSplay) {
1513 if (!(l->show_mask & SPLAYS))
1514 continue;
1515 pdc->SetPen(*pen_splay);
1516 } else {
1517 pdc->SetPen(*pen_surface_leg);
1519 vector<PointInfo>::const_iterator pos = trav->begin();
1520 vector<PointInfo>::const_iterator end = trav->end();
1521 for ( ; pos != end; ++pos) {
1522 double x = pos->GetX();
1523 double y = pos->GetY();
1524 double z = pos->GetZ();
1525 double X = x * COS - y * SIN;
1526 double Y = z * COST - (x * SIN + y * COS) * SINT;
1527 long px = (long)((X * Sc + l->xOrg) * l->scX);
1528 long py = (long)((Y * Sc + l->yOrg) * l->scY);
1529 if (pos == trav->begin()) {
1530 MoveTo(px, py);
1531 } else {
1532 DrawTo(px, py);
1538 if (l->show_mask & (LABELS|STNS)) {
1539 if (l->show_mask & LABELS) SetFont(font_labels);
1540 list<LabelInfo*>::const_iterator label = mainfrm->GetLabels();
1541 while (label != mainfrm->GetLabelsEnd()) {
1542 double px = (*label)->GetX();
1543 double py = (*label)->GetY();
1544 double pz = (*label)->GetZ();
1545 if ((l->show_mask & SURF) || (*label)->IsUnderground()) {
1546 double X = px * COS - py * SIN;
1547 double Y = pz * COST - (px * SIN + py * COS) * SINT;
1548 long xnew, ynew;
1549 xnew = (long)((X * Sc + l->xOrg) * l->scX);
1550 ynew = (long)((Y * Sc + l->yOrg) * l->scY);
1551 if (l->show_mask & STNS) {
1552 pdc->SetPen(*pen_cross);
1553 DrawCross(xnew, ynew);
1555 if (l->show_mask & LABELS) {
1556 pdc->SetTextForeground(colour_labels);
1557 MoveTo(xnew, ynew);
1558 WriteString((*label)->GetText());
1561 ++label;
1565 return true;
1568 void
1569 svxPrintout::GetPageInfo(int *minPage, int *maxPage,
1570 int *pageFrom, int *pageTo)
1572 *minPage = *pageFrom = 1;
1573 *maxPage = *pageTo = m_layout->pages;
1576 bool
1577 svxPrintout::HasPage(int pageNum) {
1578 return (pageNum <= m_layout->pages);
1581 void
1582 svxPrintout::OnBeginPrinting() {
1583 /* Initialise printer routines */
1584 fontsize_labels = 10;
1585 fontsize = 10;
1587 colour_text = colour_labels = *wxBLACK;
1589 wxColour colour_frame, colour_cross, colour_leg, colour_surface_leg;
1590 colour_frame = colour_cross = colour_leg = colour_surface_leg = *wxBLACK;
1592 pen_frame = new wxPen(colour_frame);
1593 pen_cross = new wxPen(colour_cross);
1594 pen_leg = new wxPen(colour_leg);
1595 pen_surface_leg = new wxPen(colour_surface_leg);
1596 pen_splay = new wxPen(wxColour(192, 192, 192));
1598 m_layout->scX = 1;
1599 m_layout->scY = 1;
1601 font_labels = new wxFont(fontsize_labels, wxDEFAULT, wxNORMAL, wxNORMAL,
1602 false, wxString(fontname_labels, wxConvUTF8),
1603 wxFONTENCODING_ISO8859_1);
1604 font_default = new wxFont(fontsize, wxDEFAULT, wxNORMAL, wxNORMAL,
1605 false, wxString(fontname, wxConvUTF8),
1606 wxFONTENCODING_ISO8859_1);
1609 void
1610 svxPrintout::OnEndPrinting() {
1611 delete font_labels;
1612 delete font_default;
1613 delete pen_frame;
1614 delete pen_cross;
1615 delete pen_leg;
1616 delete pen_surface_leg;
1617 delete pen_splay;
1621 svxPrintout::check_intersection(long x_p, long y_p)
1623 #define U 1
1624 #define D 2
1625 #define L 4
1626 #define R 8
1627 int mask_p = 0, mask_t = 0;
1628 if (x_p < 0)
1629 mask_p = L;
1630 else if (x_p > xpPageWidth)
1631 mask_p = R;
1633 if (y_p < 0)
1634 mask_p |= D;
1635 else if (y_p > ypPageDepth)
1636 mask_p |= U;
1638 if (x_t < 0)
1639 mask_t = L;
1640 else if (x_t > xpPageWidth)
1641 mask_t = R;
1643 if (y_t < 0)
1644 mask_t |= D;
1645 else if (y_t > ypPageDepth)
1646 mask_t |= U;
1648 #if 0
1649 /* approximation to correct answer */
1650 return !(mask_t & mask_p);
1651 #else
1652 /* One end of the line is on the page */
1653 if (!mask_t || !mask_p) return 1;
1655 /* whole line is above, left, right, or below page */
1656 if (mask_t & mask_p) return 0;
1658 if (mask_t == 0) mask_t = mask_p;
1659 if (mask_t & U) {
1660 double v = (double)(y_p - ypPageDepth) / (y_p - y_t);
1661 return v >= 0 && v <= 1;
1663 if (mask_t & D) {
1664 double v = (double)y_p / (y_p - y_t);
1665 return v >= 0 && v <= 1;
1667 if (mask_t & R) {
1668 double v = (double)(x_p - xpPageWidth) / (x_p - x_t);
1669 return v >= 0 && v <= 1;
1671 SVX_ASSERT(mask_t & L);
1673 double v = (double)x_p / (x_p - x_t);
1674 return v >= 0 && v <= 1;
1676 #endif
1677 #undef U
1678 #undef D
1679 #undef L
1680 #undef R
1683 void
1684 svxPrintout::MoveTo(long x, long y)
1686 x_t = x_offset + x - clip.x_min;
1687 y_t = y_offset + clip.y_max - y;
1690 void
1691 svxPrintout::DrawTo(long x, long y)
1693 long x_p = x_t, y_p = y_t;
1694 x_t = x_offset + x - clip.x_min;
1695 y_t = y_offset + clip.y_max - y;
1696 if (!scan_for_blank_pages) {
1697 pdc->DrawLine(x_p, y_p, x_t, y_t);
1698 } else {
1699 if (check_intersection(x_p, y_p)) fBlankPage = fFalse;
1703 #define POINTS_PER_INCH 72.0
1704 #define POINTS_PER_MM (POINTS_PER_INCH / MM_PER_INCH)
1705 #define PWX_CROSS_SIZE (int)(2 * m_layout->scX / POINTS_PER_MM)
1707 void
1708 svxPrintout::DrawCross(long x, long y)
1710 if (!scan_for_blank_pages) {
1711 MoveTo(x - PWX_CROSS_SIZE, y - PWX_CROSS_SIZE);
1712 DrawTo(x + PWX_CROSS_SIZE, y + PWX_CROSS_SIZE);
1713 MoveTo(x + PWX_CROSS_SIZE, y - PWX_CROSS_SIZE);
1714 DrawTo(x - PWX_CROSS_SIZE, y + PWX_CROSS_SIZE);
1715 MoveTo(x, y);
1716 } else {
1717 if ((x + PWX_CROSS_SIZE > clip.x_min &&
1718 x - PWX_CROSS_SIZE < clip.x_max) ||
1719 (y + PWX_CROSS_SIZE > clip.y_min &&
1720 y - PWX_CROSS_SIZE < clip.y_max)) {
1721 fBlankPage = fFalse;
1726 void
1727 svxPrintout::WriteString(const wxString & s)
1729 double xsc, ysc;
1730 pdc->GetUserScale(&xsc, &ysc);
1731 pdc->SetUserScale(xsc * font_scaling_x, ysc * font_scaling_y);
1732 if (!scan_for_blank_pages) {
1733 pdc->DrawText(s,
1734 long(x_t / font_scaling_x),
1735 long(y_t / font_scaling_y) - pdc->GetCharHeight());
1736 } else {
1737 int w, h;
1738 pdc->GetTextExtent(s, &w, &h);
1739 if ((y_t + h > 0 && y_t - h < clip.y_max - clip.y_min) ||
1740 (x_t < clip.x_max - clip.x_min && x_t + w > 0)) {
1741 fBlankPage = fFalse;
1744 pdc->SetUserScale(xsc, ysc);
1747 void
1748 svxPrintout::DrawEllipse(long x, long y, long r, long R)
1750 if (!scan_for_blank_pages) {
1751 x_t = x_offset + x - clip.x_min;
1752 y_t = y_offset + clip.y_max - y;
1753 const wxBrush & save_brush = pdc->GetBrush();
1754 pdc->SetBrush(*wxTRANSPARENT_BRUSH);
1755 pdc->DrawEllipse(x_t - r, y_t - R, 2 * r, 2 * R);
1756 pdc->SetBrush(save_brush);
1757 } else {
1758 /* No need to check - this is only used in the legend. */
1762 void
1763 svxPrintout::SolidRectangle(long x, long y, long w, long h)
1765 long X = x_offset + x - clip.x_min;
1766 long Y = y_offset + clip.y_max - y;
1767 pdc->SetBrush(*wxBLACK_BRUSH);
1768 pdc->DrawRectangle(X, Y - h, w, h);
1771 void
1772 svxPrintout::NewPage(int pg, int pagesX, int pagesY)
1774 pdc->DestroyClippingRegion();
1776 int x, y;
1777 x = (pg - 1) % pagesX;
1778 y = pagesY - 1 - ((pg - 1) / pagesX);
1780 clip.x_min = (long)x * xpPageWidth;
1781 clip.y_min = (long)y * ypPageDepth;
1782 clip.x_max = clip.x_min + xpPageWidth; /* dm/pcl/ps had -1; */
1783 clip.y_max = clip.y_min + ypPageDepth; /* dm/pcl/ps had -1; */
1785 const int FOOTERS = 4;
1786 wxString footer[FOOTERS];
1787 footer[0] = m_layout->title;
1789 double rot = m_layout->rot;
1790 double tilt = m_layout->tilt;
1791 double scale = m_layout->Scale;
1792 switch (m_layout->view) {
1793 case layout::PLAN:
1794 // TRANSLATORS: Used in the footer of printouts to compactly
1795 // indicate this is a plan view and what the viewing angle is.
1796 // Aven will replace %s with the bearing, and %.0f with the scale.
1798 // This message probably doesn't need translating for most languages.
1799 footer[1].Printf(wmsg(/*↑%s 1:%.0f*/233),
1800 format_angle(ANGLE_FMT, rot).c_str(),
1801 scale);
1802 break;
1803 case layout::ELEV:
1804 // TRANSLATORS: Used in the footer of printouts to compactly
1805 // indicate this is an elevation view and what the viewing angle
1806 // is. Aven will replace the %s codes with the bearings to the
1807 // left and right of the viewer, and %.0f with the scale.
1809 // This message probably doesn't need translating for most languages.
1810 footer[1].Printf(wmsg(/*%s↔%s 1:%.0f*/235),
1811 format_angle(ANGLE_FMT, fmod(rot + 270.0, 360.0)).c_str(),
1812 format_angle(ANGLE_FMT, fmod(rot + 90.0, 360.0)).c_str(),
1813 scale);
1814 break;
1815 case layout::TILT:
1816 // TRANSLATORS: Used in the footer of printouts to compactly
1817 // indicate this is a tilted elevation view and what the viewing
1818 // angles are. Aven will replace the %s codes with the bearings to
1819 // the left and right of the viewer and the angle the view is
1820 // tilted at, and %.0f with the scale.
1822 // This message probably doesn't need translating for most languages.
1823 footer[1].Printf(wmsg(/*%s↔%s ∡%s 1:%.0f*/236),
1824 format_angle(ANGLE_FMT, fmod(rot + 270.0, 360.0)).c_str(),
1825 format_angle(ANGLE_FMT, fmod(rot + 90.0, 360.0)).c_str(),
1826 format_angle(ANGLE2_FMT, tilt).c_str(),
1827 scale);
1828 break;
1829 case layout::EXTELEV:
1830 // TRANSLATORS: Used in the footer of printouts to compactly
1831 // indicate this is an extended elevation view. Aven will replace
1832 // %.0f with the scale.
1834 // Try to keep the translation short (for example, in English we
1835 // use "Extended" not "Extended elevation") - there is limited room
1836 // in the footer, and the details there are mostly to make it easy
1837 // to check that you have corresponding pages from a multiple page
1838 // printout.
1839 footer[1].Printf(wmsg(/*Extended 1:%.0f*/244), scale);
1840 break;
1843 // TRANSLATORS: N/M meaning page N of M in the page footer of a printout.
1844 footer[2].Printf(wmsg(/*%d/%d*/232), pg, m_layout->pagesX * m_layout->pagesY);
1846 wxString datestamp = m_layout->datestamp;
1847 if (!datestamp.empty()) {
1848 // Remove any timezone suffix (e.g. " UTC" or " +1200").
1849 wxChar ch = datestamp[datestamp.size() - 1];
1850 if (ch >= 'A' && ch <= 'Z') {
1851 for (size_t i = datestamp.size() - 1; i; --i) {
1852 ch = datestamp[i];
1853 if (ch < 'A' || ch > 'Z') {
1854 if (ch == ' ') datestamp.resize(i);
1855 break;
1858 } else if (ch >= '0' && ch <= '9') {
1859 for (size_t i = datestamp.size() - 1; i; --i) {
1860 ch = datestamp[i];
1861 if (ch < '0' || ch > '9') {
1862 if ((ch == '-' || ch == '+') && datestamp[--i] == ' ')
1863 datestamp.resize(i);
1864 break;
1869 // Remove any day prefix (e.g. "Mon,").
1870 for (size_t i = 0; i != datestamp.size(); ++i) {
1871 if (datestamp[i] == ',' && i + 1 != datestamp.size()) {
1872 // Also skip a space after the comma.
1873 if (datestamp[i + 1] == ' ') ++i;
1874 datestamp.erase(0, i + 1);
1875 break;
1880 // TRANSLATORS: Used in the footer of printouts to compactly indicate that
1881 // the date which follows is the date that the survey data was processed.
1883 // Aven will replace %s with a string giving the date and time (e.g.
1884 // "2015-06-09 12:40:44").
1885 footer[3].Printf(wmsg(/*Processed: %s*/167), datestamp.c_str());
1887 const wxChar * footer_sep = wxT(" ");
1888 int fontsize_footer = fontsize_labels;
1889 wxFont * font_footer;
1890 font_footer = new wxFont(fontsize_footer, wxDEFAULT, wxNORMAL, wxNORMAL,
1891 false, wxString(fontname_labels, wxConvUTF8),
1892 wxFONTENCODING_UTF8);
1893 font_footer->Scale(font_scaling_x);
1894 SetFont(font_footer);
1895 int w[FOOTERS], ws, h;
1896 pdc->GetTextExtent(footer_sep, &ws, &h);
1897 int wtotal = ws * (FOOTERS - 1);
1898 for (int i = 0; i < FOOTERS; ++i) {
1899 pdc->GetTextExtent(footer[i], &w[i], &h);
1900 wtotal += w[i];
1903 long X = x_offset;
1904 long Y = y_offset + ypPageDepth + (long)(7 * m_layout->scY) - pdc->GetCharHeight();
1906 if (wtotal > xpPageWidth) {
1907 // Rescale the footer so it fits.
1908 double rescale = double(wtotal) / xpPageWidth;
1909 double xsc, ysc;
1910 pdc->GetUserScale(&xsc, &ysc);
1911 pdc->SetUserScale(xsc / rescale, ysc / rescale);
1912 SetFont(font_footer);
1913 wxString fullfooter = footer[0];
1914 for (int i = 1; i < FOOTERS - 1; ++i) {
1915 fullfooter += footer_sep;
1916 fullfooter += footer[i];
1918 pdc->DrawText(fullfooter, X * rescale, Y * rescale);
1919 // Draw final item right aligned to avoid misaligning.
1920 wxRect rect(x_offset * rescale, Y * rescale,
1921 xpPageWidth * rescale, pdc->GetCharHeight() * rescale);
1922 pdc->DrawLabel(footer[FOOTERS - 1], rect, wxALIGN_RIGHT|wxALIGN_TOP);
1923 pdc->SetUserScale(xsc, ysc);
1924 } else {
1925 // Space out the elements of the footer to fill the line.
1926 double extra = double(xpPageWidth - wtotal) / (FOOTERS - 1);
1927 for (int i = 0; i < FOOTERS - 1; ++i) {
1928 pdc->DrawText(footer[i], X + extra * i, Y);
1929 X += ws + w[i];
1931 // Draw final item right aligned to avoid misaligning.
1932 wxRect rect(x_offset, Y, xpPageWidth, pdc->GetCharHeight());
1933 pdc->DrawLabel(footer[FOOTERS - 1], rect, wxALIGN_RIGHT|wxALIGN_TOP);
1935 drawticks((int)(9 * m_layout->scX / POINTS_PER_MM), x, y);
1938 void
1939 svxPrintout::PlotLR(const vector<XSect> & centreline)
1941 assert(centreline.size() > 1);
1942 XSect prev_pt_v;
1943 Vector3 last_right(1.0, 0.0, 0.0);
1945 const double Sc = 1000 / m_layout->Scale;
1946 const double SIN = sin(rad(m_layout->rot));
1947 const double COS = cos(rad(m_layout->rot));
1949 vector<XSect>::const_iterator i = centreline.begin();
1950 vector<XSect>::size_type segment = 0;
1951 while (i != centreline.end()) {
1952 // get the coordinates of this vertex
1953 const XSect & pt_v = *i++;
1955 Vector3 right;
1957 const Vector3 up_v(0.0, 0.0, 1.0);
1959 if (segment == 0) {
1960 assert(i != centreline.end());
1961 // first segment
1963 // get the coordinates of the next vertex
1964 const XSect & next_pt_v = *i;
1966 // calculate vector from this pt to the next one
1967 Vector3 leg_v = next_pt_v - pt_v;
1969 // obtain a vector in the LRUD plane
1970 right = leg_v * up_v;
1971 if (right.magnitude() == 0) {
1972 right = last_right;
1973 } else {
1974 last_right = right;
1976 } else if (segment + 1 == centreline.size()) {
1977 // last segment
1979 // Calculate vector from the previous pt to this one.
1980 Vector3 leg_v = pt_v - prev_pt_v;
1982 // Obtain a horizontal vector in the LRUD plane.
1983 right = leg_v * up_v;
1984 if (right.magnitude() == 0) {
1985 right = Vector3(last_right.GetX(), last_right.GetY(), 0.0);
1986 } else {
1987 last_right = right;
1989 } else {
1990 assert(i != centreline.end());
1991 // Intermediate segment.
1993 // Get the coordinates of the next vertex.
1994 const XSect & next_pt_v = *i;
1996 // Calculate vectors from this vertex to the
1997 // next vertex, and from the previous vertex to
1998 // this one.
1999 Vector3 leg1_v = pt_v - prev_pt_v;
2000 Vector3 leg2_v = next_pt_v - pt_v;
2002 // Obtain horizontal vectors perpendicular to
2003 // both legs, then normalise and average to get
2004 // a horizontal bisector.
2005 Vector3 r1 = leg1_v * up_v;
2006 Vector3 r2 = leg2_v * up_v;
2007 r1.normalise();
2008 r2.normalise();
2009 right = r1 + r2;
2010 if (right.magnitude() == 0) {
2011 // This is the "mid-pitch" case...
2012 right = last_right;
2014 last_right = right;
2017 // Scale to unit vectors in the LRUD plane.
2018 right.normalise();
2020 Double l = pt_v.GetL();
2021 Double r = pt_v.GetR();
2023 if (l >= 0 || r >= 0) {
2024 // Get the x and y coordinates of the survey station
2025 double pt_X = pt_v.GetX() * COS - pt_v.GetY() * SIN;
2026 double pt_Y = pt_v.GetX() * SIN + pt_v.GetY() * COS;
2027 long pt_x = (long)((pt_X * Sc + m_layout->xOrg) * m_layout->scX);
2028 long pt_y = (long)((pt_Y * Sc + m_layout->yOrg) * m_layout->scY);
2030 // Calculate dimensions for the right arrow
2031 double COSR = right.GetX();
2032 double SINR = right.GetY();
2033 long CROSS_MAJOR = (COSR + SINR) * PWX_CROSS_SIZE;
2034 long CROSS_MINOR = (COSR - SINR) * PWX_CROSS_SIZE;
2036 if (l >= 0) {
2037 // Get the x and y coordinates of the end of the left arrow
2038 Vector3 p = pt_v - right * l;
2039 double X = p.GetX() * COS - p.GetY() * SIN;
2040 double Y = (p.GetX() * SIN + p.GetY() * COS);
2041 long x = (long)((X * Sc + m_layout->xOrg) * m_layout->scX);
2042 long y = (long)((Y * Sc + m_layout->yOrg) * m_layout->scY);
2044 // Draw the arrow stem
2045 MoveTo(pt_x, pt_y);
2046 DrawTo(x, y);
2048 // Rotate the arrow by the page rotation
2049 long dx1 = (+CROSS_MINOR) * COS - (+CROSS_MAJOR) * SIN;
2050 long dy1 = (+CROSS_MINOR) * SIN + (+CROSS_MAJOR) * COS;
2051 long dx2 = (+CROSS_MAJOR) * COS - (-CROSS_MINOR) * SIN;
2052 long dy2 = (+CROSS_MAJOR) * SIN + (-CROSS_MINOR) * COS;
2054 // Draw the arrow
2055 MoveTo(x + dx1, y + dy1);
2056 DrawTo(x , y);
2057 DrawTo(x + dx2, y + dy2);
2060 if (r >= 0) {
2061 // Get the x and y coordinates of the end of the right arrow
2062 Vector3 p = pt_v + right * r;
2063 double X = p.GetX() * COS - p.GetY() * SIN;
2064 double Y = (p.GetX() * SIN + p.GetY() * COS);
2065 long x = (long)((X * Sc + m_layout->xOrg) * m_layout->scX);
2066 long y = (long)((Y * Sc + m_layout->yOrg) * m_layout->scY);
2068 // Draw the arrow stem
2069 MoveTo(pt_x, pt_y);
2070 DrawTo(x, y);
2072 // Rotate the arrow by the page rotation
2073 long dx1 = (-CROSS_MINOR) * COS - (-CROSS_MAJOR) * SIN;
2074 long dy1 = (-CROSS_MINOR) * SIN + (-CROSS_MAJOR) * COS;
2075 long dx2 = (-CROSS_MAJOR) * COS - (+CROSS_MINOR) * SIN;
2076 long dy2 = (-CROSS_MAJOR) * SIN + (+CROSS_MINOR) * COS;
2078 // Draw the arrow
2079 MoveTo(x + dx1, y + dy1);
2080 DrawTo(x , y);
2081 DrawTo(x + dx2, y + dy2);
2085 prev_pt_v = pt_v;
2087 ++segment;
2091 void
2092 svxPrintout::PlotUD(const vector<XSect> & centreline)
2094 assert(centreline.size() > 1);
2095 const double Sc = 1000 / m_layout->Scale;
2097 vector<XSect>::const_iterator i = centreline.begin();
2098 while (i != centreline.end()) {
2099 // get the coordinates of this vertex
2100 const XSect & pt_v = *i++;
2102 Double u = pt_v.GetU();
2103 Double d = pt_v.GetD();
2105 if (u >= 0 || d >= 0) {
2106 // Get the coordinates of the survey point
2107 Vector3 p = pt_v;
2108 double SIN = sin(rad(m_layout->rot));
2109 double COS = cos(rad(m_layout->rot));
2110 double X = p.GetX() * COS - p.GetY() * SIN;
2111 double Y = p.GetZ();
2112 long x = (long)((X * Sc + m_layout->xOrg) * m_layout->scX);
2113 long pt_y = (long)((Y * Sc + m_layout->yOrg) * m_layout->scX);
2115 if (u >= 0) {
2116 // Get the y coordinate of the up arrow
2117 long y = (long)(((Y + u) * Sc + m_layout->yOrg) * m_layout->scY);
2119 // Draw the arrow stem
2120 MoveTo(x, pt_y);
2121 DrawTo(x, y);
2123 // Draw the up arrow
2124 MoveTo(x - PWX_CROSS_SIZE, y - PWX_CROSS_SIZE);
2125 DrawTo(x, y);
2126 DrawTo(x + PWX_CROSS_SIZE, y - PWX_CROSS_SIZE);
2129 if (d >= 0) {
2130 // Get the y coordinate of the down arrow
2131 long y = (long)(((Y - d) * Sc + m_layout->yOrg) * m_layout->scY);
2133 // Draw the arrow stem
2134 MoveTo(x, pt_y);
2135 DrawTo(x, y);
2137 // Draw the down arrow
2138 MoveTo(x - PWX_CROSS_SIZE, y + PWX_CROSS_SIZE);
2139 DrawTo(x, y);
2140 DrawTo(x + PWX_CROSS_SIZE, y + PWX_CROSS_SIZE);