2 /* Aven printing code */
3 /* Copyright (C) 1993-2003,2004,2005,2006,2010,2011,2012,2013,2014,2015,2016,2017,2018 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('.');
122 class BitValidator
: public wxValidator
{
123 // Disallow assignment.
124 BitValidator
& operator=(const BitValidator
&);
132 BitValidator(int * val_
, int mask_
)
133 : val(val_
), mask(mask_
) { }
135 BitValidator(const BitValidator
&o
) : wxValidator() {
141 wxObject
*Clone() const { return new BitValidator(val
, mask
); }
143 bool Copy(const BitValidator
& o
) {
144 wxValidator::Copy(o
);
150 bool Validate(wxWindow
*) { return true; }
152 bool TransferToWindow() {
153 if (!m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
155 ((wxCheckBox
*)m_validatorWindow
)->SetValue(*val
& mask
);
159 bool TransferFromWindow() {
160 if (!m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
162 if (((wxCheckBox
*)m_validatorWindow
)->IsChecked())
170 class svxPrintout
: public wxPrintout
{
173 wxPageSetupDialogData
* m_data
;
175 wxFont
*font_labels
, *font_default
;
176 // Currently unused, but "skip blank pages" would use it.
177 bool scan_for_blank_pages
;
179 wxPen
*pen_frame
, *pen_cross
, *pen_leg
, *pen_surface_leg
, *pen_splay
;
180 wxColour colour_text
, colour_labels
;
183 double font_scaling_x
, font_scaling_y
;
186 long x_min
, y_min
, x_max
, y_max
;
191 int check_intersection(long x_p
, long y_p
);
192 void draw_info_box();
193 void draw_scale_bar(double x
, double y
, double MaxLength
);
194 int next_page(int *pstate
, char **q
, int pageLim
);
195 void drawticks(int tsize
, int x
, int y
);
197 void MOVEMM(double X
, double Y
) {
198 MoveTo((long)(X
* m_layout
->scX
), (long)(Y
* m_layout
->scY
));
200 void DRAWMM(double X
, double Y
) {
201 DrawTo((long)(X
* m_layout
->scX
), (long)(Y
* m_layout
->scY
));
203 void MoveTo(long x
, long y
);
204 void DrawTo(long x
, long y
);
205 void DrawCross(long x
, long y
);
206 void SetFont(wxFont
* font
) {
209 void WriteString(const wxString
& s
);
210 void DrawEllipse(long x
, long y
, long r
, long R
);
211 void SolidRectangle(long x
, long y
, long w
, long h
);
212 void NewPage(int pg
, int pagesX
, int pagesY
);
213 void PlotLR(const vector
<XSect
> & centreline
);
214 void PlotUD(const vector
<XSect
> & centreline
);
216 svxPrintout(MainFrm
*mainfrm
, layout
*l
, wxPageSetupDialogData
*data
, const wxString
& title
);
217 bool OnPrintPage(int pageNum
);
218 void GetPageInfo(int *minPage
, int *maxPage
,
219 int *pageFrom
, int *pageTo
);
220 bool HasPage(int pageNum
);
221 void OnBeginPrinting();
222 void OnEndPrinting();
225 BEGIN_EVENT_TABLE(svxPrintDlg
, wxDialog
)
226 EVT_CHOICE(svx_FORMAT
, svxPrintDlg::OnChange
)
227 EVT_TEXT(svx_SCALE
, svxPrintDlg::OnChange
)
228 EVT_COMBOBOX(svx_SCALE
, svxPrintDlg::OnChange
)
229 EVT_SPINCTRLDOUBLE(svx_BEARING
, svxPrintDlg::OnChangeSpin
)
230 EVT_SPINCTRLDOUBLE(svx_TILT
, svxPrintDlg::OnChangeSpin
)
231 EVT_BUTTON(wxID_PRINT
, svxPrintDlg::OnPrint
)
232 EVT_BUTTON(svx_EXPORT
, svxPrintDlg::OnExport
)
233 EVT_BUTTON(wxID_CANCEL
, svxPrintDlg::OnCancel
)
234 #ifdef AVEN_PRINT_PREVIEW
235 EVT_BUTTON(wxID_PREVIEW
, svxPrintDlg::OnPreview
)
237 EVT_BUTTON(svx_PLAN
, svxPrintDlg::OnPlan
)
238 EVT_BUTTON(svx_ELEV
, svxPrintDlg::OnElevation
)
239 EVT_UPDATE_UI(svx_PLAN
, svxPrintDlg::OnPlanUpdate
)
240 EVT_UPDATE_UI(svx_ELEV
, svxPrintDlg::OnElevationUpdate
)
241 EVT_CHECKBOX(svx_LEGS
, svxPrintDlg::OnChange
)
242 EVT_CHECKBOX(svx_STATIONS
, svxPrintDlg::OnChange
)
243 EVT_CHECKBOX(svx_NAMES
, svxPrintDlg::OnChange
)
244 EVT_CHECKBOX(svx_SURFACE
, svxPrintDlg::OnChange
)
245 EVT_CHECKBOX(svx_SPLAYS
, svxPrintDlg::OnChange
)
246 EVT_CHECKBOX(svx_ENTS
, svxPrintDlg::OnChange
)
247 EVT_CHECKBOX(svx_FIXES
, svxPrintDlg::OnChange
)
248 EVT_CHECKBOX(svx_EXPORTS
, svxPrintDlg::OnChange
)
251 static wxString scales
[] = {
267 // The order of these arrays must match export_format in export.h.
269 static wxString formats
[] = {
282 static_assert(sizeof(formats
) == FMT_MAX_PLUS_ONE_
* sizeof(formats
[0]),
283 "formats[] matches enum export_format");
285 // We discriminate as "One Page" isn't valid for exporting.
286 static wxString default_scale_print
;
287 static wxString default_scale_export
;
289 svxPrintDlg::svxPrintDlg(MainFrm
* mainfrm_
, const wxString
& filename
,
290 const wxString
& title
,
291 const wxString
& datestamp
,
292 double angle
, double tilt_angle
,
293 bool labels
, bool crosses
, bool legs
, bool surf
,
294 bool splays
, bool tubes
, bool ents
, bool fixes
,
295 bool exports
, bool printing
, bool close_after_
)
296 : wxDialog(mainfrm_
, -1, wxString(printing
?
297 /* TRANSLATORS: Title of the print
300 /* TRANSLATORS: Title of the export
302 wmsg(/*Export*/383))),
303 m_layout(printing
? wxGetApp().GetPageSetupDialogData() : NULL
),
304 m_File(filename
), mainfrm(mainfrm_
), close_after(close_after_
)
323 show_mask
|= XSECT
|WALLS
|PASG
;
329 show_mask
|= EXPORTS
;
330 m_layout
.show_mask
= show_mask
;
331 m_layout
.datestamp
= datestamp
;
332 m_layout
.rot
= angle
;
333 m_layout
.title
= title
;
334 if (mainfrm
->IsExtendedElevation()) {
335 m_layout
.view
= layout::EXTELEV
;
336 if (m_layout
.rot
!= 0.0 && m_layout
.rot
!= 180.0) m_layout
.rot
= 0;
339 m_layout
.tilt
= tilt_angle
;
340 if (m_layout
.tilt
== -90.0) {
341 m_layout
.view
= layout::PLAN
;
342 } else if (m_layout
.tilt
== 0.0) {
343 m_layout
.view
= layout::ELEV
;
345 m_layout
.view
= layout::TILT
;
349 /* setup our print dialog*/
350 wxBoxSizer
* v1
= new wxBoxSizer(wxVERTICAL
);
351 wxBoxSizer
* h1
= new wxBoxSizer(wxHORIZONTAL
); // holds controls
352 /* TRANSLATORS: Used as a label for the surrounding box for the "Bearing"
353 * and "Tilt angle" fields, and the "Plan view" and "Elevation" buttons in
354 * the "what to print/export" dialog. */
355 m_viewbox
= new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*View*/283)), wxVERTICAL
);
356 /* TRANSLATORS: Used as a label for the surrounding box for the "survey
357 * legs" "stations" "names" etc checkboxes in the "what to print" dialog.
358 * "Elements" isn’t a good name for this but nothing better has yet come to
360 wxBoxSizer
* v2
= new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*Elements*/256)), wxVERTICAL
);
361 wxBoxSizer
* h2
= new wxBoxSizer(wxHORIZONTAL
); // holds buttons
365 label
= new wxStaticText(this, -1, wxString(wmsg(/*Export format*/410)));
366 const size_t n_formats
= sizeof(formats
) / sizeof(formats
[0]);
367 m_format
= new wxChoice(this, svx_FORMAT
,
368 wxDefaultPosition
, wxDefaultSize
,
370 unsigned current_format
= 0;
371 wxConfigBase
* cfg
= wxConfigBase::Get();
373 if (cfg
->Read(wxT("export_format"), &s
, wxString())) {
374 for (unsigned i
= 0; i
!= n_formats
; ++i
) {
375 if (s
== formats
[i
]) {
381 m_format
->SetSelection(current_format
);
382 wxBoxSizer
* formatbox
= new wxBoxSizer(wxHORIZONTAL
);
383 formatbox
->Add(label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
384 formatbox
->Add(m_format
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
386 v1
->Add(formatbox
, 0, wxALIGN_LEFT
|wxALL
, 0);
390 label
= new wxStaticText(this, -1, wxString(wmsg(/*Scale*/154)) + wxT(" 1:"));
391 if (printing
&& scales
[0].empty()) {
392 /* TRANSLATORS: used in the scale drop down selector in the print
393 * dialog the implicit meaning is "choose a suitable scale to fit
394 * the plot on a single page", but we need something shorter */
395 scales
[0].assign(wmsg(/*One page*/258));
397 wxString default_scale
;
399 default_scale
= default_scale_print
;
400 if (default_scale
.empty()) default_scale
= scales
[0];
402 default_scale
= default_scale_export
;
403 if (default_scale
.empty()) default_scale
= wxT("1000");
405 const wxString
* scale_list
= scales
;
406 size_t n_scales
= sizeof(scales
) / sizeof(scales
[0]);
411 m_scale
= new wxComboBox(this, svx_SCALE
, default_scale
, wxDefaultPosition
,
412 wxDefaultSize
, n_scales
, scale_list
);
413 m_scalebox
= new wxBoxSizer(wxHORIZONTAL
);
414 m_scalebox
->Add(label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
415 m_scalebox
->Add(m_scale
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
417 m_viewbox
->Add(m_scalebox
, 0, wxALIGN_LEFT
|wxALL
, 0);
420 // Make the dummy string wider than any sane value and use that to
421 // fix the width of the control so the sizers allow space for bigger
423 m_printSize
= new wxStaticText(this, -1, wxString::Format(wmsg(/*%d pages (%dx%d)*/257), 9604, 98, 98));
424 m_viewbox
->Add(m_printSize
, 0, wxALIGN_LEFT
|wxALL
, 5);
427 if (m_layout
.view
!= layout::EXTELEV
) {
428 wxFlexGridSizer
* anglebox
= new wxFlexGridSizer(2);
429 wxStaticText
* brg_label
, * tilt_label
;
430 brg_label
= new wxStaticText(this, -1, wmsg(/*Bearing*/259));
431 anglebox
->Add(brg_label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALIGN_LEFT
|wxALL
, 5);
432 // wSP_WRAP means that you can scroll past 360 to 0, and vice versa.
433 m_bearing
= new wxSpinCtrlDouble(this, svx_BEARING
, wxEmptyString
,
434 wxDefaultPosition
, wxDefaultSize
,
435 wxSP_ARROW_KEYS
|wxALIGN_RIGHT
|wxSP_WRAP
);
436 m_bearing
->SetRange(0.0, 360.0);
437 m_bearing
->SetDigits(ANGLE_DP
);
438 anglebox
->Add(m_bearing
, 0, wxALIGN_CENTRE
|wxALL
, 5);
439 /* TRANSLATORS: Used in the print dialog: */
440 tilt_label
= new wxStaticText(this, -1, wmsg(/*Tilt angle*/263));
441 anglebox
->Add(tilt_label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALIGN_LEFT
|wxALL
, 5);
442 m_tilt
= new wxSpinCtrlDouble(this, svx_TILT
);
443 m_tilt
->SetRange(-90.0, 90.0);
444 m_tilt
->SetDigits(ANGLE_DP
);
445 anglebox
->Add(m_tilt
, 0, wxALIGN_CENTRE
|wxALL
, 5);
447 m_viewbox
->Add(anglebox
, 0, wxALIGN_LEFT
|wxALL
, 0);
449 wxBoxSizer
* planelevsizer
= new wxBoxSizer(wxHORIZONTAL
);
450 planelevsizer
->Add(new wxButton(this, svx_PLAN
, wmsg(/*P&lan view*/117)),
451 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
452 planelevsizer
->Add(new wxButton(this, svx_ELEV
, wmsg(/*&Elevation*/285)),
453 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
455 m_viewbox
->Add(planelevsizer
, 0, wxALIGN_LEFT
|wxALL
, 5);
458 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
459 * "survey stations". */
460 v2
->Add(new wxCheckBox(this, svx_LEGS
, wmsg(/*Underground Survey Legs*/262),
461 wxDefaultPosition
, wxDefaultSize
, 0,
462 BitValidator(&m_layout
.show_mask
, LEGS
)),
463 0, wxALIGN_LEFT
|wxALL
, 2);
464 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
465 * "survey stations". */
466 v2
->Add(new wxCheckBox(this, svx_SURFACE
, wmsg(/*Sur&face Survey Legs*/403),
467 wxDefaultPosition
, wxDefaultSize
, 0,
468 BitValidator(&m_layout
.show_mask
, SURF
)),
469 0, wxALIGN_LEFT
|wxALL
, 2);
470 v2
->Add(new wxCheckBox(this, svx_SPLAYS
, wmsg(/*Spla&y Legs*/406),
471 wxDefaultPosition
, wxDefaultSize
, 0,
472 BitValidator(&m_layout
.show_mask
, SPLAYS
)),
473 0, wxALIGN_LEFT
|wxALL
, 2);
474 v2
->Add(new wxCheckBox(this, svx_STATIONS
, wmsg(/*Crosses*/261),
475 wxDefaultPosition
, wxDefaultSize
, 0,
476 BitValidator(&m_layout
.show_mask
, STNS
)),
477 0, wxALIGN_LEFT
|wxALL
, 2);
478 v2
->Add(new wxCheckBox(this, svx_NAMES
, wmsg(/*Station Names*/260),
479 wxDefaultPosition
, wxDefaultSize
, 0,
480 BitValidator(&m_layout
.show_mask
, LABELS
)),
481 0, wxALIGN_LEFT
|wxALL
, 2);
482 v2
->Add(new wxCheckBox(this, svx_ENTS
, wmsg(/*Entrances*/418),
483 wxDefaultPosition
, wxDefaultSize
, 0,
484 BitValidator(&m_layout
.show_mask
, ENTS
)),
485 0, wxALIGN_LEFT
|wxALL
, 2);
486 v2
->Add(new wxCheckBox(this, svx_FIXES
, wmsg(/*Fixed Points*/419),
487 wxDefaultPosition
, wxDefaultSize
, 0,
488 BitValidator(&m_layout
.show_mask
, FIXES
)),
489 0, wxALIGN_LEFT
|wxALL
, 2);
490 v2
->Add(new wxCheckBox(this, svx_EXPORTS
, wmsg(/*Exported Stations*/420),
491 wxDefaultPosition
, wxDefaultSize
, 0,
492 BitValidator(&m_layout
.show_mask
, EXPORTS
)),
493 0, wxALIGN_LEFT
|wxALL
, 2);
494 v2
->Add(new wxCheckBox(this, svx_XSECT
, wmsg(/*Cross-sections*/393),
495 wxDefaultPosition
, wxDefaultSize
, 0,
496 BitValidator(&m_layout
.show_mask
, XSECT
)),
497 0, wxALIGN_LEFT
|wxALL
, 2);
499 v2
->Add(new wxCheckBox(this, svx_WALLS
, wmsg(/*Walls*/394),
500 wxDefaultPosition
, wxDefaultSize
, 0,
501 BitValidator(&m_layout
.show_mask
, WALLS
)),
502 0, wxALIGN_LEFT
|wxALL
, 2);
503 // TRANSLATORS: Label for checkbox which controls whether there's a
504 // layer in the exported file (for formats such as DXF and SVG)
505 // containing polygons for the inside of cave passages).
506 v2
->Add(new wxCheckBox(this, svx_PASSAGES
, wmsg(/*Passages*/395),
507 wxDefaultPosition
, wxDefaultSize
, 0,
508 BitValidator(&m_layout
.show_mask
, PASG
)),
509 0, wxALIGN_LEFT
|wxALL
, 2);
510 v2
->Add(new wxCheckBox(this, svx_CENTRED
, wmsg(/*Origin in centre*/421),
511 wxDefaultPosition
, wxDefaultSize
, 0,
512 BitValidator(&m_layout
.show_mask
, CENTRED
)),
513 0, wxALIGN_LEFT
|wxALL
, 2);
514 v2
->Add(new wxCheckBox(this, svx_FULLCOORDS
, wmsg(/*Full coordinates*/422),
515 wxDefaultPosition
, wxDefaultSize
, 0,
516 BitValidator(&m_layout
.show_mask
, FULL_COORDS
)),
517 0, wxALIGN_LEFT
|wxALL
, 2);
518 v2
->Add(new wxCheckBox(this, svx_CLAMP_TO_GROUND
, wmsg(/*Clamp to ground*/477),
519 wxDefaultPosition
, wxDefaultSize
, 0,
520 BitValidator(&m_layout
.show_mask
, CLAMP_TO_GROUND
)),
521 0, wxALIGN_LEFT
|wxALL
, 2);
524 /* TRANSLATORS: used in the print dialog - controls drawing lines
525 * around each page */
526 v2
->Add(new wxCheckBox(this, svx_BORDERS
, wmsg(/*Page Borders*/264),
527 wxDefaultPosition
, wxDefaultSize
, 0,
528 wxGenericValidator(&m_layout
.Border
)),
529 0, wxALIGN_LEFT
|wxALL
, 2);
530 /* TRANSLATORS: will be used in the print dialog - check this to print
531 * blank pages (otherwise they’ll be skipped to save paper) */
532 // m_blanks = new wxCheckBox(this, svx_BLANKS, wmsg(/*Blank Pages*/266));
533 // v2->Add(m_blanks, 0, wxALIGN_LEFT|wxALL, 2);
534 /* TRANSLATORS: As in the legend on a map. Used in the print dialog -
535 * controls drawing the box at the lower left with survey name, view
537 v2
->Add(new wxCheckBox(this, svx_LEGEND
, wmsg(/*Legend*/265),
538 wxDefaultPosition
, wxDefaultSize
, 0,
539 wxGenericValidator(&m_layout
.Legend
)),
540 0, wxALIGN_LEFT
|wxALL
, 2);
543 h1
->Add(v2
, 0, wxALIGN_LEFT
|wxALL
, 5);
544 h1
->Add(m_viewbox
, 0, wxALIGN_LEFT
|wxLEFT
, 5);
546 v1
->Add(h1
, 0, wxALIGN_LEFT
|wxALL
, 5);
548 // When we enable/disable checkboxes in the export dialog, ideally we'd
549 // like the dialog to resize, but not sure how to achieve that, so we
550 // add a stretchable spacer here so at least the buttons stay in the
551 // lower right corner.
552 v1
->AddStretchSpacer();
555 but
= new wxButton(this, wxID_CANCEL
);
556 h2
->Add(but
, 0, wxALL
, 5);
558 #ifdef AVEN_PRINT_PREVIEW
559 but
= new wxButton(this, wxID_PREVIEW
);
560 h2
->Add(but
, 0, wxALL
, 5);
561 but
= new wxButton(this, wxID_PRINT
);
563 but
= new wxButton(this, wxID_PRINT
, wmsg(/*&Print...*/400));
566 /* TRANSLATORS: The text on the action button in the "Export" settings
568 but
= new wxButton(this, svx_EXPORT
, wmsg(/*&Export...*/230));
571 h2
->Add(but
, 0, wxALL
, 5);
572 v1
->Add(h2
, 0, wxALIGN_RIGHT
|wxALL
, 5);
576 v1
->SetSizeHints(this);
583 svxPrintDlg::OnPrint(wxCommandEvent
&) {
585 TransferDataFromWindow();
586 wxPageSetupDialogData
* psdd
= wxGetApp().GetPageSetupDialogData();
587 wxPrintDialogData
pd(psdd
->GetPrintData());
589 svxPrintout
po(mainfrm
, &m_layout
, psdd
, m_File
);
590 if (m_layout
.SkipBlank
) {
591 // FIXME: wx's printing requires a contiguous range of valid page
592 // numbers. To achieve that, we need to run a scan for blank pages
593 // here, so that GetPageInfo() knows what range to return, and so
594 // that OnPrintPage() can map a page number back to where in the
595 // MxN multi-page layout.
597 po
.scan_for_blank_pages
= true;
598 for (int page
= 1; page
<= m_layout
->pages
; ++page
) {
599 po
.fBlankPage
= fTrue
;
600 po
.OnPrintPage(page
);
601 // FIXME: Do something with po.fBlankPage
603 po
.scan_for_blank_pages
= false;
606 if (pr
.Print(this, &po
, true)) {
607 // Close the print dialog if printing succeeded.
613 svxPrintDlg::OnExport(wxCommandEvent
&) {
615 TransferDataFromWindow();
617 wxFileName::SplitPath(m_File
, NULL
, NULL
, &leaf
, NULL
, wxPATH_NATIVE
);
618 unsigned format_idx
= ((wxChoice
*)FindWindow(svx_FORMAT
))->GetSelection();
619 const auto& info
= export_format_info
[format_idx
];
620 leaf
+= wxString::FromUTF8(info
.extension
);
622 wxString filespec
= wmsg(info
.msg_filetype
);
623 filespec
+= wxT("|*");
624 filespec
+= wxString::FromUTF8(info
.extension
);
625 filespec
+= wxT("|");
626 filespec
+= wmsg(/*All files*/208);
627 filespec
+= wxT("|");
628 filespec
+= wxFileSelectorDefaultWildcardStr
;
630 /* TRANSLATORS: Title of file dialog to choose name and type of exported
632 wxFileDialog
dlg(this, wmsg(/*Export as:*/401), wxString(), leaf
,
633 filespec
, wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
634 if (dlg
.ShowModal() == wxID_OK
) {
635 /* FIXME: Set up a way for the user to specify these: */
636 double grid
= DEFAULT_GRID_SPACING
; // metres
637 double text_height
= DEFAULT_TEXT_HEIGHT
;
638 double marker_size
= DEFAULT_MARKER_SIZE
;
641 const wxString
& export_fnm
= dlg
.GetPath();
642 unsigned mask
= info
.mask
;
644 if (mask
& EXPORT_3D
) {
649 tilt
= m_layout
.tilt
;
651 if (!Export(export_fnm
, m_layout
.title
,
652 m_layout
.datestamp
, *mainfrm
, mainfrm
->GetTreeFilter(),
653 rot
, tilt
, m_layout
.get_effective_show_mask(),
654 export_format(format_idx
),
655 grid
, text_height
, marker_size
, m_layout
.Scale
)) {
656 wxString m
= wxString::Format(wmsg(/*Couldn’t write file “%s”*/402).c_str(),
658 wxGetApp().ReportError(m
);
660 } catch (const wxString
& m
) {
661 wxGetApp().ReportError(m
);
667 #ifdef AVEN_PRINT_PREVIEW
669 svxPrintDlg::OnPreview(wxCommandEvent
&) {
671 TransferDataFromWindow();
672 wxPageSetupDialogData
* psdd
= wxGetApp().GetPageSetupDialogData();
673 wxPrintDialogData
pd(psdd
->GetPrintData());
675 pv
= new wxPrintPreview(new svxPrintout(mainfrm
, &m_layout
, psdd
, m_File
),
676 new svxPrintout(mainfrm
, &m_layout
, psdd
, m_File
),
678 // TRANSLATORS: Title of the print preview dialog
679 wxPreviewFrame
*frame
= new wxPreviewFrame(pv
, mainfrm
, wmsg(/*Print Preview*/398));
682 // Size preview frame so that all of the controlbar and canvas can be seen
685 // GetBestSize gives us the width needed to show the whole controlbar.
686 frame
->GetBestSize(&w
, &h
);
688 // On wxGTK at least, GetBestSize() returns much too small a height.
691 // Ensure that we don't make the window bigger than the screen.
692 // Use wxGetClientDisplayRect() so we don't cover the MS Windows
694 wxRect disp
= wxGetClientDisplayRect();
695 if (w
> disp
.GetWidth()) w
= disp
.GetWidth();
696 if (h
> disp
.GetHeight()) h
= disp
.GetHeight();
697 // Centre the window within the "ClientDisplayRect".
698 int x
= disp
.GetLeft() + (disp
.GetWidth() - w
) / 2;
699 int y
= disp
.GetTop() + (disp
.GetHeight() - h
) / 2;
700 frame
->SetSize(x
, y
, w
, h
);
707 svxPrintDlg::OnPlan(wxCommandEvent
&) {
708 m_tilt
->SetValue(-90.0);
709 SomethingChanged(svx_TILT
);
713 svxPrintDlg::OnElevation(wxCommandEvent
&) {
714 m_tilt
->SetValue(0.0);
715 SomethingChanged(svx_TILT
);
719 svxPrintDlg::OnPlanUpdate(wxUpdateUIEvent
& e
) {
720 e
.Enable(m_tilt
->GetValue() != -90.0);
724 svxPrintDlg::OnElevationUpdate(wxUpdateUIEvent
& e
) {
725 e
.Enable(m_tilt
->GetValue() != 0.0);
729 svxPrintDlg::OnChangeSpin(wxSpinDoubleEvent
& e
) {
730 SomethingChanged(e
.GetId());
734 svxPrintDlg::OnChange(wxCommandEvent
& e
) {
735 if (e
.GetId() == svx_SCALE
&& m_scale
) {
736 default_scale_print
= m_scale
->GetValue();
737 if (default_scale_print
!= scales
[0]) {
738 // Don't store "One Page" for use when exporting.
739 default_scale_export
= default_scale_print
;
742 SomethingChanged(e
.GetId());
746 svxPrintDlg::OnCancel(wxCommandEvent
&) {
753 svxPrintDlg::SomethingChanged(int control_id
) {
754 if ((control_id
== 0 || control_id
== svx_FORMAT
) && m_format
) {
755 // Update the shown/hidden fields for the newly selected export filter.
756 int new_filter_idx
= m_format
->GetSelection();
757 if (new_filter_idx
!= wxNOT_FOUND
) {
758 unsigned mask
= export_format_info
[new_filter_idx
].mask
;
759 static const struct { int id
; unsigned mask
; } controls
[] = {
761 { svx_SURFACE
, SURF
},
762 { svx_SPLAYS
, SPLAYS
},
763 { svx_STATIONS
, STNS
},
764 { svx_NAMES
, LABELS
},
765 { svx_XSECT
, XSECT
},
766 { svx_WALLS
, WALLS
},
767 { svx_PASSAGES
, PASG
},
769 { svx_FIXES
, FIXES
},
770 { svx_EXPORTS
, EXPORTS
},
771 { svx_CENTRED
, CENTRED
},
772 { svx_FULLCOORDS
, FULL_COORDS
},
773 { svx_CLAMP_TO_GROUND
, CLAMP_TO_GROUND
},
775 static unsigned n_controls
= sizeof(controls
) / sizeof(controls
[0]);
776 for (unsigned i
= 0; i
!= n_controls
; ++i
) {
777 wxWindow
* control
= FindWindow(controls
[i
].id
);
778 if (control
) control
->Show(mask
& controls
[i
].mask
);
780 m_scalebox
->Show(bool(mask
& SCALE
));
781 m_viewbox
->Show(!bool(mask
& EXPORT_3D
));
782 GetSizer()->Layout();
783 if (control_id
== svx_FORMAT
) {
784 wxConfigBase
* cfg
= wxConfigBase::Get();
785 cfg
->Write(wxT("export_format"), formats
[new_filter_idx
]);
792 if (m_printSize
|| m_scale
) {
793 // Update the bounding box.
797 if (!(m_scale
->GetValue()).ToDouble(&(m_layout
.Scale
)) ||
798 m_layout
.Scale
== 0.0) {
799 m_layout
.pick_scale(1, 1);
804 if (m_printSize
&& m_layout
.xMax
>= m_layout
.xMin
) {
805 m_layout
.pages_required();
806 m_printSize
->SetLabel(wxString::Format(wmsg(/*%d pages (%dx%d)*/257), m_layout
.pages
, m_layout
.pagesX
, m_layout
.pagesY
));
811 svxPrintDlg::LayoutToUI()
813 // m_blanks->SetValue(m_layout.SkipBlank);
814 if (m_layout
.view
!= layout::EXTELEV
) {
815 m_tilt
->SetValue(m_layout
.tilt
);
816 m_bearing
->SetValue(m_layout
.rot
);
819 if (m_scale
&& m_layout
.Scale
!= 0) {
820 // Do this last as it causes an OnChange message which calls UIToLayout
822 temp
<< m_layout
.Scale
;
823 m_scale
->SetValue(temp
);
828 svxPrintDlg::UIToLayout()
830 // m_layout.SkipBlank = m_blanks->IsChecked();
832 if (m_layout
.view
!= layout::EXTELEV
&& m_tilt
) {
833 m_layout
.tilt
= m_tilt
->GetValue();
834 if (m_layout
.tilt
== -90.0) {
835 m_layout
.view
= layout::PLAN
;
836 } else if (m_layout
.tilt
== 0.0) {
837 m_layout
.view
= layout::ELEV
;
839 m_layout
.view
= layout::TILT
;
842 bool enable_passage_opts
= (m_layout
.view
!= layout::TILT
);
844 win
= FindWindow(svx_XSECT
);
845 if (win
) win
->Enable(enable_passage_opts
);
846 win
= FindWindow(svx_WALLS
);
847 if (win
) win
->Enable(enable_passage_opts
);
848 win
= FindWindow(svx_PASSAGES
);
849 if (win
) win
->Enable(enable_passage_opts
);
851 m_layout
.rot
= m_bearing
->GetValue();
856 svxPrintDlg::RecalcBounds()
858 m_layout
.yMax
= m_layout
.xMax
= -DBL_MAX
;
859 m_layout
.yMin
= m_layout
.xMin
= DBL_MAX
;
861 double SIN
= sin(rad(m_layout
.rot
));
862 double COS
= cos(rad(m_layout
.rot
));
863 double SINT
= sin(rad(m_layout
.tilt
));
864 double COST
= cos(rad(m_layout
.tilt
));
866 const SurveyFilter
* filter
= mainfrm
->GetTreeFilter();
867 int show_mask
= m_layout
.get_effective_show_mask();
868 if (show_mask
& LEGS
) {
869 for (int f
= 0; f
!= 8; ++f
) {
870 if ((show_mask
& (f
& img_FLAG_SURFACE
) ? SURF
: LEGS
) == 0) {
871 // Not showing traverse because of surface/underground status.
874 if ((f
& img_FLAG_SPLAY
) && (show_mask
& SPLAYS
) == 0) {
875 // Not showing because it's a splay.
878 list
<traverse
>::const_iterator trav
= mainfrm
->traverses_begin(f
, filter
);
879 list
<traverse
>::const_iterator tend
= mainfrm
->traverses_end(f
);
880 for ( ; trav
!= tend
; trav
= mainfrm
->traverses_next(f
, filter
, trav
)) {
881 vector
<PointInfo
>::const_iterator pos
= trav
->begin();
882 vector
<PointInfo
>::const_iterator end
= trav
->end();
883 for ( ; pos
!= end
; ++pos
) {
884 double x
= pos
->GetX();
885 double y
= pos
->GetY();
886 double z
= pos
->GetZ();
887 double X
= x
* COS
- y
* SIN
;
888 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
889 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
890 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
891 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
892 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
898 if ((show_mask
& XSECT
) &&
899 (m_layout
.tilt
== 0.0 || m_layout
.tilt
== 90.0 || m_layout
.tilt
== -90.0)) {
900 list
<vector
<XSect
>>::const_iterator trav
= mainfrm
->tubes_begin();
901 list
<vector
<XSect
>>::const_iterator tend
= mainfrm
->tubes_end();
902 for ( ; trav
!= tend
; ++trav
) {
903 const XSect
* prev_pt_v
= NULL
;
904 Vector3
last_right(1.0, 0.0, 0.0);
906 vector
<XSect
>::const_iterator i
= trav
->begin();
907 vector
<XSect
>::size_type segment
= 0;
908 while (i
!= trav
->end()) {
909 // get the coordinates of this vertex
910 const XSect
& pt_v
= *i
++;
911 if (m_layout
.tilt
== 0.0) {
912 Double u
= pt_v
.GetU();
913 Double d
= pt_v
.GetD();
915 if (u
>= 0 || d
>= 0) {
916 if (filter
&& !filter
->CheckVisible(pt_v
.GetLabel()))
919 double x
= pt_v
.GetX();
920 double y
= pt_v
.GetY();
921 double z
= pt_v
.GetZ();
922 double X
= x
* COS
- y
* SIN
;
923 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
925 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
926 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
927 double U
= Y
+ max(0.0, pt_v
.GetU());
928 if (U
> m_layout
.yMax
) m_layout
.yMax
= U
;
929 double D
= Y
- max(0.0, pt_v
.GetD());
930 if (D
< m_layout
.yMin
) m_layout
.yMin
= D
;
933 // More complex, and this duplicates the algorithm from
934 // PlotLR() - we should try to share that, maybe via a
938 const Vector3
up_v(0.0, 0.0, 1.0);
941 assert(i
!= trav
->end());
944 // get the coordinates of the next vertex
945 const XSect
& next_pt_v
= *i
;
947 // calculate vector from this pt to the next one
948 Vector3 leg_v
= next_pt_v
- pt_v
;
950 // obtain a vector in the LRUD plane
951 right
= leg_v
* up_v
;
952 if (right
.magnitude() == 0) {
957 } else if (segment
+ 1 == trav
->size()) {
960 // Calculate vector from the previous pt to this one.
961 Vector3 leg_v
= pt_v
- *prev_pt_v
;
963 // Obtain a horizontal vector in the LRUD plane.
964 right
= leg_v
* up_v
;
965 if (right
.magnitude() == 0) {
966 right
= Vector3(last_right
.GetX(), last_right
.GetY(), 0.0);
971 assert(i
!= trav
->end());
972 // Intermediate segment.
974 // Get the coordinates of the next vertex.
975 const XSect
& next_pt_v
= *i
;
977 // Calculate vectors from this vertex to the
978 // next vertex, and from the previous vertex to
980 Vector3 leg1_v
= pt_v
- *prev_pt_v
;
981 Vector3 leg2_v
= next_pt_v
- pt_v
;
983 // Obtain horizontal vectors perpendicular to
984 // both legs, then normalise and average to get
985 // a horizontal bisector.
986 Vector3 r1
= leg1_v
* up_v
;
987 Vector3 r2
= leg2_v
* up_v
;
991 if (right
.magnitude() == 0) {
992 // This is the "mid-pitch" case...
998 // Scale to unit vectors in the LRUD plane.
1001 Double l
= pt_v
.GetL();
1002 Double r
= pt_v
.GetR();
1004 if (l
>= 0 || r
>= 0) {
1005 if (!filter
|| filter
->CheckVisible(pt_v
.GetLabel())) {
1006 // Get the x and y coordinates of the survey station
1007 double pt_X
= pt_v
.GetX() * COS
- pt_v
.GetY() * SIN
;
1008 double pt_Y
= pt_v
.GetX() * SIN
+ pt_v
.GetY() * COS
;
1012 // Get the x and y coordinates of the end of the left arrow
1013 Vector3 p
= pt_v
.GetPoint() - right
* l
;
1014 X
= p
.GetX() * COS
- p
.GetY() * SIN
;
1015 Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
1020 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1021 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1022 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1023 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1026 // Get the x and y coordinates of the end of the right arrow
1027 Vector3 p
= pt_v
.GetPoint() + right
* r
;
1028 X
= p
.GetX() * COS
- p
.GetY() * SIN
;
1029 Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
1034 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1035 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1036 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1037 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1049 if (show_mask
& (LABELS
|STNS
)) {
1050 for (auto label
= mainfrm
->GetLabels();
1051 label
!= mainfrm
->GetLabelsEnd();
1053 if (filter
&& !filter
->CheckVisible((*label
)->GetText()))
1055 double x
= (*label
)->GetX();
1056 double y
= (*label
)->GetY();
1057 double z
= (*label
)->GetZ();
1058 if ((show_mask
& SURF
) || (*label
)->IsUnderground()) {
1059 double X
= x
* COS
- y
* SIN
;
1060 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1061 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1062 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1063 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1064 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1070 static int xpPageWidth
, ypPageDepth
;
1071 static long x_offset
, y_offset
;
1072 static int fontsize
, fontsize_labels
;
1074 /* FIXME: allow the font to be set */
1076 static const char *fontname
= "Arial", *fontname_labels
= "Arial";
1078 svxPrintout::svxPrintout(MainFrm
*mainfrm_
, layout
*l
,
1079 wxPageSetupDialogData
*data
, const wxString
& title
)
1080 : wxPrintout(title
), font_labels(NULL
), font_default(NULL
),
1081 scan_for_blank_pages(false)
1089 svxPrintout::draw_info_box()
1091 layout
*l
= m_layout
;
1095 pdc
->SetPen(*pen_frame
);
1098 if (l
->view
!= layout::EXTELEV
) {
1099 boxwidth
+= boxheight
;
1100 MOVEMM(div
, boxheight
);
1102 MOVEMM(0, 30); DRAWMM(div
, 30);
1105 MOVEMM(0, boxheight
);
1106 DRAWMM(boxwidth
, boxheight
);
1107 DRAWMM(boxwidth
, 0);
1110 DRAWMM(0, boxheight
);
1113 MOVEMM(0, 20); DRAWMM(div
, 20);
1114 MOVEMM(0, 10); DRAWMM(div
, 10);
1117 case layout::PLAN
: {
1118 long ax
, ay
, bx
, by
, cx
, cy
, dx
, dy
;
1120 long xc
= boxwidth
- boxheight
/ 2;
1121 long yc
= boxheight
/ 2;
1122 const double RADIUS
= boxheight
/ 3;
1123 DrawEllipse(long(xc
* l
->scX
), long(yc
* l
->scY
),
1124 long(RADIUS
* l
->scX
), long(RADIUS
* l
->scY
));
1126 ax
= (long)((xc
- (RADIUS
- 1) * sin(rad(000.0 + l
->rot
))) * l
->scX
);
1127 ay
= (long)((yc
+ (RADIUS
- 1) * cos(rad(000.0 + l
->rot
))) * l
->scY
);
1128 bx
= (long)((xc
- RADIUS
* 0.5 * sin(rad(180.0 + l
->rot
))) * l
->scX
);
1129 by
= (long)((yc
+ RADIUS
* 0.5 * cos(rad(180.0 + l
->rot
))) * l
->scY
);
1130 cx
= (long)((xc
- (RADIUS
- 1) * sin(rad(160.0 + l
->rot
))) * l
->scX
);
1131 cy
= (long)((yc
+ (RADIUS
- 1) * cos(rad(160.0 + l
->rot
))) * l
->scY
);
1132 dx
= (long)((xc
- (RADIUS
- 1) * sin(rad(200.0 + l
->rot
))) * l
->scX
);
1133 dy
= (long)((yc
+ (RADIUS
- 1) * cos(rad(200.0 + l
->rot
))) * l
->scY
);
1142 pdc
->SetTextForeground(colour_text
);
1143 MOVEMM(div
+ 0.5, boxheight
- 5.5);
1144 WriteString(wmsg(/*North*/115));
1146 wxString angle
= format_angle(ANGLE_FMT
, l
->rot
);
1148 /* TRANSLATORS: This is used on printouts of plans, with %s replaced by
1149 * something like "123°". The bearing is up the page. */
1150 s
.Printf(wmsg(/*Plan view, %s up page*/168), angle
.c_str());
1151 MOVEMM(2, 12); WriteString(s
);
1154 case layout::ELEV
: case layout::TILT
: {
1155 const int L
= div
+ 2;
1156 const int R
= boxwidth
- 2;
1157 const int H
= boxheight
/ 2;
1158 MOVEMM(L
, H
); DRAWMM(L
+ 5, H
- 3); DRAWMM(L
+ 3, H
); DRAWMM(L
+ 5, H
+ 3);
1160 DRAWMM(L
, H
); DRAWMM(R
, H
);
1162 DRAWMM(R
- 5, H
+ 3); DRAWMM(R
- 3, H
); DRAWMM(R
- 5, H
- 3); DRAWMM(R
, H
);
1164 MOVEMM((L
+ R
) / 2, H
- 2); DRAWMM((L
+ R
) / 2, H
+ 2);
1166 pdc
->SetTextForeground(colour_text
);
1167 MOVEMM(div
+ 2, boxheight
- 8);
1168 /* TRANSLATORS: "Elevation on" 020 <-> 200 degrees */
1169 WriteString(wmsg(/*Elevation on*/116));
1172 WriteString(format_angle(ANGLE_FMT
, fmod(l
->rot
+ 270.0, 360.0)));
1174 WriteString(format_angle(ANGLE_FMT
, fmod(l
->rot
+ 90.0, 360.0)));
1176 wxString angle
= format_angle(ANGLE_FMT
, l
->rot
);
1178 if (l
->view
== layout::ELEV
) {
1179 /* TRANSLATORS: This is used on printouts of elevations, with %s
1180 * replaced by something like "123°". The bearing is the direction
1182 s
.Printf(wmsg(/*Elevation facing %s*/169), angle
.c_str());
1184 wxString a2
= format_angle(ANGLE2_FMT
, l
->tilt
);
1185 /* TRANSLATORS: This is used on printouts of tilted elevations, with
1186 * the first %s replaced by something like "123°", and the second by
1187 * something like "-45°". The bearing is the direction we’re
1189 s
.Printf(wmsg(/*Elevation facing %s, tilted %s*/284), angle
.c_str(), a2
.c_str());
1191 MOVEMM(2, 12); WriteString(s
);
1194 case layout::EXTELEV
:
1195 pdc
->SetTextForeground(colour_text
);
1197 /* TRANSLATORS: This is used on printouts of extended elevations. */
1198 WriteString(wmsg(/*Extended elevation*/191));
1202 MOVEMM(2, boxheight
- 8); WriteString(l
->title
);
1205 // FIXME: "Original Scale" better?
1206 WriteString(wxString::Format(wmsg(/*Scale*/154) + wxT(" 1:%.0f"),
1209 /* This used to be a copyright line, but it was occasionally
1210 * mis-interpreted as us claiming copyright on the survey, so let's
1211 * give the website URL instead */
1212 MOVEMM(boxwidth
+ 2, 2);
1213 WriteString(wxT("Survex " VERSION
" - https://survex.com/"));
1215 draw_scale_bar(boxwidth
+ 10.0, 17.0, l
->PaperWidth
- boxwidth
- 18.0);
1218 /* Draw fancy scale bar with bottom left at (x,y) (both in mm) and at most */
1219 /* MaxLength mm long. The scaling in use is 1:scale */
1221 svxPrintout::draw_scale_bar(double x
, double y
, double MaxLength
)
1226 /* Limit scalebar to 20cm to stop people with A0 plotters complaining */
1227 if (MaxLength
> 200.0) MaxLength
= 200.0;
1229 #define dmin 10.0 /* each division >= dmin mm long */
1230 #define StepMax 5 /* number in steps of at most StepMax (x 10^N) */
1231 #define epsilon (1e-4) /* fudge factor to prevent rounding problems */
1233 E
= (int)ceil(log10((dmin
* 0.001 * m_layout
->Scale
) / StepMax
));
1234 StepEst
= pow(10.0, -(double)E
) * (dmin
* 0.001) * m_layout
->Scale
- epsilon
;
1236 /* Force labelling to be in multiples of 1, 2, or 5 */
1237 Step
= (StepEst
<= 1.0 ? 1 : (StepEst
<= 2.0 ? 2 : 5));
1239 /* Work out actual length of each scale bar division */
1240 d
= Step
* pow(10.0, (double)E
) / m_layout
->Scale
* 1000.0;
1242 /* FIXME: Non-metric units here... */
1243 /* Choose appropriate units, s.t. if possible E is >=0 and minimized */
1248 } else if (E
>= 0) {
1255 buf
= wmsg(/*Scale*/154);
1257 /* Add units used - eg. "Scale (10m)" */
1258 double pow10_E
= pow(10.0, (double)E
);
1260 buf
+= wxString::Format(wxT(" (%.f%s)"), pow10_E
, wmsg(units
).c_str());
1262 int sf
= -(int)floor(E
);
1263 buf
+= wxString::Format(wxT(" (%.*f%s)"), sf
, pow10_E
, wmsg(units
).c_str());
1265 pdc
->SetTextForeground(colour_text
);
1266 MOVEMM(x
, y
+ 4); WriteString(buf
);
1268 /* Work out how many divisions there will be */
1269 n
= (int)(MaxLength
/ d
);
1271 pdc
->SetPen(*pen_frame
);
1273 long Y
= long(y
* m_layout
->scY
);
1274 long Y2
= long((y
+ 3) * m_layout
->scY
);
1275 long X
= long(x
* m_layout
->scX
);
1276 long X2
= long((x
+ n
* d
) * m_layout
->scX
);
1278 /* Draw top of scale bar */
1284 MOVEMM(x
+ n
* d
, y
); DRAWMM(x
, y
);
1286 /* Draw divisions and label them */
1287 for (c
= 0; c
<= n
; c
++) {
1288 pdc
->SetPen(*pen_frame
);
1289 X
= long((x
+ c
* d
) * m_layout
->scX
);
1292 #if 0 // Don't waste toner!
1293 /* Draw a "zebra crossing" scale bar. */
1294 if (c
< n
&& (c
& 1) == 0) {
1295 X2
= long((x
+ (c
+ 1) * d
) * m_layout
->scX
);
1296 SolidRectangle(X
, Y
, X2
- X
, Y2
- Y
);
1299 buf
.Printf(wxT("%d"), c
* Step
);
1300 pdc
->SetTextForeground(colour_text
);
1301 MOVEMM(x
+ c
* d
- buf
.length(), y
- 5);
1308 make_calibration(layout
*l
) {
1309 img_point pt
= { 0.0, 0.0, 0.0 };
1310 l
->xMax
= l
->yMax
= 0.1;
1311 l
->xMin
= l
->yMin
= 0;
1313 stack(l
, img_MOVE
, NULL
, &pt
);
1315 stack(l
, img_LINE
, NULL
, &pt
);
1317 stack(l
, img_LINE
, NULL
, &pt
);
1319 stack(l
, img_LINE
, NULL
, &pt
);
1321 stack(l
, img_LINE
, NULL
, &pt
);
1324 stack(l
, img_LABEL
, "10cm", &pt
);
1327 stack(l
, img_LABEL
, "10cm", &pt
);
1333 svxPrintout::next_page(int *pstate
, char **q
, int pageLim
)
1342 wxASSERT(*p
== '-');
1344 while (isspace((unsigned char)*p
)) p
++;
1345 if (sscanf(p
, "%u%n", &page
, &c
) > 0) {
1350 if (*pstate
> page
) goto err
;
1351 if (*pstate
< page
) return *pstate
;
1357 while (isspace((unsigned char)*p
) || *p
== ',') p
++;
1359 if (!*p
) return 0; /* done */
1364 return 1; /* range with initial parameter omitted */
1366 if (sscanf(p
, "%u%n", &page
, &c
) > 0) {
1368 while (isspace((unsigned char)*p
)) p
++;
1370 if (0 < page
&& page
<= pageLim
) {
1371 if (*p
== '-') *pstate
= page
; /* range with start */
1380 /* Draws in alignment marks on each page or borders on edge pages */
1382 svxPrintout::drawticks(int tsize
, int x
, int y
)
1387 bool fAtCorner
= fFalse
;
1388 pdc
->SetPen(*pen_frame
);
1389 if (x
== 0 && m_layout
->Border
) {
1390 /* solid left border */
1391 MoveTo(clip
.x_min
, clip
.y_min
);
1392 DrawTo(clip
.x_min
, clip
.y_max
);
1395 if (x
> 0 || y
> 0) {
1396 MoveTo(clip
.x_min
, clip
.y_min
);
1397 DrawTo(clip
.x_min
, clip
.y_min
+ tsize
);
1399 if (s
&& x
> 0 && m_layout
->Cutlines
) {
1400 /* dashed left border */
1401 i
= (clip
.y_max
- clip
.y_min
) -
1402 (tsize
+ ((clip
.y_max
- clip
.y_min
- tsize
* 2L) % s
) / 2);
1403 for ( ; i
> tsize
; i
-= s
) {
1404 MoveTo(clip
.x_min
, clip
.y_max
- (i
+ o
));
1405 DrawTo(clip
.x_min
, clip
.y_max
- (i
- o
));
1408 if (x
> 0 || y
< m_layout
->pagesY
- 1) {
1409 MoveTo(clip
.x_min
, clip
.y_max
- tsize
);
1410 DrawTo(clip
.x_min
, clip
.y_max
);
1415 if (y
== m_layout
->pagesY
- 1 && m_layout
->Border
) {
1416 /* solid top border */
1417 if (!fAtCorner
) MoveTo(clip
.x_min
, clip
.y_max
);
1418 DrawTo(clip
.x_max
, clip
.y_max
);
1421 if (y
< m_layout
->pagesY
- 1 || x
> 0) {
1422 if (!fAtCorner
) MoveTo(clip
.x_min
, clip
.y_max
);
1423 DrawTo(clip
.x_min
+ tsize
, clip
.y_max
);
1425 if (s
&& y
< m_layout
->pagesY
- 1 && m_layout
->Cutlines
) {
1426 /* dashed top border */
1427 i
= (clip
.x_max
- clip
.x_min
) -
1428 (tsize
+ ((clip
.x_max
- clip
.x_min
- tsize
* 2L) % s
) / 2);
1429 for ( ; i
> tsize
; i
-= s
) {
1430 MoveTo(clip
.x_max
- (i
+ o
), clip
.y_max
);
1431 DrawTo(clip
.x_max
- (i
- o
), clip
.y_max
);
1434 if (y
< m_layout
->pagesY
- 1 || x
< m_layout
->pagesX
- 1) {
1435 MoveTo(clip
.x_max
- tsize
, clip
.y_max
);
1436 DrawTo(clip
.x_max
, clip
.y_max
);
1443 if (x
== m_layout
->pagesX
- 1 && m_layout
->Border
) {
1444 /* solid right border */
1445 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_max
);
1446 DrawTo(clip
.x_max
, clip
.y_min
);
1449 if (x
< m_layout
->pagesX
- 1 || y
< m_layout
->pagesY
- 1) {
1450 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_max
);
1451 DrawTo(clip
.x_max
, clip
.y_max
- tsize
);
1453 if (s
&& x
< m_layout
->pagesX
- 1 && m_layout
->Cutlines
) {
1454 /* dashed right border */
1455 i
= (clip
.y_max
- clip
.y_min
) -
1456 (tsize
+ ((clip
.y_max
- clip
.y_min
- tsize
* 2L) % s
) / 2);
1457 for ( ; i
> tsize
; i
-= s
) {
1458 MoveTo(clip
.x_max
, clip
.y_min
+ (i
+ o
));
1459 DrawTo(clip
.x_max
, clip
.y_min
+ (i
- o
));
1462 if (x
< m_layout
->pagesX
- 1 || y
> 0) {
1463 MoveTo(clip
.x_max
, clip
.y_min
+ tsize
);
1464 DrawTo(clip
.x_max
, clip
.y_min
);
1471 if (y
== 0 && m_layout
->Border
) {
1472 /* solid bottom border */
1473 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_min
);
1474 DrawTo(clip
.x_min
, clip
.y_min
);
1476 if (y
> 0 || x
< m_layout
->pagesX
- 1) {
1477 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_min
);
1478 DrawTo(clip
.x_max
- tsize
, clip
.y_min
);
1480 if (s
&& y
> 0 && m_layout
->Cutlines
) {
1481 /* dashed bottom border */
1482 i
= (clip
.x_max
- clip
.x_min
) -
1483 (tsize
+ ((clip
.x_max
- clip
.x_min
- tsize
* 2L) % s
) / 2);
1484 for ( ; i
> tsize
; i
-= s
) {
1485 MoveTo(clip
.x_min
+ (i
+ o
), clip
.y_min
);
1486 DrawTo(clip
.x_min
+ (i
- o
), clip
.y_min
);
1489 if (y
> 0 || x
> 0) {
1490 MoveTo(clip
.x_min
+ tsize
, clip
.y_min
);
1491 DrawTo(clip
.x_min
, clip
.y_min
);
1497 svxPrintout::OnPrintPage(int pageNum
) {
1498 GetPageSizePixels(&xpPageWidth
, &ypPageDepth
);
1500 pdc
->SetBackgroundMode(wxTRANSPARENT
);
1501 #ifdef AVEN_PRINT_PREVIEW
1504 pdc
->GetSize(&dcx
, &dcy
);
1505 pdc
->SetUserScale((double)dcx
/ xpPageWidth
, (double)dcy
/ ypPageDepth
);
1509 layout
* l
= m_layout
;
1512 GetPageSizeMM(&pwidth
, &pdepth
);
1513 l
->scX
= (double)xpPageWidth
/ pwidth
;
1514 l
->scY
= (double)ypPageDepth
/ pdepth
;
1515 font_scaling_x
= l
->scX
* (25.4 / 72.0);
1516 font_scaling_y
= l
->scY
* (25.4 / 72.0);
1517 long MarginLeft
= m_data
->GetMarginTopLeft().x
;
1518 long MarginTop
= m_data
->GetMarginTopLeft().y
;
1519 long MarginBottom
= m_data
->GetMarginBottomRight().y
;
1520 long MarginRight
= m_data
->GetMarginBottomRight().x
;
1521 xpPageWidth
-= (int)(l
->scX
* (MarginLeft
+ MarginRight
));
1522 ypPageDepth
-= (int)(l
->scY
* (FOOTER_HEIGHT_MM
+ MarginBottom
+ MarginTop
));
1523 // xpPageWidth -= 1;
1524 pdepth
-= FOOTER_HEIGHT_MM
;
1525 x_offset
= (long)(l
->scX
* MarginLeft
);
1526 y_offset
= (long)(l
->scY
* MarginTop
);
1527 l
->PaperWidth
= pwidth
-= MarginLeft
+ MarginRight
;
1528 l
->PaperDepth
= pdepth
-= MarginTop
+ MarginBottom
;
1531 double SIN
= sin(rad(l
->rot
));
1532 double COS
= cos(rad(l
->rot
));
1533 double SINT
= sin(rad(l
->tilt
));
1534 double COST
= cos(rad(l
->tilt
));
1536 NewPage(pageNum
, l
->pagesX
, l
->pagesY
);
1538 if (l
->Legend
&& pageNum
== (l
->pagesY
- 1) * l
->pagesX
+ 1) {
1539 SetFont(font_default
);
1543 pdc
->SetClippingRegion(x_offset
, y_offset
, xpPageWidth
+ 1, ypPageDepth
+ 1);
1545 const double Sc
= 1000 / l
->Scale
;
1547 const SurveyFilter
* filter
= mainfrm
->GetTreeFilter();
1548 int show_mask
= l
->get_effective_show_mask();
1549 if (show_mask
& (LEGS
|SURF
)) {
1550 for (int f
= 0; f
!= 8; ++f
) {
1551 if ((show_mask
& (f
& img_FLAG_SURFACE
) ? SURF
: LEGS
) == 0) {
1552 // Not showing traverse because of surface/underground status.
1555 if ((f
& img_FLAG_SPLAY
) && (show_mask
& SPLAYS
) == 0) {
1556 // Not showing because it's a splay.
1559 if (f
& img_FLAG_SPLAY
) {
1560 pdc
->SetPen(*pen_splay
);
1561 } else if (f
& img_FLAG_SURFACE
) {
1562 pdc
->SetPen(*pen_surface_leg
);
1564 pdc
->SetPen(*pen_leg
);
1566 list
<traverse
>::const_iterator trav
= mainfrm
->traverses_begin(f
, filter
);
1567 list
<traverse
>::const_iterator tend
= mainfrm
->traverses_end(f
);
1568 for ( ; trav
!= tend
; trav
= mainfrm
->traverses_next(f
, filter
, trav
)) {
1569 vector
<PointInfo
>::const_iterator pos
= trav
->begin();
1570 vector
<PointInfo
>::const_iterator end
= trav
->end();
1571 for ( ; pos
!= end
; ++pos
) {
1572 double x
= pos
->GetX();
1573 double y
= pos
->GetY();
1574 double z
= pos
->GetZ();
1575 double X
= x
* COS
- y
* SIN
;
1576 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1577 long px
= (long)((X
* Sc
+ l
->xOrg
) * l
->scX
);
1578 long py
= (long)((Y
* Sc
+ l
->yOrg
) * l
->scY
);
1579 if (pos
== trav
->begin()) {
1589 if ((show_mask
& XSECT
) &&
1590 (l
->tilt
== 0.0 || l
->tilt
== 90.0 || l
->tilt
== -90.0)) {
1591 pdc
->SetPen(*pen_splay
);
1592 list
<vector
<XSect
>>::const_iterator trav
= mainfrm
->tubes_begin();
1593 list
<vector
<XSect
>>::const_iterator tend
= mainfrm
->tubes_end();
1594 for ( ; trav
!= tend
; ++trav
) {
1595 if (l
->tilt
== 0.0) {
1598 // m_layout.tilt is 90.0 or -90.0 due to check above.
1604 if (show_mask
& (LABELS
|STNS
)) {
1605 if (show_mask
& LABELS
) SetFont(font_labels
);
1606 for (auto label
= mainfrm
->GetLabels();
1607 label
!= mainfrm
->GetLabelsEnd();
1609 if (filter
&& !filter
->CheckVisible((*label
)->GetText()))
1611 double px
= (*label
)->GetX();
1612 double py
= (*label
)->GetY();
1613 double pz
= (*label
)->GetZ();
1614 if ((show_mask
& SURF
) || (*label
)->IsUnderground()) {
1615 double X
= px
* COS
- py
* SIN
;
1616 double Y
= pz
* COST
- (px
* SIN
+ py
* COS
) * SINT
;
1618 xnew
= (long)((X
* Sc
+ l
->xOrg
) * l
->scX
);
1619 ynew
= (long)((Y
* Sc
+ l
->yOrg
) * l
->scY
);
1620 if (show_mask
& STNS
) {
1621 pdc
->SetPen(*pen_cross
);
1622 DrawCross(xnew
, ynew
);
1624 if (show_mask
& LABELS
) {
1625 pdc
->SetTextForeground(colour_labels
);
1627 WriteString((*label
)->GetText());
1637 svxPrintout::GetPageInfo(int *minPage
, int *maxPage
,
1638 int *pageFrom
, int *pageTo
)
1640 *minPage
= *pageFrom
= 1;
1641 *maxPage
= *pageTo
= m_layout
->pages
;
1645 svxPrintout::HasPage(int pageNum
) {
1646 return (pageNum
<= m_layout
->pages
);
1650 svxPrintout::OnBeginPrinting() {
1651 /* Initialise printer routines */
1652 fontsize_labels
= 10;
1655 colour_text
= colour_labels
= *wxBLACK
;
1657 wxColour colour_frame
, colour_cross
, colour_leg
, colour_surface_leg
;
1658 colour_frame
= colour_cross
= colour_leg
= colour_surface_leg
= *wxBLACK
;
1660 pen_frame
= new wxPen(colour_frame
);
1661 pen_cross
= new wxPen(colour_cross
);
1662 pen_leg
= new wxPen(colour_leg
);
1663 pen_surface_leg
= new wxPen(colour_surface_leg
);
1664 pen_splay
= new wxPen(wxColour(128, 128, 128));
1669 font_labels
= new wxFont(fontsize_labels
, wxFONTFAMILY_DEFAULT
,
1670 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
1671 false, wxString(fontname_labels
, wxConvUTF8
),
1672 wxFONTENCODING_ISO8859_1
);
1673 font_default
= new wxFont(fontsize
, wxFONTFAMILY_DEFAULT
,
1674 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
1675 false, wxString(fontname
, wxConvUTF8
),
1676 wxFONTENCODING_ISO8859_1
);
1680 svxPrintout::OnEndPrinting() {
1682 delete font_default
;
1686 delete pen_surface_leg
;
1691 svxPrintout::check_intersection(long x_p
, long y_p
)
1697 int mask_p
= 0, mask_t
= 0;
1700 else if (x_p
> xpPageWidth
)
1705 else if (y_p
> ypPageDepth
)
1710 else if (x_t
> xpPageWidth
)
1715 else if (y_t
> ypPageDepth
)
1719 /* approximation to correct answer */
1720 return !(mask_t
& mask_p
);
1722 /* One end of the line is on the page */
1723 if (!mask_t
|| !mask_p
) return 1;
1725 /* whole line is above, left, right, or below page */
1726 if (mask_t
& mask_p
) return 0;
1728 if (mask_t
== 0) mask_t
= mask_p
;
1730 double v
= (double)(y_p
- ypPageDepth
) / (y_p
- y_t
);
1731 return v
>= 0 && v
<= 1;
1734 double v
= (double)y_p
/ (y_p
- y_t
);
1735 return v
>= 0 && v
<= 1;
1738 double v
= (double)(x_p
- xpPageWidth
) / (x_p
- x_t
);
1739 return v
>= 0 && v
<= 1;
1741 wxASSERT(mask_t
& L
);
1743 double v
= (double)x_p
/ (x_p
- x_t
);
1744 return v
>= 0 && v
<= 1;
1754 svxPrintout::MoveTo(long x
, long y
)
1756 x_t
= x_offset
+ x
- clip
.x_min
;
1757 y_t
= y_offset
+ clip
.y_max
- y
;
1761 svxPrintout::DrawTo(long x
, long y
)
1763 long x_p
= x_t
, y_p
= y_t
;
1764 x_t
= x_offset
+ x
- clip
.x_min
;
1765 y_t
= y_offset
+ clip
.y_max
- y
;
1766 if (!scan_for_blank_pages
) {
1767 pdc
->DrawLine(x_p
, y_p
, x_t
, y_t
);
1769 if (check_intersection(x_p
, y_p
)) fBlankPage
= fFalse
;
1773 #define POINTS_PER_INCH 72.0
1774 #define POINTS_PER_MM (POINTS_PER_INCH / MM_PER_INCH)
1775 #define PWX_CROSS_SIZE (int)(2 * m_layout->scX / POINTS_PER_MM)
1778 svxPrintout::DrawCross(long x
, long y
)
1780 if (!scan_for_blank_pages
) {
1781 MoveTo(x
- PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
1782 DrawTo(x
+ PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
1783 MoveTo(x
+ PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
1784 DrawTo(x
- PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
1787 if ((x
+ PWX_CROSS_SIZE
> clip
.x_min
&&
1788 x
- PWX_CROSS_SIZE
< clip
.x_max
) ||
1789 (y
+ PWX_CROSS_SIZE
> clip
.y_min
&&
1790 y
- PWX_CROSS_SIZE
< clip
.y_max
)) {
1791 fBlankPage
= fFalse
;
1797 svxPrintout::WriteString(const wxString
& s
)
1800 pdc
->GetUserScale(&xsc
, &ysc
);
1801 pdc
->SetUserScale(xsc
* font_scaling_x
, ysc
* font_scaling_y
);
1802 if (!scan_for_blank_pages
) {
1804 long(x_t
/ font_scaling_x
),
1805 long(y_t
/ font_scaling_y
) - pdc
->GetCharHeight());
1808 pdc
->GetTextExtent(s
, &w
, &h
);
1809 if ((y_t
+ h
> 0 && y_t
- h
< clip
.y_max
- clip
.y_min
) ||
1810 (x_t
< clip
.x_max
- clip
.x_min
&& x_t
+ w
> 0)) {
1811 fBlankPage
= fFalse
;
1814 pdc
->SetUserScale(xsc
, ysc
);
1818 svxPrintout::DrawEllipse(long x
, long y
, long r
, long R
)
1820 if (!scan_for_blank_pages
) {
1821 x_t
= x_offset
+ x
- clip
.x_min
;
1822 y_t
= y_offset
+ clip
.y_max
- y
;
1823 const wxBrush
& save_brush
= pdc
->GetBrush();
1824 pdc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1825 pdc
->DrawEllipse(x_t
- r
, y_t
- R
, 2 * r
, 2 * R
);
1826 pdc
->SetBrush(save_brush
);
1828 /* No need to check - this is only used in the legend. */
1833 svxPrintout::SolidRectangle(long x
, long y
, long w
, long h
)
1835 long X
= x_offset
+ x
- clip
.x_min
;
1836 long Y
= y_offset
+ clip
.y_max
- y
;
1837 pdc
->SetBrush(*wxBLACK_BRUSH
);
1838 pdc
->DrawRectangle(X
, Y
- h
, w
, h
);
1842 svxPrintout::NewPage(int pg
, int pagesX
, int pagesY
)
1844 pdc
->DestroyClippingRegion();
1847 x
= (pg
- 1) % pagesX
;
1848 y
= pagesY
- 1 - ((pg
- 1) / pagesX
);
1850 clip
.x_min
= (long)x
* xpPageWidth
;
1851 clip
.y_min
= (long)y
* ypPageDepth
;
1852 clip
.x_max
= clip
.x_min
+ xpPageWidth
; /* dm/pcl/ps had -1; */
1853 clip
.y_max
= clip
.y_min
+ ypPageDepth
; /* dm/pcl/ps had -1; */
1855 const int FOOTERS
= 4;
1856 wxString footer
[FOOTERS
];
1857 footer
[0] = m_layout
->title
;
1859 double rot
= m_layout
->rot
;
1860 double tilt
= m_layout
->tilt
;
1861 double scale
= m_layout
->Scale
;
1862 switch (m_layout
->view
) {
1864 // TRANSLATORS: Used in the footer of printouts to compactly
1865 // indicate this is a plan view and what the viewing angle is.
1866 // Aven will replace %s with the bearing, and %.0f with the scale.
1868 // This message probably doesn't need translating for most languages.
1869 footer
[1].Printf(wmsg(/*↑%s 1:%.0f*/233),
1870 format_angle(ANGLE_FMT
, rot
).c_str(),
1874 // TRANSLATORS: Used in the footer of printouts to compactly
1875 // indicate this is an elevation view and what the viewing angle
1876 // is. Aven will replace the %s codes with the bearings to the
1877 // left and right of the viewer, and %.0f with the scale.
1879 // This message probably doesn't need translating for most languages.
1880 footer
[1].Printf(wmsg(/*%s↔%s 1:%.0f*/235),
1881 format_angle(ANGLE_FMT
, fmod(rot
+ 270.0, 360.0)).c_str(),
1882 format_angle(ANGLE_FMT
, fmod(rot
+ 90.0, 360.0)).c_str(),
1886 // TRANSLATORS: Used in the footer of printouts to compactly
1887 // indicate this is a tilted elevation view and what the viewing
1888 // angles are. Aven will replace the %s codes with the bearings to
1889 // the left and right of the viewer and the angle the view is
1890 // tilted at, and %.0f with the scale.
1892 // This message probably doesn't need translating for most languages.
1893 footer
[1].Printf(wmsg(/*%s↔%s ∡%s 1:%.0f*/236),
1894 format_angle(ANGLE_FMT
, fmod(rot
+ 270.0, 360.0)).c_str(),
1895 format_angle(ANGLE_FMT
, fmod(rot
+ 90.0, 360.0)).c_str(),
1896 format_angle(ANGLE2_FMT
, tilt
).c_str(),
1899 case layout::EXTELEV
:
1900 // TRANSLATORS: Used in the footer of printouts to compactly
1901 // indicate this is an extended elevation view. Aven will replace
1902 // %.0f with the scale.
1904 // Try to keep the translation short (for example, in English we
1905 // use "Extended" not "Extended elevation") - there is limited room
1906 // in the footer, and the details there are mostly to make it easy
1907 // to check that you have corresponding pages from a multiple page
1909 footer
[1].Printf(wmsg(/*Extended 1:%.0f*/244), scale
);
1913 // TRANSLATORS: N/M meaning page N of M in the page footer of a printout.
1914 footer
[2].Printf(wmsg(/*%d/%d*/232), pg
, m_layout
->pagesX
* m_layout
->pagesY
);
1916 wxString datestamp
= m_layout
->datestamp
;
1917 if (!datestamp
.empty()) {
1918 // Remove any timezone suffix (e.g. " UTC" or " +1200").
1919 wxChar ch
= datestamp
[datestamp
.size() - 1];
1920 if (ch
>= 'A' && ch
<= 'Z') {
1921 for (size_t i
= datestamp
.size() - 1; i
; --i
) {
1923 if (ch
< 'A' || ch
> 'Z') {
1924 if (ch
== ' ') datestamp
.resize(i
);
1928 } else if (ch
>= '0' && ch
<= '9') {
1929 for (size_t i
= datestamp
.size() - 1; i
; --i
) {
1931 if (ch
< '0' || ch
> '9') {
1932 if ((ch
== '-' || ch
== '+') && datestamp
[--i
] == ' ')
1933 datestamp
.resize(i
);
1939 // Remove any day prefix (e.g. "Mon,").
1940 for (size_t i
= 0; i
!= datestamp
.size(); ++i
) {
1941 if (datestamp
[i
] == ',' && i
+ 1 != datestamp
.size()) {
1942 // Also skip a space after the comma.
1943 if (datestamp
[i
+ 1] == ' ') ++i
;
1944 datestamp
.erase(0, i
+ 1);
1950 // TRANSLATORS: Used in the footer of printouts to compactly indicate that
1951 // the date which follows is the date that the survey data was processed.
1953 // Aven will replace %s with a string giving the date and time (e.g.
1954 // "2015-06-09 12:40:44").
1955 footer
[3].Printf(wmsg(/*Processed: %s*/167), datestamp
.c_str());
1957 const wxChar
* footer_sep
= wxT(" ");
1958 int fontsize_footer
= fontsize_labels
;
1959 wxFont
* font_footer
;
1960 font_footer
= new wxFont(fontsize_footer
, wxFONTFAMILY_DEFAULT
,
1961 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
1962 false, wxString(fontname_labels
, wxConvUTF8
),
1963 wxFONTENCODING_UTF8
);
1964 font_footer
->Scale(font_scaling_x
);
1965 SetFont(font_footer
);
1966 int w
[FOOTERS
], ws
, h
;
1967 pdc
->GetTextExtent(footer_sep
, &ws
, &h
);
1968 int wtotal
= ws
* (FOOTERS
- 1);
1969 for (int i
= 0; i
< FOOTERS
; ++i
) {
1970 pdc
->GetTextExtent(footer
[i
], &w
[i
], &h
);
1975 long Y
= y_offset
+ ypPageDepth
+ (long)(7 * m_layout
->scY
) - pdc
->GetCharHeight();
1977 if (wtotal
> xpPageWidth
) {
1978 // Rescale the footer so it fits.
1979 double rescale
= double(wtotal
) / xpPageWidth
;
1981 pdc
->GetUserScale(&xsc
, &ysc
);
1982 pdc
->SetUserScale(xsc
/ rescale
, ysc
/ rescale
);
1983 SetFont(font_footer
);
1984 wxString fullfooter
= footer
[0];
1985 for (int i
= 1; i
< FOOTERS
- 1; ++i
) {
1986 fullfooter
+= footer_sep
;
1987 fullfooter
+= footer
[i
];
1989 pdc
->DrawText(fullfooter
, X
* rescale
, Y
* rescale
);
1990 // Draw final item right aligned to avoid misaligning.
1991 wxRect
rect(x_offset
* rescale
, Y
* rescale
,
1992 xpPageWidth
* rescale
, pdc
->GetCharHeight() * rescale
);
1993 pdc
->DrawLabel(footer
[FOOTERS
- 1], rect
, wxALIGN_RIGHT
|wxALIGN_TOP
);
1994 pdc
->SetUserScale(xsc
, ysc
);
1996 // Space out the elements of the footer to fill the line.
1997 double extra
= double(xpPageWidth
- wtotal
) / (FOOTERS
- 1);
1998 for (int i
= 0; i
< FOOTERS
- 1; ++i
) {
1999 pdc
->DrawText(footer
[i
], X
+ extra
* i
, Y
);
2002 // Draw final item right aligned to avoid misaligning.
2003 wxRect
rect(x_offset
, Y
, xpPageWidth
, pdc
->GetCharHeight());
2004 pdc
->DrawLabel(footer
[FOOTERS
- 1], rect
, wxALIGN_RIGHT
|wxALIGN_TOP
);
2006 drawticks((int)(9 * m_layout
->scX
/ POINTS_PER_MM
), x
, y
);
2010 svxPrintout::PlotLR(const vector
<XSect
> & centreline
)
2012 const SurveyFilter
* filter
= mainfrm
->GetTreeFilter();
2013 assert(centreline
.size() > 1);
2014 const XSect
* prev_pt_v
= NULL
;
2015 Vector3
last_right(1.0, 0.0, 0.0);
2017 const double Sc
= 1000 / m_layout
->Scale
;
2018 const double SIN
= sin(rad(m_layout
->rot
));
2019 const double COS
= cos(rad(m_layout
->rot
));
2021 vector
<XSect
>::const_iterator i
= centreline
.begin();
2022 vector
<XSect
>::size_type segment
= 0;
2023 while (i
!= centreline
.end()) {
2024 // get the coordinates of this vertex
2025 const XSect
& pt_v
= *i
++;
2029 const Vector3
up_v(0.0, 0.0, 1.0);
2032 assert(i
!= centreline
.end());
2035 // get the coordinates of the next vertex
2036 const XSect
& next_pt_v
= *i
;
2038 // calculate vector from this pt to the next one
2039 Vector3 leg_v
= next_pt_v
- pt_v
;
2041 // obtain a vector in the LRUD plane
2042 right
= leg_v
* up_v
;
2043 if (right
.magnitude() == 0) {
2048 } else if (segment
+ 1 == centreline
.size()) {
2051 // Calculate vector from the previous pt to this one.
2052 Vector3 leg_v
= pt_v
- *prev_pt_v
;
2054 // Obtain a horizontal vector in the LRUD plane.
2055 right
= leg_v
* up_v
;
2056 if (right
.magnitude() == 0) {
2057 right
= Vector3(last_right
.GetX(), last_right
.GetY(), 0.0);
2062 assert(i
!= centreline
.end());
2063 // Intermediate segment.
2065 // Get the coordinates of the next vertex.
2066 const XSect
& next_pt_v
= *i
;
2068 // Calculate vectors from this vertex to the
2069 // next vertex, and from the previous vertex to
2071 Vector3 leg1_v
= pt_v
- *prev_pt_v
;
2072 Vector3 leg2_v
= next_pt_v
- pt_v
;
2074 // Obtain horizontal vectors perpendicular to
2075 // both legs, then normalise and average to get
2076 // a horizontal bisector.
2077 Vector3 r1
= leg1_v
* up_v
;
2078 Vector3 r2
= leg2_v
* up_v
;
2082 if (right
.magnitude() == 0) {
2083 // This is the "mid-pitch" case...
2089 // Scale to unit vectors in the LRUD plane.
2092 Double l
= pt_v
.GetL();
2093 Double r
= pt_v
.GetR();
2095 if (l
>= 0 || r
>= 0) {
2096 if (!filter
|| filter
->CheckVisible(pt_v
.GetLabel())) {
2097 // Get the x and y coordinates of the survey station
2098 double pt_X
= pt_v
.GetX() * COS
- pt_v
.GetY() * SIN
;
2099 double pt_Y
= pt_v
.GetX() * SIN
+ pt_v
.GetY() * COS
;
2100 long pt_x
= (long)((pt_X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2101 long pt_y
= (long)((pt_Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2103 // Calculate dimensions for the right arrow
2104 double COSR
= right
.GetX();
2105 double SINR
= right
.GetY();
2106 long CROSS_MAJOR
= (COSR
+ SINR
) * PWX_CROSS_SIZE
;
2107 long CROSS_MINOR
= (COSR
- SINR
) * PWX_CROSS_SIZE
;
2110 // Get the x and y coordinates of the end of the left arrow
2111 Vector3 p
= pt_v
.GetPoint() - right
* l
;
2112 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2113 double Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
2114 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2115 long y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2117 // Draw the arrow stem
2121 // Rotate the arrow by the page rotation
2122 long dx1
= (+CROSS_MINOR
) * COS
- (+CROSS_MAJOR
) * SIN
;
2123 long dy1
= (+CROSS_MINOR
) * SIN
+ (+CROSS_MAJOR
) * COS
;
2124 long dx2
= (+CROSS_MAJOR
) * COS
- (-CROSS_MINOR
) * SIN
;
2125 long dy2
= (+CROSS_MAJOR
) * SIN
+ (-CROSS_MINOR
) * COS
;
2128 MoveTo(x
+ dx1
, y
+ dy1
);
2130 DrawTo(x
+ dx2
, y
+ dy2
);
2134 // Get the x and y coordinates of the end of the right arrow
2135 Vector3 p
= pt_v
.GetPoint() + right
* r
;
2136 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2137 double Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
2138 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2139 long y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2141 // Draw the arrow stem
2145 // Rotate the arrow by the page rotation
2146 long dx1
= (-CROSS_MINOR
) * COS
- (-CROSS_MAJOR
) * SIN
;
2147 long dy1
= (-CROSS_MINOR
) * SIN
+ (-CROSS_MAJOR
) * COS
;
2148 long dx2
= (-CROSS_MAJOR
) * COS
- (+CROSS_MINOR
) * SIN
;
2149 long dy2
= (-CROSS_MAJOR
) * SIN
+ (+CROSS_MINOR
) * COS
;
2152 MoveTo(x
+ dx1
, y
+ dy1
);
2154 DrawTo(x
+ dx2
, y
+ dy2
);
2166 svxPrintout::PlotUD(const vector
<XSect
> & centreline
)
2168 const SurveyFilter
* filter
= mainfrm
->GetTreeFilter();
2169 assert(centreline
.size() > 1);
2170 const double Sc
= 1000 / m_layout
->Scale
;
2172 vector
<XSect
>::const_iterator i
= centreline
.begin();
2173 while (i
!= centreline
.end()) {
2174 // get the coordinates of this vertex
2175 const XSect
& pt_v
= *i
++;
2177 Double u
= pt_v
.GetU();
2178 Double d
= pt_v
.GetD();
2180 if (u
>= 0 || d
>= 0) {
2181 if (filter
&& !filter
->CheckVisible(pt_v
.GetLabel()))
2184 // Get the coordinates of the survey point
2185 Vector3 p
= pt_v
.GetPoint();
2186 double SIN
= sin(rad(m_layout
->rot
));
2187 double COS
= cos(rad(m_layout
->rot
));
2188 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2189 double Y
= p
.GetZ();
2190 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2191 long pt_y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scX
);
2194 // Get the y coordinate of the up arrow
2195 long y
= (long)(((Y
+ u
) * Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2197 // Draw the arrow stem
2201 // Draw the up arrow
2202 MoveTo(x
- PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
2204 DrawTo(x
+ PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
2208 // Get the y coordinate of the down arrow
2209 long y
= (long)(((Y
- d
) * Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2211 // Draw the arrow stem
2215 // Draw the down arrow
2216 MoveTo(x
- PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
2218 DrawTo(x
+ PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);