2 /* Aven printing code */
3 /* Copyright (C) 1993-2003,2004,2005,2006,2010,2011,2012,2013,2014,2015,2016 Olly Betts
4 * Copyright (C) 2001,2004 Philip Underwood
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <wx/confbase.h>
26 #include <wx/filename.h>
28 #include <wx/printdlg.h>
29 #include <wx/spinctrl.h>
30 #include <wx/radiobox.h>
31 #include <wx/statbox.h>
32 #include <wx/valgen.h>
51 #include "avenprcore.h"
57 // How many decimal points to show on angles:
61 # define ANGLE_FMT wxT("%03.f")
62 # define ANGLE2_FMT wxT("%.f")
64 # define ANGLE_FMT wxT("%05.1f")
65 # define ANGLE2_FMT wxT("%.1f")
67 # define ANGLE_FMT wxT("%06.2f")
68 # define ANGLE2_FMT wxT("%.2f")
70 # error Need to add ANGLE_FMT and ANGLE2_FMT for the currently set ANGLE_DP
74 format_angle(const wxChar
* fmt
, double angle
)
78 size_t dot
= s
.find('.');
123 class BitValidator
: public wxValidator
{
124 // Disallow assignment.
125 BitValidator
& operator=(const BitValidator
&);
133 BitValidator(int * val_
, int mask_
)
134 : val(val_
), mask(mask_
) { }
136 BitValidator(const BitValidator
&o
) : wxValidator() {
142 wxObject
*Clone() const { return new BitValidator(val
, mask
); }
144 bool Copy(const BitValidator
& o
) {
145 wxValidator::Copy(o
);
151 bool Validate(wxWindow
*) { return true; }
153 bool TransferToWindow() {
154 if (!m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
156 ((wxCheckBox
*)m_validatorWindow
)->SetValue(*val
& mask
);
160 bool TransferFromWindow() {
161 if (!m_validatorWindow
->IsKindOf(CLASSINFO(wxCheckBox
)))
163 if (((wxCheckBox
*)m_validatorWindow
)->IsChecked())
171 class svxPrintout
: public wxPrintout
{
174 wxPageSetupDialogData
* m_data
;
176 wxFont
*font_labels
, *font_default
;
177 // Currently unused, but "skip blank pages" would use it.
178 bool scan_for_blank_pages
;
180 wxPen
*pen_frame
, *pen_cross
, *pen_leg
, *pen_surface_leg
, *pen_splay
;
181 wxColour colour_text
, colour_labels
;
184 double font_scaling_x
, font_scaling_y
;
187 long x_min
, y_min
, x_max
, y_max
;
192 int check_intersection(long x_p
, long y_p
);
193 void draw_info_box();
194 void draw_scale_bar(double x
, double y
, double MaxLength
);
195 int next_page(int *pstate
, char **q
, int pageLim
);
196 void drawticks(int tsize
, int x
, int y
);
198 void MOVEMM(double X
, double Y
) {
199 MoveTo((long)(X
* m_layout
->scX
), (long)(Y
* m_layout
->scY
));
201 void DRAWMM(double X
, double Y
) {
202 DrawTo((long)(X
* m_layout
->scX
), (long)(Y
* m_layout
->scY
));
204 void MoveTo(long x
, long y
);
205 void DrawTo(long x
, long y
);
206 void DrawCross(long x
, long y
);
207 void SetFont(wxFont
* font
) {
210 void WriteString(const wxString
& s
);
211 void DrawEllipse(long x
, long y
, long r
, long R
);
212 void SolidRectangle(long x
, long y
, long w
, long h
);
213 void NewPage(int pg
, int pagesX
, int pagesY
);
214 void PlotLR(const vector
<XSect
> & centreline
);
215 void PlotUD(const vector
<XSect
> & centreline
);
217 svxPrintout(MainFrm
*mainfrm
, layout
*l
, wxPageSetupDialogData
*data
, const wxString
& title
);
218 bool OnPrintPage(int pageNum
);
219 void GetPageInfo(int *minPage
, int *maxPage
,
220 int *pageFrom
, int *pageTo
);
221 bool HasPage(int pageNum
);
222 void OnBeginPrinting();
223 void OnEndPrinting();
226 BEGIN_EVENT_TABLE(svxPrintDlg
, wxDialog
)
227 EVT_CHOICE(svx_FORMAT
, svxPrintDlg::OnChange
)
228 EVT_TEXT(svx_SCALE
, svxPrintDlg::OnChange
)
229 EVT_COMBOBOX(svx_SCALE
, svxPrintDlg::OnChange
)
230 EVT_SPINCTRLDOUBLE(svx_BEARING
, svxPrintDlg::OnChangeSpin
)
231 EVT_SPINCTRLDOUBLE(svx_TILT
, svxPrintDlg::OnChangeSpin
)
232 EVT_BUTTON(wxID_PRINT
, svxPrintDlg::OnPrint
)
233 EVT_BUTTON(svx_EXPORT
, svxPrintDlg::OnExport
)
234 EVT_BUTTON(wxID_CANCEL
, svxPrintDlg::OnCancel
)
235 #ifdef AVEN_PRINT_PREVIEW
236 EVT_BUTTON(wxID_PREVIEW
, svxPrintDlg::OnPreview
)
238 EVT_BUTTON(svx_PLAN
, svxPrintDlg::OnPlan
)
239 EVT_BUTTON(svx_ELEV
, svxPrintDlg::OnElevation
)
240 EVT_UPDATE_UI(svx_PLAN
, svxPrintDlg::OnPlanUpdate
)
241 EVT_UPDATE_UI(svx_ELEV
, svxPrintDlg::OnElevationUpdate
)
242 EVT_CHECKBOX(svx_LEGS
, svxPrintDlg::OnChange
)
243 EVT_CHECKBOX(svx_STATIONS
, svxPrintDlg::OnChange
)
244 EVT_CHECKBOX(svx_NAMES
, svxPrintDlg::OnChange
)
245 EVT_CHECKBOX(svx_SURFACE
, svxPrintDlg::OnChange
)
246 EVT_CHECKBOX(svx_SPLAYS
, svxPrintDlg::OnChange
)
247 EVT_CHECKBOX(svx_ENTS
, svxPrintDlg::OnChange
)
248 EVT_CHECKBOX(svx_FIXES
, svxPrintDlg::OnChange
)
249 EVT_CHECKBOX(svx_EXPORTS
, svxPrintDlg::OnChange
)
252 static wxString scales
[] = {
268 static wxString formats
[] = {
282 static wxString projs
[] = {
284 wxT("+proj=tmerc +lat_0=0 +lon_0=13d20 +k=1 +x_0=0 +y_0=-5200000 +ellps=bessel +towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232"),
285 /* British grid SD (Yorkshire): */
286 wxT("+proj=tmerc +lat_0=49d +lon_0=-2d +k=0.999601 +x_0=100000 +y_0=-500000 +ellps=airy +towgs84=375,-111,431,0,0,0,0"),
287 /* British full grid reference: */
288 wxT("+proj=tmerc +lat_0=49d +lon_0=-2d +k=0.999601 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=375,-111,431,0,0,0,0")
292 static const unsigned format_info
[] = {
293 LABELS
|LEGS
|SURF
|SPLAYS
|STNS
|PASG
|XSECT
|WALLS
|MARKER_SIZE
|TEXT_HEIGHT
|GRID
|FULL_COORDS
,
294 LABELS
|LEGS
|SURF
|SPLAYS
|STNS
|PASG
|XSECT
|WALLS
,
295 LABELS
|LEGS
|SURF
|SPLAYS
|ENTS
|FIXES
|EXPORTS
|PROJ
|EXPORT_3D
,
296 LABELS
|LEGS
|SURF
|SPLAYS
|STNS
|CENTRED
,
297 LEGS
|SPLAYS
|CENTRED
|EXPORT_3D
,
298 LABELS
|LEGS
|SPLAYS
|ENTS
|FIXES
|EXPORTS
|PROJ
|EXPORT_3D
,
299 LABELS
|LEGS
|SURF
|SPLAYS
,
300 LABELS
|LEGS
|SURF
|SPLAYS
|STNS
|MARKER_SIZE
|GRID
|SCALE
,
301 LABELS
|ENTS
|FIXES
|EXPORTS
|EXPORT_3D
,
302 LABELS
|LEGS
|SURF
|SPLAYS
|STNS
|PASG
|XSECT
|WALLS
|MARKER_SIZE
|TEXT_HEIGHT
|SCALE
305 static const char * extension
[] = {
318 static const int msg_filetype
[] = {
322 /* TRANSLATORS: Here "plotter" refers to a machine which draws a printout
323 * on a (usually large) sheet of paper using a pen mounted in a motorised
325 /*HPGL for plotters*/414,
328 /* TRANSLATORS: "Compass" and "Carto" are the names of software packages,
329 * so should not be translated:
330 * http://www.fountainware.com/compass/
331 * http://www.psc-cavers.org/carto/ */
332 /*Compass PLT for use with Carto*/415,
333 /* TRANSLATORS: "Skencil" is the name of a software package, so should not be
334 * translated: http://www.skencil.org/ */
335 /*Skencil files*/416,
336 /* TRANSLATORS: Survex is the name of the software, and "pos" refers to a
337 * file extension, so neither should be translated. */
338 /*Survex pos files*/166,
342 svxPrintDlg::svxPrintDlg(MainFrm
* mainfrm_
, const wxString
& filename
,
343 const wxString
& title
, const wxString
& cs_proj
,
344 const wxString
& datestamp
, time_t datestamp_numeric
,
345 double angle
, double tilt_angle
,
346 bool labels
, bool crosses
, bool legs
, bool surf
,
347 bool splays
, bool tubes
, bool ents
, bool fixes
,
348 bool exports
, bool printing
, bool close_after_
)
349 : wxDialog(mainfrm_
, -1, wxString(printing
?
350 /* TRANSLATORS: Title of the print
353 /* TRANSLATORS: Title of the export
355 wmsg(/*Export*/383))),
356 m_layout(printing
? wxGetApp().GetPageSetupDialogData() : NULL
),
357 m_File(filename
), mainfrm(mainfrm_
), close_after(close_after_
)
376 show_mask
|= XSECT
|WALLS
|PASG
;
382 show_mask
|= EXPORTS
;
383 m_layout
.show_mask
= show_mask
;
384 m_layout
.datestamp
= datestamp
;
385 m_layout
.datestamp_numeric
= datestamp_numeric
;
386 m_layout
.rot
= angle
;
387 m_layout
.title
= title
;
388 m_layout
.cs_proj
= cs_proj
;
389 if (mainfrm
->IsExtendedElevation()) {
390 m_layout
.view
= layout::EXTELEV
;
391 if (m_layout
.rot
!= 0.0 && m_layout
.rot
!= 180.0) m_layout
.rot
= 0;
394 m_layout
.tilt
= tilt_angle
;
395 if (m_layout
.tilt
== -90.0) {
396 m_layout
.view
= layout::PLAN
;
397 } else if (m_layout
.tilt
== 0.0) {
398 m_layout
.view
= layout::ELEV
;
400 m_layout
.view
= layout::TILT
;
404 /* setup our print dialog*/
405 wxBoxSizer
* v1
= new wxBoxSizer(wxVERTICAL
);
406 wxBoxSizer
* h1
= new wxBoxSizer(wxHORIZONTAL
); // holds controls
407 /* TRANSLATORS: Used as a label for the surrounding box for the "Bearing"
408 * and "Tilt angle" fields, and the "Plan view" and "Elevation" buttons in
409 * the "what to print/export" dialog. */
410 m_viewbox
= new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*View*/283)), wxVERTICAL
);
411 /* TRANSLATORS: Used as a label for the surrounding box for the "survey
412 * legs" "stations" "names" etc checkboxes in the "what to print" dialog.
413 * "Elements" isn’t a good name for this but nothing better has yet come to
415 wxBoxSizer
* v3
= new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*Elements*/256)), wxVERTICAL
);
416 wxBoxSizer
* h2
= new wxBoxSizer(wxHORIZONTAL
);
417 wxBoxSizer
* h3
= new wxBoxSizer(wxHORIZONTAL
); // holds buttons
421 label
= new wxStaticText(this, -1, wxString(wmsg(/*Export format*/410)));
422 const size_t n_formats
= sizeof(formats
) / sizeof(formats
[0]);
423 m_format
= new wxChoice(this, svx_FORMAT
,
424 wxDefaultPosition
, wxDefaultSize
,
426 unsigned current_format
= 0;
427 wxConfigBase
* cfg
= wxConfigBase::Get();
429 if (cfg
->Read(wxT("export_format"), &s
, wxString())) {
430 for (unsigned i
= 0; i
!= n_formats
; ++i
) {
431 if (s
== formats
[i
]) {
437 m_format
->SetSelection(current_format
);
438 wxBoxSizer
* formatbox
= new wxBoxSizer(wxHORIZONTAL
);
439 formatbox
->Add(label
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
440 formatbox
->Add(m_format
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
442 v1
->Add(formatbox
, 0, wxALIGN_LEFT
|wxALL
, 0);
446 label
= new wxStaticText(this, -1, wxString(wmsg(/*Scale*/154)) + wxT(" 1:"));
447 if (scales
[0].empty()) {
449 /* TRANSLATORS: used in the scale drop down selector in the print
450 * dialog the implicit meaning is "choose a suitable scale to fit
451 * the plot on a single page", but we need something shorter */
452 scales
[0].assign(wmsg(/*One page*/258));
454 scales
[0].assign(wxT("1000"));
457 m_scale
= new wxComboBox(this, svx_SCALE
, scales
[0], wxDefaultPosition
,
458 wxDefaultSize
, sizeof(scales
) / sizeof(scales
[0]),
460 m_scalebox
= new wxBoxSizer(wxHORIZONTAL
);
461 m_scalebox
->Add(label
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
462 m_scalebox
->Add(m_scale
, 0, wxALIGN_CENTER_VERTICAL
|wxALL
, 5);
464 m_viewbox
->Add(m_scalebox
, 0, wxALIGN_LEFT
|wxALL
, 0);
467 // Make the dummy string wider than any sane value and use that to
468 // fix the width of the control so the sizers allow space for bigger
470 m_printSize
= new wxStaticText(this, -1, wxString::Format(wmsg(/*%d pages (%dx%d)*/257), 9604, 98, 98));
471 m_viewbox
->Add(m_printSize
, 0, wxALIGN_LEFT
|wxALL
, 5);
475 * svx_GRID, // double - spacing, default: 100m
476 * svx_TEXT_HEIGHT, // default 0.6
477 * svx_MARKER_SIZE // default 0.8
480 if (m_layout
.view
!= layout::EXTELEV
) {
481 wxFlexGridSizer
* anglebox
= new wxFlexGridSizer(2);
482 wxStaticText
* brg_label
, * tilt_label
;
483 brg_label
= new wxStaticText(this, -1, wmsg(/*Bearing*/259));
484 anglebox
->Add(brg_label
, 0, wxALIGN_CENTER_VERTICAL
|wxALIGN_LEFT
|wxALL
, 5);
485 // wSP_WRAP means that you can scroll past 360 to 0, and vice versa.
486 m_bearing
= new wxSpinCtrlDouble(this, svx_BEARING
, wxEmptyString
,
487 wxDefaultPosition
, wxDefaultSize
, wxSP_ARROW_KEYS
|wxSP_WRAP
);
488 m_bearing
->SetRange(0.0, 360.0);
489 m_bearing
->SetDigits(ANGLE_DP
);
490 anglebox
->Add(m_bearing
, 0, wxALIGN_CENTER
|wxALL
, 5);
491 /* TRANSLATORS: Used in the print dialog: */
492 tilt_label
= new wxStaticText(this, -1, wmsg(/*Tilt angle*/263));
493 anglebox
->Add(tilt_label
, 0, wxALIGN_CENTER_VERTICAL
|wxALIGN_LEFT
|wxALL
, 5);
494 m_tilt
= new wxSpinCtrlDouble(this, svx_TILT
);
495 m_tilt
->SetRange(-90.0, 90.0);
496 m_tilt
->SetDigits(ANGLE_DP
);
497 anglebox
->Add(m_tilt
, 0, wxALIGN_CENTER
|wxALL
, 5);
499 m_viewbox
->Add(anglebox
, 0, wxALIGN_LEFT
|wxALL
, 0);
501 wxBoxSizer
* planelevsizer
= new wxBoxSizer(wxHORIZONTAL
);
502 planelevsizer
->Add(new wxButton(this, svx_PLAN
, wmsg(/*P&lan view*/117)),
503 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
504 planelevsizer
->Add(new wxButton(this, svx_ELEV
, wmsg(/*&Elevation*/285)),
505 0, wxALIGN_CENTRE_VERTICAL
|wxALL
, 5);
507 m_viewbox
->Add(planelevsizer
, 0, wxALIGN_LEFT
|wxALL
, 5);
510 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
511 * "survey stations". */
512 v3
->Add(new wxCheckBox(this, svx_LEGS
, wmsg(/*Underground Survey Legs*/262),
513 wxDefaultPosition
, wxDefaultSize
, 0,
514 BitValidator(&m_layout
.show_mask
, LEGS
)),
515 0, wxALIGN_LEFT
|wxALL
, 2);
516 /* TRANSLATORS: Here a "survey leg" is a set of measurements between two
517 * "survey stations". */
518 v3
->Add(new wxCheckBox(this, svx_SURFACE
, wmsg(/*Sur&face Survey Legs*/403),
519 wxDefaultPosition
, wxDefaultSize
, 0,
520 BitValidator(&m_layout
.show_mask
, SURF
)),
521 0, wxALIGN_LEFT
|wxALL
, 2);
522 v3
->Add(new wxCheckBox(this, svx_SPLAYS
, wmsg(/*Spla&y Legs*/406),
523 wxDefaultPosition
, wxDefaultSize
, 0,
524 BitValidator(&m_layout
.show_mask
, SPLAYS
)),
525 0, wxALIGN_LEFT
|wxALL
, 2);
526 v3
->Add(new wxCheckBox(this, svx_STATIONS
, wmsg(/*Crosses*/261),
527 wxDefaultPosition
, wxDefaultSize
, 0,
528 BitValidator(&m_layout
.show_mask
, STNS
)),
529 0, wxALIGN_LEFT
|wxALL
, 2);
530 v3
->Add(new wxCheckBox(this, svx_NAMES
, wmsg(/*Station Names*/260),
531 wxDefaultPosition
, wxDefaultSize
, 0,
532 BitValidator(&m_layout
.show_mask
, LABELS
)),
533 0, wxALIGN_LEFT
|wxALL
, 2);
534 v3
->Add(new wxCheckBox(this, svx_ENTS
, wmsg(/*Entrances*/418),
535 wxDefaultPosition
, wxDefaultSize
, 0,
536 BitValidator(&m_layout
.show_mask
, ENTS
)),
537 0, wxALIGN_LEFT
|wxALL
, 2);
538 v3
->Add(new wxCheckBox(this, svx_FIXES
, wmsg(/*Fixed Points*/419),
539 wxDefaultPosition
, wxDefaultSize
, 0,
540 BitValidator(&m_layout
.show_mask
, FIXES
)),
541 0, wxALIGN_LEFT
|wxALL
, 2);
542 v3
->Add(new wxCheckBox(this, svx_EXPORTS
, wmsg(/*Exported Stations*/420),
543 wxDefaultPosition
, wxDefaultSize
, 0,
544 BitValidator(&m_layout
.show_mask
, EXPORTS
)),
545 0, wxALIGN_LEFT
|wxALL
, 2);
546 v3
->Add(new wxCheckBox(this, svx_XSECT
, wmsg(/*Cross-sections*/393),
547 wxDefaultPosition
, wxDefaultSize
, 0,
548 BitValidator(&m_layout
.show_mask
, XSECT
)),
549 0, wxALIGN_LEFT
|wxALL
, 2);
551 v3
->Add(new wxCheckBox(this, svx_WALLS
, wmsg(/*Walls*/394),
552 wxDefaultPosition
, wxDefaultSize
, 0,
553 BitValidator(&m_layout
.show_mask
, WALLS
)),
554 0, wxALIGN_LEFT
|wxALL
, 2);
555 // TRANSLATORS: Label for checkbox which controls whether there's a
556 // layer in the exported file (for formats such as DXF and SVG)
557 // containing polygons for the inside of cave passages).
558 v3
->Add(new wxCheckBox(this, svx_PASSAGES
, wmsg(/*Passages*/395),
559 wxDefaultPosition
, wxDefaultSize
, 0,
560 BitValidator(&m_layout
.show_mask
, PASG
)),
561 0, wxALIGN_LEFT
|wxALL
, 2);
562 v3
->Add(new wxCheckBox(this, svx_CENTRED
, wmsg(/*Origin in centre*/421),
563 wxDefaultPosition
, wxDefaultSize
, 0,
564 BitValidator(&m_layout
.show_mask
, CENTRED
)),
565 0, wxALIGN_LEFT
|wxALL
, 2);
566 v3
->Add(new wxCheckBox(this, svx_FULLCOORDS
, wmsg(/*Full coordinates*/422),
567 wxDefaultPosition
, wxDefaultSize
, 0,
568 BitValidator(&m_layout
.show_mask
, FULL_COORDS
)),
569 0, wxALIGN_LEFT
|wxALL
, 2);
572 /* TRANSLATORS: used in the print dialog - controls drawing lines
573 * around each page */
574 v3
->Add(new wxCheckBox(this, svx_BORDERS
, wmsg(/*Page Borders*/264),
575 wxDefaultPosition
, wxDefaultSize
, 0,
576 wxGenericValidator(&m_layout
.Border
)),
577 0, wxALIGN_LEFT
|wxALL
, 2);
578 /* TRANSLATORS: will be used in the print dialog - check this to print
579 * blank pages (otherwise they’ll be skipped to save paper) */
580 // m_blanks = new wxCheckBox(this, svx_BLANKS, wmsg(/*Blank Pages*/266));
581 // v3->Add(m_blanks, 0, wxALIGN_LEFT|wxALL, 2);
582 /* TRANSLATORS: As in the legend on a map. Used in the print dialog -
583 * controls drawing the box at the lower left with survey name, view
585 v3
->Add(new wxCheckBox(this, svx_LEGEND
, wmsg(/*Legend*/265),
586 wxDefaultPosition
, wxDefaultSize
, 0,
587 wxGenericValidator(&m_layout
.Legend
)),
588 0, wxALIGN_LEFT
|wxALL
, 2);
591 h1
->Add(v3
, 0, wxALIGN_LEFT
|wxALL
, 5);
592 h1
->Add(m_viewbox
, 0, wxALIGN_LEFT
|wxLEFT
, 5);
595 /* TRANSLATORS: The PROJ library is used to do coordinate
596 * transformations (https://trac.osgeo.org/proj/) - if the .3d file
597 * doesn't contain details of the coordinate projection in use, the
598 * user must specify it here for export formats which need to know it
601 h2
->Add(new wxStaticText(this, svx_PROJ_LABEL
, wmsg(/*Coordinate projection*/440)),
602 0, wxLEFT
|wxALIGN_CENTRE_VERTICAL
, 5);
604 if (!m_layout
.cs_proj
.empty()) {
605 // If the input file specified the coordinate system, don't let the
606 // user mess with it.
607 style
= wxTE_READONLY
;
609 #if 0 // FIXME: Is it a good idea to save this?
610 wxConfigBase
* cfg
= wxConfigBase::Get();
611 wxString input_projection
;
612 cfg
->Read(wxT("input_projection"), &input_projection
);
613 if (!input_projection
.empty())
614 proj_edit
.SetValue(input_projection
);
617 wxTextCtrl
* proj_edit
= new wxTextCtrl(this, svx_PROJ
, m_layout
.cs_proj
,
618 wxDefaultPosition
, wxDefaultSize
,
620 h2
->Add(proj_edit
, 1, wxALL
|wxEXPAND
|wxALIGN_CENTRE_VERTICAL
, 5);
621 v1
->Add(h2
, 0, wxALIGN_LEFT
|wxEXPAND
, 5);
624 v1
->Add(h1
, 0, wxALIGN_LEFT
|wxALL
, 5);
626 // When we enable/disable checkboxes in the export dialog, ideally we'd
627 // like the dialog to resize, but not sure how to achieve that, so we
628 // add a stretchable spacer here so at least the buttons stay in the
629 // lower right corner.
630 v1
->AddStretchSpacer();
633 but
= new wxButton(this, wxID_CANCEL
);
634 h3
->Add(but
, 0, wxALIGN_RIGHT
|wxALL
, 5);
636 #ifdef AVEN_PRINT_PREVIEW
637 but
= new wxButton(this, wxID_PREVIEW
);
638 h3
->Add(but
, 0, wxALIGN_RIGHT
|wxALL
, 5);
639 but
= new wxButton(this, wxID_PRINT
);
641 but
= new wxButton(this, wxID_PRINT
, wmsg(/*&Print...*/400));
644 /* TRANSLATORS: The text on the action button in the "Export" settings
646 but
= new wxButton(this, svx_EXPORT
, wmsg(/*&Export...*/230));
649 h3
->Add(but
, 0, wxALIGN_RIGHT
|wxALL
, 5);
650 v1
->Add(h3
, 0, wxALIGN_RIGHT
|wxALL
, 5);
654 v1
->SetSizeHints(this);
661 svxPrintDlg::OnPrint(wxCommandEvent
&) {
663 TransferDataFromWindow();
664 wxPageSetupDialogData
* psdd
= wxGetApp().GetPageSetupDialogData();
665 wxPrintDialogData
pd(psdd
->GetPrintData());
667 svxPrintout
po(mainfrm
, &m_layout
, psdd
, m_File
);
668 if (m_layout
.SkipBlank
) {
669 // FIXME: wx's printing requires a contiguous range of valid page
670 // numbers. To achieve that, we need to run a scan for blank pages
671 // here, so that GetPageInfo() knows what range to return, and so
672 // that OnPrintPage() can map a page number back to where in the
673 // MxN multi-page layout.
675 po
.scan_for_blank_pages
= true;
676 for (int page
= 1; page
<= m_layout
->pages
; ++page
) {
677 po
.fBlankPage
= fTrue
;
678 po
.OnPrintPage(page
);
679 // FIXME: Do something with po.fBlankPage
681 po
.scan_for_blank_pages
= false;
684 if (pr
.Print(this, &po
, true)) {
685 // Close the print dialog if printing succeeded.
691 svxPrintDlg::OnExport(wxCommandEvent
&) {
693 TransferDataFromWindow();
695 wxFileName::SplitPath(m_File
, NULL
, NULL
, &leaf
, NULL
, wxPATH_NATIVE
);
696 unsigned format_idx
= ((wxChoice
*)FindWindow(svx_FORMAT
))->GetSelection();
697 leaf
+= wxString::FromUTF8(extension
[format_idx
]);
699 wxString filespec
= wmsg(msg_filetype
[format_idx
]);
700 filespec
+= wxT("|*");
701 filespec
+= wxString::FromUTF8(extension
[format_idx
]);
702 filespec
+= wxT("|");
703 filespec
+= wmsg(/*All files*/208);
704 filespec
+= wxT("|");
705 filespec
+= wxFileSelectorDefaultWildcardStr
;
707 /* TRANSLATORS: Title of file dialog to choose name and type of exported
709 wxFileDialog
dlg(this, wmsg(/*Export as:*/401), wxString(), leaf
,
710 filespec
, wxFD_SAVE
|wxFD_OVERWRITE_PROMPT
);
711 if (dlg
.ShowModal() == wxID_OK
) {
712 wxString input_projection
= ((wxTextCtrl
*)FindWindow(svx_PROJ
))->GetValue();
713 double grid
= 100; // metres
714 double text_height
= 0.6;
715 double marker_size
= 0.8;
718 if (!Export(dlg
.GetPath(), m_layout
.title
,
719 m_layout
.datestamp
, m_layout
.datestamp_numeric
, mainfrm
,
720 m_layout
.rot
, m_layout
.tilt
,
721 m_layout
.get_effective_show_mask(),
722 export_format(format_idx
), input_projection
.utf8_str(),
723 grid
, text_height
, marker_size
, m_layout
.Scale
)) {
724 wxString m
= wxString::Format(wmsg(/*Couldn’t write file “%s”*/402).c_str(),
726 wxGetApp().ReportError(m
);
728 } catch (const wxString
& m
) {
729 wxGetApp().ReportError(m
);
735 #ifdef AVEN_PRINT_PREVIEW
737 svxPrintDlg::OnPreview(wxCommandEvent
&) {
739 TransferDataFromWindow();
740 wxPageSetupDialogData
* psdd
= wxGetApp().GetPageSetupDialogData();
741 wxPrintDialogData
pd(psdd
->GetPrintData());
743 pv
= new wxPrintPreview(new svxPrintout(mainfrm
, &m_layout
, psdd
, m_File
),
744 new svxPrintout(mainfrm
, &m_layout
, psdd
, m_File
),
746 // TRANSLATORS: Title of the print preview dialog
747 wxPreviewFrame
*frame
= new wxPreviewFrame(pv
, mainfrm
, wmsg(/*Print Preview*/398));
750 // Size preview frame so that all of the controlbar and canvas can be seen
753 // GetBestSize gives us the width needed to show the whole controlbar.
754 frame
->GetBestSize(&w
, &h
);
756 // On wxGTK at least, GetBestSize() returns much too small a height.
759 // Ensure that we don't make the window bigger than the screen.
760 // Use wxGetClientDisplayRect() so we don't cover the MS Windows
762 wxRect disp
= wxGetClientDisplayRect();
763 if (w
> disp
.GetWidth()) w
= disp
.GetWidth();
764 if (h
> disp
.GetHeight()) h
= disp
.GetHeight();
765 // Centre the window within the "ClientDisplayRect".
766 int x
= disp
.GetLeft() + (disp
.GetWidth() - w
) / 2;
767 int y
= disp
.GetTop() + (disp
.GetHeight() - h
) / 2;
768 frame
->SetSize(x
, y
, w
, h
);
775 svxPrintDlg::OnPlan(wxCommandEvent
&) {
776 m_tilt
->SetValue(-90.0);
777 SomethingChanged(svx_TILT
);
781 svxPrintDlg::OnElevation(wxCommandEvent
&) {
782 m_tilt
->SetValue(0.0);
783 SomethingChanged(svx_TILT
);
787 svxPrintDlg::OnPlanUpdate(wxUpdateUIEvent
& e
) {
788 e
.Enable(m_tilt
->GetValue() != -90.0);
792 svxPrintDlg::OnElevationUpdate(wxUpdateUIEvent
& e
) {
793 e
.Enable(m_tilt
->GetValue() != 0.0);
797 svxPrintDlg::OnChangeSpin(wxSpinDoubleEvent
& e
) {
798 SomethingChanged(e
.GetId());
802 svxPrintDlg::OnChange(wxCommandEvent
& e
) {
803 SomethingChanged(e
.GetId());
807 svxPrintDlg::OnCancel(wxCommandEvent
&) {
814 svxPrintDlg::SomethingChanged(int control_id
) {
815 if ((control_id
== 0 || control_id
== svx_FORMAT
) && m_format
) {
816 // Update the shown/hidden fields for the newly selected export filter.
817 int new_filter_idx
= m_format
->GetSelection();
818 if (new_filter_idx
!= wxNOT_FOUND
) {
819 unsigned mask
= format_info
[new_filter_idx
];
820 static const struct { int id
; unsigned mask
; } controls
[] = {
822 { svx_SURFACE
, SURF
},
823 { svx_SPLAYS
, SPLAYS
},
824 { svx_STATIONS
, STNS
},
825 { svx_NAMES
, LABELS
},
826 { svx_XSECT
, XSECT
},
827 { svx_WALLS
, WALLS
},
828 { svx_PASSAGES
, PASG
},
830 { svx_FIXES
, FIXES
},
831 { svx_EXPORTS
, EXPORTS
},
832 { svx_CENTRED
, CENTRED
},
833 { svx_FULLCOORDS
, FULL_COORDS
},
834 { svx_PROJ_LABEL
, PROJ
},
837 static unsigned n_controls
= sizeof(controls
) / sizeof(controls
[0]);
838 for (unsigned i
= 0; i
!= n_controls
; ++i
) {
839 wxWindow
* control
= FindWindow(controls
[i
].id
);
840 if (control
) control
->Show(mask
& controls
[i
].mask
);
842 m_scalebox
->Show(bool(mask
& SCALE
));
843 m_viewbox
->Show(!bool(mask
& EXPORT_3D
));
844 GetSizer()->Layout();
845 if (control_id
== svx_FORMAT
) {
846 wxConfigBase
* cfg
= wxConfigBase::Get();
847 cfg
->Write(wxT("export_format"), formats
[new_filter_idx
]);
854 if (m_printSize
|| m_scale
) {
855 // Update the bounding box.
859 if (!(m_scale
->GetValue()).ToDouble(&(m_layout
.Scale
)) ||
860 m_layout
.Scale
== 0.0) {
861 m_layout
.pick_scale(1, 1);
866 if (m_printSize
&& m_layout
.xMax
>= m_layout
.xMin
) {
867 m_layout
.pages_required();
868 m_printSize
->SetLabel(wxString::Format(wmsg(/*%d pages (%dx%d)*/257), m_layout
.pages
, m_layout
.pagesX
, m_layout
.pagesY
));
873 svxPrintDlg::LayoutToUI()
875 // m_blanks->SetValue(m_layout.SkipBlank);
876 if (m_layout
.view
!= layout::EXTELEV
) {
877 m_tilt
->SetValue(m_layout
.tilt
);
878 m_bearing
->SetValue(m_layout
.rot
);
881 // Do this last as it causes an OnChange message which calls UIToLayout
883 if (m_layout
.Scale
!= 0) {
885 temp
<< m_layout
.Scale
;
886 m_scale
->SetValue(temp
);
888 if (scales
[0].empty()) scales
[0].assign(wmsg(/*One page*/258));
889 m_scale
->SetValue(scales
[0]);
895 svxPrintDlg::UIToLayout()
897 // m_layout.SkipBlank = m_blanks->IsChecked();
899 if (m_layout
.view
!= layout::EXTELEV
&& m_tilt
) {
900 m_layout
.tilt
= m_tilt
->GetValue();
901 if (m_layout
.tilt
== -90.0) {
902 m_layout
.view
= layout::PLAN
;
903 } else if (m_layout
.tilt
== 0.0) {
904 m_layout
.view
= layout::ELEV
;
906 m_layout
.view
= layout::TILT
;
909 bool enable_passage_opts
= (m_layout
.view
!= layout::TILT
);
911 win
= FindWindow(svx_XSECT
);
912 if (win
) win
->Enable(enable_passage_opts
);
913 win
= FindWindow(svx_WALLS
);
914 if (win
) win
->Enable(enable_passage_opts
);
915 win
= FindWindow(svx_PASSAGES
);
916 if (win
) win
->Enable(enable_passage_opts
);
918 m_layout
.rot
= m_bearing
->GetValue();
923 svxPrintDlg::RecalcBounds()
925 m_layout
.yMax
= m_layout
.xMax
= -DBL_MAX
;
926 m_layout
.yMin
= m_layout
.xMin
= DBL_MAX
;
928 double SIN
= sin(rad(m_layout
.rot
));
929 double COS
= cos(rad(m_layout
.rot
));
930 double SINT
= sin(rad(m_layout
.tilt
));
931 double COST
= cos(rad(m_layout
.tilt
));
933 int show_mask
= m_layout
.get_effective_show_mask();
934 if (show_mask
& LEGS
) {
935 list
<traverse
>::const_iterator trav
= mainfrm
->traverses_begin();
936 list
<traverse
>::const_iterator tend
= mainfrm
->traverses_end();
937 for ( ; trav
!= tend
; ++trav
) {
938 if (trav
->isSplay
&& !(show_mask
& SPLAYS
))
940 vector
<PointInfo
>::const_iterator pos
= trav
->begin();
941 vector
<PointInfo
>::const_iterator end
= trav
->end();
942 for ( ; pos
!= end
; ++pos
) {
943 double x
= pos
->GetX();
944 double y
= pos
->GetY();
945 double z
= pos
->GetZ();
946 double X
= x
* COS
- y
* SIN
;
947 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
948 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
949 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
950 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
951 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
956 if ((show_mask
& XSECT
) &&
957 (m_layout
.tilt
== 0.0 || m_layout
.tilt
== 90.0 || m_layout
.tilt
== -90.0)) {
958 list
<vector
<XSect
> >::const_iterator trav
= mainfrm
->tubes_begin();
959 list
<vector
<XSect
> >::const_iterator tend
= mainfrm
->tubes_end();
960 for ( ; trav
!= tend
; ++trav
) {
962 Vector3
last_right(1.0, 0.0, 0.0);
964 vector
<XSect
>::const_iterator i
= trav
->begin();
965 vector
<XSect
>::size_type segment
= 0;
966 while (i
!= trav
->end()) {
967 // get the coordinates of this vertex
968 const XSect
& pt_v
= *i
++;
969 if (m_layout
.tilt
== 0.0) {
970 Double u
= pt_v
.GetU();
971 Double d
= pt_v
.GetD();
973 if (u
>= 0 || d
>= 0) {
974 double x
= pt_v
.GetX();
975 double y
= pt_v
.GetY();
976 double z
= pt_v
.GetZ();
977 double X
= x
* COS
- y
* SIN
;
978 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
980 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
981 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
982 double U
= Y
+ max(0.0, pt_v
.GetU());
983 if (U
> m_layout
.yMax
) m_layout
.yMax
= U
;
984 double D
= Y
- max(0.0, pt_v
.GetD());
985 if (D
< m_layout
.yMin
) m_layout
.yMin
= D
;
988 // More complex, and this duplicates the algorithm from
989 // PlotLR() - we should try to share that, maybe via a
993 const Vector3
up_v(0.0, 0.0, 1.0);
996 assert(i
!= trav
->end());
999 // get the coordinates of the next vertex
1000 const XSect
& next_pt_v
= *i
;
1002 // calculate vector from this pt to the next one
1003 Vector3 leg_v
= next_pt_v
- pt_v
;
1005 // obtain a vector in the LRUD plane
1006 right
= leg_v
* up_v
;
1007 if (right
.magnitude() == 0) {
1012 } else if (segment
+ 1 == trav
->size()) {
1015 // Calculate vector from the previous pt to this one.
1016 Vector3 leg_v
= pt_v
- prev_pt_v
;
1018 // Obtain a horizontal vector in the LRUD plane.
1019 right
= leg_v
* up_v
;
1020 if (right
.magnitude() == 0) {
1021 right
= Vector3(last_right
.GetX(), last_right
.GetY(), 0.0);
1026 assert(i
!= trav
->end());
1027 // Intermediate segment.
1029 // Get the coordinates of the next vertex.
1030 const XSect
& next_pt_v
= *i
;
1032 // Calculate vectors from this vertex to the
1033 // next vertex, and from the previous vertex to
1035 Vector3 leg1_v
= pt_v
- prev_pt_v
;
1036 Vector3 leg2_v
= next_pt_v
- pt_v
;
1038 // Obtain horizontal vectors perpendicular to
1039 // both legs, then normalise and average to get
1040 // a horizontal bisector.
1041 Vector3 r1
= leg1_v
* up_v
;
1042 Vector3 r2
= leg2_v
* up_v
;
1046 if (right
.magnitude() == 0) {
1047 // This is the "mid-pitch" case...
1053 // Scale to unit vectors in the LRUD plane.
1056 Double l
= pt_v
.GetL();
1057 Double r
= pt_v
.GetR();
1059 if (l
>= 0 || r
>= 0) {
1060 // Get the x and y coordinates of the survey station
1061 double pt_X
= pt_v
.GetX() * COS
- pt_v
.GetY() * SIN
;
1062 double pt_Y
= pt_v
.GetX() * SIN
+ pt_v
.GetY() * COS
;
1066 // Get the x and y coordinates of the end of the left arrow
1067 Vector3 p
= pt_v
- right
* l
;
1068 X
= p
.GetX() * COS
- p
.GetY() * SIN
;
1069 Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
1074 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1075 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1076 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1077 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1080 // Get the x and y coordinates of the end of the right arrow
1081 Vector3 p
= pt_v
+ right
* r
;
1082 X
= p
.GetX() * COS
- p
.GetY() * SIN
;
1083 Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
1088 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1089 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1090 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1091 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1102 if (show_mask
& SURF
) {
1103 list
<traverse
>::const_iterator trav
= mainfrm
->surface_traverses_begin();
1104 list
<traverse
>::const_iterator tend
= mainfrm
->surface_traverses_end();
1105 for ( ; trav
!= tend
; ++trav
) {
1106 if (trav
->isSplay
&& !(show_mask
& SPLAYS
))
1108 vector
<PointInfo
>::const_iterator pos
= trav
->begin();
1109 vector
<PointInfo
>::const_iterator end
= trav
->end();
1110 for ( ; pos
!= end
; ++pos
) {
1111 double x
= pos
->GetX();
1112 double y
= pos
->GetY();
1113 double z
= pos
->GetZ();
1114 double X
= x
* COS
- y
* SIN
;
1115 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1116 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1117 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1118 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1119 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1123 if (show_mask
& (LABELS
|STNS
)) {
1124 list
<LabelInfo
*>::const_iterator label
= mainfrm
->GetLabels();
1125 while (label
!= mainfrm
->GetLabelsEnd()) {
1126 double x
= (*label
)->GetX();
1127 double y
= (*label
)->GetY();
1128 double z
= (*label
)->GetZ();
1129 if ((show_mask
& SURF
) || (*label
)->IsUnderground()) {
1130 double X
= x
* COS
- y
* SIN
;
1131 if (X
> m_layout
.xMax
) m_layout
.xMax
= X
;
1132 if (X
< m_layout
.xMin
) m_layout
.xMin
= X
;
1133 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1134 if (Y
> m_layout
.yMax
) m_layout
.yMax
= Y
;
1135 if (Y
< m_layout
.yMin
) m_layout
.yMin
= Y
;
1142 static int xpPageWidth
, ypPageDepth
;
1143 static long x_offset
, y_offset
;
1144 static int fontsize
, fontsize_labels
;
1146 /* FIXME: allow the font to be set */
1148 static const char *fontname
= "Arial", *fontname_labels
= "Arial";
1150 svxPrintout::svxPrintout(MainFrm
*mainfrm_
, layout
*l
,
1151 wxPageSetupDialogData
*data
, const wxString
& title
)
1152 : wxPrintout(title
), font_labels(NULL
), font_default(NULL
),
1153 scan_for_blank_pages(false)
1161 svxPrintout::draw_info_box()
1163 layout
*l
= m_layout
;
1167 pdc
->SetPen(*pen_frame
);
1170 if (l
->view
!= layout::EXTELEV
) {
1171 boxwidth
+= boxheight
;
1172 MOVEMM(div
, boxheight
);
1174 MOVEMM(0, 30); DRAWMM(div
, 30);
1177 MOVEMM(0, boxheight
);
1178 DRAWMM(boxwidth
, boxheight
);
1179 DRAWMM(boxwidth
, 0);
1182 DRAWMM(0, boxheight
);
1185 MOVEMM(0, 20); DRAWMM(div
, 20);
1186 MOVEMM(0, 10); DRAWMM(div
, 10);
1189 case layout::PLAN
: {
1190 long ax
, ay
, bx
, by
, cx
, cy
, dx
, dy
;
1192 long xc
= boxwidth
- boxheight
/ 2;
1193 long yc
= boxheight
/ 2;
1194 const double RADIUS
= boxheight
/ 3;
1195 DrawEllipse(long(xc
* l
->scX
), long(yc
* l
->scY
),
1196 long(RADIUS
* l
->scX
), long(RADIUS
* l
->scY
));
1198 ax
= (long)((xc
- (RADIUS
- 1) * sin(rad(000.0 + l
->rot
))) * l
->scX
);
1199 ay
= (long)((yc
+ (RADIUS
- 1) * cos(rad(000.0 + l
->rot
))) * l
->scY
);
1200 bx
= (long)((xc
- RADIUS
* 0.5 * sin(rad(180.0 + l
->rot
))) * l
->scX
);
1201 by
= (long)((yc
+ RADIUS
* 0.5 * cos(rad(180.0 + l
->rot
))) * l
->scY
);
1202 cx
= (long)((xc
- (RADIUS
- 1) * sin(rad(160.0 + l
->rot
))) * l
->scX
);
1203 cy
= (long)((yc
+ (RADIUS
- 1) * cos(rad(160.0 + l
->rot
))) * l
->scY
);
1204 dx
= (long)((xc
- (RADIUS
- 1) * sin(rad(200.0 + l
->rot
))) * l
->scX
);
1205 dy
= (long)((yc
+ (RADIUS
- 1) * cos(rad(200.0 + l
->rot
))) * l
->scY
);
1214 pdc
->SetTextForeground(colour_text
);
1215 MOVEMM(div
+ 0.5, boxheight
- 5.5);
1216 WriteString(wmsg(/*North*/115));
1218 wxString angle
= format_angle(ANGLE_FMT
, l
->rot
);
1220 /* TRANSLATORS: This is used on printouts of plans, with %s replaced by
1221 * something like "123°". The bearing is up the page. */
1222 s
.Printf(wmsg(/*Plan view, %s up page*/168), angle
.c_str());
1223 MOVEMM(2, 12); WriteString(s
);
1226 case layout::ELEV
: case layout::TILT
: {
1227 const int L
= div
+ 2;
1228 const int R
= boxwidth
- 2;
1229 const int H
= boxheight
/ 2;
1230 MOVEMM(L
, H
); DRAWMM(L
+ 5, H
- 3); DRAWMM(L
+ 3, H
); DRAWMM(L
+ 5, H
+ 3);
1232 DRAWMM(L
, H
); DRAWMM(R
, H
);
1234 DRAWMM(R
- 5, H
+ 3); DRAWMM(R
- 3, H
); DRAWMM(R
- 5, H
- 3); DRAWMM(R
, H
);
1236 MOVEMM((L
+ R
) / 2, H
- 2); DRAWMM((L
+ R
) / 2, H
+ 2);
1238 pdc
->SetTextForeground(colour_text
);
1239 MOVEMM(div
+ 2, boxheight
- 8);
1240 /* TRANSLATORS: "Elevation on" 020 <-> 200 degrees */
1241 WriteString(wmsg(/*Elevation on*/116));
1244 WriteString(format_angle(ANGLE_FMT
, fmod(l
->rot
+ 270.0, 360.0)));
1246 WriteString(format_angle(ANGLE_FMT
, fmod(l
->rot
+ 90.0, 360.0)));
1248 wxString angle
= format_angle(ANGLE_FMT
, l
->rot
);
1250 if (l
->view
== layout::ELEV
) {
1251 /* TRANSLATORS: This is used on printouts of elevations, with %s
1252 * replaced by something like "123°". The bearing is the direction
1254 s
.Printf(wmsg(/*Elevation facing %s*/169), angle
.c_str());
1256 wxString a2
= format_angle(ANGLE2_FMT
, l
->tilt
);
1257 /* TRANSLATORS: This is used on printouts of tilted elevations, with
1258 * the first %s replaced by something like "123°", and the second by
1259 * something like "-45°". The bearing is the direction we’re
1261 s
.Printf(wmsg(/*Elevation facing %s, tilted %s*/284), angle
.c_str(), a2
.c_str());
1263 MOVEMM(2, 12); WriteString(s
);
1266 case layout::EXTELEV
:
1267 pdc
->SetTextForeground(colour_text
);
1269 /* TRANSLATORS: This is used on printouts of extended elevations. */
1270 WriteString(wmsg(/*Extended elevation*/191));
1274 MOVEMM(2, boxheight
- 8); WriteString(l
->title
);
1277 // FIXME: "Original Scale" better?
1278 WriteString(wxString::Format(wmsg(/*Scale*/154) + wxT(" 1:%.0f"),
1281 /* This used to be a copyright line, but it was occasionally
1282 * mis-interpreted as us claiming copyright on the survey, so let's
1283 * give the website URL instead */
1284 MOVEMM(boxwidth
+ 2, 2);
1285 WriteString(wxT("Survex " VERSION
" - https://survex.com/"));
1287 draw_scale_bar(boxwidth
+ 10.0, 17.0, l
->PaperWidth
- boxwidth
- 18.0);
1290 /* Draw fancy scale bar with bottom left at (x,y) (both in mm) and at most */
1291 /* MaxLength mm long. The scaling in use is 1:scale */
1293 svxPrintout::draw_scale_bar(double x
, double y
, double MaxLength
)
1298 /* Limit scalebar to 20cm to stop people with A0 plotters complaining */
1299 if (MaxLength
> 200.0) MaxLength
= 200.0;
1301 #define dmin 10.0 /* each division >= dmin mm long */
1302 #define StepMax 5 /* number in steps of at most StepMax (x 10^N) */
1303 #define epsilon (1e-4) /* fudge factor to prevent rounding problems */
1305 E
= (int)ceil(log10((dmin
* 0.001 * m_layout
->Scale
) / StepMax
));
1306 StepEst
= pow(10.0, -(double)E
) * (dmin
* 0.001) * m_layout
->Scale
- epsilon
;
1308 /* Force labelling to be in multiples of 1, 2, or 5 */
1309 Step
= (StepEst
<= 1.0 ? 1 : (StepEst
<= 2.0 ? 2 : 5));
1311 /* Work out actual length of each scale bar division */
1312 d
= Step
* pow(10.0, (double)E
) / m_layout
->Scale
* 1000.0;
1314 /* FIXME: Non-metric units here... */
1315 /* Choose appropriate units, s.t. if possible E is >=0 and minimized */
1320 } else if (E
>= 0) {
1327 buf
= wmsg(/*Scale*/154);
1329 /* Add units used - eg. "Scale (10m)" */
1330 double pow10_E
= pow(10.0, (double)E
);
1332 buf
+= wxString::Format(wxT(" (%.f%s)"), pow10_E
, wmsg(units
).c_str());
1334 int sf
= -(int)floor(E
);
1335 buf
+= wxString::Format(wxT(" (%.*f%s)"), sf
, pow10_E
, wmsg(units
).c_str());
1337 pdc
->SetTextForeground(colour_text
);
1338 MOVEMM(x
, y
+ 4); WriteString(buf
);
1340 /* Work out how many divisions there will be */
1341 n
= (int)(MaxLength
/ d
);
1343 pdc
->SetPen(*pen_frame
);
1345 long Y
= long(y
* m_layout
->scY
);
1346 long Y2
= long((y
+ 3) * m_layout
->scY
);
1347 long X
= long(x
* m_layout
->scX
);
1348 long X2
= long((x
+ n
* d
) * m_layout
->scX
);
1350 /* Draw top of scale bar */
1356 MOVEMM(x
+ n
* d
, y
); DRAWMM(x
, y
);
1358 /* Draw divisions and label them */
1359 for (c
= 0; c
<= n
; c
++) {
1360 pdc
->SetPen(*pen_frame
);
1361 X
= long((x
+ c
* d
) * m_layout
->scX
);
1364 #if 0 // Don't waste toner!
1365 /* Draw a "zebra crossing" scale bar. */
1366 if (c
< n
&& (c
& 1) == 0) {
1367 X2
= long((x
+ (c
+ 1) * d
) * m_layout
->scX
);
1368 SolidRectangle(X
, Y
, X2
- X
, Y2
- Y
);
1371 buf
.Printf(wxT("%d"), c
* Step
);
1372 pdc
->SetTextForeground(colour_text
);
1373 MOVEMM(x
+ c
* d
- buf
.length(), y
- 5);
1380 make_calibration(layout
*l
) {
1381 img_point pt
= { 0.0, 0.0, 0.0 };
1382 l
->xMax
= l
->yMax
= 0.1;
1383 l
->xMin
= l
->yMin
= 0;
1385 stack(l
, img_MOVE
, NULL
, &pt
);
1387 stack(l
, img_LINE
, NULL
, &pt
);
1389 stack(l
, img_LINE
, NULL
, &pt
);
1391 stack(l
, img_LINE
, NULL
, &pt
);
1393 stack(l
, img_LINE
, NULL
, &pt
);
1396 stack(l
, img_LABEL
, "10cm", &pt
);
1399 stack(l
, img_LABEL
, "10cm", &pt
);
1405 svxPrintout::next_page(int *pstate
, char **q
, int pageLim
)
1414 wxASSERT(*p
== '-');
1416 while (isspace((unsigned char)*p
)) p
++;
1417 if (sscanf(p
, "%u%n", &page
, &c
) > 0) {
1422 if (*pstate
> page
) goto err
;
1423 if (*pstate
< page
) return *pstate
;
1429 while (isspace((unsigned char)*p
) || *p
== ',') p
++;
1431 if (!*p
) return 0; /* done */
1436 return 1; /* range with initial parameter omitted */
1438 if (sscanf(p
, "%u%n", &page
, &c
) > 0) {
1440 while (isspace((unsigned char)*p
)) p
++;
1442 if (0 < page
&& page
<= pageLim
) {
1443 if (*p
== '-') *pstate
= page
; /* range with start */
1452 /* Draws in alignment marks on each page or borders on edge pages */
1454 svxPrintout::drawticks(int tsize
, int x
, int y
)
1459 bool fAtCorner
= fFalse
;
1460 pdc
->SetPen(*pen_frame
);
1461 if (x
== 0 && m_layout
->Border
) {
1462 /* solid left border */
1463 MoveTo(clip
.x_min
, clip
.y_min
);
1464 DrawTo(clip
.x_min
, clip
.y_max
);
1467 if (x
> 0 || y
> 0) {
1468 MoveTo(clip
.x_min
, clip
.y_min
);
1469 DrawTo(clip
.x_min
, clip
.y_min
+ tsize
);
1471 if (s
&& x
> 0 && m_layout
->Cutlines
) {
1472 /* dashed left border */
1473 i
= (clip
.y_max
- clip
.y_min
) -
1474 (tsize
+ ((clip
.y_max
- clip
.y_min
- tsize
* 2L) % s
) / 2);
1475 for ( ; i
> tsize
; i
-= s
) {
1476 MoveTo(clip
.x_min
, clip
.y_max
- (i
+ o
));
1477 DrawTo(clip
.x_min
, clip
.y_max
- (i
- o
));
1480 if (x
> 0 || y
< m_layout
->pagesY
- 1) {
1481 MoveTo(clip
.x_min
, clip
.y_max
- tsize
);
1482 DrawTo(clip
.x_min
, clip
.y_max
);
1487 if (y
== m_layout
->pagesY
- 1 && m_layout
->Border
) {
1488 /* solid top border */
1489 if (!fAtCorner
) MoveTo(clip
.x_min
, clip
.y_max
);
1490 DrawTo(clip
.x_max
, clip
.y_max
);
1493 if (y
< m_layout
->pagesY
- 1 || x
> 0) {
1494 if (!fAtCorner
) MoveTo(clip
.x_min
, clip
.y_max
);
1495 DrawTo(clip
.x_min
+ tsize
, clip
.y_max
);
1497 if (s
&& y
< m_layout
->pagesY
- 1 && m_layout
->Cutlines
) {
1498 /* dashed top border */
1499 i
= (clip
.x_max
- clip
.x_min
) -
1500 (tsize
+ ((clip
.x_max
- clip
.x_min
- tsize
* 2L) % s
) / 2);
1501 for ( ; i
> tsize
; i
-= s
) {
1502 MoveTo(clip
.x_max
- (i
+ o
), clip
.y_max
);
1503 DrawTo(clip
.x_max
- (i
- o
), clip
.y_max
);
1506 if (y
< m_layout
->pagesY
- 1 || x
< m_layout
->pagesX
- 1) {
1507 MoveTo(clip
.x_max
- tsize
, clip
.y_max
);
1508 DrawTo(clip
.x_max
, clip
.y_max
);
1515 if (x
== m_layout
->pagesX
- 1 && m_layout
->Border
) {
1516 /* solid right border */
1517 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_max
);
1518 DrawTo(clip
.x_max
, clip
.y_min
);
1521 if (x
< m_layout
->pagesX
- 1 || y
< m_layout
->pagesY
- 1) {
1522 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_max
);
1523 DrawTo(clip
.x_max
, clip
.y_max
- tsize
);
1525 if (s
&& x
< m_layout
->pagesX
- 1 && m_layout
->Cutlines
) {
1526 /* dashed right border */
1527 i
= (clip
.y_max
- clip
.y_min
) -
1528 (tsize
+ ((clip
.y_max
- clip
.y_min
- tsize
* 2L) % s
) / 2);
1529 for ( ; i
> tsize
; i
-= s
) {
1530 MoveTo(clip
.x_max
, clip
.y_min
+ (i
+ o
));
1531 DrawTo(clip
.x_max
, clip
.y_min
+ (i
- o
));
1534 if (x
< m_layout
->pagesX
- 1 || y
> 0) {
1535 MoveTo(clip
.x_max
, clip
.y_min
+ tsize
);
1536 DrawTo(clip
.x_max
, clip
.y_min
);
1543 if (y
== 0 && m_layout
->Border
) {
1544 /* solid bottom border */
1545 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_min
);
1546 DrawTo(clip
.x_min
, clip
.y_min
);
1548 if (y
> 0 || x
< m_layout
->pagesX
- 1) {
1549 if (!fAtCorner
) MoveTo(clip
.x_max
, clip
.y_min
);
1550 DrawTo(clip
.x_max
- tsize
, clip
.y_min
);
1552 if (s
&& y
> 0 && m_layout
->Cutlines
) {
1553 /* dashed bottom border */
1554 i
= (clip
.x_max
- clip
.x_min
) -
1555 (tsize
+ ((clip
.x_max
- clip
.x_min
- tsize
* 2L) % s
) / 2);
1556 for ( ; i
> tsize
; i
-= s
) {
1557 MoveTo(clip
.x_min
+ (i
+ o
), clip
.y_min
);
1558 DrawTo(clip
.x_min
+ (i
- o
), clip
.y_min
);
1561 if (y
> 0 || x
> 0) {
1562 MoveTo(clip
.x_min
+ tsize
, clip
.y_min
);
1563 DrawTo(clip
.x_min
, clip
.y_min
);
1569 svxPrintout::OnPrintPage(int pageNum
) {
1570 GetPageSizePixels(&xpPageWidth
, &ypPageDepth
);
1572 pdc
->SetBackgroundMode(wxTRANSPARENT
);
1573 #ifdef AVEN_PRINT_PREVIEW
1576 pdc
->GetSize(&dcx
, &dcy
);
1577 pdc
->SetUserScale((double)dcx
/ xpPageWidth
, (double)dcy
/ ypPageDepth
);
1581 layout
* l
= m_layout
;
1584 GetPageSizeMM(&pwidth
, &pdepth
);
1585 l
->scX
= (double)xpPageWidth
/ pwidth
;
1586 l
->scY
= (double)ypPageDepth
/ pdepth
;
1587 font_scaling_x
= l
->scX
* (25.4 / 72.0);
1588 font_scaling_y
= l
->scY
* (25.4 / 72.0);
1589 long MarginLeft
= m_data
->GetMarginTopLeft().x
;
1590 long MarginTop
= m_data
->GetMarginTopLeft().y
;
1591 long MarginBottom
= m_data
->GetMarginBottomRight().y
;
1592 long MarginRight
= m_data
->GetMarginBottomRight().x
;
1593 xpPageWidth
-= (int)(l
->scX
* (MarginLeft
+ MarginRight
));
1594 ypPageDepth
-= (int)(l
->scY
* (FOOTER_HEIGHT_MM
+ MarginBottom
+ MarginTop
));
1595 // xpPageWidth -= 1;
1596 pdepth
-= FOOTER_HEIGHT_MM
;
1597 x_offset
= (long)(l
->scX
* MarginLeft
);
1598 y_offset
= (long)(l
->scY
* MarginTop
);
1599 l
->PaperWidth
= pwidth
-= MarginLeft
+ MarginRight
;
1600 l
->PaperDepth
= pdepth
-= MarginTop
+ MarginBottom
;
1603 double SIN
= sin(rad(l
->rot
));
1604 double COS
= cos(rad(l
->rot
));
1605 double SINT
= sin(rad(l
->tilt
));
1606 double COST
= cos(rad(l
->tilt
));
1608 NewPage(pageNum
, l
->pagesX
, l
->pagesY
);
1610 if (l
->Legend
&& pageNum
== (l
->pagesY
- 1) * l
->pagesX
+ 1) {
1611 SetFont(font_default
);
1615 pdc
->SetClippingRegion(x_offset
, y_offset
, xpPageWidth
+ 1, ypPageDepth
+ 1);
1617 const double Sc
= 1000 / l
->Scale
;
1619 int show_mask
= l
->get_effective_show_mask();
1620 if (show_mask
& LEGS
) {
1621 list
<traverse
>::const_iterator trav
= mainfrm
->traverses_begin();
1622 list
<traverse
>::const_iterator tend
= mainfrm
->traverses_end();
1623 for ( ; trav
!= tend
; ++trav
) {
1624 if (trav
->isSplay
) {
1625 if (!(show_mask
& SPLAYS
))
1627 pdc
->SetPen(*pen_splay
);
1629 pdc
->SetPen(*pen_leg
);
1631 vector
<PointInfo
>::const_iterator pos
= trav
->begin();
1632 vector
<PointInfo
>::const_iterator end
= trav
->end();
1633 for ( ; pos
!= end
; ++pos
) {
1634 double x
= pos
->GetX();
1635 double y
= pos
->GetY();
1636 double z
= pos
->GetZ();
1637 double X
= x
* COS
- y
* SIN
;
1638 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1639 long px
= (long)((X
* Sc
+ l
->xOrg
) * l
->scX
);
1640 long py
= (long)((Y
* Sc
+ l
->yOrg
) * l
->scY
);
1641 if (pos
== trav
->begin()) {
1650 if ((show_mask
& XSECT
) &&
1651 (l
->tilt
== 0.0 || l
->tilt
== 90.0 || l
->tilt
== -90.0)) {
1652 pdc
->SetPen(*pen_splay
);
1653 list
<vector
<XSect
> >::const_iterator trav
= mainfrm
->tubes_begin();
1654 list
<vector
<XSect
> >::const_iterator tend
= mainfrm
->tubes_end();
1655 for ( ; trav
!= tend
; ++trav
) {
1656 if (l
->tilt
== 0.0) {
1659 // m_layout.tilt is 90.0 or -90.0 due to check above.
1665 if (show_mask
& SURF
) {
1666 list
<traverse
>::const_iterator trav
= mainfrm
->surface_traverses_begin();
1667 list
<traverse
>::const_iterator tend
= mainfrm
->surface_traverses_end();
1668 for ( ; trav
!= tend
; ++trav
) {
1669 if (trav
->isSplay
) {
1670 if (!(show_mask
& SPLAYS
))
1672 pdc
->SetPen(*pen_splay
);
1674 pdc
->SetPen(*pen_surface_leg
);
1676 vector
<PointInfo
>::const_iterator pos
= trav
->begin();
1677 vector
<PointInfo
>::const_iterator end
= trav
->end();
1678 for ( ; pos
!= end
; ++pos
) {
1679 double x
= pos
->GetX();
1680 double y
= pos
->GetY();
1681 double z
= pos
->GetZ();
1682 double X
= x
* COS
- y
* SIN
;
1683 double Y
= z
* COST
- (x
* SIN
+ y
* COS
) * SINT
;
1684 long px
= (long)((X
* Sc
+ l
->xOrg
) * l
->scX
);
1685 long py
= (long)((Y
* Sc
+ l
->yOrg
) * l
->scY
);
1686 if (pos
== trav
->begin()) {
1695 if (show_mask
& (LABELS
|STNS
)) {
1696 if (show_mask
& LABELS
) SetFont(font_labels
);
1697 list
<LabelInfo
*>::const_iterator label
= mainfrm
->GetLabels();
1698 while (label
!= mainfrm
->GetLabelsEnd()) {
1699 double px
= (*label
)->GetX();
1700 double py
= (*label
)->GetY();
1701 double pz
= (*label
)->GetZ();
1702 if ((show_mask
& SURF
) || (*label
)->IsUnderground()) {
1703 double X
= px
* COS
- py
* SIN
;
1704 double Y
= pz
* COST
- (px
* SIN
+ py
* COS
) * SINT
;
1706 xnew
= (long)((X
* Sc
+ l
->xOrg
) * l
->scX
);
1707 ynew
= (long)((Y
* Sc
+ l
->yOrg
) * l
->scY
);
1708 if (show_mask
& STNS
) {
1709 pdc
->SetPen(*pen_cross
);
1710 DrawCross(xnew
, ynew
);
1712 if (show_mask
& LABELS
) {
1713 pdc
->SetTextForeground(colour_labels
);
1715 WriteString((*label
)->GetText());
1726 svxPrintout::GetPageInfo(int *minPage
, int *maxPage
,
1727 int *pageFrom
, int *pageTo
)
1729 *minPage
= *pageFrom
= 1;
1730 *maxPage
= *pageTo
= m_layout
->pages
;
1734 svxPrintout::HasPage(int pageNum
) {
1735 return (pageNum
<= m_layout
->pages
);
1739 svxPrintout::OnBeginPrinting() {
1740 /* Initialise printer routines */
1741 fontsize_labels
= 10;
1744 colour_text
= colour_labels
= *wxBLACK
;
1746 wxColour colour_frame
, colour_cross
, colour_leg
, colour_surface_leg
;
1747 colour_frame
= colour_cross
= colour_leg
= colour_surface_leg
= *wxBLACK
;
1749 pen_frame
= new wxPen(colour_frame
);
1750 pen_cross
= new wxPen(colour_cross
);
1751 pen_leg
= new wxPen(colour_leg
);
1752 pen_surface_leg
= new wxPen(colour_surface_leg
);
1753 pen_splay
= new wxPen(wxColour(192, 192, 192));
1758 font_labels
= new wxFont(fontsize_labels
, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
1759 false, wxString(fontname_labels
, wxConvUTF8
),
1760 wxFONTENCODING_ISO8859_1
);
1761 font_default
= new wxFont(fontsize
, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
1762 false, wxString(fontname
, wxConvUTF8
),
1763 wxFONTENCODING_ISO8859_1
);
1767 svxPrintout::OnEndPrinting() {
1769 delete font_default
;
1773 delete pen_surface_leg
;
1778 svxPrintout::check_intersection(long x_p
, long y_p
)
1784 int mask_p
= 0, mask_t
= 0;
1787 else if (x_p
> xpPageWidth
)
1792 else if (y_p
> ypPageDepth
)
1797 else if (x_t
> xpPageWidth
)
1802 else if (y_t
> ypPageDepth
)
1806 /* approximation to correct answer */
1807 return !(mask_t
& mask_p
);
1809 /* One end of the line is on the page */
1810 if (!mask_t
|| !mask_p
) return 1;
1812 /* whole line is above, left, right, or below page */
1813 if (mask_t
& mask_p
) return 0;
1815 if (mask_t
== 0) mask_t
= mask_p
;
1817 double v
= (double)(y_p
- ypPageDepth
) / (y_p
- y_t
);
1818 return v
>= 0 && v
<= 1;
1821 double v
= (double)y_p
/ (y_p
- y_t
);
1822 return v
>= 0 && v
<= 1;
1825 double v
= (double)(x_p
- xpPageWidth
) / (x_p
- x_t
);
1826 return v
>= 0 && v
<= 1;
1828 wxASSERT(mask_t
& L
);
1830 double v
= (double)x_p
/ (x_p
- x_t
);
1831 return v
>= 0 && v
<= 1;
1841 svxPrintout::MoveTo(long x
, long y
)
1843 x_t
= x_offset
+ x
- clip
.x_min
;
1844 y_t
= y_offset
+ clip
.y_max
- y
;
1848 svxPrintout::DrawTo(long x
, long y
)
1850 long x_p
= x_t
, y_p
= y_t
;
1851 x_t
= x_offset
+ x
- clip
.x_min
;
1852 y_t
= y_offset
+ clip
.y_max
- y
;
1853 if (!scan_for_blank_pages
) {
1854 pdc
->DrawLine(x_p
, y_p
, x_t
, y_t
);
1856 if (check_intersection(x_p
, y_p
)) fBlankPage
= fFalse
;
1860 #define POINTS_PER_INCH 72.0
1861 #define POINTS_PER_MM (POINTS_PER_INCH / MM_PER_INCH)
1862 #define PWX_CROSS_SIZE (int)(2 * m_layout->scX / POINTS_PER_MM)
1865 svxPrintout::DrawCross(long x
, long y
)
1867 if (!scan_for_blank_pages
) {
1868 MoveTo(x
- PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
1869 DrawTo(x
+ PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
1870 MoveTo(x
+ PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
1871 DrawTo(x
- PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
1874 if ((x
+ PWX_CROSS_SIZE
> clip
.x_min
&&
1875 x
- PWX_CROSS_SIZE
< clip
.x_max
) ||
1876 (y
+ PWX_CROSS_SIZE
> clip
.y_min
&&
1877 y
- PWX_CROSS_SIZE
< clip
.y_max
)) {
1878 fBlankPage
= fFalse
;
1884 svxPrintout::WriteString(const wxString
& s
)
1887 pdc
->GetUserScale(&xsc
, &ysc
);
1888 pdc
->SetUserScale(xsc
* font_scaling_x
, ysc
* font_scaling_y
);
1889 if (!scan_for_blank_pages
) {
1891 long(x_t
/ font_scaling_x
),
1892 long(y_t
/ font_scaling_y
) - pdc
->GetCharHeight());
1895 pdc
->GetTextExtent(s
, &w
, &h
);
1896 if ((y_t
+ h
> 0 && y_t
- h
< clip
.y_max
- clip
.y_min
) ||
1897 (x_t
< clip
.x_max
- clip
.x_min
&& x_t
+ w
> 0)) {
1898 fBlankPage
= fFalse
;
1901 pdc
->SetUserScale(xsc
, ysc
);
1905 svxPrintout::DrawEllipse(long x
, long y
, long r
, long R
)
1907 if (!scan_for_blank_pages
) {
1908 x_t
= x_offset
+ x
- clip
.x_min
;
1909 y_t
= y_offset
+ clip
.y_max
- y
;
1910 const wxBrush
& save_brush
= pdc
->GetBrush();
1911 pdc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1912 pdc
->DrawEllipse(x_t
- r
, y_t
- R
, 2 * r
, 2 * R
);
1913 pdc
->SetBrush(save_brush
);
1915 /* No need to check - this is only used in the legend. */
1920 svxPrintout::SolidRectangle(long x
, long y
, long w
, long h
)
1922 long X
= x_offset
+ x
- clip
.x_min
;
1923 long Y
= y_offset
+ clip
.y_max
- y
;
1924 pdc
->SetBrush(*wxBLACK_BRUSH
);
1925 pdc
->DrawRectangle(X
, Y
- h
, w
, h
);
1929 svxPrintout::NewPage(int pg
, int pagesX
, int pagesY
)
1931 pdc
->DestroyClippingRegion();
1934 x
= (pg
- 1) % pagesX
;
1935 y
= pagesY
- 1 - ((pg
- 1) / pagesX
);
1937 clip
.x_min
= (long)x
* xpPageWidth
;
1938 clip
.y_min
= (long)y
* ypPageDepth
;
1939 clip
.x_max
= clip
.x_min
+ xpPageWidth
; /* dm/pcl/ps had -1; */
1940 clip
.y_max
= clip
.y_min
+ ypPageDepth
; /* dm/pcl/ps had -1; */
1942 const int FOOTERS
= 4;
1943 wxString footer
[FOOTERS
];
1944 footer
[0] = m_layout
->title
;
1946 double rot
= m_layout
->rot
;
1947 double tilt
= m_layout
->tilt
;
1948 double scale
= m_layout
->Scale
;
1949 switch (m_layout
->view
) {
1951 // TRANSLATORS: Used in the footer of printouts to compactly
1952 // indicate this is a plan view and what the viewing angle is.
1953 // Aven will replace %s with the bearing, and %.0f with the scale.
1955 // This message probably doesn't need translating for most languages.
1956 footer
[1].Printf(wmsg(/*↑%s 1:%.0f*/233),
1957 format_angle(ANGLE_FMT
, rot
).c_str(),
1961 // TRANSLATORS: Used in the footer of printouts to compactly
1962 // indicate this is an elevation view and what the viewing angle
1963 // is. Aven will replace the %s codes with the bearings to the
1964 // left and right of the viewer, and %.0f with the scale.
1966 // This message probably doesn't need translating for most languages.
1967 footer
[1].Printf(wmsg(/*%s↔%s 1:%.0f*/235),
1968 format_angle(ANGLE_FMT
, fmod(rot
+ 270.0, 360.0)).c_str(),
1969 format_angle(ANGLE_FMT
, fmod(rot
+ 90.0, 360.0)).c_str(),
1973 // TRANSLATORS: Used in the footer of printouts to compactly
1974 // indicate this is a tilted elevation view and what the viewing
1975 // angles are. Aven will replace the %s codes with the bearings to
1976 // the left and right of the viewer and the angle the view is
1977 // tilted at, and %.0f with the scale.
1979 // This message probably doesn't need translating for most languages.
1980 footer
[1].Printf(wmsg(/*%s↔%s ∡%s 1:%.0f*/236),
1981 format_angle(ANGLE_FMT
, fmod(rot
+ 270.0, 360.0)).c_str(),
1982 format_angle(ANGLE_FMT
, fmod(rot
+ 90.0, 360.0)).c_str(),
1983 format_angle(ANGLE2_FMT
, tilt
).c_str(),
1986 case layout::EXTELEV
:
1987 // TRANSLATORS: Used in the footer of printouts to compactly
1988 // indicate this is an extended elevation view. Aven will replace
1989 // %.0f with the scale.
1991 // Try to keep the translation short (for example, in English we
1992 // use "Extended" not "Extended elevation") - there is limited room
1993 // in the footer, and the details there are mostly to make it easy
1994 // to check that you have corresponding pages from a multiple page
1996 footer
[1].Printf(wmsg(/*Extended 1:%.0f*/244), scale
);
2000 // TRANSLATORS: N/M meaning page N of M in the page footer of a printout.
2001 footer
[2].Printf(wmsg(/*%d/%d*/232), pg
, m_layout
->pagesX
* m_layout
->pagesY
);
2003 wxString datestamp
= m_layout
->datestamp
;
2004 if (!datestamp
.empty()) {
2005 // Remove any timezone suffix (e.g. " UTC" or " +1200").
2006 wxChar ch
= datestamp
[datestamp
.size() - 1];
2007 if (ch
>= 'A' && ch
<= 'Z') {
2008 for (size_t i
= datestamp
.size() - 1; i
; --i
) {
2010 if (ch
< 'A' || ch
> 'Z') {
2011 if (ch
== ' ') datestamp
.resize(i
);
2015 } else if (ch
>= '0' && ch
<= '9') {
2016 for (size_t i
= datestamp
.size() - 1; i
; --i
) {
2018 if (ch
< '0' || ch
> '9') {
2019 if ((ch
== '-' || ch
== '+') && datestamp
[--i
] == ' ')
2020 datestamp
.resize(i
);
2026 // Remove any day prefix (e.g. "Mon,").
2027 for (size_t i
= 0; i
!= datestamp
.size(); ++i
) {
2028 if (datestamp
[i
] == ',' && i
+ 1 != datestamp
.size()) {
2029 // Also skip a space after the comma.
2030 if (datestamp
[i
+ 1] == ' ') ++i
;
2031 datestamp
.erase(0, i
+ 1);
2037 // TRANSLATORS: Used in the footer of printouts to compactly indicate that
2038 // the date which follows is the date that the survey data was processed.
2040 // Aven will replace %s with a string giving the date and time (e.g.
2041 // "2015-06-09 12:40:44").
2042 footer
[3].Printf(wmsg(/*Processed: %s*/167), datestamp
.c_str());
2044 const wxChar
* footer_sep
= wxT(" ");
2045 int fontsize_footer
= fontsize_labels
;
2046 wxFont
* font_footer
;
2047 font_footer
= new wxFont(fontsize_footer
, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
2048 false, wxString(fontname_labels
, wxConvUTF8
),
2049 wxFONTENCODING_UTF8
);
2050 font_footer
->Scale(font_scaling_x
);
2051 SetFont(font_footer
);
2052 int w
[FOOTERS
], ws
, h
;
2053 pdc
->GetTextExtent(footer_sep
, &ws
, &h
);
2054 int wtotal
= ws
* (FOOTERS
- 1);
2055 for (int i
= 0; i
< FOOTERS
; ++i
) {
2056 pdc
->GetTextExtent(footer
[i
], &w
[i
], &h
);
2061 long Y
= y_offset
+ ypPageDepth
+ (long)(7 * m_layout
->scY
) - pdc
->GetCharHeight();
2063 if (wtotal
> xpPageWidth
) {
2064 // Rescale the footer so it fits.
2065 double rescale
= double(wtotal
) / xpPageWidth
;
2067 pdc
->GetUserScale(&xsc
, &ysc
);
2068 pdc
->SetUserScale(xsc
/ rescale
, ysc
/ rescale
);
2069 SetFont(font_footer
);
2070 wxString fullfooter
= footer
[0];
2071 for (int i
= 1; i
< FOOTERS
- 1; ++i
) {
2072 fullfooter
+= footer_sep
;
2073 fullfooter
+= footer
[i
];
2075 pdc
->DrawText(fullfooter
, X
* rescale
, Y
* rescale
);
2076 // Draw final item right aligned to avoid misaligning.
2077 wxRect
rect(x_offset
* rescale
, Y
* rescale
,
2078 xpPageWidth
* rescale
, pdc
->GetCharHeight() * rescale
);
2079 pdc
->DrawLabel(footer
[FOOTERS
- 1], rect
, wxALIGN_RIGHT
|wxALIGN_TOP
);
2080 pdc
->SetUserScale(xsc
, ysc
);
2082 // Space out the elements of the footer to fill the line.
2083 double extra
= double(xpPageWidth
- wtotal
) / (FOOTERS
- 1);
2084 for (int i
= 0; i
< FOOTERS
- 1; ++i
) {
2085 pdc
->DrawText(footer
[i
], X
+ extra
* i
, Y
);
2088 // Draw final item right aligned to avoid misaligning.
2089 wxRect
rect(x_offset
, Y
, xpPageWidth
, pdc
->GetCharHeight());
2090 pdc
->DrawLabel(footer
[FOOTERS
- 1], rect
, wxALIGN_RIGHT
|wxALIGN_TOP
);
2092 drawticks((int)(9 * m_layout
->scX
/ POINTS_PER_MM
), x
, y
);
2096 svxPrintout::PlotLR(const vector
<XSect
> & centreline
)
2098 assert(centreline
.size() > 1);
2100 Vector3
last_right(1.0, 0.0, 0.0);
2102 const double Sc
= 1000 / m_layout
->Scale
;
2103 const double SIN
= sin(rad(m_layout
->rot
));
2104 const double COS
= cos(rad(m_layout
->rot
));
2106 vector
<XSect
>::const_iterator i
= centreline
.begin();
2107 vector
<XSect
>::size_type segment
= 0;
2108 while (i
!= centreline
.end()) {
2109 // get the coordinates of this vertex
2110 const XSect
& pt_v
= *i
++;
2114 const Vector3
up_v(0.0, 0.0, 1.0);
2117 assert(i
!= centreline
.end());
2120 // get the coordinates of the next vertex
2121 const XSect
& next_pt_v
= *i
;
2123 // calculate vector from this pt to the next one
2124 Vector3 leg_v
= next_pt_v
- pt_v
;
2126 // obtain a vector in the LRUD plane
2127 right
= leg_v
* up_v
;
2128 if (right
.magnitude() == 0) {
2133 } else if (segment
+ 1 == centreline
.size()) {
2136 // Calculate vector from the previous pt to this one.
2137 Vector3 leg_v
= pt_v
- prev_pt_v
;
2139 // Obtain a horizontal vector in the LRUD plane.
2140 right
= leg_v
* up_v
;
2141 if (right
.magnitude() == 0) {
2142 right
= Vector3(last_right
.GetX(), last_right
.GetY(), 0.0);
2147 assert(i
!= centreline
.end());
2148 // Intermediate segment.
2150 // Get the coordinates of the next vertex.
2151 const XSect
& next_pt_v
= *i
;
2153 // Calculate vectors from this vertex to the
2154 // next vertex, and from the previous vertex to
2156 Vector3 leg1_v
= pt_v
- prev_pt_v
;
2157 Vector3 leg2_v
= next_pt_v
- pt_v
;
2159 // Obtain horizontal vectors perpendicular to
2160 // both legs, then normalise and average to get
2161 // a horizontal bisector.
2162 Vector3 r1
= leg1_v
* up_v
;
2163 Vector3 r2
= leg2_v
* up_v
;
2167 if (right
.magnitude() == 0) {
2168 // This is the "mid-pitch" case...
2174 // Scale to unit vectors in the LRUD plane.
2177 Double l
= pt_v
.GetL();
2178 Double r
= pt_v
.GetR();
2180 if (l
>= 0 || r
>= 0) {
2181 // Get the x and y coordinates of the survey station
2182 double pt_X
= pt_v
.GetX() * COS
- pt_v
.GetY() * SIN
;
2183 double pt_Y
= pt_v
.GetX() * SIN
+ pt_v
.GetY() * COS
;
2184 long pt_x
= (long)((pt_X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2185 long pt_y
= (long)((pt_Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2187 // Calculate dimensions for the right arrow
2188 double COSR
= right
.GetX();
2189 double SINR
= right
.GetY();
2190 long CROSS_MAJOR
= (COSR
+ SINR
) * PWX_CROSS_SIZE
;
2191 long CROSS_MINOR
= (COSR
- SINR
) * PWX_CROSS_SIZE
;
2194 // Get the x and y coordinates of the end of the left arrow
2195 Vector3 p
= pt_v
- right
* l
;
2196 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2197 double Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
2198 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2199 long y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2201 // Draw the arrow stem
2205 // Rotate the arrow by the page rotation
2206 long dx1
= (+CROSS_MINOR
) * COS
- (+CROSS_MAJOR
) * SIN
;
2207 long dy1
= (+CROSS_MINOR
) * SIN
+ (+CROSS_MAJOR
) * COS
;
2208 long dx2
= (+CROSS_MAJOR
) * COS
- (-CROSS_MINOR
) * SIN
;
2209 long dy2
= (+CROSS_MAJOR
) * SIN
+ (-CROSS_MINOR
) * COS
;
2212 MoveTo(x
+ dx1
, y
+ dy1
);
2214 DrawTo(x
+ dx2
, y
+ dy2
);
2218 // Get the x and y coordinates of the end of the right arrow
2219 Vector3 p
= pt_v
+ right
* r
;
2220 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2221 double Y
= (p
.GetX() * SIN
+ p
.GetY() * COS
);
2222 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2223 long y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2225 // Draw the arrow stem
2229 // Rotate the arrow by the page rotation
2230 long dx1
= (-CROSS_MINOR
) * COS
- (-CROSS_MAJOR
) * SIN
;
2231 long dy1
= (-CROSS_MINOR
) * SIN
+ (-CROSS_MAJOR
) * COS
;
2232 long dx2
= (-CROSS_MAJOR
) * COS
- (+CROSS_MINOR
) * SIN
;
2233 long dy2
= (-CROSS_MAJOR
) * SIN
+ (+CROSS_MINOR
) * COS
;
2236 MoveTo(x
+ dx1
, y
+ dy1
);
2238 DrawTo(x
+ dx2
, y
+ dy2
);
2249 svxPrintout::PlotUD(const vector
<XSect
> & centreline
)
2251 assert(centreline
.size() > 1);
2252 const double Sc
= 1000 / m_layout
->Scale
;
2254 vector
<XSect
>::const_iterator i
= centreline
.begin();
2255 while (i
!= centreline
.end()) {
2256 // get the coordinates of this vertex
2257 const XSect
& pt_v
= *i
++;
2259 Double u
= pt_v
.GetU();
2260 Double d
= pt_v
.GetD();
2262 if (u
>= 0 || d
>= 0) {
2263 // Get the coordinates of the survey point
2265 double SIN
= sin(rad(m_layout
->rot
));
2266 double COS
= cos(rad(m_layout
->rot
));
2267 double X
= p
.GetX() * COS
- p
.GetY() * SIN
;
2268 double Y
= p
.GetZ();
2269 long x
= (long)((X
* Sc
+ m_layout
->xOrg
) * m_layout
->scX
);
2270 long pt_y
= (long)((Y
* Sc
+ m_layout
->yOrg
) * m_layout
->scX
);
2273 // Get the y coordinate of the up arrow
2274 long y
= (long)(((Y
+ u
) * Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2276 // Draw the arrow stem
2280 // Draw the up arrow
2281 MoveTo(x
- PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
2283 DrawTo(x
+ PWX_CROSS_SIZE
, y
- PWX_CROSS_SIZE
);
2287 // Get the y coordinate of the down arrow
2288 long y
= (long)(((Y
- d
) * Sc
+ m_layout
->yOrg
) * m_layout
->scY
);
2290 // Draw the arrow stem
2294 // Draw the down arrow
2295 MoveTo(x
- PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);
2297 DrawTo(x
+ PWX_CROSS_SIZE
, y
+ PWX_CROSS_SIZE
);