2 /* Aven printing code */
3 /* Copyright (C) 1993-2003,2004,2005,2006,2010,2011,2012,2013,2014,2015,2016,2017 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
25 #include <wx/confbase.h>
26 #include <wx/filename.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>
51 #include "avenprcore.h"
57 // How many decimal points to show on angles:
61 # define ANGLE_FMT wxT("%03.f")
62 # define ANGLE2_FMT wxT("%.f")
64 # define ANGLE_FMT wxT("%05.1f")
65 # define ANGLE2_FMT wxT("%.1f")
67 # define ANGLE_FMT wxT("%06.2f")
68 # define ANGLE2_FMT wxT("%.2f")
70 # error Need to add ANGLE_FMT and ANGLE2_FMT for the currently set ANGLE_DP
74 format_angle(const wxChar
* fmt
, double angle
)
78 size_t dot
= s
.find('.');
123 class BitValidator
: public wxValidator
{
124 // Disallow assignment.
125 BitValidator
& operator=(const BitValidator
&);
133 BitValidator(int * val_
, int mask_
)
134 : val(val_
), mask(mask_
) { }
136 BitValidator(const BitValidator
&o
) : wxValidator() {
142 wxObject
*Clone() const { return new BitValidator(val
, mask
); }
144 bool Copy(const BitValidator
& o
) {
145 wxValidator::Copy(o
);
151 bool Validate(wxWindow
*) { return true; }
153 bool TransferToWindow() {
154 if (!m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
156 ((wxCheckBox
*)m_validatorWindow
)->SetValue(*val
& mask
);
160 bool TransferFromWindow() {
161 if (!m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
163 if (((wxCheckBox
*)m_validatorWindow
)->IsChecked())
171 class svxPrintout
: public wxPrintout
{
174 wxPageSetupDialogData
* m_data
;
176 wxFont
*font_labels
, *font_default
;
177 // Currently unused, but "skip blank pages" would use it.
178 bool scan_for_blank_pages
;
180 wxPen
*pen_frame
, *pen_cross
, *pen_leg
, *pen_surface_leg
, *pen_splay
;
181 wxColour colour_text
, colour_labels
;
184 double font_scaling_x
, font_scaling_y
;
187 long x_min
, y_min
, x_max
, y_max
;
192 int check_intersection(long x_p
, long y_p
);
193 void draw_info_box();
194 void draw_scale_bar(double x
, double y
, double MaxLength
);
195 int next_page(int *pstate
, char **q
, int pageLim
);
196 void drawticks(int tsize
, int x
, int y
);
198 void MOVEMM(double X
, double Y
) {
199 MoveTo((long)(X
* m_layout
->scX
), (long)(Y
* m_layout
->scY
));
201 void DRAWMM(double X
, double Y
) {
202 DrawTo((long)(X
* m_layout
->scX
), (long)(Y
* m_layout
->scY
));
204 void MoveTo(long x
, long y
);
205 void DrawTo(long x
, long y
);
206 void DrawCross(long x
, long y
);
207 void SetFont(wxFont
* font
) {
210 void WriteString(const wxString
& s
);
211 void DrawEllipse(long x
, long y
, long r
, long R
);
212 void SolidRectangle(long x
, long y
, long w
, long h
);
213 void NewPage(int pg
, int pagesX
, int pagesY
);
214 void PlotLR(const vector
<XSect
> & centreline
);
215 void PlotUD(const vector
<XSect
> & centreline
);
217 svxPrintout(MainFrm
*mainfrm
, layout
*l
, wxPageSetupDialogData
*data
, const wxString
& title
);
218 bool OnPrintPage(int pageNum
);
219 void GetPageInfo(int *minPage
, int *maxPage
,
220 int *pageFrom
, int *pageTo
);
221 bool HasPage(int pageNum
);
222 void OnBeginPrinting();
223 void OnEndPrinting();
226 BEGIN_EVENT_TABLE(svxPrintDlg
, wxDialog
)
227 EVT_CHOICE(svx_FORMAT
, svxPrintDlg::OnChange
)
228 EVT_TEXT(svx_SCALE
, svxPrintDlg::OnChange
)
229 EVT_COMBOBOX(svx_SCALE
, svxPrintDlg::OnChange
)
230 EVT_SPINCTRLDOUBLE(svx_BEARING
, svxPrintDlg::OnChangeSpin
)
231 EVT_SPINCTRLDOUBLE(svx_TILT
, svxPrintDlg::OnChangeSpin
)
232 EVT_BUTTON(wxID_PRINT
, svxPrintDlg::OnPrint
)
233 EVT_BUTTON(svx_EXPORT
, svxPrintDlg::OnExport
)
234 EVT_BUTTON(wxID_CANCEL
, svxPrintDlg::OnCancel
)
235 #ifdef AVEN_PRINT_PREVIEW
236 EVT_BUTTON(wxID_PREVIEW
, svxPrintDlg::OnPreview
)
238 EVT_BUTTON(svx_PLAN
, svxPrintDlg::OnPlan
)
239 EVT_BUTTON(svx_ELEV
, svxPrintDlg::OnElevation
)
240 EVT_UPDATE_UI(svx_PLAN
, svxPrintDlg::OnPlanUpdate
)
241 EVT_UPDATE_UI(svx_ELEV
, svxPrintDlg::OnElevationUpdate
)
242 EVT_CHECKBOX(svx_LEGS
, svxPrintDlg::OnChange
)
243 EVT_CHECKBOX(svx_STATIONS
, svxPrintDlg::OnChange
)
244 EVT_CHECKBOX(svx_NAMES
, svxPrintDlg::OnChange
)
245 EVT_CHECKBOX(svx_SURFACE
, svxPrintDlg::OnChange
)
246 EVT_CHECKBOX(svx_SPLAYS
, svxPrintDlg::OnChange
)
247 EVT_CHECKBOX(svx_ENTS
, svxPrintDlg::OnChange
)
248 EVT_CHECKBOX(svx_FIXES
, svxPrintDlg::OnChange
)
249 EVT_CHECKBOX(svx_EXPORTS
, svxPrintDlg::OnChange
)
252 static wxString scales
[] = {
268 // The order of these arrays must match export_format in export.h.
270 static wxString formats
[] = {
284 static wxString projs
[] = {
286 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"),
287 /* British grid SD (Yorkshire): */
288 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"),
289 /* British full grid reference: */
290 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")
294 static const unsigned format_info
[] = {
295 LABELS
|LEGS
|SURF
|SPLAYS
|STNS
|PASG
|XSECT
|WALLS
|MARKER_SIZE
|TEXT_HEIGHT
|GRID
|FULL_COORDS
,
296 LABELS
|LEGS
|SURF
|SPLAYS
|STNS
|PASG
|XSECT
|WALLS
,
297 LABELS
|LEGS
|SURF
|SPLAYS
|ENTS
|FIXES
|EXPORTS
|PROJ
|EXPORT_3D
,
298 LABELS
|LEGS
|SURF
|SPLAYS
|STNS
|CENTRED
,
299 LEGS
|SPLAYS
|CENTRED
|EXPORT_3D
,
300 LABELS
|LEGS
|SPLAYS
|PASG
|XSECT
|WALLS
|ENTS
|FIXES
|EXPORTS
|PROJ
|EXPORT_3D
,
301 LABELS
|LEGS
|SURF
|SPLAYS
,
302 LABELS
|LEGS
|SURF
|SPLAYS
|STNS
|MARKER_SIZE
|GRID
|SCALE
,
303 LABELS
|ENTS
|FIXES
|EXPORTS
|EXPORT_3D
,
304 LABELS
|LEGS
|SURF
|SPLAYS
|STNS
|PASG
|XSECT
|WALLS
|MARKER_SIZE
|TEXT_HEIGHT
|SCALE
307 static const char * extension
[] = {
320 static const int msg_filetype
[] = {
324 /* TRANSLATORS: Here "plotter" refers to a machine which draws a printout
325 * on a (usually large) sheet of paper using a pen mounted in a motorised
327 /*HPGL for plotters*/414,
330 /* TRANSLATORS: "Compass" and "Carto" are the names of software packages,
331 * so should not be translated:
332 * http://www.fountainware.com/compass/
333 * http://www.psc-cavers.org/carto/ */
334 /*Compass PLT for use with Carto*/415,
335 /* TRANSLATORS: "Skencil" is the name of a software package, so should not be
336 * translated: http://www.skencil.org/ */
337 /*Skencil files*/416,
338 /* TRANSLATORS: Survex is the name of the software, and "pos" refers to a
339 * file extension, so neither should be translated. */
340 /*Survex pos files*/166,
344 // We discriminate as "One Page" isn't valid for exporting.
345 static wxString default_scale_print
;
346 static wxString default_scale_export
;
348 svxPrintDlg::svxPrintDlg(MainFrm
* mainfrm_
, const wxString
& filename
,
349 const wxString
& title
, const wxString
& cs_proj
,
350 const wxString
& datestamp
, time_t datestamp_numeric
,
351 double angle
, double tilt_angle
,
352 bool labels
, bool crosses
, bool legs
, bool surf
,
353 bool splays
, bool tubes
, bool ents
, bool fixes
,
354 bool exports
, bool printing
, bool close_after_
)
355 : wxDialog(mainfrm_
, -1, wxString(printing
?
356 /* TRANSLATORS: Title of the print
359 /* TRANSLATORS: Title of the export
361 wmsg(/*Export*/383))),
362 m_layout(printing
? wxGetApp().GetPageSetupDialogData() : NULL
),
363 m_File(filename
), mainfrm(mainfrm_
), close_after(close_after_
)
382 show_mask
|= XSECT
|WALLS
|PASG
;
388 show_mask
|= EXPORTS
;
389 m_layout
.show_mask
= show_mask
;
390 m_layout
.datestamp
= datestamp
;
391 m_layout
.datestamp_numeric
= datestamp_numeric
;
392 m_layout
.rot
= angle
;
393 m_layout
.title
= title
;
394 m_layout
.cs_proj
= cs_proj
;
395 if (mainfrm
->IsExtendedElevation()) {
396 m_layout
.view
= layout::EXTELEV
;
397 if (m_layout
.rot
!= 0.0 && m_layout
.rot
!= 180.0) m_layout
.rot
= 0;
400 m_layout
.tilt
= tilt_angle
;
401 if (m_layout
.tilt
== -90.0) {
402 m_layout
.view
= layout::PLAN
;
403 } else if (m_layout
.tilt
== 0.0) {
404 m_layout
.view
= layout::ELEV
;
406 m_layout
.view
= layout::TILT
;
410 /* setup our print dialog*/
411 wxBoxSizer
* v1
= new wxBoxSizer(wxVERTICAL
);
412 wxBoxSizer
* h1
= new wxBoxSizer(wxHORIZONTAL
); // holds controls
413 /* TRANSLATORS: Used as a label for the surrounding box for the "Bearing"
414 * and "Tilt angle" fields, and the "Plan view" and "Elevation" buttons in
415 * the "what to print/export" dialog. */
416 m_viewbox
= new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*View*/283)), wxVERTICAL
);
417 /* TRANSLATORS: Used as a label for the surrounding box for the "survey
418 * legs" "stations" "names" etc checkboxes in the "what to print" dialog.
419 * "Elements" isn’t a good name for this but nothing better has yet come to
421 wxBoxSizer
* v3
= new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*Elements*/256)), wxVERTICAL
);
422 wxBoxSizer
* h2
= new wxBoxSizer(wxHORIZONTAL
);
423 wxBoxSizer
* h3
= new wxBoxSizer(wxHORIZONTAL
); // holds buttons
427 label
= new wxStaticText(this, -1, wxString(wmsg(/*Export format*/410)));
428 const size_t n_formats
= sizeof(formats
) / sizeof(formats
[0]);
429 m_format
= new wxChoice(this, svx_FORMAT
,
430 wxDefaultPosition
, wxDefaultSize
,
432 unsigned current_format
= 0;
433 wxConfigBase
* cfg
= wxConfigBase::Get();
435 if (cfg
->Read(wxT("export_format"), &s
, wxString())) {
436 for (unsigned i
= 0; i
!= n_formats
; ++i
) {
437 if (s
== formats
[i
]) {
443 m_format
->SetSelection(current_format
);
444 wxBoxSizer
* formatbox
= new wxBoxSizer(wxHORIZONTAL
);
445 formatbox
->Add(label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
446 formatbox
->Add(m_format
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
448 v1
->Add(formatbox
, 0, wxALIGN_LEFT
|wxALL
, 0);
452 label
= new wxStaticText(this, -1, wxString(wmsg(/*Scale*/154)) + wxT(" 1:"));
453 if (printing
&& scales
[0].empty()) {
454 /* TRANSLATORS: used in the scale drop down selector in the print
455 * dialog the implicit meaning is "choose a suitable scale to fit
456 * the plot on a single page", but we need something shorter */
457 scales
[0].assign(wmsg(/*One page*/258));
459 wxString default_scale
;
461 default_scale
= default_scale_print
;
462 if (default_scale
.empty()) default_scale
= scales
[0];
464 default_scale
= default_scale_export
;
465 if (default_scale
.empty()) default_scale
= wxT("1000");
467 const wxString
* scale_list
= scales
;
468 size_t n_scales
= sizeof(scales
) / sizeof(scales
[0]);
473 m_scale
= new wxComboBox(this, svx_SCALE
, default_scale
, wxDefaultPosition
,
474 wxDefaultSize
, n_scales
, scale_list
);
475 m_scalebox
= new wxBoxSizer(wxHORIZONTAL
);
476 m_scalebox
->Add(label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
477 m_scalebox
->Add(m_scale
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
479 m_viewbox
->Add(m_scalebox
, 0, wxALIGN_LEFT
|wxALL
, 0);
482 // Make the dummy string wider than any sane value and use that to
483 // fix the width of the control so the sizers allow space for bigger
485 m_printSize
= new wxStaticText(this, -1, wxString::Format(wmsg(/*%d pages (%dx%d)*/257), 9604, 98, 98));
486 m_viewbox
->Add(m_printSize
, 0, wxALIGN_LEFT
|wxALL
, 5);
490 * svx_GRID, // double - spacing, default: 100m
491 * svx_TEXT_HEIGHT, // default 0.6
492 * svx_MARKER_SIZE // default 0.8
495 if (m_layout
.view
!= layout::EXTELEV
) {
496 wxFlexGridSizer
* anglebox
= new wxFlexGridSizer(2);
497 wxStaticText
* brg_label
, * tilt_label
;
498 brg_label
= new wxStaticText(this, -1, wmsg(/*Bearing*/259));
499 anglebox
->Add(brg_label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALIGN_LEFT
|wxALL
, 5);
500 // wSP_WRAP means that you can scroll past 360 to 0, and vice versa.
501 m_bearing
= new wxSpinCtrlDouble(this, svx_BEARING
, wxEmptyString
,
502 wxDefaultPosition
, wxDefaultSize
,
503 wxSP_ARROW_KEYS
|wxALIGN_RIGHT
|wxSP_WRAP
);
504 m_bearing
->SetRange(0.0, 360.0);
505 m_bearing
->SetDigits(ANGLE_DP
);
506 anglebox
->Add(m_bearing
, 0, wxALIGN_CENTRE
|wxALL
, 5);
507 /* TRANSLATORS: Used in the print dialog: */
508 tilt_label
= new wxStaticText(this, -1, wmsg(/*Tilt angle*/263));
509 anglebox
->Add(tilt_label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALIGN_LEFT
|wxALL
, 5);
510 m_tilt
= new wxSpinCtrlDouble(this, svx_TILT
);
511 m_tilt
->SetRange(-90.0, 90.0);
512 m_tilt
->SetDigits(ANGLE_DP
);
513 anglebox
->Add(m_tilt
, 0, wxALIGN_CENTRE
|wxALL
, 5);
515 m_viewbox
->Add(anglebox
, 0, wxALIGN_LEFT
|wxALL
, 0);
517 wxBoxSizer
* planelevsizer
= new wxBoxSizer(wxHORIZONTAL
);
518 planelevsizer
->Add(new wxButton(this, svx_PLAN
, wmsg(/*P&lan view*/117)),
519 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
520 planelevsizer
->Add(new wxButton(this, svx_ELEV
, wmsg(/*&Elevation*/285)),
521 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
523 m_viewbox
->Add(planelevsizer
, 0, wxALIGN_LEFT
|wxALL
, 5);
526 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
527 * "survey stations". */
528 v3
->Add(new wxCheckBox(this, svx_LEGS
, wmsg(/*Underground Survey Legs*/262),
529 wxDefaultPosition
, wxDefaultSize
, 0,
530 BitValidator(&m_layout
.show_mask
, LEGS
)),
531 0, wxALIGN_LEFT
|wxALL
, 2);
532 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
533 * "survey stations". */
534 v3
->Add(new wxCheckBox(this, svx_SURFACE
, wmsg(/*Sur&face Survey Legs*/403),
535 wxDefaultPosition
, wxDefaultSize
, 0,
536 BitValidator(&m_layout
.show_mask
, SURF
)),
537 0, wxALIGN_LEFT
|wxALL
, 2);
538 v3
->Add(new wxCheckBox(this, svx_SPLAYS
, wmsg(/*Spla&y Legs*/406),
539 wxDefaultPosition
, wxDefaultSize
, 0,
540 BitValidator(&m_layout
.show_mask
, SPLAYS
)),
541 0, wxALIGN_LEFT
|wxALL
, 2);
542 v3
->Add(new wxCheckBox(this, svx_STATIONS
, wmsg(/*Crosses*/261),
543 wxDefaultPosition
, wxDefaultSize
, 0,
544 BitValidator(&m_layout
.show_mask
, STNS
)),
545 0, wxALIGN_LEFT
|wxALL
, 2);
546 v3
->Add(new wxCheckBox(this, svx_NAMES
, wmsg(/*Station Names*/260),
547 wxDefaultPosition
, wxDefaultSize
, 0,
548 BitValidator(&m_layout
.show_mask
, LABELS
)),
549 0, wxALIGN_LEFT
|wxALL
, 2);
550 v3
->Add(new wxCheckBox(this, svx_ENTS
, wmsg(/*Entrances*/418),
551 wxDefaultPosition
, wxDefaultSize
, 0,
552 BitValidator(&m_layout
.show_mask
, ENTS
)),
553 0, wxALIGN_LEFT
|wxALL
, 2);
554 v3
->Add(new wxCheckBox(this, svx_FIXES
, wmsg(/*Fixed Points*/419),
555 wxDefaultPosition
, wxDefaultSize
, 0,
556 BitValidator(&m_layout
.show_mask
, FIXES
)),
557 0, wxALIGN_LEFT
|wxALL
, 2);
558 v3
->Add(new wxCheckBox(this, svx_EXPORTS
, wmsg(/*Exported Stations*/420),
559 wxDefaultPosition
, wxDefaultSize
, 0,
560 BitValidator(&m_layout
.show_mask
, EXPORTS
)),
561 0, wxALIGN_LEFT
|wxALL
, 2);
562 v3
->Add(new wxCheckBox(this, svx_XSECT
, wmsg(/*Cross-sections*/393),
563 wxDefaultPosition
, wxDefaultSize
, 0,
564 BitValidator(&m_layout
.show_mask
, XSECT
)),
565 0, wxALIGN_LEFT
|wxALL
, 2);
567 v3
->Add(new wxCheckBox(this, svx_WALLS
, wmsg(/*Walls*/394),
568 wxDefaultPosition
, wxDefaultSize
, 0,
569 BitValidator(&m_layout
.show_mask
, WALLS
)),
570 0, wxALIGN_LEFT
|wxALL
, 2);
571 // TRANSLATORS: Label for checkbox which controls whether there's a
572 // layer in the exported file (for formats such as DXF and SVG)
573 // containing polygons for the inside of cave passages).
574 v3
->Add(new wxCheckBox(this, svx_PASSAGES
, wmsg(/*Passages*/395),
575 wxDefaultPosition
, wxDefaultSize
, 0,
576 BitValidator(&m_layout
.show_mask
, PASG
)),
577 0, wxALIGN_LEFT
|wxALL
, 2);
578 v3
->Add(new wxCheckBox(this, svx_CENTRED
, wmsg(/*Origin in centre*/421),
579 wxDefaultPosition
, wxDefaultSize
, 0,
580 BitValidator(&m_layout
.show_mask
, CENTRED
)),
581 0, wxALIGN_LEFT
|wxALL
, 2);
582 v3
->Add(new wxCheckBox(this, svx_FULLCOORDS
, wmsg(/*Full coordinates*/422),
583 wxDefaultPosition
, wxDefaultSize
, 0,
584 BitValidator(&m_layout
.show_mask
, FULL_COORDS
)),
585 0, wxALIGN_LEFT
|wxALL
, 2);
588 /* TRANSLATORS: used in the print dialog - controls drawing lines
589 * around each page */
590 v3
->Add(new wxCheckBox(this, svx_BORDERS
, wmsg(/*Page Borders*/264),
591 wxDefaultPosition
, wxDefaultSize
, 0,
592 wxGenericValidator(&m_layout
.Border
)),
593 0, wxALIGN_LEFT
|wxALL
, 2);
594 /* TRANSLATORS: will be used in the print dialog - check this to print
595 * blank pages (otherwise they’ll be skipped to save paper) */
596 // m_blanks = new wxCheckBox(this, svx_BLANKS, wmsg(/*Blank Pages*/266));
597 // v3->Add(m_blanks, 0, wxALIGN_LEFT|wxALL, 2);
598 /* TRANSLATORS: As in the legend on a map. Used in the print dialog -
599 * controls drawing the box at the lower left with survey name, view
601 v3
->Add(new wxCheckBox(this, svx_LEGEND
, wmsg(/*Legend*/265),
602 wxDefaultPosition
, wxDefaultSize
, 0,
603 wxGenericValidator(&m_layout
.Legend
)),
604 0, wxALIGN_LEFT
|wxALL
, 2);
607 h1
->Add(v3
, 0, wxALIGN_LEFT
|wxALL
, 5);
608 h1
->Add(m_viewbox
, 0, wxALIGN_LEFT
|wxLEFT
, 5);
611 /* TRANSLATORS: The PROJ library is used to do coordinate
612 * transformations (https://trac.osgeo.org/proj/) - if the .3d file
613 * doesn't contain details of the coordinate projection in use, the
614 * user must specify it here for export formats which need to know it
617 h2
->Add(new wxStaticText(this, svx_PROJ_LABEL
, wmsg(/*Coordinate projection*/440)),
618 0, wxLEFT
|wxALIGN_CENTRE_VERTICAL
, 5);
620 if (!m_layout
.cs_proj
.empty()) {
621 // If the input file specified the coordinate system, don't let the
622 // user mess with it.
623 style
= wxTE_READONLY
;
625 #if 0 // FIXME: Is it a good idea to save this?
626 wxConfigBase
* cfg
= wxConfigBase::Get();
627 wxString input_projection
;
628 cfg
->Read(wxT("input_projection"), &input_projection
);
629 if (!input_projection
.empty())
630 proj_edit
.SetValue(input_projection
);
633 wxTextCtrl
* proj_edit
= new wxTextCtrl(this, svx_PROJ
, m_layout
.cs_proj
,
634 wxDefaultPosition
, wxDefaultSize
,
636 h2
->Add(proj_edit
, 1, wxALL
|wxEXPAND
, 5);
637 v1
->Add(h2
, 0, wxALIGN_LEFT
|wxEXPAND
, 5);
640 v1
->Add(h1
, 0, wxALIGN_LEFT
|wxALL
, 5);
642 // When we enable/disable checkboxes in the export dialog, ideally we'd
643 // like the dialog to resize, but not sure how to achieve that, so we
644 // add a stretchable spacer here so at least the buttons stay in the
645 // lower right corner.
646 v1
->AddStretchSpacer();
649 but
= new wxButton(this, wxID_CANCEL
);
650 h3
->Add(but
, 0, wxALL
, 5);
652 #ifdef AVEN_PRINT_PREVIEW
653 but
= new wxButton(this, wxID_PREVIEW
);
654 h3
->Add(but
, 0, wxALL
, 5);
655 but
= new wxButton(this, wxID_PRINT
);
657 but
= new wxButton(this, wxID_PRINT
, wmsg(/*&Print...*/400));
660 /* TRANSLATORS: The text on the action button in the "Export" settings
662 but
= new wxButton(this, svx_EXPORT
, wmsg(/*&Export...*/230));
665 h3
->Add(but
, 0, wxALL
, 5);
666 v1
->Add(h3
, 0, wxALIGN_RIGHT
|wxALL
, 5);
670 v1
->SetSizeHints(this);
677 svxPrintDlg::OnPrint(wxCommandEvent
&) {
679 TransferDataFromWindow();
680 wxPageSetupDialogData
* psdd
= wxGetApp().GetPageSetupDialogData();
681 wxPrintDialogData
pd(psdd
->GetPrintData());
683 svxPrintout
po(mainfrm
, &m_layout
, psdd
, m_File
);
684 if (m_layout
.SkipBlank
) {
685 // FIXME: wx's printing requires a contiguous range of valid page
686 // numbers. To achieve that, we need to run a scan for blank pages
687 // here, so that GetPageInfo() knows what range to return, and so
688 // that OnPrintPage() can map a page number back to where in the
689 // MxN multi-page layout.
691 po
.scan_for_blank_pages
= true;
692 for (int page
= 1; page
<= m_layout
->pages
; ++page
) {
693 po
.fBlankPage
= fTrue
;
694 po
.OnPrintPage(page
);
695 // FIXME: Do something with po.fBlankPage
697 po
.scan_for_blank_pages
= false;
700 if (pr
.Print(this, &po
, true)) {
701 // Close the print dialog if printing succeeded.
707 svxPrintDlg::OnExport(wxCommandEvent
&) {
709 TransferDataFromWindow();
711 wxFileName::SplitPath(m_File
, NULL
, NULL
, &leaf
, NULL
, wxPATH_NATIVE
);
712 unsigned format_idx
= ((wxChoice
*)FindWindow(svx_FORMAT
))->GetSelection();
713 leaf
+= wxString::FromUTF8(extension
[format_idx
]);
715 wxString filespec
= wmsg(msg_filetype
[format_idx
]);
716 filespec
+= wxT("|*");
717 filespec
+= wxString::FromUTF8(extension
[format_idx
]);
718 filespec
+= wxT("|");
719 filespec
+= wmsg(/*All files*/208);
720 filespec
+= wxT("|");
721 filespec
+= wxFileSelectorDefaultWildcardStr
;
723 /* TRANSLATORS: Title of file dialog to choose name and type of exported
725 wxFileDialog
dlg(this, wmsg(/*Export as:*/401), wxString(), leaf
,
726 filespec
, wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
727 if (dlg
.ShowModal() == wxID_OK
) {
728 wxString input_projection
= ((wxTextCtrl
*)FindWindow(svx_PROJ
))->GetValue();
729 double grid
= 100; // metres
730 double text_height
= 0.6;
731 double marker_size
= 0.8;
734 const wxString
& export_fnm
= dlg
.GetPath();
735 unsigned mask
= format_info
[format_idx
];
737 if (mask
& EXPORT_3D
) {
742 tilt
= m_layout
.tilt
;
744 if (!Export(export_fnm
, m_layout
.title
,
745 m_layout
.datestamp
, m_layout
.datestamp_numeric
, mainfrm
,
746 rot
, tilt
, m_layout
.get_effective_show_mask(),
747 export_format(format_idx
), input_projection
.utf8_str(),
748 grid
, text_height
, marker_size
, m_layout
.Scale
)) {
749 wxString m
= wxString::Format(wmsg(/*Couldn’t write file “%s”*/402).c_str(),
751 wxGetApp().ReportError(m
);
753 } catch (const wxString
& m
) {
754 wxGetApp().ReportError(m
);
760 #ifdef AVEN_PRINT_PREVIEW
762 svxPrintDlg::OnPreview(wxCommandEvent
&) {
764 TransferDataFromWindow();
765 wxPageSetupDialogData
* psdd
= wxGetApp().GetPageSetupDialogData();
766 wxPrintDialogData
pd(psdd
->GetPrintData());
768 pv
= new wxPrintPreview(new svxPrintout(mainfrm
, &m_layout
, psdd
, m_File
),
769 new svxPrintout(mainfrm
, &m_layout
, psdd
, m_File
),
771 // TRANSLATORS: Title of the print preview dialog
772 wxPreviewFrame
*frame
= new wxPreviewFrame(pv
, mainfrm
, wmsg(/*Print Preview*/398));
775 // Size preview frame so that all of the controlbar and canvas can be seen
778 // GetBestSize gives us the width needed to show the whole controlbar.
779 frame
->GetBestSize(&w
, &h
);
781 // On wxGTK at least, GetBestSize() returns much too small a height.
784 // Ensure that we don't make the window bigger than the screen.
785 // Use wxGetClientDisplayRect() so we don't cover the MS Windows
787 wxRect disp
= wxGetClientDisplayRect();
788 if (w
> disp
.GetWidth()) w
= disp
.GetWidth();
789 if (h
> disp
.GetHeight()) h
= disp
.GetHeight();
790 // Centre the window within the "ClientDisplayRect".
791 int x
= disp
.GetLeft() + (disp
.GetWidth() - w
) / 2;
792 int y
= disp
.GetTop() + (disp
.GetHeight() - h
) / 2;
793 frame
->SetSize(x
, y
, w
, h
);
800 svxPrintDlg::OnPlan(wxCommandEvent
&) {
801 m_tilt
->SetValue(-90.0);
802 SomethingChanged(svx_TILT
);
806 svxPrintDlg::OnElevation(wxCommandEvent
&) {
807 m_tilt
->SetValue(0.0);
808 SomethingChanged(svx_TILT
);
812 svxPrintDlg::OnPlanUpdate(wxUpdateUIEvent
& e
) {
813 e
.Enable(m_tilt
->GetValue() != -90.0);
817 svxPrintDlg::OnElevationUpdate(wxUpdateUIEvent
& e
) {
818 e
.Enable(m_tilt
->GetValue() != 0.0);
822 svxPrintDlg::OnChangeSpin(wxSpinDoubleEvent
& e
) {
823 SomethingChanged(e
.GetId());
827 svxPrintDlg::OnChange(wxCommandEvent
& e
) {
828 if (e
.GetId() == svx_SCALE
&& m_scale
) {
829 default_scale_print
= m_scale
->GetValue();
830 if (default_scale_print
!= scales
[0]) {
831 // Don't store "One Page" for use when exporting.
832 default_scale_export
= default_scale_print
;
835 SomethingChanged(e
.GetId());
839 svxPrintDlg::OnCancel(wxCommandEvent
&) {
846 svxPrintDlg::SomethingChanged(int control_id
) {
847 if ((control_id
== 0 || control_id
== svx_FORMAT
) && m_format
) {
848 // Update the shown/hidden fields for the newly selected export filter.
849 int new_filter_idx
= m_format
->GetSelection();
850 if (new_filter_idx
!= wxNOT_FOUND
) {
851 unsigned mask
= format_info
[new_filter_idx
];
852 static const struct { int id
; unsigned mask
; } controls
[] = {
854 { svx_SURFACE
, SURF
},
855 { svx_SPLAYS
, SPLAYS
},
856 { svx_STATIONS
, STNS
},
857 { svx_NAMES
, LABELS
},
858 { svx_XSECT
, XSECT
},
859 { svx_WALLS
, WALLS
},
860 { svx_PASSAGES
, PASG
},
862 { svx_FIXES
, FIXES
},
863 { svx_EXPORTS
, EXPORTS
},
864 { svx_CENTRED
, CENTRED
},
865 { svx_FULLCOORDS
, FULL_COORDS
},
866 { svx_PROJ_LABEL
, PROJ
},
869 static unsigned n_controls
= sizeof(controls
) / sizeof(controls
[0]);
870 for (unsigned i
= 0; i
!= n_controls
; ++i
) {
871 wxWindow
* control
= FindWindow(controls
[i
].id
);
872 if (control
) control
->Show(mask
& controls
[i
].mask
);
874 m_scalebox
->Show(bool(mask
& SCALE
));
875 m_viewbox
->Show(!bool(mask
& EXPORT_3D
));
876 GetSizer()->Layout();
877 if (control_id
== svx_FORMAT
) {
878 wxConfigBase
* cfg
= wxConfigBase::Get();
879 cfg
->Write(wxT("export_format"), formats
[new_filter_idx
]);
886 if (m_printSize
|| m_scale
) {
887 // Update the bounding box.
891 if (!(m_scale
->GetValue()).ToDouble(&(m_layout
.Scale
)) ||
892 m_layout
.Scale
== 0.0) {
893 m_layout
.pick_scale(1, 1);
898 if (m_printSize
&& m_layout
.xMax
>= m_layout
.xMin
) {
899 m_layout
.pages_required();
900 m_printSize
->SetLabel(wxString::Format(wmsg(/*%d pages (%dx%d)*/257), m_layout
.pages
, m_layout
.pagesX
, m_layout
.pagesY
));
905 svxPrintDlg::LayoutToUI()
907 // m_blanks->SetValue(m_layout.SkipBlank);
908 if (m_layout
.view
!= layout::EXTELEV
) {
909 m_tilt
->SetValue(m_layout
.tilt
);
910 m_bearing
->SetValue(m_layout
.rot
);
913 if (m_scale
&& m_layout
.Scale
!= 0) {
914 // Do this last as it causes an OnChange message which calls UIToLayout
916 temp
<< m_layout
.Scale
;
917 m_scale
->SetValue(temp
);
922 svxPrintDlg::UIToLayout()
924 // m_layout.SkipBlank = m_blanks->IsChecked();
926 if (m_layout
.view
!= layout::EXTELEV
&& m_tilt
) {
927 m_layout
.tilt
= m_tilt
->GetValue();
928 if (m_layout
.tilt
== -90.0) {
929 m_layout
.view
= layout::PLAN
;
930 } else if (m_layout
.tilt
== 0.0) {
931 m_layout
.view
= layout::ELEV
;
933 m_layout
.view
= layout::TILT
;
936 bool enable_passage_opts
= (m_layout
.view
!= layout::TILT
);
938 win
= FindWindow(svx_XSECT
);
939 if (win
) win
->Enable(enable_passage_opts
);
940 win
= FindWindow(svx_WALLS
);
941 if (win
) win
->Enable(enable_passage_opts
);
942 win
= FindWindow(svx_PASSAGES
);
943 if (win
) win
->Enable(enable_passage_opts
);
945 m_layout
.rot
= m_bearing
->GetValue();
950 svxPrintDlg::RecalcBounds()
952 m_layout
.yMax
= m_layout
.xMax
= -DBL_MAX
;
953 m_layout
.yMin
= m_layout
.xMin
= DBL_MAX
;
955 double SIN
= sin(rad(m_layout
.rot
));
956 double COS
= cos(rad(m_layout
.rot
));
957 double SINT
= sin(rad(m_layout
.tilt
));
958 double COST
= cos(rad(m_layout
.tilt
));
960 int show_mask
= m_layout
.get_effective_show_mask();
961 if (show_mask
& LEGS
) {
962 for (int f
= 0; f
!= 8; ++f
) {
963 if ((show_mask
& (f
& img_FLAG_SURFACE
) ? SURF
: LEGS
) == 0) {
964 // Not showing traverse because of surface/underground status.
967 if ((f
& img_FLAG_SPLAY
) && (show_mask
& SPLAYS
) == 0) {
968 // Not showing because it's a splay.
971 list
<traverse
>::const_iterator trav
= mainfrm
->traverses_begin(f
);
972 list
<traverse
>::const_iterator tend
= mainfrm
->traverses_end(f
);
973 for ( ; trav
!= tend
; ++trav
) {
974 vector
<PointInfo
>::const_iterator pos
= trav
->begin();
975 vector
<PointInfo
>::const_iterator end
= trav
->end();
976 for ( ; pos
!= end
; ++pos
) {
977 double x
= pos
->GetX();
978 double y
= pos
->GetY();
979 double z
= pos
->GetZ();
980 double X
= x
* COS
- y
* SIN
;
981 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
982 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
983 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
984 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
985 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
991 if ((show_mask
& XSECT
) &&
992 (m_layout
.tilt
== 0.0 || m_layout
.tilt
== 90.0 || m_layout
.tilt
== -90.0)) {
993 list
<vector
<XSect
> >::const_iterator trav
= mainfrm
->tubes_begin();
994 list
<vector
<XSect
> >::const_iterator tend
= mainfrm
->tubes_end();
995 for ( ; trav
!= tend
; ++trav
) {
997 Vector3
last_right(1.0, 0.0, 0.0);
999 vector
<XSect
>::const_iterator i
= trav
->begin();
1000 vector
<XSect
>::size_type segment
= 0;
1001 while (i
!= trav
->end()) {
1002 // get the coordinates of this vertex
1003 const XSect
& pt_v
= *i
++;
1004 if (m_layout
.tilt
== 0.0) {
1005 Double u
= pt_v
.GetU();
1006 Double d
= pt_v
.GetD();
1008 if (u
>= 0 || d
>= 0) {
1009 double x
= pt_v
.GetX();
1010 double y
= pt_v
.GetY();
1011 double z
= pt_v
.GetZ();
1012 double X
= x
* COS
- y
* SIN
;
1013 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1015 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1016 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1017 double U
= Y
+ max(0.0, pt_v
.GetU());
1018 if (U
> m_layout
.yMax
) m_layout
.yMax
= U
;
1019 double D
= Y
- max(0.0, pt_v
.GetD());
1020 if (D
< m_layout
.yMin
) m_layout
.yMin
= D
;
1023 // More complex, and this duplicates the algorithm from
1024 // PlotLR() - we should try to share that, maybe via a
1028 const Vector3
up_v(0.0, 0.0, 1.0);
1031 assert(i
!= trav
->end());
1034 // get the coordinates of the next vertex
1035 const XSect
& next_pt_v
= *i
;
1037 // calculate vector from this pt to the next one
1038 Vector3 leg_v
= next_pt_v
- pt_v
;
1040 // obtain a vector in the LRUD plane
1041 right
= leg_v
* up_v
;
1042 if (right
.magnitude() == 0) {
1047 } else if (segment
+ 1 == trav
->size()) {
1050 // Calculate vector from the previous pt to this one.
1051 Vector3 leg_v
= pt_v
- prev_pt_v
;
1053 // Obtain a horizontal vector in the LRUD plane.
1054 right
= leg_v
* up_v
;
1055 if (right
.magnitude() == 0) {
1056 right
= Vector3(last_right
.GetX(), last_right
.GetY(), 0.0);
1061 assert(i
!= trav
->end());
1062 // Intermediate segment.
1064 // Get the coordinates of the next vertex.
1065 const XSect
& next_pt_v
= *i
;
1067 // Calculate vectors from this vertex to the
1068 // next vertex, and from the previous vertex to
1070 Vector3 leg1_v
= pt_v
- prev_pt_v
;
1071 Vector3 leg2_v
= next_pt_v
- pt_v
;
1073 // Obtain horizontal vectors perpendicular to
1074 // both legs, then normalise and average to get
1075 // a horizontal bisector.
1076 Vector3 r1
= leg1_v
* up_v
;
1077 Vector3 r2
= leg2_v
* up_v
;
1081 if (right
.magnitude() == 0) {
1082 // This is the "mid-pitch" case...
1088 // Scale to unit vectors in the LRUD plane.
1091 Double l
= pt_v
.GetL();
1092 Double r
= pt_v
.GetR();
1094 if (l
>= 0 || r
>= 0) {
1095 // Get the x and y coordinates of the survey station
1096 double pt_X
= pt_v
.GetX() * COS
- pt_v
.GetY() * SIN
;
1097 double pt_Y
= pt_v
.GetX() * SIN
+ pt_v
.GetY() * COS
;
1101 // Get the x and y coordinates of the end of the left arrow
1102 Vector3 p
= pt_v
- right
* l
;
1103 X
= p
.GetX() * COS
- p
.GetY() * SIN
;
1104 Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
1109 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1110 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1111 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1112 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1115 // Get the x and y coordinates of the end of the right arrow
1116 Vector3 p
= pt_v
+ right
* r
;
1117 X
= p
.GetX() * COS
- p
.GetY() * SIN
;
1118 Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
1123 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1124 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1125 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1126 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1137 if (show_mask
& (LABELS
|STNS
)) {
1138 list
<LabelInfo
*>::const_iterator label
= mainfrm
->GetLabels();
1139 while (label
!= mainfrm
->GetLabelsEnd()) {
1140 double x
= (*label
)->GetX();
1141 double y
= (*label
)->GetY();
1142 double z
= (*label
)->GetZ();
1143 if ((show_mask
& SURF
) || (*label
)->IsUnderground()) {
1144 double X
= x
* COS
- y
* SIN
;
1145 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1146 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1147 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1148 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1149 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1156 static int xpPageWidth
, ypPageDepth
;
1157 static long x_offset
, y_offset
;
1158 static int fontsize
, fontsize_labels
;
1160 /* FIXME: allow the font to be set */
1162 static const char *fontname
= "Arial", *fontname_labels
= "Arial";
1164 svxPrintout::svxPrintout(MainFrm
*mainfrm_
, layout
*l
,
1165 wxPageSetupDialogData
*data
, const wxString
& title
)
1166 : wxPrintout(title
), font_labels(NULL
), font_default(NULL
),
1167 scan_for_blank_pages(false)
1175 svxPrintout::draw_info_box()
1177 layout
*l
= m_layout
;
1181 pdc
->SetPen(*pen_frame
);
1184 if (l
->view
!= layout::EXTELEV
) {
1185 boxwidth
+= boxheight
;
1186 MOVEMM(div
, boxheight
);
1188 MOVEMM(0, 30); DRAWMM(div
, 30);
1191 MOVEMM(0, boxheight
);
1192 DRAWMM(boxwidth
, boxheight
);
1193 DRAWMM(boxwidth
, 0);
1196 DRAWMM(0, boxheight
);
1199 MOVEMM(0, 20); DRAWMM(div
, 20);
1200 MOVEMM(0, 10); DRAWMM(div
, 10);
1203 case layout::PLAN
: {
1204 long ax
, ay
, bx
, by
, cx
, cy
, dx
, dy
;
1206 long xc
= boxwidth
- boxheight
/ 2;
1207 long yc
= boxheight
/ 2;
1208 const double RADIUS
= boxheight
/ 3;
1209 DrawEllipse(long(xc
* l
->scX
), long(yc
* l
->scY
),
1210 long(RADIUS
* l
->scX
), long(RADIUS
* l
->scY
));
1212 ax
= (long)((xc
- (RADIUS
- 1) * sin(rad(000.0 + l
->rot
))) * l
->scX
);
1213 ay
= (long)((yc
+ (RADIUS
- 1) * cos(rad(000.0 + l
->rot
))) * l
->scY
);
1214 bx
= (long)((xc
- RADIUS
* 0.5 * sin(rad(180.0 + l
->rot
))) * l
->scX
);
1215 by
= (long)((yc
+ RADIUS
* 0.5 * cos(rad(180.0 + l
->rot
))) * l
->scY
);
1216 cx
= (long)((xc
- (RADIUS
- 1) * sin(rad(160.0 + l
->rot
))) * l
->scX
);
1217 cy
= (long)((yc
+ (RADIUS
- 1) * cos(rad(160.0 + l
->rot
))) * l
->scY
);
1218 dx
= (long)((xc
- (RADIUS
- 1) * sin(rad(200.0 + l
->rot
))) * l
->scX
);
1219 dy
= (long)((yc
+ (RADIUS
- 1) * cos(rad(200.0 + l
->rot
))) * l
->scY
);
1228 pdc
->SetTextForeground(colour_text
);
1229 MOVEMM(div
+ 0.5, boxheight
- 5.5);
1230 WriteString(wmsg(/*North*/115));
1232 wxString angle
= format_angle(ANGLE_FMT
, l
->rot
);
1234 /* TRANSLATORS: This is used on printouts of plans, with %s replaced by
1235 * something like "123°". The bearing is up the page. */
1236 s
.Printf(wmsg(/*Plan view, %s up page*/168), angle
.c_str());
1237 MOVEMM(2, 12); WriteString(s
);
1240 case layout::ELEV
: case layout::TILT
: {
1241 const int L
= div
+ 2;
1242 const int R
= boxwidth
- 2;
1243 const int H
= boxheight
/ 2;
1244 MOVEMM(L
, H
); DRAWMM(L
+ 5, H
- 3); DRAWMM(L
+ 3, H
); DRAWMM(L
+ 5, H
+ 3);
1246 DRAWMM(L
, H
); DRAWMM(R
, H
);
1248 DRAWMM(R
- 5, H
+ 3); DRAWMM(R
- 3, H
); DRAWMM(R
- 5, H
- 3); DRAWMM(R
, H
);
1250 MOVEMM((L
+ R
) / 2, H
- 2); DRAWMM((L
+ R
) / 2, H
+ 2);
1252 pdc
->SetTextForeground(colour_text
);
1253 MOVEMM(div
+ 2, boxheight
- 8);
1254 /* TRANSLATORS: "Elevation on" 020 <-> 200 degrees */
1255 WriteString(wmsg(/*Elevation on*/116));
1258 WriteString(format_angle(ANGLE_FMT
, fmod(l
->rot
+ 270.0, 360.0)));
1260 WriteString(format_angle(ANGLE_FMT
, fmod(l
->rot
+ 90.0, 360.0)));
1262 wxString angle
= format_angle(ANGLE_FMT
, l
->rot
);
1264 if (l
->view
== layout::ELEV
) {
1265 /* TRANSLATORS: This is used on printouts of elevations, with %s
1266 * replaced by something like "123°". The bearing is the direction
1268 s
.Printf(wmsg(/*Elevation facing %s*/169), angle
.c_str());
1270 wxString a2
= format_angle(ANGLE2_FMT
, l
->tilt
);
1271 /* TRANSLATORS: This is used on printouts of tilted elevations, with
1272 * the first %s replaced by something like "123°", and the second by
1273 * something like "-45°". The bearing is the direction we’re
1275 s
.Printf(wmsg(/*Elevation facing %s, tilted %s*/284), angle
.c_str(), a2
.c_str());
1277 MOVEMM(2, 12); WriteString(s
);
1280 case layout::EXTELEV
:
1281 pdc
->SetTextForeground(colour_text
);
1283 /* TRANSLATORS: This is used on printouts of extended elevations. */
1284 WriteString(wmsg(/*Extended elevation*/191));
1288 MOVEMM(2, boxheight
- 8); WriteString(l
->title
);
1291 // FIXME: "Original Scale" better?
1292 WriteString(wxString::Format(wmsg(/*Scale*/154) + wxT(" 1:%.0f"),
1295 /* This used to be a copyright line, but it was occasionally
1296 * mis-interpreted as us claiming copyright on the survey, so let's
1297 * give the website URL instead */
1298 MOVEMM(boxwidth
+ 2, 2);
1299 WriteString(wxT("Survex " VERSION
" - https://survex.com/"));
1301 draw_scale_bar(boxwidth
+ 10.0, 17.0, l
->PaperWidth
- boxwidth
- 18.0);
1304 /* Draw fancy scale bar with bottom left at (x,y) (both in mm) and at most */
1305 /* MaxLength mm long. The scaling in use is 1:scale */
1307 svxPrintout::draw_scale_bar(double x
, double y
, double MaxLength
)
1312 /* Limit scalebar to 20cm to stop people with A0 plotters complaining */
1313 if (MaxLength
> 200.0) MaxLength
= 200.0;
1315 #define dmin 10.0 /* each division >= dmin mm long */
1316 #define StepMax 5 /* number in steps of at most StepMax (x 10^N) */
1317 #define epsilon (1e-4) /* fudge factor to prevent rounding problems */
1319 E
= (int)ceil(log10((dmin
* 0.001 * m_layout
->Scale
) / StepMax
));
1320 StepEst
= pow(10.0, -(double)E
) * (dmin
* 0.001) * m_layout
->Scale
- epsilon
;
1322 /* Force labelling to be in multiples of 1, 2, or 5 */
1323 Step
= (StepEst
<= 1.0 ? 1 : (StepEst
<= 2.0 ? 2 : 5));
1325 /* Work out actual length of each scale bar division */
1326 d
= Step
* pow(10.0, (double)E
) / m_layout
->Scale
* 1000.0;
1328 /* FIXME: Non-metric units here... */
1329 /* Choose appropriate units, s.t. if possible E is >=0 and minimized */
1334 } else if (E
>= 0) {
1341 buf
= wmsg(/*Scale*/154);
1343 /* Add units used - eg. "Scale (10m)" */
1344 double pow10_E
= pow(10.0, (double)E
);
1346 buf
+= wxString::Format(wxT(" (%.f%s)"), pow10_E
, wmsg(units
).c_str());
1348 int sf
= -(int)floor(E
);
1349 buf
+= wxString::Format(wxT(" (%.*f%s)"), sf
, pow10_E
, wmsg(units
).c_str());
1351 pdc
->SetTextForeground(colour_text
);
1352 MOVEMM(x
, y
+ 4); WriteString(buf
);
1354 /* Work out how many divisions there will be */
1355 n
= (int)(MaxLength
/ d
);
1357 pdc
->SetPen(*pen_frame
);
1359 long Y
= long(y
* m_layout
->scY
);
1360 long Y2
= long((y
+ 3) * m_layout
->scY
);
1361 long X
= long(x
* m_layout
->scX
);
1362 long X2
= long((x
+ n
* d
) * m_layout
->scX
);
1364 /* Draw top of scale bar */
1370 MOVEMM(x
+ n
* d
, y
); DRAWMM(x
, y
);
1372 /* Draw divisions and label them */
1373 for (c
= 0; c
<= n
; c
++) {
1374 pdc
->SetPen(*pen_frame
);
1375 X
= long((x
+ c
* d
) * m_layout
->scX
);
1378 #if 0 // Don't waste toner!
1379 /* Draw a "zebra crossing" scale bar. */
1380 if (c
< n
&& (c
& 1) == 0) {
1381 X2
= long((x
+ (c
+ 1) * d
) * m_layout
->scX
);
1382 SolidRectangle(X
, Y
, X2
- X
, Y2
- Y
);
1385 buf
.Printf(wxT("%d"), c
* Step
);
1386 pdc
->SetTextForeground(colour_text
);
1387 MOVEMM(x
+ c
* d
- buf
.length(), y
- 5);
1394 make_calibration(layout
*l
) {
1395 img_point pt
= { 0.0, 0.0, 0.0 };
1396 l
->xMax
= l
->yMax
= 0.1;
1397 l
->xMin
= l
->yMin
= 0;
1399 stack(l
, img_MOVE
, NULL
, &pt
);
1401 stack(l
, img_LINE
, NULL
, &pt
);
1403 stack(l
, img_LINE
, NULL
, &pt
);
1405 stack(l
, img_LINE
, NULL
, &pt
);
1407 stack(l
, img_LINE
, NULL
, &pt
);
1410 stack(l
, img_LABEL
, "10cm", &pt
);
1413 stack(l
, img_LABEL
, "10cm", &pt
);
1419 svxPrintout::next_page(int *pstate
, char **q
, int pageLim
)
1428 wxASSERT(*p
== '-');
1430 while (isspace((unsigned char)*p
)) p
++;
1431 if (sscanf(p
, "%u%n", &page
, &c
) > 0) {
1436 if (*pstate
> page
) goto err
;
1437 if (*pstate
< page
) return *pstate
;
1443 while (isspace((unsigned char)*p
) || *p
== ',') p
++;
1445 if (!*p
) return 0; /* done */
1450 return 1; /* range with initial parameter omitted */
1452 if (sscanf(p
, "%u%n", &page
, &c
) > 0) {
1454 while (isspace((unsigned char)*p
)) p
++;
1456 if (0 < page
&& page
<= pageLim
) {
1457 if (*p
== '-') *pstate
= page
; /* range with start */
1466 /* Draws in alignment marks on each page or borders on edge pages */
1468 svxPrintout::drawticks(int tsize
, int x
, int y
)
1473 bool fAtCorner
= fFalse
;
1474 pdc
->SetPen(*pen_frame
);
1475 if (x
== 0 && m_layout
->Border
) {
1476 /* solid left border */
1477 MoveTo(clip
.x_min
, clip
.y_min
);
1478 DrawTo(clip
.x_min
, clip
.y_max
);
1481 if (x
> 0 || y
> 0) {
1482 MoveTo(clip
.x_min
, clip
.y_min
);
1483 DrawTo(clip
.x_min
, clip
.y_min
+ tsize
);
1485 if (s
&& x
> 0 && m_layout
->Cutlines
) {
1486 /* dashed left border */
1487 i
= (clip
.y_max
- clip
.y_min
) -
1488 (tsize
+ ((clip
.y_max
- clip
.y_min
- tsize
* 2L) % s
) / 2);
1489 for ( ; i
> tsize
; i
-= s
) {
1490 MoveTo(clip
.x_min
, clip
.y_max
- (i
+ o
));
1491 DrawTo(clip
.x_min
, clip
.y_max
- (i
- o
));
1494 if (x
> 0 || y
< m_layout
->pagesY
- 1) {
1495 MoveTo(clip
.x_min
, clip
.y_max
- tsize
);
1496 DrawTo(clip
.x_min
, clip
.y_max
);
1501 if (y
== m_layout
->pagesY
- 1 && m_layout
->Border
) {
1502 /* solid top border */
1503 if (!fAtCorner
) MoveTo(clip
.x_min
, clip
.y_max
);
1504 DrawTo(clip
.x_max
, clip
.y_max
);
1507 if (y
< m_layout
->pagesY
- 1 || x
> 0) {
1508 if (!fAtCorner
) MoveTo(clip
.x_min
, clip
.y_max
);
1509 DrawTo(clip
.x_min
+ tsize
, clip
.y_max
);
1511 if (s
&& y
< m_layout
->pagesY
- 1 && m_layout
->Cutlines
) {
1512 /* dashed top border */
1513 i
= (clip
.x_max
- clip
.x_min
) -
1514 (tsize
+ ((clip
.x_max
- clip
.x_min
- tsize
* 2L) % s
) / 2);
1515 for ( ; i
> tsize
; i
-= s
) {
1516 MoveTo(clip
.x_max
- (i
+ o
), clip
.y_max
);
1517 DrawTo(clip
.x_max
- (i
- o
), clip
.y_max
);
1520 if (y
< m_layout
->pagesY
- 1 || x
< m_layout
->pagesX
- 1) {
1521 MoveTo(clip
.x_max
- tsize
, clip
.y_max
);
1522 DrawTo(clip
.x_max
, clip
.y_max
);
1529 if (x
== m_layout
->pagesX
- 1 && m_layout
->Border
) {
1530 /* solid right border */
1531 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_max
);
1532 DrawTo(clip
.x_max
, clip
.y_min
);
1535 if (x
< m_layout
->pagesX
- 1 || y
< m_layout
->pagesY
- 1) {
1536 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_max
);
1537 DrawTo(clip
.x_max
, clip
.y_max
- tsize
);
1539 if (s
&& x
< m_layout
->pagesX
- 1 && m_layout
->Cutlines
) {
1540 /* dashed right border */
1541 i
= (clip
.y_max
- clip
.y_min
) -
1542 (tsize
+ ((clip
.y_max
- clip
.y_min
- tsize
* 2L) % s
) / 2);
1543 for ( ; i
> tsize
; i
-= s
) {
1544 MoveTo(clip
.x_max
, clip
.y_min
+ (i
+ o
));
1545 DrawTo(clip
.x_max
, clip
.y_min
+ (i
- o
));
1548 if (x
< m_layout
->pagesX
- 1 || y
> 0) {
1549 MoveTo(clip
.x_max
, clip
.y_min
+ tsize
);
1550 DrawTo(clip
.x_max
, clip
.y_min
);
1557 if (y
== 0 && m_layout
->Border
) {
1558 /* solid bottom border */
1559 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_min
);
1560 DrawTo(clip
.x_min
, clip
.y_min
);
1562 if (y
> 0 || x
< m_layout
->pagesX
- 1) {
1563 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_min
);
1564 DrawTo(clip
.x_max
- tsize
, clip
.y_min
);
1566 if (s
&& y
> 0 && m_layout
->Cutlines
) {
1567 /* dashed bottom border */
1568 i
= (clip
.x_max
- clip
.x_min
) -
1569 (tsize
+ ((clip
.x_max
- clip
.x_min
- tsize
* 2L) % s
) / 2);
1570 for ( ; i
> tsize
; i
-= s
) {
1571 MoveTo(clip
.x_min
+ (i
+ o
), clip
.y_min
);
1572 DrawTo(clip
.x_min
+ (i
- o
), clip
.y_min
);
1575 if (y
> 0 || x
> 0) {
1576 MoveTo(clip
.x_min
+ tsize
, clip
.y_min
);
1577 DrawTo(clip
.x_min
, clip
.y_min
);
1583 svxPrintout::OnPrintPage(int pageNum
) {
1584 GetPageSizePixels(&xpPageWidth
, &ypPageDepth
);
1586 pdc
->SetBackgroundMode(wxTRANSPARENT
);
1587 #ifdef AVEN_PRINT_PREVIEW
1590 pdc
->GetSize(&dcx
, &dcy
);
1591 pdc
->SetUserScale((double)dcx
/ xpPageWidth
, (double)dcy
/ ypPageDepth
);
1595 layout
* l
= m_layout
;
1598 GetPageSizeMM(&pwidth
, &pdepth
);
1599 l
->scX
= (double)xpPageWidth
/ pwidth
;
1600 l
->scY
= (double)ypPageDepth
/ pdepth
;
1601 font_scaling_x
= l
->scX
* (25.4 / 72.0);
1602 font_scaling_y
= l
->scY
* (25.4 / 72.0);
1603 long MarginLeft
= m_data
->GetMarginTopLeft().x
;
1604 long MarginTop
= m_data
->GetMarginTopLeft().y
;
1605 long MarginBottom
= m_data
->GetMarginBottomRight().y
;
1606 long MarginRight
= m_data
->GetMarginBottomRight().x
;
1607 xpPageWidth
-= (int)(l
->scX
* (MarginLeft
+ MarginRight
));
1608 ypPageDepth
-= (int)(l
->scY
* (FOOTER_HEIGHT_MM
+ MarginBottom
+ MarginTop
));
1609 // xpPageWidth -= 1;
1610 pdepth
-= FOOTER_HEIGHT_MM
;
1611 x_offset
= (long)(l
->scX
* MarginLeft
);
1612 y_offset
= (long)(l
->scY
* MarginTop
);
1613 l
->PaperWidth
= pwidth
-= MarginLeft
+ MarginRight
;
1614 l
->PaperDepth
= pdepth
-= MarginTop
+ MarginBottom
;
1617 double SIN
= sin(rad(l
->rot
));
1618 double COS
= cos(rad(l
->rot
));
1619 double SINT
= sin(rad(l
->tilt
));
1620 double COST
= cos(rad(l
->tilt
));
1622 NewPage(pageNum
, l
->pagesX
, l
->pagesY
);
1624 if (l
->Legend
&& pageNum
== (l
->pagesY
- 1) * l
->pagesX
+ 1) {
1625 SetFont(font_default
);
1629 pdc
->SetClippingRegion(x_offset
, y_offset
, xpPageWidth
+ 1, ypPageDepth
+ 1);
1631 const double Sc
= 1000 / l
->Scale
;
1633 int show_mask
= l
->get_effective_show_mask();
1634 if (show_mask
& (LEGS
|SURF
)) {
1635 for (int f
= 0; f
!= 8; ++f
) {
1636 if ((show_mask
& (f
& img_FLAG_SURFACE
) ? SURF
: LEGS
) == 0) {
1637 // Not showing traverse because of surface/underground status.
1640 if ((f
& img_FLAG_SPLAY
) && (show_mask
& SPLAYS
) == 0) {
1641 // Not showing because it's a splay.
1644 if (f
& img_FLAG_SPLAY
) {
1645 pdc
->SetPen(*pen_splay
);
1646 } else if (f
& img_FLAG_SURFACE
) {
1647 pdc
->SetPen(*pen_surface_leg
);
1649 pdc
->SetPen(*pen_leg
);
1651 list
<traverse
>::const_iterator trav
= mainfrm
->traverses_begin(f
);
1652 list
<traverse
>::const_iterator tend
= mainfrm
->traverses_end(f
);
1653 for ( ; trav
!= tend
; ++trav
) {
1654 vector
<PointInfo
>::const_iterator pos
= trav
->begin();
1655 vector
<PointInfo
>::const_iterator end
= trav
->end();
1656 for ( ; pos
!= end
; ++pos
) {
1657 double x
= pos
->GetX();
1658 double y
= pos
->GetY();
1659 double z
= pos
->GetZ();
1660 double X
= x
* COS
- y
* SIN
;
1661 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1662 long px
= (long)((X
* Sc
+ l
->xOrg
) * l
->scX
);
1663 long py
= (long)((Y
* Sc
+ l
->yOrg
) * l
->scY
);
1664 if (pos
== trav
->begin()) {
1674 if ((show_mask
& XSECT
) &&
1675 (l
->tilt
== 0.0 || l
->tilt
== 90.0 || l
->tilt
== -90.0)) {
1676 pdc
->SetPen(*pen_splay
);
1677 list
<vector
<XSect
> >::const_iterator trav
= mainfrm
->tubes_begin();
1678 list
<vector
<XSect
> >::const_iterator tend
= mainfrm
->tubes_end();
1679 for ( ; trav
!= tend
; ++trav
) {
1680 if (l
->tilt
== 0.0) {
1683 // m_layout.tilt is 90.0 or -90.0 due to check above.
1689 if (show_mask
& (LABELS
|STNS
)) {
1690 if (show_mask
& LABELS
) SetFont(font_labels
);
1691 list
<LabelInfo
*>::const_iterator label
= mainfrm
->GetLabels();
1692 while (label
!= mainfrm
->GetLabelsEnd()) {
1693 double px
= (*label
)->GetX();
1694 double py
= (*label
)->GetY();
1695 double pz
= (*label
)->GetZ();
1696 if ((show_mask
& SURF
) || (*label
)->IsUnderground()) {
1697 double X
= px
* COS
- py
* SIN
;
1698 double Y
= pz
* COST
- (px
* SIN
+ py
* COS
) * SINT
;
1700 xnew
= (long)((X
* Sc
+ l
->xOrg
) * l
->scX
);
1701 ynew
= (long)((Y
* Sc
+ l
->yOrg
) * l
->scY
);
1702 if (show_mask
& STNS
) {
1703 pdc
->SetPen(*pen_cross
);
1704 DrawCross(xnew
, ynew
);
1706 if (show_mask
& LABELS
) {
1707 pdc
->SetTextForeground(colour_labels
);
1709 WriteString((*label
)->GetText());
1720 svxPrintout::GetPageInfo(int *minPage
, int *maxPage
,
1721 int *pageFrom
, int *pageTo
)
1723 *minPage
= *pageFrom
= 1;
1724 *maxPage
= *pageTo
= m_layout
->pages
;
1728 svxPrintout::HasPage(int pageNum
) {
1729 return (pageNum
<= m_layout
->pages
);
1733 svxPrintout::OnBeginPrinting() {
1734 /* Initialise printer routines */
1735 fontsize_labels
= 10;
1738 colour_text
= colour_labels
= *wxBLACK
;
1740 wxColour colour_frame
, colour_cross
, colour_leg
, colour_surface_leg
;
1741 colour_frame
= colour_cross
= colour_leg
= colour_surface_leg
= *wxBLACK
;
1743 pen_frame
= new wxPen(colour_frame
);
1744 pen_cross
= new wxPen(colour_cross
);
1745 pen_leg
= new wxPen(colour_leg
);
1746 pen_surface_leg
= new wxPen(colour_surface_leg
);
1747 pen_splay
= new wxPen(wxColour(128, 128, 128));
1752 font_labels
= new wxFont(fontsize_labels
, wxFONTFAMILY_DEFAULT
,
1753 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
1754 false, wxString(fontname_labels
, wxConvUTF8
),
1755 wxFONTENCODING_ISO8859_1
);
1756 font_default
= new wxFont(fontsize
, wxFONTFAMILY_DEFAULT
,
1757 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
1758 false, wxString(fontname
, wxConvUTF8
),
1759 wxFONTENCODING_ISO8859_1
);
1763 svxPrintout::OnEndPrinting() {
1765 delete font_default
;
1769 delete pen_surface_leg
;
1774 svxPrintout::check_intersection(long x_p
, long y_p
)
1780 int mask_p
= 0, mask_t
= 0;
1783 else if (x_p
> xpPageWidth
)
1788 else if (y_p
> ypPageDepth
)
1793 else if (x_t
> xpPageWidth
)
1798 else if (y_t
> ypPageDepth
)
1802 /* approximation to correct answer */
1803 return !(mask_t
& mask_p
);
1805 /* One end of the line is on the page */
1806 if (!mask_t
|| !mask_p
) return 1;
1808 /* whole line is above, left, right, or below page */
1809 if (mask_t
& mask_p
) return 0;
1811 if (mask_t
== 0) mask_t
= mask_p
;
1813 double v
= (double)(y_p
- ypPageDepth
) / (y_p
- y_t
);
1814 return v
>= 0 && v
<= 1;
1817 double v
= (double)y_p
/ (y_p
- y_t
);
1818 return v
>= 0 && v
<= 1;
1821 double v
= (double)(x_p
- xpPageWidth
) / (x_p
- x_t
);
1822 return v
>= 0 && v
<= 1;
1824 wxASSERT(mask_t
& L
);
1826 double v
= (double)x_p
/ (x_p
- x_t
);
1827 return v
>= 0 && v
<= 1;
1837 svxPrintout::MoveTo(long x
, long y
)
1839 x_t
= x_offset
+ x
- clip
.x_min
;
1840 y_t
= y_offset
+ clip
.y_max
- y
;
1844 svxPrintout::DrawTo(long x
, long y
)
1846 long x_p
= x_t
, y_p
= y_t
;
1847 x_t
= x_offset
+ x
- clip
.x_min
;
1848 y_t
= y_offset
+ clip
.y_max
- y
;
1849 if (!scan_for_blank_pages
) {
1850 pdc
->DrawLine(x_p
, y_p
, x_t
, y_t
);
1852 if (check_intersection(x_p
, y_p
)) fBlankPage
= fFalse
;
1856 #define POINTS_PER_INCH 72.0
1857 #define POINTS_PER_MM (POINTS_PER_INCH / MM_PER_INCH)
1858 #define PWX_CROSS_SIZE (int)(2 * m_layout->scX / POINTS_PER_MM)
1861 svxPrintout::DrawCross(long x
, long y
)
1863 if (!scan_for_blank_pages
) {
1864 MoveTo(x
- PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
1865 DrawTo(x
+ PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
1866 MoveTo(x
+ PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
1867 DrawTo(x
- PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
1870 if ((x
+ PWX_CROSS_SIZE
> clip
.x_min
&&
1871 x
- PWX_CROSS_SIZE
< clip
.x_max
) ||
1872 (y
+ PWX_CROSS_SIZE
> clip
.y_min
&&
1873 y
- PWX_CROSS_SIZE
< clip
.y_max
)) {
1874 fBlankPage
= fFalse
;
1880 svxPrintout::WriteString(const wxString
& s
)
1883 pdc
->GetUserScale(&xsc
, &ysc
);
1884 pdc
->SetUserScale(xsc
* font_scaling_x
, ysc
* font_scaling_y
);
1885 if (!scan_for_blank_pages
) {
1887 long(x_t
/ font_scaling_x
),
1888 long(y_t
/ font_scaling_y
) - pdc
->GetCharHeight());
1891 pdc
->GetTextExtent(s
, &w
, &h
);
1892 if ((y_t
+ h
> 0 && y_t
- h
< clip
.y_max
- clip
.y_min
) ||
1893 (x_t
< clip
.x_max
- clip
.x_min
&& x_t
+ w
> 0)) {
1894 fBlankPage
= fFalse
;
1897 pdc
->SetUserScale(xsc
, ysc
);
1901 svxPrintout::DrawEllipse(long x
, long y
, long r
, long R
)
1903 if (!scan_for_blank_pages
) {
1904 x_t
= x_offset
+ x
- clip
.x_min
;
1905 y_t
= y_offset
+ clip
.y_max
- y
;
1906 const wxBrush
& save_brush
= pdc
->GetBrush();
1907 pdc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1908 pdc
->DrawEllipse(x_t
- r
, y_t
- R
, 2 * r
, 2 * R
);
1909 pdc
->SetBrush(save_brush
);
1911 /* No need to check - this is only used in the legend. */
1916 svxPrintout::SolidRectangle(long x
, long y
, long w
, long h
)
1918 long X
= x_offset
+ x
- clip
.x_min
;
1919 long Y
= y_offset
+ clip
.y_max
- y
;
1920 pdc
->SetBrush(*wxBLACK_BRUSH
);
1921 pdc
->DrawRectangle(X
, Y
- h
, w
, h
);
1925 svxPrintout::NewPage(int pg
, int pagesX
, int pagesY
)
1927 pdc
->DestroyClippingRegion();
1930 x
= (pg
- 1) % pagesX
;
1931 y
= pagesY
- 1 - ((pg
- 1) / pagesX
);
1933 clip
.x_min
= (long)x
* xpPageWidth
;
1934 clip
.y_min
= (long)y
* ypPageDepth
;
1935 clip
.x_max
= clip
.x_min
+ xpPageWidth
; /* dm/pcl/ps had -1; */
1936 clip
.y_max
= clip
.y_min
+ ypPageDepth
; /* dm/pcl/ps had -1; */
1938 const int FOOTERS
= 4;
1939 wxString footer
[FOOTERS
];
1940 footer
[0] = m_layout
->title
;
1942 double rot
= m_layout
->rot
;
1943 double tilt
= m_layout
->tilt
;
1944 double scale
= m_layout
->Scale
;
1945 switch (m_layout
->view
) {
1947 // TRANSLATORS: Used in the footer of printouts to compactly
1948 // indicate this is a plan view and what the viewing angle is.
1949 // Aven will replace %s with the bearing, and %.0f with the scale.
1951 // This message probably doesn't need translating for most languages.
1952 footer
[1].Printf(wmsg(/*↑%s 1:%.0f*/233),
1953 format_angle(ANGLE_FMT
, rot
).c_str(),
1957 // TRANSLATORS: Used in the footer of printouts to compactly
1958 // indicate this is an elevation view and what the viewing angle
1959 // is. Aven will replace the %s codes with the bearings to the
1960 // left and right of the viewer, and %.0f with the scale.
1962 // This message probably doesn't need translating for most languages.
1963 footer
[1].Printf(wmsg(/*%s↔%s 1:%.0f*/235),
1964 format_angle(ANGLE_FMT
, fmod(rot
+ 270.0, 360.0)).c_str(),
1965 format_angle(ANGLE_FMT
, fmod(rot
+ 90.0, 360.0)).c_str(),
1969 // TRANSLATORS: Used in the footer of printouts to compactly
1970 // indicate this is a tilted elevation view and what the viewing
1971 // angles are. Aven will replace the %s codes with the bearings to
1972 // the left and right of the viewer and the angle the view is
1973 // tilted at, and %.0f with the scale.
1975 // This message probably doesn't need translating for most languages.
1976 footer
[1].Printf(wmsg(/*%s↔%s ∡%s 1:%.0f*/236),
1977 format_angle(ANGLE_FMT
, fmod(rot
+ 270.0, 360.0)).c_str(),
1978 format_angle(ANGLE_FMT
, fmod(rot
+ 90.0, 360.0)).c_str(),
1979 format_angle(ANGLE2_FMT
, tilt
).c_str(),
1982 case layout::EXTELEV
:
1983 // TRANSLATORS: Used in the footer of printouts to compactly
1984 // indicate this is an extended elevation view. Aven will replace
1985 // %.0f with the scale.
1987 // Try to keep the translation short (for example, in English we
1988 // use "Extended" not "Extended elevation") - there is limited room
1989 // in the footer, and the details there are mostly to make it easy
1990 // to check that you have corresponding pages from a multiple page
1992 footer
[1].Printf(wmsg(/*Extended 1:%.0f*/244), scale
);
1996 // TRANSLATORS: N/M meaning page N of M in the page footer of a printout.
1997 footer
[2].Printf(wmsg(/*%d/%d*/232), pg
, m_layout
->pagesX
* m_layout
->pagesY
);
1999 wxString datestamp
= m_layout
->datestamp
;
2000 if (!datestamp
.empty()) {
2001 // Remove any timezone suffix (e.g. " UTC" or " +1200").
2002 wxChar ch
= datestamp
[datestamp
.size() - 1];
2003 if (ch
>= 'A' && ch
<= 'Z') {
2004 for (size_t i
= datestamp
.size() - 1; i
; --i
) {
2006 if (ch
< 'A' || ch
> 'Z') {
2007 if (ch
== ' ') datestamp
.resize(i
);
2011 } else if (ch
>= '0' && ch
<= '9') {
2012 for (size_t i
= datestamp
.size() - 1; i
; --i
) {
2014 if (ch
< '0' || ch
> '9') {
2015 if ((ch
== '-' || ch
== '+') && datestamp
[--i
] == ' ')
2016 datestamp
.resize(i
);
2022 // Remove any day prefix (e.g. "Mon,").
2023 for (size_t i
= 0; i
!= datestamp
.size(); ++i
) {
2024 if (datestamp
[i
] == ',' && i
+ 1 != datestamp
.size()) {
2025 // Also skip a space after the comma.
2026 if (datestamp
[i
+ 1] == ' ') ++i
;
2027 datestamp
.erase(0, i
+ 1);
2033 // TRANSLATORS: Used in the footer of printouts to compactly indicate that
2034 // the date which follows is the date that the survey data was processed.
2036 // Aven will replace %s with a string giving the date and time (e.g.
2037 // "2015-06-09 12:40:44").
2038 footer
[3].Printf(wmsg(/*Processed: %s*/167), datestamp
.c_str());
2040 const wxChar
* footer_sep
= wxT(" ");
2041 int fontsize_footer
= fontsize_labels
;
2042 wxFont
* font_footer
;
2043 font_footer
= new wxFont(fontsize_footer
, wxFONTFAMILY_DEFAULT
,
2044 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
2045 false, wxString(fontname_labels
, wxConvUTF8
),
2046 wxFONTENCODING_UTF8
);
2047 font_footer
->Scale(font_scaling_x
);
2048 SetFont(font_footer
);
2049 int w
[FOOTERS
], ws
, h
;
2050 pdc
->GetTextExtent(footer_sep
, &ws
, &h
);
2051 int wtotal
= ws
* (FOOTERS
- 1);
2052 for (int i
= 0; i
< FOOTERS
; ++i
) {
2053 pdc
->GetTextExtent(footer
[i
], &w
[i
], &h
);
2058 long Y
= y_offset
+ ypPageDepth
+ (long)(7 * m_layout
->scY
) - pdc
->GetCharHeight();
2060 if (wtotal
> xpPageWidth
) {
2061 // Rescale the footer so it fits.
2062 double rescale
= double(wtotal
) / xpPageWidth
;
2064 pdc
->GetUserScale(&xsc
, &ysc
);
2065 pdc
->SetUserScale(xsc
/ rescale
, ysc
/ rescale
);
2066 SetFont(font_footer
);
2067 wxString fullfooter
= footer
[0];
2068 for (int i
= 1; i
< FOOTERS
- 1; ++i
) {
2069 fullfooter
+= footer_sep
;
2070 fullfooter
+= footer
[i
];
2072 pdc
->DrawText(fullfooter
, X
* rescale
, Y
* rescale
);
2073 // Draw final item right aligned to avoid misaligning.
2074 wxRect
rect(x_offset
* rescale
, Y
* rescale
,
2075 xpPageWidth
* rescale
, pdc
->GetCharHeight() * rescale
);
2076 pdc
->DrawLabel(footer
[FOOTERS
- 1], rect
, wxALIGN_RIGHT
|wxALIGN_TOP
);
2077 pdc
->SetUserScale(xsc
, ysc
);
2079 // Space out the elements of the footer to fill the line.
2080 double extra
= double(xpPageWidth
- wtotal
) / (FOOTERS
- 1);
2081 for (int i
= 0; i
< FOOTERS
- 1; ++i
) {
2082 pdc
->DrawText(footer
[i
], X
+ extra
* i
, Y
);
2085 // Draw final item right aligned to avoid misaligning.
2086 wxRect
rect(x_offset
, Y
, xpPageWidth
, pdc
->GetCharHeight());
2087 pdc
->DrawLabel(footer
[FOOTERS
- 1], rect
, wxALIGN_RIGHT
|wxALIGN_TOP
);
2089 drawticks((int)(9 * m_layout
->scX
/ POINTS_PER_MM
), x
, y
);
2093 svxPrintout::PlotLR(const vector
<XSect
> & centreline
)
2095 assert(centreline
.size() > 1);
2097 Vector3
last_right(1.0, 0.0, 0.0);
2099 const double Sc
= 1000 / m_layout
->Scale
;
2100 const double SIN
= sin(rad(m_layout
->rot
));
2101 const double COS
= cos(rad(m_layout
->rot
));
2103 vector
<XSect
>::const_iterator i
= centreline
.begin();
2104 vector
<XSect
>::size_type segment
= 0;
2105 while (i
!= centreline
.end()) {
2106 // get the coordinates of this vertex
2107 const XSect
& pt_v
= *i
++;
2111 const Vector3
up_v(0.0, 0.0, 1.0);
2114 assert(i
!= centreline
.end());
2117 // get the coordinates of the next vertex
2118 const XSect
& next_pt_v
= *i
;
2120 // calculate vector from this pt to the next one
2121 Vector3 leg_v
= next_pt_v
- pt_v
;
2123 // obtain a vector in the LRUD plane
2124 right
= leg_v
* up_v
;
2125 if (right
.magnitude() == 0) {
2130 } else if (segment
+ 1 == centreline
.size()) {
2133 // Calculate vector from the previous pt to this one.
2134 Vector3 leg_v
= pt_v
- prev_pt_v
;
2136 // Obtain a horizontal vector in the LRUD plane.
2137 right
= leg_v
* up_v
;
2138 if (right
.magnitude() == 0) {
2139 right
= Vector3(last_right
.GetX(), last_right
.GetY(), 0.0);
2144 assert(i
!= centreline
.end());
2145 // Intermediate segment.
2147 // Get the coordinates of the next vertex.
2148 const XSect
& next_pt_v
= *i
;
2150 // Calculate vectors from this vertex to the
2151 // next vertex, and from the previous vertex to
2153 Vector3 leg1_v
= pt_v
- prev_pt_v
;
2154 Vector3 leg2_v
= next_pt_v
- pt_v
;
2156 // Obtain horizontal vectors perpendicular to
2157 // both legs, then normalise and average to get
2158 // a horizontal bisector.
2159 Vector3 r1
= leg1_v
* up_v
;
2160 Vector3 r2
= leg2_v
* up_v
;
2164 if (right
.magnitude() == 0) {
2165 // This is the "mid-pitch" case...
2171 // Scale to unit vectors in the LRUD plane.
2174 Double l
= pt_v
.GetL();
2175 Double r
= pt_v
.GetR();
2177 if (l
>= 0 || r
>= 0) {
2178 // Get the x and y coordinates of the survey station
2179 double pt_X
= pt_v
.GetX() * COS
- pt_v
.GetY() * SIN
;
2180 double pt_Y
= pt_v
.GetX() * SIN
+ pt_v
.GetY() * COS
;
2181 long pt_x
= (long)((pt_X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2182 long pt_y
= (long)((pt_Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2184 // Calculate dimensions for the right arrow
2185 double COSR
= right
.GetX();
2186 double SINR
= right
.GetY();
2187 long CROSS_MAJOR
= (COSR
+ SINR
) * PWX_CROSS_SIZE
;
2188 long CROSS_MINOR
= (COSR
- SINR
) * PWX_CROSS_SIZE
;
2191 // Get the x and y coordinates of the end of the left arrow
2192 Vector3 p
= pt_v
- right
* l
;
2193 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2194 double Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
2195 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2196 long y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2198 // Draw the arrow stem
2202 // Rotate the arrow by the page rotation
2203 long dx1
= (+CROSS_MINOR
) * COS
- (+CROSS_MAJOR
) * SIN
;
2204 long dy1
= (+CROSS_MINOR
) * SIN
+ (+CROSS_MAJOR
) * COS
;
2205 long dx2
= (+CROSS_MAJOR
) * COS
- (-CROSS_MINOR
) * SIN
;
2206 long dy2
= (+CROSS_MAJOR
) * SIN
+ (-CROSS_MINOR
) * COS
;
2209 MoveTo(x
+ dx1
, y
+ dy1
);
2211 DrawTo(x
+ dx2
, y
+ dy2
);
2215 // Get the x and y coordinates of the end of the right arrow
2216 Vector3 p
= pt_v
+ right
* r
;
2217 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2218 double Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
2219 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2220 long y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2222 // Draw the arrow stem
2226 // Rotate the arrow by the page rotation
2227 long dx1
= (-CROSS_MINOR
) * COS
- (-CROSS_MAJOR
) * SIN
;
2228 long dy1
= (-CROSS_MINOR
) * SIN
+ (-CROSS_MAJOR
) * COS
;
2229 long dx2
= (-CROSS_MAJOR
) * COS
- (+CROSS_MINOR
) * SIN
;
2230 long dy2
= (-CROSS_MAJOR
) * SIN
+ (+CROSS_MINOR
) * COS
;
2233 MoveTo(x
+ dx1
, y
+ dy1
);
2235 DrawTo(x
+ dx2
, y
+ dy2
);
2246 svxPrintout::PlotUD(const vector
<XSect
> & centreline
)
2248 assert(centreline
.size() > 1);
2249 const double Sc
= 1000 / m_layout
->Scale
;
2251 vector
<XSect
>::const_iterator i
= centreline
.begin();
2252 while (i
!= centreline
.end()) {
2253 // get the coordinates of this vertex
2254 const XSect
& pt_v
= *i
++;
2256 Double u
= pt_v
.GetU();
2257 Double d
= pt_v
.GetD();
2259 if (u
>= 0 || d
>= 0) {
2260 // Get the coordinates of the survey point
2262 double SIN
= sin(rad(m_layout
->rot
));
2263 double COS
= cos(rad(m_layout
->rot
));
2264 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2265 double Y
= p
.GetZ();
2266 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2267 long pt_y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scX
);
2270 // Get the y coordinate of the up arrow
2271 long y
= (long)(((Y
+ u
) * Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2273 // Draw the arrow stem
2277 // Draw the up arrow
2278 MoveTo(x
- PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
2280 DrawTo(x
+ PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
2284 // Get the y coordinate of the down arrow
2285 long y
= (long)(((Y
- d
) * Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2287 // Draw the arrow stem
2291 // Draw the down arrow
2292 MoveTo(x
- PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
2294 DrawTo(x
+ PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);