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
[] = {
283 static_assert(sizeof(formats
) == FMT_MAX_PLUS_ONE_
* sizeof(formats
[0]),
284 "formats[] matches enum export_format");
286 // We discriminate as "One Page" isn't valid for exporting.
287 static wxString default_scale_print
;
288 static wxString default_scale_export
;
290 svxPrintDlg::svxPrintDlg(MainFrm
* mainfrm_
, const wxString
& filename
,
291 const wxString
& title
,
292 const wxString
& datestamp
,
293 double angle
, double tilt_angle
,
294 bool labels
, bool crosses
, bool legs
, bool surf
,
295 bool splays
, bool tubes
, bool ents
, bool fixes
,
296 bool exports
, bool printing
, bool close_after_
)
297 : wxDialog(mainfrm_
, -1, wxString(printing
?
298 /* TRANSLATORS: Title of the print
301 /* TRANSLATORS: Title of the export
303 wmsg(/*Export*/383))),
304 m_layout(printing
? wxGetApp().GetPageSetupDialogData() : NULL
),
305 m_File(filename
), mainfrm(mainfrm_
), close_after(close_after_
)
324 show_mask
|= XSECT
|WALLS
|PASG
;
330 show_mask
|= EXPORTS
;
331 m_layout
.show_mask
= show_mask
;
332 m_layout
.datestamp
= datestamp
;
333 m_layout
.rot
= angle
;
334 m_layout
.title
= title
;
335 if (mainfrm
->IsExtendedElevation()) {
336 m_layout
.view
= layout::EXTELEV
;
337 if (m_layout
.rot
!= 0.0 && m_layout
.rot
!= 180.0) m_layout
.rot
= 0;
340 m_layout
.tilt
= tilt_angle
;
341 if (m_layout
.tilt
== -90.0) {
342 m_layout
.view
= layout::PLAN
;
343 } else if (m_layout
.tilt
== 0.0) {
344 m_layout
.view
= layout::ELEV
;
346 m_layout
.view
= layout::TILT
;
350 /* setup our print dialog*/
351 wxBoxSizer
* v1
= new wxBoxSizer(wxVERTICAL
);
352 wxBoxSizer
* h1
= new wxBoxSizer(wxHORIZONTAL
); // holds controls
353 /* TRANSLATORS: Used as a label for the surrounding box for the "Bearing"
354 * and "Tilt angle" fields, and the "Plan view" and "Elevation" buttons in
355 * the "what to print/export" dialog. */
356 m_viewbox
= new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*View*/283)), wxVERTICAL
);
357 /* TRANSLATORS: Used as a label for the surrounding box for the "survey
358 * legs" "stations" "names" etc checkboxes in the "what to print" dialog.
359 * "Elements" isn’t a good name for this but nothing better has yet come to
361 wxBoxSizer
* v2
= new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*Elements*/256)), wxVERTICAL
);
362 wxBoxSizer
* h2
= new wxBoxSizer(wxHORIZONTAL
); // holds buttons
366 label
= new wxStaticText(this, -1, wxString(wmsg(/*Export format*/410)));
367 const size_t n_formats
= sizeof(formats
) / sizeof(formats
[0]);
368 m_format
= new wxChoice(this, svx_FORMAT
,
369 wxDefaultPosition
, wxDefaultSize
,
371 unsigned current_format
= 0;
372 wxConfigBase
* cfg
= wxConfigBase::Get();
374 if (cfg
->Read(wxT("export_format"), &s
, wxString())) {
375 for (unsigned i
= 0; i
!= n_formats
; ++i
) {
376 if (s
== formats
[i
]) {
382 m_format
->SetSelection(current_format
);
383 wxBoxSizer
* formatbox
= new wxBoxSizer(wxHORIZONTAL
);
384 formatbox
->Add(label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
385 formatbox
->Add(m_format
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
387 v1
->Add(formatbox
, 0, wxALIGN_LEFT
|wxALL
, 0);
391 label
= new wxStaticText(this, -1, wxString(wmsg(/*Scale*/154)) + wxT(" 1:"));
392 if (printing
&& scales
[0].empty()) {
393 /* TRANSLATORS: used in the scale drop down selector in the print
394 * dialog the implicit meaning is "choose a suitable scale to fit
395 * the plot on a single page", but we need something shorter */
396 scales
[0].assign(wmsg(/*One page*/258));
398 wxString default_scale
;
400 default_scale
= default_scale_print
;
401 if (default_scale
.empty()) default_scale
= scales
[0];
403 default_scale
= default_scale_export
;
404 if (default_scale
.empty()) default_scale
= wxT("1000");
406 const wxString
* scale_list
= scales
;
407 size_t n_scales
= sizeof(scales
) / sizeof(scales
[0]);
412 m_scale
= new wxComboBox(this, svx_SCALE
, default_scale
, wxDefaultPosition
,
413 wxDefaultSize
, n_scales
, scale_list
);
414 m_scalebox
= new wxBoxSizer(wxHORIZONTAL
);
415 m_scalebox
->Add(label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
416 m_scalebox
->Add(m_scale
, 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
418 m_viewbox
->Add(m_scalebox
, 0, wxALIGN_LEFT
|wxALL
, 0);
421 // Make the dummy string wider than any sane value and use that to
422 // fix the width of the control so the sizers allow space for bigger
424 m_printSize
= new wxStaticText(this, -1, wxString::Format(wmsg(/*%d pages (%dx%d)*/257), 9604, 98, 98));
425 m_viewbox
->Add(m_printSize
, 0, wxALIGN_LEFT
|wxALL
, 5);
428 if (m_layout
.view
!= layout::EXTELEV
) {
429 wxFlexGridSizer
* anglebox
= new wxFlexGridSizer(2);
430 wxStaticText
* brg_label
, * tilt_label
;
431 brg_label
= new wxStaticText(this, -1, wmsg(/*Bearing*/259));
432 anglebox
->Add(brg_label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALIGN_LEFT
|wxALL
, 5);
433 // wSP_WRAP means that you can scroll past 360 to 0, and vice versa.
434 m_bearing
= new wxSpinCtrlDouble(this, svx_BEARING
, wxEmptyString
,
435 wxDefaultPosition
, wxDefaultSize
,
436 wxSP_ARROW_KEYS
|wxALIGN_RIGHT
|wxSP_WRAP
);
437 m_bearing
->SetRange(0.0, 360.0);
438 m_bearing
->SetDigits(ANGLE_DP
);
439 anglebox
->Add(m_bearing
, 0, wxALIGN_CENTRE
|wxALL
, 5);
440 /* TRANSLATORS: Used in the print dialog: */
441 tilt_label
= new wxStaticText(this, -1, wmsg(/*Tilt angle*/263));
442 anglebox
->Add(tilt_label
, 0, wxALIGN_CENTRE_VERTICAL
|wxALIGN_LEFT
|wxALL
, 5);
443 m_tilt
= new wxSpinCtrlDouble(this, svx_TILT
);
444 m_tilt
->SetRange(-90.0, 90.0);
445 m_tilt
->SetDigits(ANGLE_DP
);
446 anglebox
->Add(m_tilt
, 0, wxALIGN_CENTRE
|wxALL
, 5);
448 m_viewbox
->Add(anglebox
, 0, wxALIGN_LEFT
|wxALL
, 0);
450 wxBoxSizer
* planelevsizer
= new wxBoxSizer(wxHORIZONTAL
);
451 planelevsizer
->Add(new wxButton(this, svx_PLAN
, wmsg(/*P&lan view*/117)),
452 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
453 planelevsizer
->Add(new wxButton(this, svx_ELEV
, wmsg(/*&Elevation*/285)),
454 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
456 m_viewbox
->Add(planelevsizer
, 0, wxALIGN_LEFT
|wxALL
, 5);
459 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
460 * "survey stations". */
461 v2
->Add(new wxCheckBox(this, svx_LEGS
, wmsg(/*Underground Survey Legs*/262),
462 wxDefaultPosition
, wxDefaultSize
, 0,
463 BitValidator(&m_layout
.show_mask
, LEGS
)),
464 0, wxALIGN_LEFT
|wxALL
, 2);
465 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
466 * "survey stations". */
467 v2
->Add(new wxCheckBox(this, svx_SURFACE
, wmsg(/*Sur&face Survey Legs*/403),
468 wxDefaultPosition
, wxDefaultSize
, 0,
469 BitValidator(&m_layout
.show_mask
, SURF
)),
470 0, wxALIGN_LEFT
|wxALL
, 2);
471 v2
->Add(new wxCheckBox(this, svx_SPLAYS
, wmsg(/*Spla&y Legs*/406),
472 wxDefaultPosition
, wxDefaultSize
, 0,
473 BitValidator(&m_layout
.show_mask
, SPLAYS
)),
474 0, wxALIGN_LEFT
|wxALL
, 2);
475 v2
->Add(new wxCheckBox(this, svx_STATIONS
, wmsg(/*Crosses*/261),
476 wxDefaultPosition
, wxDefaultSize
, 0,
477 BitValidator(&m_layout
.show_mask
, STNS
)),
478 0, wxALIGN_LEFT
|wxALL
, 2);
479 v2
->Add(new wxCheckBox(this, svx_NAMES
, wmsg(/*Station Names*/260),
480 wxDefaultPosition
, wxDefaultSize
, 0,
481 BitValidator(&m_layout
.show_mask
, LABELS
)),
482 0, wxALIGN_LEFT
|wxALL
, 2);
483 v2
->Add(new wxCheckBox(this, svx_ENTS
, wmsg(/*Entrances*/418),
484 wxDefaultPosition
, wxDefaultSize
, 0,
485 BitValidator(&m_layout
.show_mask
, ENTS
)),
486 0, wxALIGN_LEFT
|wxALL
, 2);
487 v2
->Add(new wxCheckBox(this, svx_FIXES
, wmsg(/*Fixed Points*/419),
488 wxDefaultPosition
, wxDefaultSize
, 0,
489 BitValidator(&m_layout
.show_mask
, FIXES
)),
490 0, wxALIGN_LEFT
|wxALL
, 2);
491 v2
->Add(new wxCheckBox(this, svx_EXPORTS
, wmsg(/*Exported Stations*/420),
492 wxDefaultPosition
, wxDefaultSize
, 0,
493 BitValidator(&m_layout
.show_mask
, EXPORTS
)),
494 0, wxALIGN_LEFT
|wxALL
, 2);
495 v2
->Add(new wxCheckBox(this, svx_XSECT
, wmsg(/*Cross-sections*/393),
496 wxDefaultPosition
, wxDefaultSize
, 0,
497 BitValidator(&m_layout
.show_mask
, XSECT
)),
498 0, wxALIGN_LEFT
|wxALL
, 2);
500 v2
->Add(new wxCheckBox(this, svx_WALLS
, wmsg(/*Walls*/394),
501 wxDefaultPosition
, wxDefaultSize
, 0,
502 BitValidator(&m_layout
.show_mask
, WALLS
)),
503 0, wxALIGN_LEFT
|wxALL
, 2);
504 // TRANSLATORS: Label for checkbox which controls whether there's a
505 // layer in the exported file (for formats such as DXF and SVG)
506 // containing polygons for the inside of cave passages).
507 v2
->Add(new wxCheckBox(this, svx_PASSAGES
, wmsg(/*Passages*/395),
508 wxDefaultPosition
, wxDefaultSize
, 0,
509 BitValidator(&m_layout
.show_mask
, PASG
)),
510 0, wxALIGN_LEFT
|wxALL
, 2);
511 v2
->Add(new wxCheckBox(this, svx_CENTRED
, wmsg(/*Origin in centre*/421),
512 wxDefaultPosition
, wxDefaultSize
, 0,
513 BitValidator(&m_layout
.show_mask
, CENTRED
)),
514 0, wxALIGN_LEFT
|wxALL
, 2);
515 v2
->Add(new wxCheckBox(this, svx_FULLCOORDS
, wmsg(/*Full coordinates*/422),
516 wxDefaultPosition
, wxDefaultSize
, 0,
517 BitValidator(&m_layout
.show_mask
, FULL_COORDS
)),
518 0, wxALIGN_LEFT
|wxALL
, 2);
519 v2
->Add(new wxCheckBox(this, svx_CLAMP_TO_GROUND
, wmsg(/*Clamp to ground*/477),
520 wxDefaultPosition
, wxDefaultSize
, 0,
521 BitValidator(&m_layout
.show_mask
, CLAMP_TO_GROUND
)),
522 0, wxALIGN_LEFT
|wxALL
, 2);
525 /* TRANSLATORS: used in the print dialog - controls drawing lines
526 * around each page */
527 v2
->Add(new wxCheckBox(this, svx_BORDERS
, wmsg(/*Page Borders*/264),
528 wxDefaultPosition
, wxDefaultSize
, 0,
529 wxGenericValidator(&m_layout
.Border
)),
530 0, wxALIGN_LEFT
|wxALL
, 2);
531 /* TRANSLATORS: will be used in the print dialog - check this to print
532 * blank pages (otherwise they’ll be skipped to save paper) */
533 // m_blanks = new wxCheckBox(this, svx_BLANKS, wmsg(/*Blank Pages*/266));
534 // v2->Add(m_blanks, 0, wxALIGN_LEFT|wxALL, 2);
535 /* TRANSLATORS: As in the legend on a map. Used in the print dialog -
536 * controls drawing the box at the lower left with survey name, view
538 v2
->Add(new wxCheckBox(this, svx_LEGEND
, wmsg(/*Legend*/265),
539 wxDefaultPosition
, wxDefaultSize
, 0,
540 wxGenericValidator(&m_layout
.Legend
)),
541 0, wxALIGN_LEFT
|wxALL
, 2);
544 h1
->Add(v2
, 0, wxALIGN_LEFT
|wxALL
, 5);
545 h1
->Add(m_viewbox
, 0, wxALIGN_LEFT
|wxLEFT
, 5);
547 v1
->Add(h1
, 0, wxALIGN_LEFT
|wxALL
, 5);
549 // When we enable/disable checkboxes in the export dialog, ideally we'd
550 // like the dialog to resize, but not sure how to achieve that, so we
551 // add a stretchable spacer here so at least the buttons stay in the
552 // lower right corner.
553 v1
->AddStretchSpacer();
556 but
= new wxButton(this, wxID_CANCEL
);
557 h2
->Add(but
, 0, wxALL
, 5);
559 #ifdef AVEN_PRINT_PREVIEW
560 but
= new wxButton(this, wxID_PREVIEW
);
561 h2
->Add(but
, 0, wxALL
, 5);
562 but
= new wxButton(this, wxID_PRINT
);
564 but
= new wxButton(this, wxID_PRINT
, wmsg(/*&Print...*/400));
567 /* TRANSLATORS: The text on the action button in the "Export" settings
569 but
= new wxButton(this, svx_EXPORT
, wmsg(/*&Export...*/230));
572 h2
->Add(but
, 0, wxALL
, 5);
573 v1
->Add(h2
, 0, wxALIGN_RIGHT
|wxALL
, 5);
577 v1
->SetSizeHints(this);
584 svxPrintDlg::OnPrint(wxCommandEvent
&) {
586 TransferDataFromWindow();
587 wxPageSetupDialogData
* psdd
= wxGetApp().GetPageSetupDialogData();
588 wxPrintDialogData
pd(psdd
->GetPrintData());
590 svxPrintout
po(mainfrm
, &m_layout
, psdd
, m_File
);
591 if (m_layout
.SkipBlank
) {
592 // FIXME: wx's printing requires a contiguous range of valid page
593 // numbers. To achieve that, we need to run a scan for blank pages
594 // here, so that GetPageInfo() knows what range to return, and so
595 // that OnPrintPage() can map a page number back to where in the
596 // MxN multi-page layout.
598 po
.scan_for_blank_pages
= true;
599 for (int page
= 1; page
<= m_layout
->pages
; ++page
) {
600 po
.fBlankPage
= fTrue
;
601 po
.OnPrintPage(page
);
602 // FIXME: Do something with po.fBlankPage
604 po
.scan_for_blank_pages
= false;
607 if (pr
.Print(this, &po
, true)) {
608 // Close the print dialog if printing succeeded.
614 svxPrintDlg::OnExport(wxCommandEvent
&) {
616 TransferDataFromWindow();
618 wxFileName::SplitPath(m_File
, NULL
, NULL
, &leaf
, NULL
, wxPATH_NATIVE
);
619 unsigned format_idx
= ((wxChoice
*)FindWindow(svx_FORMAT
))->GetSelection();
620 const auto& info
= export_format_info
[format_idx
];
621 leaf
+= wxString::FromUTF8(info
.extension
);
623 wxString filespec
= wmsg(info
.msg_filetype
);
624 filespec
+= wxT("|*");
625 filespec
+= wxString::FromUTF8(info
.extension
);
626 filespec
+= wxT("|");
627 filespec
+= wmsg(/*All files*/208);
628 filespec
+= wxT("|");
629 filespec
+= wxFileSelectorDefaultWildcardStr
;
631 /* TRANSLATORS: Title of file dialog to choose name and type of exported
633 wxFileDialog
dlg(this, wmsg(/*Export as:*/401), wxString(), leaf
,
634 filespec
, wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
635 if (dlg
.ShowModal() == wxID_OK
) {
636 /* FIXME: Set up a way for the user to specify these: */
637 double grid
= DEFAULT_GRID_SPACING
; // metres
638 double text_height
= DEFAULT_TEXT_HEIGHT
;
639 double marker_size
= DEFAULT_MARKER_SIZE
;
642 const wxString
& export_fnm
= dlg
.GetPath();
643 unsigned mask
= info
.mask
;
645 if (mask
& EXPORT_3D
) {
650 tilt
= m_layout
.tilt
;
652 if (!Export(export_fnm
, m_layout
.title
,
653 m_layout
.datestamp
, *mainfrm
, mainfrm
->GetTreeFilter(),
654 rot
, tilt
, m_layout
.get_effective_show_mask(),
655 export_format(format_idx
),
656 grid
, text_height
, marker_size
, m_layout
.Scale
)) {
657 wxString m
= wxString::Format(wmsg(/*Couldn’t write file “%s”*/402).c_str(),
659 wxGetApp().ReportError(m
);
661 } catch (const wxString
& m
) {
662 wxGetApp().ReportError(m
);
668 #ifdef AVEN_PRINT_PREVIEW
670 svxPrintDlg::OnPreview(wxCommandEvent
&) {
672 TransferDataFromWindow();
673 wxPageSetupDialogData
* psdd
= wxGetApp().GetPageSetupDialogData();
674 wxPrintDialogData
pd(psdd
->GetPrintData());
676 pv
= new wxPrintPreview(new svxPrintout(mainfrm
, &m_layout
, psdd
, m_File
),
677 new svxPrintout(mainfrm
, &m_layout
, psdd
, m_File
),
679 // TRANSLATORS: Title of the print preview dialog
680 wxPreviewFrame
*frame
= new wxPreviewFrame(pv
, mainfrm
, wmsg(/*Print Preview*/398));
683 // Size preview frame so that all of the controlbar and canvas can be seen
686 // GetBestSize gives us the width needed to show the whole controlbar.
687 frame
->GetBestSize(&w
, &h
);
689 // On wxGTK at least, GetBestSize() returns much too small a height.
692 // Ensure that we don't make the window bigger than the screen.
693 // Use wxGetClientDisplayRect() so we don't cover the MS Windows
695 wxRect disp
= wxGetClientDisplayRect();
696 if (w
> disp
.GetWidth()) w
= disp
.GetWidth();
697 if (h
> disp
.GetHeight()) h
= disp
.GetHeight();
698 // Centre the window within the "ClientDisplayRect".
699 int x
= disp
.GetLeft() + (disp
.GetWidth() - w
) / 2;
700 int y
= disp
.GetTop() + (disp
.GetHeight() - h
) / 2;
701 frame
->SetSize(x
, y
, w
, h
);
708 svxPrintDlg::OnPlan(wxCommandEvent
&) {
709 m_tilt
->SetValue(-90.0);
710 SomethingChanged(svx_TILT
);
714 svxPrintDlg::OnElevation(wxCommandEvent
&) {
715 m_tilt
->SetValue(0.0);
716 SomethingChanged(svx_TILT
);
720 svxPrintDlg::OnPlanUpdate(wxUpdateUIEvent
& e
) {
721 e
.Enable(m_tilt
->GetValue() != -90.0);
725 svxPrintDlg::OnElevationUpdate(wxUpdateUIEvent
& e
) {
726 e
.Enable(m_tilt
->GetValue() != 0.0);
730 svxPrintDlg::OnChangeSpin(wxSpinDoubleEvent
& e
) {
731 SomethingChanged(e
.GetId());
735 svxPrintDlg::OnChange(wxCommandEvent
& e
) {
736 if (e
.GetId() == svx_SCALE
&& m_scale
) {
737 default_scale_print
= m_scale
->GetValue();
738 if (default_scale_print
!= scales
[0]) {
739 // Don't store "One Page" for use when exporting.
740 default_scale_export
= default_scale_print
;
743 SomethingChanged(e
.GetId());
747 svxPrintDlg::OnCancel(wxCommandEvent
&) {
754 svxPrintDlg::SomethingChanged(int control_id
) {
755 if ((control_id
== 0 || control_id
== svx_FORMAT
) && m_format
) {
756 // Update the shown/hidden fields for the newly selected export filter.
757 int new_filter_idx
= m_format
->GetSelection();
758 if (new_filter_idx
!= wxNOT_FOUND
) {
759 unsigned mask
= export_format_info
[new_filter_idx
].mask
;
760 static const struct { int id
; unsigned mask
; } controls
[] = {
762 { svx_SURFACE
, SURF
},
763 { svx_SPLAYS
, SPLAYS
},
764 { svx_STATIONS
, STNS
},
765 { svx_NAMES
, LABELS
},
766 { svx_XSECT
, XSECT
},
767 { svx_WALLS
, WALLS
},
768 { svx_PASSAGES
, PASG
},
770 { svx_FIXES
, FIXES
},
771 { svx_EXPORTS
, EXPORTS
},
772 { svx_CENTRED
, CENTRED
},
773 { svx_FULLCOORDS
, FULL_COORDS
},
774 { svx_CLAMP_TO_GROUND
, CLAMP_TO_GROUND
},
776 static unsigned n_controls
= sizeof(controls
) / sizeof(controls
[0]);
777 for (unsigned i
= 0; i
!= n_controls
; ++i
) {
778 wxWindow
* control
= FindWindow(controls
[i
].id
);
779 if (control
) control
->Show(mask
& controls
[i
].mask
);
781 m_scalebox
->Show(bool(mask
& SCALE
));
782 m_viewbox
->Show(!bool(mask
& EXPORT_3D
));
783 GetSizer()->Layout();
784 if (control_id
== svx_FORMAT
) {
785 wxConfigBase
* cfg
= wxConfigBase::Get();
786 cfg
->Write(wxT("export_format"), formats
[new_filter_idx
]);
793 if (m_printSize
|| m_scale
) {
794 // Update the bounding box.
798 if (!(m_scale
->GetValue()).ToDouble(&(m_layout
.Scale
)) ||
799 m_layout
.Scale
== 0.0) {
800 m_layout
.pick_scale(1, 1);
805 if (m_printSize
&& m_layout
.xMax
>= m_layout
.xMin
) {
806 m_layout
.pages_required();
807 m_printSize
->SetLabel(wxString::Format(wmsg(/*%d pages (%dx%d)*/257), m_layout
.pages
, m_layout
.pagesX
, m_layout
.pagesY
));
812 svxPrintDlg::LayoutToUI()
814 // m_blanks->SetValue(m_layout.SkipBlank);
815 if (m_layout
.view
!= layout::EXTELEV
) {
816 m_tilt
->SetValue(m_layout
.tilt
);
817 m_bearing
->SetValue(m_layout
.rot
);
820 if (m_scale
&& m_layout
.Scale
!= 0) {
821 // Do this last as it causes an OnChange message which calls UIToLayout
823 temp
<< m_layout
.Scale
;
824 m_scale
->SetValue(temp
);
829 svxPrintDlg::UIToLayout()
831 // m_layout.SkipBlank = m_blanks->IsChecked();
833 if (m_layout
.view
!= layout::EXTELEV
&& m_tilt
) {
834 m_layout
.tilt
= m_tilt
->GetValue();
835 if (m_layout
.tilt
== -90.0) {
836 m_layout
.view
= layout::PLAN
;
837 } else if (m_layout
.tilt
== 0.0) {
838 m_layout
.view
= layout::ELEV
;
840 m_layout
.view
= layout::TILT
;
843 bool enable_passage_opts
= (m_layout
.view
!= layout::TILT
);
845 win
= FindWindow(svx_XSECT
);
846 if (win
) win
->Enable(enable_passage_opts
);
847 win
= FindWindow(svx_WALLS
);
848 if (win
) win
->Enable(enable_passage_opts
);
849 win
= FindWindow(svx_PASSAGES
);
850 if (win
) win
->Enable(enable_passage_opts
);
852 m_layout
.rot
= m_bearing
->GetValue();
857 svxPrintDlg::RecalcBounds()
859 m_layout
.yMax
= m_layout
.xMax
= -DBL_MAX
;
860 m_layout
.yMin
= m_layout
.xMin
= DBL_MAX
;
862 double SIN
= sin(rad(m_layout
.rot
));
863 double COS
= cos(rad(m_layout
.rot
));
864 double SINT
= sin(rad(m_layout
.tilt
));
865 double COST
= cos(rad(m_layout
.tilt
));
867 const SurveyFilter
* filter
= mainfrm
->GetTreeFilter();
868 int show_mask
= m_layout
.get_effective_show_mask();
869 if (show_mask
& LEGS
) {
870 for (int f
= 0; f
!= 8; ++f
) {
871 if ((show_mask
& (f
& img_FLAG_SURFACE
) ? SURF
: LEGS
) == 0) {
872 // Not showing traverse because of surface/underground status.
875 if ((f
& img_FLAG_SPLAY
) && (show_mask
& SPLAYS
) == 0) {
876 // Not showing because it's a splay.
879 list
<traverse
>::const_iterator trav
= mainfrm
->traverses_begin(f
, filter
);
880 list
<traverse
>::const_iterator tend
= mainfrm
->traverses_end(f
);
881 for ( ; trav
!= tend
; trav
= mainfrm
->traverses_next(f
, filter
, trav
)) {
882 vector
<PointInfo
>::const_iterator pos
= trav
->begin();
883 vector
<PointInfo
>::const_iterator end
= trav
->end();
884 for ( ; pos
!= end
; ++pos
) {
885 double x
= pos
->GetX();
886 double y
= pos
->GetY();
887 double z
= pos
->GetZ();
888 double X
= x
* COS
- y
* SIN
;
889 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
890 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
891 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
892 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
893 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
899 if ((show_mask
& XSECT
) &&
900 (m_layout
.tilt
== 0.0 || m_layout
.tilt
== 90.0 || m_layout
.tilt
== -90.0)) {
901 list
<vector
<XSect
>>::const_iterator trav
= mainfrm
->tubes_begin();
902 list
<vector
<XSect
>>::const_iterator tend
= mainfrm
->tubes_end();
903 for ( ; trav
!= tend
; ++trav
) {
904 const XSect
* prev_pt_v
= NULL
;
905 Vector3
last_right(1.0, 0.0, 0.0);
907 vector
<XSect
>::const_iterator i
= trav
->begin();
908 vector
<XSect
>::size_type segment
= 0;
909 while (i
!= trav
->end()) {
910 // get the coordinates of this vertex
911 const XSect
& pt_v
= *i
++;
912 if (m_layout
.tilt
== 0.0) {
913 Double u
= pt_v
.GetU();
914 Double d
= pt_v
.GetD();
916 if (u
>= 0 || d
>= 0) {
917 if (filter
&& !filter
->CheckVisible(pt_v
.GetLabel()))
920 double x
= pt_v
.GetX();
921 double y
= pt_v
.GetY();
922 double z
= pt_v
.GetZ();
923 double X
= x
* COS
- y
* SIN
;
924 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
926 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
927 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
928 double U
= Y
+ max(0.0, pt_v
.GetU());
929 if (U
> m_layout
.yMax
) m_layout
.yMax
= U
;
930 double D
= Y
- max(0.0, pt_v
.GetD());
931 if (D
< m_layout
.yMin
) m_layout
.yMin
= D
;
934 // More complex, and this duplicates the algorithm from
935 // PlotLR() - we should try to share that, maybe via a
939 const Vector3
up_v(0.0, 0.0, 1.0);
942 assert(i
!= trav
->end());
945 // get the coordinates of the next vertex
946 const XSect
& next_pt_v
= *i
;
948 // calculate vector from this pt to the next one
949 Vector3 leg_v
= next_pt_v
- pt_v
;
951 // obtain a vector in the LRUD plane
952 right
= leg_v
* up_v
;
953 if (right
.magnitude() == 0) {
958 } else if (segment
+ 1 == trav
->size()) {
961 // Calculate vector from the previous pt to this one.
962 Vector3 leg_v
= pt_v
- *prev_pt_v
;
964 // Obtain a horizontal vector in the LRUD plane.
965 right
= leg_v
* up_v
;
966 if (right
.magnitude() == 0) {
967 right
= Vector3(last_right
.GetX(), last_right
.GetY(), 0.0);
972 assert(i
!= trav
->end());
973 // Intermediate segment.
975 // Get the coordinates of the next vertex.
976 const XSect
& next_pt_v
= *i
;
978 // Calculate vectors from this vertex to the
979 // next vertex, and from the previous vertex to
981 Vector3 leg1_v
= pt_v
- *prev_pt_v
;
982 Vector3 leg2_v
= next_pt_v
- pt_v
;
984 // Obtain horizontal vectors perpendicular to
985 // both legs, then normalise and average to get
986 // a horizontal bisector.
987 Vector3 r1
= leg1_v
* up_v
;
988 Vector3 r2
= leg2_v
* up_v
;
992 if (right
.magnitude() == 0) {
993 // This is the "mid-pitch" case...
999 // Scale to unit vectors in the LRUD plane.
1002 Double l
= pt_v
.GetL();
1003 Double r
= pt_v
.GetR();
1005 if (l
>= 0 || r
>= 0) {
1006 if (!filter
|| filter
->CheckVisible(pt_v
.GetLabel())) {
1007 // Get the x and y coordinates of the survey station
1008 double pt_X
= pt_v
.GetX() * COS
- pt_v
.GetY() * SIN
;
1009 double pt_Y
= pt_v
.GetX() * SIN
+ pt_v
.GetY() * COS
;
1013 // Get the x and y coordinates of the end of the left arrow
1014 Vector3 p
= pt_v
.GetPoint() - right
* l
;
1015 X
= p
.GetX() * COS
- p
.GetY() * SIN
;
1016 Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
1021 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1022 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1023 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1024 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1027 // Get the x and y coordinates of the end of the right arrow
1028 Vector3 p
= pt_v
.GetPoint() + right
* r
;
1029 X
= p
.GetX() * COS
- p
.GetY() * SIN
;
1030 Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
1035 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1036 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1037 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1038 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1050 if (show_mask
& (LABELS
|STNS
)) {
1051 for (auto label
= mainfrm
->GetLabels();
1052 label
!= mainfrm
->GetLabelsEnd();
1054 if (filter
&& !filter
->CheckVisible((*label
)->GetText()))
1056 double x
= (*label
)->GetX();
1057 double y
= (*label
)->GetY();
1058 double z
= (*label
)->GetZ();
1059 if ((show_mask
& SURF
) || (*label
)->IsUnderground()) {
1060 double X
= x
* COS
- y
* SIN
;
1061 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1062 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1063 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1064 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1065 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1071 static int xpPageWidth
, ypPageDepth
;
1072 static long x_offset
, y_offset
;
1073 static int fontsize
, fontsize_labels
;
1075 /* FIXME: allow the font to be set */
1077 static const char *fontname
= "Arial", *fontname_labels
= "Arial";
1079 svxPrintout::svxPrintout(MainFrm
*mainfrm_
, layout
*l
,
1080 wxPageSetupDialogData
*data
, const wxString
& title
)
1081 : wxPrintout(title
), font_labels(NULL
), font_default(NULL
),
1082 scan_for_blank_pages(false)
1090 svxPrintout::draw_info_box()
1092 layout
*l
= m_layout
;
1096 pdc
->SetPen(*pen_frame
);
1099 if (l
->view
!= layout::EXTELEV
) {
1100 boxwidth
+= boxheight
;
1101 MOVEMM(div
, boxheight
);
1103 MOVEMM(0, 30); DRAWMM(div
, 30);
1106 MOVEMM(0, boxheight
);
1107 DRAWMM(boxwidth
, boxheight
);
1108 DRAWMM(boxwidth
, 0);
1111 DRAWMM(0, boxheight
);
1114 MOVEMM(0, 20); DRAWMM(div
, 20);
1115 MOVEMM(0, 10); DRAWMM(div
, 10);
1118 case layout::PLAN
: {
1119 long ax
, ay
, bx
, by
, cx
, cy
, dx
, dy
;
1121 long xc
= boxwidth
- boxheight
/ 2;
1122 long yc
= boxheight
/ 2;
1123 const double RADIUS
= boxheight
/ 3;
1124 DrawEllipse(long(xc
* l
->scX
), long(yc
* l
->scY
),
1125 long(RADIUS
* l
->scX
), long(RADIUS
* l
->scY
));
1127 ax
= (long)((xc
- (RADIUS
- 1) * sin(rad(000.0 + l
->rot
))) * l
->scX
);
1128 ay
= (long)((yc
+ (RADIUS
- 1) * cos(rad(000.0 + l
->rot
))) * l
->scY
);
1129 bx
= (long)((xc
- RADIUS
* 0.5 * sin(rad(180.0 + l
->rot
))) * l
->scX
);
1130 by
= (long)((yc
+ RADIUS
* 0.5 * cos(rad(180.0 + l
->rot
))) * l
->scY
);
1131 cx
= (long)((xc
- (RADIUS
- 1) * sin(rad(160.0 + l
->rot
))) * l
->scX
);
1132 cy
= (long)((yc
+ (RADIUS
- 1) * cos(rad(160.0 + l
->rot
))) * l
->scY
);
1133 dx
= (long)((xc
- (RADIUS
- 1) * sin(rad(200.0 + l
->rot
))) * l
->scX
);
1134 dy
= (long)((yc
+ (RADIUS
- 1) * cos(rad(200.0 + l
->rot
))) * l
->scY
);
1143 pdc
->SetTextForeground(colour_text
);
1144 MOVEMM(div
+ 0.5, boxheight
- 5.5);
1145 WriteString(wmsg(/*North*/115));
1147 wxString angle
= format_angle(ANGLE_FMT
, l
->rot
);
1149 /* TRANSLATORS: This is used on printouts of plans, with %s replaced by
1150 * something like "123°". The bearing is up the page. */
1151 s
.Printf(wmsg(/*Plan view, %s up page*/168), angle
.c_str());
1152 MOVEMM(2, 12); WriteString(s
);
1155 case layout::ELEV
: case layout::TILT
: {
1156 const int L
= div
+ 2;
1157 const int R
= boxwidth
- 2;
1158 const int H
= boxheight
/ 2;
1159 MOVEMM(L
, H
); DRAWMM(L
+ 5, H
- 3); DRAWMM(L
+ 3, H
); DRAWMM(L
+ 5, H
+ 3);
1161 DRAWMM(L
, H
); DRAWMM(R
, H
);
1163 DRAWMM(R
- 5, H
+ 3); DRAWMM(R
- 3, H
); DRAWMM(R
- 5, H
- 3); DRAWMM(R
, H
);
1165 MOVEMM((L
+ R
) / 2, H
- 2); DRAWMM((L
+ R
) / 2, H
+ 2);
1167 pdc
->SetTextForeground(colour_text
);
1168 MOVEMM(div
+ 2, boxheight
- 8);
1169 /* TRANSLATORS: "Elevation on" 020 <-> 200 degrees */
1170 WriteString(wmsg(/*Elevation on*/116));
1173 WriteString(format_angle(ANGLE_FMT
, fmod(l
->rot
+ 270.0, 360.0)));
1175 WriteString(format_angle(ANGLE_FMT
, fmod(l
->rot
+ 90.0, 360.0)));
1177 wxString angle
= format_angle(ANGLE_FMT
, l
->rot
);
1179 if (l
->view
== layout::ELEV
) {
1180 /* TRANSLATORS: This is used on printouts of elevations, with %s
1181 * replaced by something like "123°". The bearing is the direction
1183 s
.Printf(wmsg(/*Elevation facing %s*/169), angle
.c_str());
1185 wxString a2
= format_angle(ANGLE2_FMT
, l
->tilt
);
1186 /* TRANSLATORS: This is used on printouts of tilted elevations, with
1187 * the first %s replaced by something like "123°", and the second by
1188 * something like "-45°". The bearing is the direction we’re
1190 s
.Printf(wmsg(/*Elevation facing %s, tilted %s*/284), angle
.c_str(), a2
.c_str());
1192 MOVEMM(2, 12); WriteString(s
);
1195 case layout::EXTELEV
:
1196 pdc
->SetTextForeground(colour_text
);
1198 /* TRANSLATORS: This is used on printouts of extended elevations. */
1199 WriteString(wmsg(/*Extended elevation*/191));
1203 MOVEMM(2, boxheight
- 8); WriteString(l
->title
);
1206 // FIXME: "Original Scale" better?
1207 WriteString(wxString::Format(wmsg(/*Scale*/154) + wxT(" 1:%.0f"),
1210 /* This used to be a copyright line, but it was occasionally
1211 * mis-interpreted as us claiming copyright on the survey, so let's
1212 * give the website URL instead */
1213 MOVEMM(boxwidth
+ 2, 2);
1214 WriteString(wxT("Survex " VERSION
" - https://survex.com/"));
1216 draw_scale_bar(boxwidth
+ 10.0, 17.0, l
->PaperWidth
- boxwidth
- 18.0);
1219 /* Draw fancy scale bar with bottom left at (x,y) (both in mm) and at most */
1220 /* MaxLength mm long. The scaling in use is 1:scale */
1222 svxPrintout::draw_scale_bar(double x
, double y
, double MaxLength
)
1227 /* Limit scalebar to 20cm to stop people with A0 plotters complaining */
1228 if (MaxLength
> 200.0) MaxLength
= 200.0;
1230 #define dmin 10.0 /* each division >= dmin mm long */
1231 #define StepMax 5 /* number in steps of at most StepMax (x 10^N) */
1232 #define epsilon (1e-4) /* fudge factor to prevent rounding problems */
1234 E
= (int)ceil(log10((dmin
* 0.001 * m_layout
->Scale
) / StepMax
));
1235 StepEst
= pow(10.0, -(double)E
) * (dmin
* 0.001) * m_layout
->Scale
- epsilon
;
1237 /* Force labelling to be in multiples of 1, 2, or 5 */
1238 Step
= (StepEst
<= 1.0 ? 1 : (StepEst
<= 2.0 ? 2 : 5));
1240 /* Work out actual length of each scale bar division */
1241 d
= Step
* pow(10.0, (double)E
) / m_layout
->Scale
* 1000.0;
1243 /* FIXME: Non-metric units here... */
1244 /* Choose appropriate units, s.t. if possible E is >=0 and minimized */
1249 } else if (E
>= 0) {
1256 buf
= wmsg(/*Scale*/154);
1258 /* Add units used - eg. "Scale (10m)" */
1259 double pow10_E
= pow(10.0, (double)E
);
1261 buf
+= wxString::Format(wxT(" (%.f%s)"), pow10_E
, wmsg(units
).c_str());
1263 int sf
= -(int)floor(E
);
1264 buf
+= wxString::Format(wxT(" (%.*f%s)"), sf
, pow10_E
, wmsg(units
).c_str());
1266 pdc
->SetTextForeground(colour_text
);
1267 MOVEMM(x
, y
+ 4); WriteString(buf
);
1269 /* Work out how many divisions there will be */
1270 n
= (int)(MaxLength
/ d
);
1272 pdc
->SetPen(*pen_frame
);
1274 long Y
= long(y
* m_layout
->scY
);
1275 long Y2
= long((y
+ 3) * m_layout
->scY
);
1276 long X
= long(x
* m_layout
->scX
);
1277 long X2
= long((x
+ n
* d
) * m_layout
->scX
);
1279 /* Draw top of scale bar */
1285 MOVEMM(x
+ n
* d
, y
); DRAWMM(x
, y
);
1287 /* Draw divisions and label them */
1288 for (c
= 0; c
<= n
; c
++) {
1289 pdc
->SetPen(*pen_frame
);
1290 X
= long((x
+ c
* d
) * m_layout
->scX
);
1293 #if 0 // Don't waste toner!
1294 /* Draw a "zebra crossing" scale bar. */
1295 if (c
< n
&& (c
& 1) == 0) {
1296 X2
= long((x
+ (c
+ 1) * d
) * m_layout
->scX
);
1297 SolidRectangle(X
, Y
, X2
- X
, Y2
- Y
);
1300 buf
.Printf(wxT("%d"), c
* Step
);
1301 pdc
->SetTextForeground(colour_text
);
1302 MOVEMM(x
+ c
* d
- buf
.length(), y
- 5);
1309 make_calibration(layout
*l
) {
1310 img_point pt
= { 0.0, 0.0, 0.0 };
1311 l
->xMax
= l
->yMax
= 0.1;
1312 l
->xMin
= l
->yMin
= 0;
1314 stack(l
, img_MOVE
, NULL
, &pt
);
1316 stack(l
, img_LINE
, NULL
, &pt
);
1318 stack(l
, img_LINE
, NULL
, &pt
);
1320 stack(l
, img_LINE
, NULL
, &pt
);
1322 stack(l
, img_LINE
, NULL
, &pt
);
1325 stack(l
, img_LABEL
, "10cm", &pt
);
1328 stack(l
, img_LABEL
, "10cm", &pt
);
1334 svxPrintout::next_page(int *pstate
, char **q
, int pageLim
)
1343 wxASSERT(*p
== '-');
1345 while (isspace((unsigned char)*p
)) p
++;
1346 if (sscanf(p
, "%u%n", &page
, &c
) > 0) {
1351 if (*pstate
> page
) goto err
;
1352 if (*pstate
< page
) return *pstate
;
1358 while (isspace((unsigned char)*p
) || *p
== ',') p
++;
1360 if (!*p
) return 0; /* done */
1365 return 1; /* range with initial parameter omitted */
1367 if (sscanf(p
, "%u%n", &page
, &c
) > 0) {
1369 while (isspace((unsigned char)*p
)) p
++;
1371 if (0 < page
&& page
<= pageLim
) {
1372 if (*p
== '-') *pstate
= page
; /* range with start */
1381 /* Draws in alignment marks on each page or borders on edge pages */
1383 svxPrintout::drawticks(int tsize
, int x
, int y
)
1388 bool fAtCorner
= fFalse
;
1389 pdc
->SetPen(*pen_frame
);
1390 if (x
== 0 && m_layout
->Border
) {
1391 /* solid left border */
1392 MoveTo(clip
.x_min
, clip
.y_min
);
1393 DrawTo(clip
.x_min
, clip
.y_max
);
1396 if (x
> 0 || y
> 0) {
1397 MoveTo(clip
.x_min
, clip
.y_min
);
1398 DrawTo(clip
.x_min
, clip
.y_min
+ tsize
);
1400 if (s
&& x
> 0 && m_layout
->Cutlines
) {
1401 /* dashed left border */
1402 i
= (clip
.y_max
- clip
.y_min
) -
1403 (tsize
+ ((clip
.y_max
- clip
.y_min
- tsize
* 2L) % s
) / 2);
1404 for ( ; i
> tsize
; i
-= s
) {
1405 MoveTo(clip
.x_min
, clip
.y_max
- (i
+ o
));
1406 DrawTo(clip
.x_min
, clip
.y_max
- (i
- o
));
1409 if (x
> 0 || y
< m_layout
->pagesY
- 1) {
1410 MoveTo(clip
.x_min
, clip
.y_max
- tsize
);
1411 DrawTo(clip
.x_min
, clip
.y_max
);
1416 if (y
== m_layout
->pagesY
- 1 && m_layout
->Border
) {
1417 /* solid top border */
1418 if (!fAtCorner
) MoveTo(clip
.x_min
, clip
.y_max
);
1419 DrawTo(clip
.x_max
, clip
.y_max
);
1422 if (y
< m_layout
->pagesY
- 1 || x
> 0) {
1423 if (!fAtCorner
) MoveTo(clip
.x_min
, clip
.y_max
);
1424 DrawTo(clip
.x_min
+ tsize
, clip
.y_max
);
1426 if (s
&& y
< m_layout
->pagesY
- 1 && m_layout
->Cutlines
) {
1427 /* dashed top border */
1428 i
= (clip
.x_max
- clip
.x_min
) -
1429 (tsize
+ ((clip
.x_max
- clip
.x_min
- tsize
* 2L) % s
) / 2);
1430 for ( ; i
> tsize
; i
-= s
) {
1431 MoveTo(clip
.x_max
- (i
+ o
), clip
.y_max
);
1432 DrawTo(clip
.x_max
- (i
- o
), clip
.y_max
);
1435 if (y
< m_layout
->pagesY
- 1 || x
< m_layout
->pagesX
- 1) {
1436 MoveTo(clip
.x_max
- tsize
, clip
.y_max
);
1437 DrawTo(clip
.x_max
, clip
.y_max
);
1444 if (x
== m_layout
->pagesX
- 1 && m_layout
->Border
) {
1445 /* solid right border */
1446 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_max
);
1447 DrawTo(clip
.x_max
, clip
.y_min
);
1450 if (x
< m_layout
->pagesX
- 1 || y
< m_layout
->pagesY
- 1) {
1451 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_max
);
1452 DrawTo(clip
.x_max
, clip
.y_max
- tsize
);
1454 if (s
&& x
< m_layout
->pagesX
- 1 && m_layout
->Cutlines
) {
1455 /* dashed right border */
1456 i
= (clip
.y_max
- clip
.y_min
) -
1457 (tsize
+ ((clip
.y_max
- clip
.y_min
- tsize
* 2L) % s
) / 2);
1458 for ( ; i
> tsize
; i
-= s
) {
1459 MoveTo(clip
.x_max
, clip
.y_min
+ (i
+ o
));
1460 DrawTo(clip
.x_max
, clip
.y_min
+ (i
- o
));
1463 if (x
< m_layout
->pagesX
- 1 || y
> 0) {
1464 MoveTo(clip
.x_max
, clip
.y_min
+ tsize
);
1465 DrawTo(clip
.x_max
, clip
.y_min
);
1472 if (y
== 0 && m_layout
->Border
) {
1473 /* solid bottom border */
1474 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_min
);
1475 DrawTo(clip
.x_min
, clip
.y_min
);
1477 if (y
> 0 || x
< m_layout
->pagesX
- 1) {
1478 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_min
);
1479 DrawTo(clip
.x_max
- tsize
, clip
.y_min
);
1481 if (s
&& y
> 0 && m_layout
->Cutlines
) {
1482 /* dashed bottom border */
1483 i
= (clip
.x_max
- clip
.x_min
) -
1484 (tsize
+ ((clip
.x_max
- clip
.x_min
- tsize
* 2L) % s
) / 2);
1485 for ( ; i
> tsize
; i
-= s
) {
1486 MoveTo(clip
.x_min
+ (i
+ o
), clip
.y_min
);
1487 DrawTo(clip
.x_min
+ (i
- o
), clip
.y_min
);
1490 if (y
> 0 || x
> 0) {
1491 MoveTo(clip
.x_min
+ tsize
, clip
.y_min
);
1492 DrawTo(clip
.x_min
, clip
.y_min
);
1498 svxPrintout::OnPrintPage(int pageNum
) {
1499 GetPageSizePixels(&xpPageWidth
, &ypPageDepth
);
1501 pdc
->SetBackgroundMode(wxTRANSPARENT
);
1502 #ifdef AVEN_PRINT_PREVIEW
1505 pdc
->GetSize(&dcx
, &dcy
);
1506 pdc
->SetUserScale((double)dcx
/ xpPageWidth
, (double)dcy
/ ypPageDepth
);
1510 layout
* l
= m_layout
;
1513 GetPageSizeMM(&pwidth
, &pdepth
);
1514 l
->scX
= (double)xpPageWidth
/ pwidth
;
1515 l
->scY
= (double)ypPageDepth
/ pdepth
;
1516 font_scaling_x
= l
->scX
* (25.4 / 72.0);
1517 font_scaling_y
= l
->scY
* (25.4 / 72.0);
1518 long MarginLeft
= m_data
->GetMarginTopLeft().x
;
1519 long MarginTop
= m_data
->GetMarginTopLeft().y
;
1520 long MarginBottom
= m_data
->GetMarginBottomRight().y
;
1521 long MarginRight
= m_data
->GetMarginBottomRight().x
;
1522 xpPageWidth
-= (int)(l
->scX
* (MarginLeft
+ MarginRight
));
1523 ypPageDepth
-= (int)(l
->scY
* (FOOTER_HEIGHT_MM
+ MarginBottom
+ MarginTop
));
1524 // xpPageWidth -= 1;
1525 pdepth
-= FOOTER_HEIGHT_MM
;
1526 x_offset
= (long)(l
->scX
* MarginLeft
);
1527 y_offset
= (long)(l
->scY
* MarginTop
);
1528 l
->PaperWidth
= pwidth
-= MarginLeft
+ MarginRight
;
1529 l
->PaperDepth
= pdepth
-= MarginTop
+ MarginBottom
;
1532 double SIN
= sin(rad(l
->rot
));
1533 double COS
= cos(rad(l
->rot
));
1534 double SINT
= sin(rad(l
->tilt
));
1535 double COST
= cos(rad(l
->tilt
));
1537 NewPage(pageNum
, l
->pagesX
, l
->pagesY
);
1539 if (l
->Legend
&& pageNum
== (l
->pagesY
- 1) * l
->pagesX
+ 1) {
1540 SetFont(font_default
);
1544 pdc
->SetClippingRegion(x_offset
, y_offset
, xpPageWidth
+ 1, ypPageDepth
+ 1);
1546 const double Sc
= 1000 / l
->Scale
;
1548 const SurveyFilter
* filter
= mainfrm
->GetTreeFilter();
1549 int show_mask
= l
->get_effective_show_mask();
1550 if (show_mask
& (LEGS
|SURF
)) {
1551 for (int f
= 0; f
!= 8; ++f
) {
1552 if ((show_mask
& (f
& img_FLAG_SURFACE
) ? SURF
: LEGS
) == 0) {
1553 // Not showing traverse because of surface/underground status.
1556 if ((f
& img_FLAG_SPLAY
) && (show_mask
& SPLAYS
) == 0) {
1557 // Not showing because it's a splay.
1560 if (f
& img_FLAG_SPLAY
) {
1561 pdc
->SetPen(*pen_splay
);
1562 } else if (f
& img_FLAG_SURFACE
) {
1563 pdc
->SetPen(*pen_surface_leg
);
1565 pdc
->SetPen(*pen_leg
);
1567 list
<traverse
>::const_iterator trav
= mainfrm
->traverses_begin(f
, filter
);
1568 list
<traverse
>::const_iterator tend
= mainfrm
->traverses_end(f
);
1569 for ( ; trav
!= tend
; trav
= mainfrm
->traverses_next(f
, filter
, trav
)) {
1570 vector
<PointInfo
>::const_iterator pos
= trav
->begin();
1571 vector
<PointInfo
>::const_iterator end
= trav
->end();
1572 for ( ; pos
!= end
; ++pos
) {
1573 double x
= pos
->GetX();
1574 double y
= pos
->GetY();
1575 double z
= pos
->GetZ();
1576 double X
= x
* COS
- y
* SIN
;
1577 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1578 long px
= (long)((X
* Sc
+ l
->xOrg
) * l
->scX
);
1579 long py
= (long)((Y
* Sc
+ l
->yOrg
) * l
->scY
);
1580 if (pos
== trav
->begin()) {
1590 if ((show_mask
& XSECT
) &&
1591 (l
->tilt
== 0.0 || l
->tilt
== 90.0 || l
->tilt
== -90.0)) {
1592 pdc
->SetPen(*pen_splay
);
1593 list
<vector
<XSect
>>::const_iterator trav
= mainfrm
->tubes_begin();
1594 list
<vector
<XSect
>>::const_iterator tend
= mainfrm
->tubes_end();
1595 for ( ; trav
!= tend
; ++trav
) {
1596 if (l
->tilt
== 0.0) {
1599 // m_layout.tilt is 90.0 or -90.0 due to check above.
1605 if (show_mask
& (LABELS
|STNS
)) {
1606 if (show_mask
& LABELS
) SetFont(font_labels
);
1607 for (auto label
= mainfrm
->GetLabels();
1608 label
!= mainfrm
->GetLabelsEnd();
1610 if (filter
&& !filter
->CheckVisible((*label
)->GetText()))
1612 double px
= (*label
)->GetX();
1613 double py
= (*label
)->GetY();
1614 double pz
= (*label
)->GetZ();
1615 if ((show_mask
& SURF
) || (*label
)->IsUnderground()) {
1616 double X
= px
* COS
- py
* SIN
;
1617 double Y
= pz
* COST
- (px
* SIN
+ py
* COS
) * SINT
;
1619 xnew
= (long)((X
* Sc
+ l
->xOrg
) * l
->scX
);
1620 ynew
= (long)((Y
* Sc
+ l
->yOrg
) * l
->scY
);
1621 if (show_mask
& STNS
) {
1622 pdc
->SetPen(*pen_cross
);
1623 DrawCross(xnew
, ynew
);
1625 if (show_mask
& LABELS
) {
1626 pdc
->SetTextForeground(colour_labels
);
1628 WriteString((*label
)->GetText());
1638 svxPrintout::GetPageInfo(int *minPage
, int *maxPage
,
1639 int *pageFrom
, int *pageTo
)
1641 *minPage
= *pageFrom
= 1;
1642 *maxPage
= *pageTo
= m_layout
->pages
;
1646 svxPrintout::HasPage(int pageNum
) {
1647 return (pageNum
<= m_layout
->pages
);
1651 svxPrintout::OnBeginPrinting() {
1652 /* Initialise printer routines */
1653 fontsize_labels
= 10;
1656 colour_text
= colour_labels
= *wxBLACK
;
1658 wxColour colour_frame
, colour_cross
, colour_leg
, colour_surface_leg
;
1659 colour_frame
= colour_cross
= colour_leg
= colour_surface_leg
= *wxBLACK
;
1661 pen_frame
= new wxPen(colour_frame
);
1662 pen_cross
= new wxPen(colour_cross
);
1663 pen_leg
= new wxPen(colour_leg
);
1664 pen_surface_leg
= new wxPen(colour_surface_leg
);
1665 pen_splay
= new wxPen(wxColour(128, 128, 128));
1670 font_labels
= new wxFont(fontsize_labels
, wxFONTFAMILY_DEFAULT
,
1671 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
1672 false, wxString(fontname_labels
, wxConvUTF8
),
1673 wxFONTENCODING_ISO8859_1
);
1674 font_default
= new wxFont(fontsize
, wxFONTFAMILY_DEFAULT
,
1675 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
1676 false, wxString(fontname
, wxConvUTF8
),
1677 wxFONTENCODING_ISO8859_1
);
1681 svxPrintout::OnEndPrinting() {
1683 delete font_default
;
1687 delete pen_surface_leg
;
1692 svxPrintout::check_intersection(long x_p
, long y_p
)
1698 int mask_p
= 0, mask_t
= 0;
1701 else if (x_p
> xpPageWidth
)
1706 else if (y_p
> ypPageDepth
)
1711 else if (x_t
> xpPageWidth
)
1716 else if (y_t
> ypPageDepth
)
1720 /* approximation to correct answer */
1721 return !(mask_t
& mask_p
);
1723 /* One end of the line is on the page */
1724 if (!mask_t
|| !mask_p
) return 1;
1726 /* whole line is above, left, right, or below page */
1727 if (mask_t
& mask_p
) return 0;
1729 if (mask_t
== 0) mask_t
= mask_p
;
1731 double v
= (double)(y_p
- ypPageDepth
) / (y_p
- y_t
);
1732 return v
>= 0 && v
<= 1;
1735 double v
= (double)y_p
/ (y_p
- y_t
);
1736 return v
>= 0 && v
<= 1;
1739 double v
= (double)(x_p
- xpPageWidth
) / (x_p
- x_t
);
1740 return v
>= 0 && v
<= 1;
1742 wxASSERT(mask_t
& L
);
1744 double v
= (double)x_p
/ (x_p
- x_t
);
1745 return v
>= 0 && v
<= 1;
1755 svxPrintout::MoveTo(long x
, long y
)
1757 x_t
= x_offset
+ x
- clip
.x_min
;
1758 y_t
= y_offset
+ clip
.y_max
- y
;
1762 svxPrintout::DrawTo(long x
, long y
)
1764 long x_p
= x_t
, y_p
= y_t
;
1765 x_t
= x_offset
+ x
- clip
.x_min
;
1766 y_t
= y_offset
+ clip
.y_max
- y
;
1767 if (!scan_for_blank_pages
) {
1768 pdc
->DrawLine(x_p
, y_p
, x_t
, y_t
);
1770 if (check_intersection(x_p
, y_p
)) fBlankPage
= fFalse
;
1774 #define POINTS_PER_INCH 72.0
1775 #define POINTS_PER_MM (POINTS_PER_INCH / MM_PER_INCH)
1776 #define PWX_CROSS_SIZE (int)(2 * m_layout->scX / POINTS_PER_MM)
1779 svxPrintout::DrawCross(long x
, long y
)
1781 if (!scan_for_blank_pages
) {
1782 MoveTo(x
- PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
1783 DrawTo(x
+ PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
1784 MoveTo(x
+ PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
1785 DrawTo(x
- PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
1788 if ((x
+ PWX_CROSS_SIZE
> clip
.x_min
&&
1789 x
- PWX_CROSS_SIZE
< clip
.x_max
) ||
1790 (y
+ PWX_CROSS_SIZE
> clip
.y_min
&&
1791 y
- PWX_CROSS_SIZE
< clip
.y_max
)) {
1792 fBlankPage
= fFalse
;
1798 svxPrintout::WriteString(const wxString
& s
)
1801 pdc
->GetUserScale(&xsc
, &ysc
);
1802 pdc
->SetUserScale(xsc
* font_scaling_x
, ysc
* font_scaling_y
);
1803 if (!scan_for_blank_pages
) {
1805 long(x_t
/ font_scaling_x
),
1806 long(y_t
/ font_scaling_y
) - pdc
->GetCharHeight());
1809 pdc
->GetTextExtent(s
, &w
, &h
);
1810 if ((y_t
+ h
> 0 && y_t
- h
< clip
.y_max
- clip
.y_min
) ||
1811 (x_t
< clip
.x_max
- clip
.x_min
&& x_t
+ w
> 0)) {
1812 fBlankPage
= fFalse
;
1815 pdc
->SetUserScale(xsc
, ysc
);
1819 svxPrintout::DrawEllipse(long x
, long y
, long r
, long R
)
1821 if (!scan_for_blank_pages
) {
1822 x_t
= x_offset
+ x
- clip
.x_min
;
1823 y_t
= y_offset
+ clip
.y_max
- y
;
1824 const wxBrush
& save_brush
= pdc
->GetBrush();
1825 pdc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1826 pdc
->DrawEllipse(x_t
- r
, y_t
- R
, 2 * r
, 2 * R
);
1827 pdc
->SetBrush(save_brush
);
1829 /* No need to check - this is only used in the legend. */
1834 svxPrintout::SolidRectangle(long x
, long y
, long w
, long h
)
1836 long X
= x_offset
+ x
- clip
.x_min
;
1837 long Y
= y_offset
+ clip
.y_max
- y
;
1838 pdc
->SetBrush(*wxBLACK_BRUSH
);
1839 pdc
->DrawRectangle(X
, Y
- h
, w
, h
);
1843 svxPrintout::NewPage(int pg
, int pagesX
, int pagesY
)
1845 pdc
->DestroyClippingRegion();
1848 x
= (pg
- 1) % pagesX
;
1849 y
= pagesY
- 1 - ((pg
- 1) / pagesX
);
1851 clip
.x_min
= (long)x
* xpPageWidth
;
1852 clip
.y_min
= (long)y
* ypPageDepth
;
1853 clip
.x_max
= clip
.x_min
+ xpPageWidth
; /* dm/pcl/ps had -1; */
1854 clip
.y_max
= clip
.y_min
+ ypPageDepth
; /* dm/pcl/ps had -1; */
1856 const int FOOTERS
= 4;
1857 wxString footer
[FOOTERS
];
1858 footer
[0] = m_layout
->title
;
1860 double rot
= m_layout
->rot
;
1861 double tilt
= m_layout
->tilt
;
1862 double scale
= m_layout
->Scale
;
1863 switch (m_layout
->view
) {
1865 // TRANSLATORS: Used in the footer of printouts to compactly
1866 // indicate this is a plan view and what the viewing angle is.
1867 // Aven will replace %s with the bearing, and %.0f with the scale.
1869 // This message probably doesn't need translating for most languages.
1870 footer
[1].Printf(wmsg(/*↑%s 1:%.0f*/233),
1871 format_angle(ANGLE_FMT
, rot
).c_str(),
1875 // TRANSLATORS: Used in the footer of printouts to compactly
1876 // indicate this is an elevation view and what the viewing angle
1877 // is. Aven will replace the %s codes with the bearings to the
1878 // left and right of the viewer, and %.0f with the scale.
1880 // This message probably doesn't need translating for most languages.
1881 footer
[1].Printf(wmsg(/*%s↔%s 1:%.0f*/235),
1882 format_angle(ANGLE_FMT
, fmod(rot
+ 270.0, 360.0)).c_str(),
1883 format_angle(ANGLE_FMT
, fmod(rot
+ 90.0, 360.0)).c_str(),
1887 // TRANSLATORS: Used in the footer of printouts to compactly
1888 // indicate this is a tilted elevation view and what the viewing
1889 // angles are. Aven will replace the %s codes with the bearings to
1890 // the left and right of the viewer and the angle the view is
1891 // tilted at, and %.0f with the scale.
1893 // This message probably doesn't need translating for most languages.
1894 footer
[1].Printf(wmsg(/*%s↔%s ∡%s 1:%.0f*/236),
1895 format_angle(ANGLE_FMT
, fmod(rot
+ 270.0, 360.0)).c_str(),
1896 format_angle(ANGLE_FMT
, fmod(rot
+ 90.0, 360.0)).c_str(),
1897 format_angle(ANGLE2_FMT
, tilt
).c_str(),
1900 case layout::EXTELEV
:
1901 // TRANSLATORS: Used in the footer of printouts to compactly
1902 // indicate this is an extended elevation view. Aven will replace
1903 // %.0f with the scale.
1905 // Try to keep the translation short (for example, in English we
1906 // use "Extended" not "Extended elevation") - there is limited room
1907 // in the footer, and the details there are mostly to make it easy
1908 // to check that you have corresponding pages from a multiple page
1910 footer
[1].Printf(wmsg(/*Extended 1:%.0f*/244), scale
);
1914 // TRANSLATORS: N/M meaning page N of M in the page footer of a printout.
1915 footer
[2].Printf(wmsg(/*%d/%d*/232), pg
, m_layout
->pagesX
* m_layout
->pagesY
);
1917 wxString datestamp
= m_layout
->datestamp
;
1918 if (!datestamp
.empty()) {
1919 // Remove any timezone suffix (e.g. " UTC" or " +1200").
1920 wxChar ch
= datestamp
[datestamp
.size() - 1];
1921 if (ch
>= 'A' && ch
<= 'Z') {
1922 for (size_t i
= datestamp
.size() - 1; i
; --i
) {
1924 if (ch
< 'A' || ch
> 'Z') {
1925 if (ch
== ' ') datestamp
.resize(i
);
1929 } else if (ch
>= '0' && ch
<= '9') {
1930 for (size_t i
= datestamp
.size() - 1; i
; --i
) {
1932 if (ch
< '0' || ch
> '9') {
1933 if ((ch
== '-' || ch
== '+') && datestamp
[--i
] == ' ')
1934 datestamp
.resize(i
);
1940 // Remove any day prefix (e.g. "Mon,").
1941 for (size_t i
= 0; i
!= datestamp
.size(); ++i
) {
1942 if (datestamp
[i
] == ',' && i
+ 1 != datestamp
.size()) {
1943 // Also skip a space after the comma.
1944 if (datestamp
[i
+ 1] == ' ') ++i
;
1945 datestamp
.erase(0, i
+ 1);
1951 // TRANSLATORS: Used in the footer of printouts to compactly indicate that
1952 // the date which follows is the date that the survey data was processed.
1954 // Aven will replace %s with a string giving the date and time (e.g.
1955 // "2015-06-09 12:40:44").
1956 footer
[3].Printf(wmsg(/*Processed: %s*/167), datestamp
.c_str());
1958 const wxChar
* footer_sep
= wxT(" ");
1959 int fontsize_footer
= fontsize_labels
;
1960 wxFont
* font_footer
;
1961 font_footer
= new wxFont(fontsize_footer
, wxFONTFAMILY_DEFAULT
,
1962 wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
,
1963 false, wxString(fontname_labels
, wxConvUTF8
),
1964 wxFONTENCODING_UTF8
);
1965 font_footer
->Scale(font_scaling_x
);
1966 SetFont(font_footer
);
1967 int w
[FOOTERS
], ws
, h
;
1968 pdc
->GetTextExtent(footer_sep
, &ws
, &h
);
1969 int wtotal
= ws
* (FOOTERS
- 1);
1970 for (int i
= 0; i
< FOOTERS
; ++i
) {
1971 pdc
->GetTextExtent(footer
[i
], &w
[i
], &h
);
1976 long Y
= y_offset
+ ypPageDepth
+ (long)(7 * m_layout
->scY
) - pdc
->GetCharHeight();
1978 if (wtotal
> xpPageWidth
) {
1979 // Rescale the footer so it fits.
1980 double rescale
= double(wtotal
) / xpPageWidth
;
1982 pdc
->GetUserScale(&xsc
, &ysc
);
1983 pdc
->SetUserScale(xsc
/ rescale
, ysc
/ rescale
);
1984 SetFont(font_footer
);
1985 wxString fullfooter
= footer
[0];
1986 for (int i
= 1; i
< FOOTERS
- 1; ++i
) {
1987 fullfooter
+= footer_sep
;
1988 fullfooter
+= footer
[i
];
1990 pdc
->DrawText(fullfooter
, X
* rescale
, Y
* rescale
);
1991 // Draw final item right aligned to avoid misaligning.
1992 wxRect
rect(x_offset
* rescale
, Y
* rescale
,
1993 xpPageWidth
* rescale
, pdc
->GetCharHeight() * rescale
);
1994 pdc
->DrawLabel(footer
[FOOTERS
- 1], rect
, wxALIGN_RIGHT
|wxALIGN_TOP
);
1995 pdc
->SetUserScale(xsc
, ysc
);
1997 // Space out the elements of the footer to fill the line.
1998 double extra
= double(xpPageWidth
- wtotal
) / (FOOTERS
- 1);
1999 for (int i
= 0; i
< FOOTERS
- 1; ++i
) {
2000 pdc
->DrawText(footer
[i
], X
+ extra
* i
, Y
);
2003 // Draw final item right aligned to avoid misaligning.
2004 wxRect
rect(x_offset
, Y
, xpPageWidth
, pdc
->GetCharHeight());
2005 pdc
->DrawLabel(footer
[FOOTERS
- 1], rect
, wxALIGN_RIGHT
|wxALIGN_TOP
);
2007 drawticks((int)(9 * m_layout
->scX
/ POINTS_PER_MM
), x
, y
);
2011 svxPrintout::PlotLR(const vector
<XSect
> & centreline
)
2013 const SurveyFilter
* filter
= mainfrm
->GetTreeFilter();
2014 assert(centreline
.size() > 1);
2015 const XSect
* prev_pt_v
= NULL
;
2016 Vector3
last_right(1.0, 0.0, 0.0);
2018 const double Sc
= 1000 / m_layout
->Scale
;
2019 const double SIN
= sin(rad(m_layout
->rot
));
2020 const double COS
= cos(rad(m_layout
->rot
));
2022 vector
<XSect
>::const_iterator i
= centreline
.begin();
2023 vector
<XSect
>::size_type segment
= 0;
2024 while (i
!= centreline
.end()) {
2025 // get the coordinates of this vertex
2026 const XSect
& pt_v
= *i
++;
2030 const Vector3
up_v(0.0, 0.0, 1.0);
2033 assert(i
!= centreline
.end());
2036 // get the coordinates of the next vertex
2037 const XSect
& next_pt_v
= *i
;
2039 // calculate vector from this pt to the next one
2040 Vector3 leg_v
= next_pt_v
- pt_v
;
2042 // obtain a vector in the LRUD plane
2043 right
= leg_v
* up_v
;
2044 if (right
.magnitude() == 0) {
2049 } else if (segment
+ 1 == centreline
.size()) {
2052 // Calculate vector from the previous pt to this one.
2053 Vector3 leg_v
= pt_v
- *prev_pt_v
;
2055 // Obtain a horizontal vector in the LRUD plane.
2056 right
= leg_v
* up_v
;
2057 if (right
.magnitude() == 0) {
2058 right
= Vector3(last_right
.GetX(), last_right
.GetY(), 0.0);
2063 assert(i
!= centreline
.end());
2064 // Intermediate segment.
2066 // Get the coordinates of the next vertex.
2067 const XSect
& next_pt_v
= *i
;
2069 // Calculate vectors from this vertex to the
2070 // next vertex, and from the previous vertex to
2072 Vector3 leg1_v
= pt_v
- *prev_pt_v
;
2073 Vector3 leg2_v
= next_pt_v
- pt_v
;
2075 // Obtain horizontal vectors perpendicular to
2076 // both legs, then normalise and average to get
2077 // a horizontal bisector.
2078 Vector3 r1
= leg1_v
* up_v
;
2079 Vector3 r2
= leg2_v
* up_v
;
2083 if (right
.magnitude() == 0) {
2084 // This is the "mid-pitch" case...
2090 // Scale to unit vectors in the LRUD plane.
2093 Double l
= pt_v
.GetL();
2094 Double r
= pt_v
.GetR();
2096 if (l
>= 0 || r
>= 0) {
2097 if (!filter
|| filter
->CheckVisible(pt_v
.GetLabel())) {
2098 // Get the x and y coordinates of the survey station
2099 double pt_X
= pt_v
.GetX() * COS
- pt_v
.GetY() * SIN
;
2100 double pt_Y
= pt_v
.GetX() * SIN
+ pt_v
.GetY() * COS
;
2101 long pt_x
= (long)((pt_X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2102 long pt_y
= (long)((pt_Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2104 // Calculate dimensions for the right arrow
2105 double COSR
= right
.GetX();
2106 double SINR
= right
.GetY();
2107 long CROSS_MAJOR
= (COSR
+ SINR
) * PWX_CROSS_SIZE
;
2108 long CROSS_MINOR
= (COSR
- SINR
) * PWX_CROSS_SIZE
;
2111 // Get the x and y coordinates of the end of the left arrow
2112 Vector3 p
= pt_v
.GetPoint() - right
* l
;
2113 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2114 double Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
2115 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2116 long y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2118 // Draw the arrow stem
2122 // Rotate the arrow by the page rotation
2123 long dx1
= (+CROSS_MINOR
) * COS
- (+CROSS_MAJOR
) * SIN
;
2124 long dy1
= (+CROSS_MINOR
) * SIN
+ (+CROSS_MAJOR
) * COS
;
2125 long dx2
= (+CROSS_MAJOR
) * COS
- (-CROSS_MINOR
) * SIN
;
2126 long dy2
= (+CROSS_MAJOR
) * SIN
+ (-CROSS_MINOR
) * COS
;
2129 MoveTo(x
+ dx1
, y
+ dy1
);
2131 DrawTo(x
+ dx2
, y
+ dy2
);
2135 // Get the x and y coordinates of the end of the right arrow
2136 Vector3 p
= pt_v
.GetPoint() + right
* r
;
2137 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2138 double Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
2139 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2140 long y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2142 // Draw the arrow stem
2146 // Rotate the arrow by the page rotation
2147 long dx1
= (-CROSS_MINOR
) * COS
- (-CROSS_MAJOR
) * SIN
;
2148 long dy1
= (-CROSS_MINOR
) * SIN
+ (-CROSS_MAJOR
) * COS
;
2149 long dx2
= (-CROSS_MAJOR
) * COS
- (+CROSS_MINOR
) * SIN
;
2150 long dy2
= (-CROSS_MAJOR
) * SIN
+ (+CROSS_MINOR
) * COS
;
2153 MoveTo(x
+ dx1
, y
+ dy1
);
2155 DrawTo(x
+ dx2
, y
+ dy2
);
2167 svxPrintout::PlotUD(const vector
<XSect
> & centreline
)
2169 const SurveyFilter
* filter
= mainfrm
->GetTreeFilter();
2170 assert(centreline
.size() > 1);
2171 const double Sc
= 1000 / m_layout
->Scale
;
2173 vector
<XSect
>::const_iterator i
= centreline
.begin();
2174 while (i
!= centreline
.end()) {
2175 // get the coordinates of this vertex
2176 const XSect
& pt_v
= *i
++;
2178 Double u
= pt_v
.GetU();
2179 Double d
= pt_v
.GetD();
2181 if (u
>= 0 || d
>= 0) {
2182 if (filter
&& !filter
->CheckVisible(pt_v
.GetLabel()))
2185 // Get the coordinates of the survey point
2186 Vector3 p
= pt_v
.GetPoint();
2187 double SIN
= sin(rad(m_layout
->rot
));
2188 double COS
= cos(rad(m_layout
->rot
));
2189 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2190 double Y
= p
.GetZ();
2191 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2192 long pt_y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scX
);
2195 // Get the y coordinate of the up arrow
2196 long y
= (long)(((Y
+ u
) * Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2198 // Draw the arrow stem
2202 // Draw the up arrow
2203 MoveTo(x
- PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
2205 DrawTo(x
+ PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
2209 // Get the y coordinate of the down arrow
2210 long y
= (long)(((Y
- d
) * Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2212 // Draw the arrow stem
2216 // Draw the down arrow
2217 MoveTo(x
- PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
2219 DrawTo(x
+ PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);