[a80e6f3] | 1 | /* printwx.cc */ |
---|
[1324d6c] | 2 | /* wxWidgets specific parts of Survex wxWidgets printing code */ |
---|
[18ff765] | 3 | /* Copyright (C) 1993-2003,2004,2005,2006,2010,2011,2012,2013,2014,2015 Olly Betts |
---|
[79c239e] | 4 | * Copyright (C) 2001,2004 Philip Underwood |
---|
| 5 | * |
---|
| 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. |
---|
| 10 | * |
---|
| 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. |
---|
| 15 | * |
---|
| 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 |
---|
[9f6ea6c] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[79c239e] | 19 | */ |
---|
| 20 | |
---|
| 21 | #ifdef HAVE_CONFIG_H |
---|
| 22 | # include <config.h> |
---|
| 23 | #endif |
---|
| 24 | |
---|
[255f3269] | 25 | #include <wx/confbase.h> |
---|
| 26 | #include <wx/filename.h> |
---|
| 27 | #include <wx/print.h> |
---|
| 28 | #include <wx/printdlg.h> |
---|
| 29 | #include <wx/spinctrl.h> |
---|
| 30 | #include <wx/radiobox.h> |
---|
| 31 | #include <wx/statbox.h> |
---|
| 32 | #include <wx/valgen.h> |
---|
[741d94f] | 33 | |
---|
[255f3269] | 34 | #include <vector> |
---|
[741d94f] | 35 | |
---|
[79c239e] | 36 | #include <stdio.h> |
---|
| 37 | #include <stdlib.h> |
---|
| 38 | #include <math.h> |
---|
| 39 | #include <string.h> |
---|
| 40 | #include <ctype.h> |
---|
| 41 | #include <float.h> |
---|
| 42 | #include <limits.h> |
---|
| 43 | |
---|
| 44 | #include "debug.h" /* for BUG and SVX_ASSERT */ |
---|
[5940815] | 45 | #include "export.h" |
---|
[79c239e] | 46 | #include "filelist.h" |
---|
| 47 | #include "filename.h" |
---|
| 48 | #include "ini.h" |
---|
| 49 | #include "message.h" |
---|
| 50 | #include "useful.h" |
---|
| 51 | |
---|
[e0ffc2c] | 52 | #include "aven.h" |
---|
[79c239e] | 53 | #include "avenprcore.h" |
---|
| 54 | #include "mainfrm.h" |
---|
[741d94f] | 55 | #include "printwx.h" |
---|
[79c239e] | 56 | |
---|
[255f3269] | 57 | using namespace std; |
---|
| 58 | |
---|
[4a66219] | 59 | // How many decimal points to show on angles: |
---|
| 60 | #define ANGLE_DP 1 |
---|
| 61 | |
---|
| 62 | #if ANGLE_DP == 0 |
---|
| 63 | # define ANGLE_FMT wxT("%03.f") |
---|
| 64 | # define ANGLE2_FMT wxT("%.f") |
---|
| 65 | #elif ANGLE_DP == 1 |
---|
| 66 | # define ANGLE_FMT wxT("%05.1f") |
---|
| 67 | # define ANGLE2_FMT wxT("%.1f") |
---|
| 68 | #elif ANGLE_DP == 2 |
---|
| 69 | # define ANGLE_FMT wxT("%06.2f") |
---|
| 70 | # define ANGLE2_FMT wxT("%.2f") |
---|
| 71 | #else |
---|
| 72 | # error Need to add ANGLE_FMT and ANGLE2_FMT for the currently set ANGLE_DP |
---|
| 73 | #endif |
---|
| 74 | |
---|
| 75 | static wxString |
---|
| 76 | format_angle(const wxChar * fmt, double angle) |
---|
| 77 | { |
---|
| 78 | wxString s; |
---|
| 79 | s.Printf(fmt, angle); |
---|
| 80 | size_t dot = s.find('.'); |
---|
| 81 | size_t i = s.size(); |
---|
| 82 | while (i > dot) { |
---|
| 83 | --i; |
---|
| 84 | if (s[i] != '0') { |
---|
| 85 | if (i != dot) ++i; |
---|
| 86 | s.resize(i); |
---|
| 87 | break; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | s += wmsg(/*°*/344); |
---|
| 91 | return s; |
---|
| 92 | } |
---|
| 93 | |
---|
[d64e7df] | 94 | enum { |
---|
[de8488a6] | 95 | svx_EXPORT = 1200, |
---|
[583c17d] | 96 | svx_FORMAT, |
---|
[d64e7df] | 97 | svx_SCALE, |
---|
| 98 | svx_BEARING, |
---|
| 99 | svx_TILT, |
---|
| 100 | svx_LEGS, |
---|
| 101 | svx_STATIONS, |
---|
| 102 | svx_NAMES, |
---|
[e90a41e] | 103 | svx_XSECT, |
---|
| 104 | svx_WALLS, |
---|
| 105 | svx_PASSAGES, |
---|
[d64e7df] | 106 | svx_BORDERS, |
---|
| 107 | svx_BLANKS, |
---|
[08e858b] | 108 | svx_LEGEND, |
---|
[d180604] | 109 | svx_SURFACE, |
---|
[d64e7df] | 110 | svx_PLAN, |
---|
[583c17d] | 111 | svx_ELEV, |
---|
[7b55ac2] | 112 | svx_ENTS, |
---|
| 113 | svx_FIXES, |
---|
| 114 | svx_EXPORTS, |
---|
[6d3938b] | 115 | svx_PROJ_LABEL, |
---|
[7b55ac2] | 116 | svx_PROJ, |
---|
| 117 | svx_GRID, |
---|
| 118 | svx_TEXT_HEIGHT, |
---|
[bc1fac5] | 119 | svx_MARKER_SIZE, |
---|
| 120 | svx_CENTRED, |
---|
| 121 | svx_FULLCOORDS |
---|
[d64e7df] | 122 | }; |
---|
| 123 | |
---|
[256c4c8] | 124 | class BitValidator : public wxValidator { |
---|
| 125 | // Disallow assignment. |
---|
| 126 | BitValidator & operator=(const BitValidator&); |
---|
| 127 | |
---|
| 128 | protected: |
---|
| 129 | int * val; |
---|
| 130 | |
---|
| 131 | int mask; |
---|
| 132 | |
---|
| 133 | public: |
---|
| 134 | BitValidator(int * val_, int mask_) |
---|
| 135 | : val(val_), mask(mask_) { } |
---|
| 136 | |
---|
[38500b0] | 137 | BitValidator(const BitValidator &o) : wxValidator() { |
---|
| 138 | Copy(o); |
---|
| 139 | } |
---|
| 140 | |
---|
[256c4c8] | 141 | ~BitValidator() { } |
---|
| 142 | |
---|
[1298787] | 143 | wxObject *Clone() const { return new BitValidator(val, mask); } |
---|
[256c4c8] | 144 | |
---|
[38500b0] | 145 | bool Copy(const BitValidator& o) { |
---|
| 146 | wxValidator::Copy(o); |
---|
| 147 | val = o.val; |
---|
| 148 | mask = o.mask; |
---|
| 149 | return true; |
---|
| 150 | } |
---|
| 151 | |
---|
[256c4c8] | 152 | bool Validate(wxWindow *) { return true; } |
---|
| 153 | |
---|
| 154 | bool TransferToWindow() { |
---|
| 155 | if (!m_validatorWindow->IsKindOf(CLASSINFO(wxCheckBox))) |
---|
| 156 | return false; |
---|
| 157 | ((wxCheckBox*)m_validatorWindow)->SetValue(*val & mask); |
---|
| 158 | return true; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | bool TransferFromWindow() { |
---|
| 162 | if (!m_validatorWindow->IsKindOf(CLASSINFO(wxCheckBox))) |
---|
| 163 | return false; |
---|
| 164 | if (((wxCheckBox*)m_validatorWindow)->IsChecked()) |
---|
| 165 | *val |= mask; |
---|
| 166 | else |
---|
| 167 | *val &= ~mask; |
---|
| 168 | return true; |
---|
| 169 | } |
---|
| 170 | }; |
---|
| 171 | |
---|
[79c239e] | 172 | class svxPrintout : public wxPrintout { |
---|
[ce403f1] | 173 | MainFrm *mainfrm; |
---|
[79c239e] | 174 | layout *m_layout; |
---|
[5a36f76] | 175 | wxPageSetupDialogData* m_data; |
---|
[79c239e] | 176 | wxDC* pdc; |
---|
[3d3a91c] | 177 | // Currently unused, but "skip blank pages" would use it. |
---|
[79c239e] | 178 | static const int cur_pass = 0; |
---|
| 179 | |
---|
| 180 | wxPen *pen_frame, *pen_cross, *pen_surface_leg, *pen_leg; |
---|
| 181 | wxColour colour_text, colour_labels, colour_frame, colour_leg; |
---|
| 182 | wxColour colour_cross,colour_surface_leg; |
---|
| 183 | |
---|
| 184 | long x_t, y_t; |
---|
| 185 | double font_scaling_x, font_scaling_y; |
---|
| 186 | wxFont * current_font; |
---|
| 187 | |
---|
| 188 | int check_intersection(long x_p, long y_p); |
---|
| 189 | void draw_info_box(); |
---|
| 190 | void draw_scale_bar(double x, double y, double MaxLength); |
---|
| 191 | int next_page(int *pstate, char **q, int pageLim); |
---|
| 192 | void drawticks(border clip, int tsize, int x, int y); |
---|
| 193 | |
---|
| 194 | void MOVEMM(double X, double Y) { |
---|
| 195 | MoveTo((long)(X * m_layout->scX), (long)(Y * m_layout->scY)); |
---|
| 196 | } |
---|
| 197 | void DRAWMM(double X, double Y) { |
---|
| 198 | DrawTo((long)(X * m_layout->scX), (long)(Y * m_layout->scY)); |
---|
| 199 | } |
---|
| 200 | void MoveTo(long x, long y); |
---|
| 201 | void DrawTo(long x, long y); |
---|
| 202 | void DrawCross(long x, long y); |
---|
| 203 | void SetFont(int fontcode); |
---|
| 204 | void SetColour(int colourcode); |
---|
[5627cbb] | 205 | void WriteString(const wxString & s); |
---|
[79c239e] | 206 | void DrawEllipse(long x, long y, long r, long R); |
---|
| 207 | void SolidRectangle(long x, long y, long w, long h); |
---|
| 208 | int Pre(); |
---|
| 209 | void NewPage(int pg, int pagesX, int pagesY); |
---|
[ee05463] | 210 | void PlotLR(const vector<XSect> & centreline); |
---|
| 211 | void PlotUD(const vector<XSect> & centreline); |
---|
[79c239e] | 212 | char * Init(FILE **fh_list, bool fCalibrate); |
---|
| 213 | public: |
---|
[5a36f76] | 214 | svxPrintout(MainFrm *mainfrm, layout *l, wxPageSetupDialogData *data, const wxString & title); |
---|
[79c239e] | 215 | bool OnPrintPage(int pageNum); |
---|
[13da582] | 216 | void GetPageInfo(int *minPage, int *maxPage, |
---|
| 217 | int *pageFrom, int *pageTo); |
---|
| 218 | bool HasPage(int pageNum); |
---|
[79c239e] | 219 | void OnBeginPrinting(); |
---|
| 220 | void OnEndPrinting(); |
---|
| 221 | }; |
---|
| 222 | |
---|
| 223 | BEGIN_EVENT_TABLE(svxPrintDlg, wxDialog) |
---|
[583c17d] | 224 | EVT_CHOICE(svx_FORMAT, svxPrintDlg::OnChange) |
---|
[79c239e] | 225 | EVT_TEXT(svx_SCALE, svxPrintDlg::OnChange) |
---|
| 226 | EVT_COMBOBOX(svx_SCALE, svxPrintDlg::OnChange) |
---|
| 227 | EVT_SPINCTRL(svx_BEARING, svxPrintDlg::OnChangeSpin) |
---|
| 228 | EVT_SPINCTRL(svx_TILT, svxPrintDlg::OnChangeSpin) |
---|
[de8488a6] | 229 | EVT_BUTTON(wxID_PRINT, svxPrintDlg::OnPrint) |
---|
[5940815] | 230 | EVT_BUTTON(svx_EXPORT, svxPrintDlg::OnExport) |
---|
[4ed8154] | 231 | EVT_BUTTON(wxID_CANCEL, svxPrintDlg::OnCancel) |
---|
[cca2ce1] | 232 | #ifdef AVEN_PRINT_PREVIEW |
---|
[de8488a6] | 233 | EVT_BUTTON(wxID_PREVIEW, svxPrintDlg::OnPreview) |
---|
[cca2ce1] | 234 | #endif |
---|
[79c239e] | 235 | EVT_BUTTON(svx_PLAN, svxPrintDlg::OnPlan) |
---|
| 236 | EVT_BUTTON(svx_ELEV, svxPrintDlg::OnElevation) |
---|
[102ba1d] | 237 | EVT_UPDATE_UI(svx_PLAN, svxPrintDlg::OnPlanUpdate) |
---|
| 238 | EVT_UPDATE_UI(svx_ELEV, svxPrintDlg::OnElevationUpdate) |
---|
[6b2113d] | 239 | EVT_CHECKBOX(svx_LEGS, svxPrintDlg::OnChange) |
---|
| 240 | EVT_CHECKBOX(svx_STATIONS, svxPrintDlg::OnChange) |
---|
| 241 | EVT_CHECKBOX(svx_NAMES, svxPrintDlg::OnChange) |
---|
| 242 | EVT_CHECKBOX(svx_SURFACE, svxPrintDlg::OnChange) |
---|
[7b55ac2] | 243 | EVT_CHECKBOX(svx_ENTS, svxPrintDlg::OnChange) |
---|
| 244 | EVT_CHECKBOX(svx_FIXES, svxPrintDlg::OnChange) |
---|
| 245 | EVT_CHECKBOX(svx_EXPORTS, svxPrintDlg::OnChange) |
---|
[79c239e] | 246 | END_EVENT_TABLE() |
---|
| 247 | |
---|
[4c46260] | 248 | static wxString scales[] = { |
---|
[5627cbb] | 249 | wxT(""), |
---|
| 250 | wxT("25"), |
---|
| 251 | wxT("50"), |
---|
| 252 | wxT("100"), |
---|
| 253 | wxT("250"), |
---|
| 254 | wxT("500"), |
---|
| 255 | wxT("1000"), |
---|
| 256 | wxT("2500"), |
---|
| 257 | wxT("5000"), |
---|
| 258 | wxT("10000"), |
---|
| 259 | wxT("25000"), |
---|
| 260 | wxT("50000"), |
---|
| 261 | wxT("100000") |
---|
[79c239e] | 262 | }; |
---|
| 263 | |
---|
[583c17d] | 264 | static wxString formats[] = { |
---|
| 265 | wxT("DXF"), |
---|
| 266 | wxT("EPS"), |
---|
| 267 | wxT("GPX"), |
---|
| 268 | wxT("HPGL"), |
---|
[1fe107a] | 269 | wxT("JSON"), |
---|
[1534ed9] | 270 | wxT("KML"), |
---|
[583c17d] | 271 | wxT("Plot"), |
---|
[9fc1cac] | 272 | wxT("Skencil"), |
---|
[583c17d] | 273 | wxT("SVG") |
---|
| 274 | }; |
---|
| 275 | |
---|
[9b5a5fd] | 276 | #if 0 |
---|
| 277 | static wxString projs[] = { |
---|
| 278 | /* CUCC Austria: */ |
---|
| 279 | 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"), |
---|
| 280 | /* British grid SD (Yorkshire): */ |
---|
| 281 | 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"), |
---|
| 282 | /* British full grid reference: */ |
---|
| 283 | 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") |
---|
| 284 | }; |
---|
| 285 | #endif |
---|
| 286 | |
---|
[583c17d] | 287 | static unsigned format_info[] = { |
---|
[bc1fac5] | 288 | LABELS|LEGS|SURF|STNS|PASG|XSECT|WALLS|MARKER_SIZE|TEXT_HEIGHT|GRID|FULL_COORDS, |
---|
[583c17d] | 289 | LABELS|LEGS|SURF|STNS, |
---|
[6d3938b] | 290 | LABELS|LEGS|SURF|ENTS|FIXES|EXPORTS|PROJ|EXPORT_3D, |
---|
[bc1fac5] | 291 | LABELS|LEGS|SURF|STNS|CENTRED, |
---|
[1fe107a] | 292 | LEGS|CENTRED|EXPORT_3D, |
---|
[1534ed9] | 293 | LABELS|ENTS|FIXES|EXPORTS|PROJ|EXPORT_3D, |
---|
[583c17d] | 294 | LABELS|LEGS|SURF, |
---|
[7b55ac2] | 295 | LABELS|LEGS|SURF|STNS|MARKER_SIZE|GRID|SCALE, |
---|
| 296 | LABELS|LEGS|SURF|STNS|PASG|XSECT|WALLS|MARKER_SIZE|TEXT_HEIGHT|SCALE |
---|
[583c17d] | 297 | }; |
---|
| 298 | |
---|
| 299 | static const char * extension[] = { |
---|
| 300 | ".dxf", |
---|
| 301 | ".eps", |
---|
| 302 | ".gpx", |
---|
| 303 | ".hpgl", |
---|
[1fe107a] | 304 | ".json", |
---|
[1534ed9] | 305 | ".kml", |
---|
[583c17d] | 306 | ".plt", |
---|
| 307 | ".sk", |
---|
| 308 | ".svg" |
---|
| 309 | }; |
---|
| 310 | |
---|
| 311 | static int msg_filetype[] = { |
---|
| 312 | /*DXF files*/411, |
---|
| 313 | /*EPS files*/412, |
---|
| 314 | /*GPX files*/413, |
---|
[0b8c321] | 315 | /* TRANSLATORS: Here "plotter" refers to a machine which draws a printout |
---|
| 316 | * on a (usually large) sheet of paper using a pen mounted in a motorised |
---|
| 317 | * mechanism. */ |
---|
[583c17d] | 318 | /*HPGL for plotters*/414, |
---|
[1fe107a] | 319 | /*JSON files*/445, |
---|
[1534ed9] | 320 | /*KML files*/444, |
---|
[0b8c321] | 321 | /* TRANSLATORS: "Compass" and "Carto" are the names of software packages, |
---|
| 322 | * so should not be translated: |
---|
| 323 | * http://www.fountainware.com/compass/ |
---|
| 324 | * http://www.psc-cavers.org/carto/ */ |
---|
[583c17d] | 325 | /*Compass PLT for use with Carto*/415, |
---|
[0b8c321] | 326 | /* TRANSLATORS: "Skencil" is the name of a software package, so should not be |
---|
| 327 | * translated: http://www.skencil.org/ */ |
---|
[9fc1cac] | 328 | /*Skencil files*/416, |
---|
[583c17d] | 329 | /*SVG files*/417 |
---|
| 330 | }; |
---|
| 331 | |
---|
[79c239e] | 332 | // there are three jobs to do here... |
---|
| 333 | // User <-> wx - this should possibly be done in a separate file |
---|
[ce403f1] | 334 | svxPrintDlg::svxPrintDlg(MainFrm* mainfrm_, const wxString & filename, |
---|
[6d3938b] | 335 | const wxString & title, const wxString & cs_proj, |
---|
[f10cf8f] | 336 | const wxString & datestamp, time_t datestamp_numeric, |
---|
[79c239e] | 337 | double angle, double tilt_angle, |
---|
[5940815] | 338 | bool labels, bool crosses, bool legs, bool surf, |
---|
[fdea415] | 339 | bool tubes, bool ents, bool fixes, bool exports, |
---|
[4ed8154] | 340 | bool printing, bool close_after_) |
---|
[736f7df] | 341 | : wxDialog(mainfrm_, -1, wxString(printing ? |
---|
| 342 | /* TRANSLATORS: Title of the print |
---|
| 343 | * dialog */ |
---|
| 344 | wmsg(/*Print*/399) : |
---|
| 345 | /* TRANSLATORS: Title of the export |
---|
| 346 | * dialog */ |
---|
| 347 | wmsg(/*Export*/383))), |
---|
[ea69247] | 348 | m_layout(printing ? wxGetApp().GetPageSetupDialogData() : NULL), |
---|
[4ed8154] | 349 | m_File(filename), mainfrm(mainfrm_), close_after(close_after_) |
---|
[79c239e] | 350 | { |
---|
[5940815] | 351 | m_scale = NULL; |
---|
| 352 | m_printSize = NULL; |
---|
| 353 | m_bearing = NULL; |
---|
| 354 | m_tilt = NULL; |
---|
[583c17d] | 355 | m_format = NULL; |
---|
[d713e5d] | 356 | int show_mask = 0; |
---|
| 357 | if (labels) |
---|
| 358 | show_mask |= LABELS; |
---|
| 359 | if (crosses) |
---|
| 360 | show_mask |= STNS; |
---|
| 361 | if (legs) |
---|
| 362 | show_mask |= LEGS; |
---|
| 363 | if (surf) |
---|
| 364 | show_mask |= SURF; |
---|
[fdea415] | 365 | if (tubes) |
---|
[5624403] | 366 | show_mask |= XSECT|WALLS|PASG; |
---|
[fdea415] | 367 | if (ents) |
---|
| 368 | show_mask |= ENTS; |
---|
| 369 | if (fixes) |
---|
| 370 | show_mask |= FIXES; |
---|
| 371 | if (exports) |
---|
| 372 | show_mask |= EXPORTS; |
---|
[d713e5d] | 373 | m_layout.show_mask = show_mask; |
---|
[5627cbb] | 374 | m_layout.datestamp = datestamp; |
---|
[f10cf8f] | 375 | m_layout.datestamp_numeric = datestamp_numeric; |
---|
[4a66219] | 376 | m_layout.rot = angle; |
---|
[5627cbb] | 377 | m_layout.title = title; |
---|
[6d3938b] | 378 | m_layout.cs_proj = cs_proj; |
---|
[eef68f9] | 379 | if (mainfrm->IsExtendedElevation()) { |
---|
[79c239e] | 380 | m_layout.view = layout::EXTELEV; |
---|
[4a66219] | 381 | if (m_layout.rot != 0.0 && m_layout.rot != 180.0) m_layout.rot = 0; |
---|
[79c239e] | 382 | m_layout.tilt = 0; |
---|
| 383 | } else { |
---|
[4a66219] | 384 | m_layout.tilt = tilt_angle; |
---|
| 385 | if (m_layout.tilt == -90.0) { |
---|
[79c239e] | 386 | m_layout.view = layout::PLAN; |
---|
[4a66219] | 387 | } else if (m_layout.tilt == 0.0) { |
---|
[79c239e] | 388 | m_layout.view = layout::ELEV; |
---|
| 389 | } else { |
---|
| 390 | m_layout.view = layout::TILT; |
---|
| 391 | } |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | /* setup our print dialog*/ |
---|
| 395 | wxBoxSizer* v1 = new wxBoxSizer(wxVERTICAL); |
---|
| 396 | wxBoxSizer* h1 = new wxBoxSizer(wxHORIZONTAL); // holds controls |
---|
[736f7df] | 397 | /* TRANSLATORS: Used as a label for the surrounding box for the "Bearing" |
---|
| 398 | * and "Tilt angle" fields, and the "Plan view" and "Elevation" buttons in |
---|
| 399 | * the "what to print/export" dialog. */ |
---|
[7b55ac2] | 400 | m_viewbox = new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*View*/283)), wxVERTICAL); |
---|
[736f7df] | 401 | /* TRANSLATORS: Used as a label for the surrounding box for the "survey |
---|
| 402 | * legs" "stations" "names" etc checkboxes in the "what to print" dialog. |
---|
| 403 | * "Elements" isn’t a good name for this but nothing better has yet come to |
---|
| 404 | * mind! */ |
---|
[5627cbb] | 405 | wxBoxSizer* v3 = new wxStaticBoxSizer(new wxStaticBox(this, -1, wmsg(/*Elements*/256)), wxVERTICAL); |
---|
[9b5a5fd] | 406 | wxBoxSizer* h2 = new wxBoxSizer(wxHORIZONTAL); |
---|
| 407 | wxBoxSizer* h3 = new wxBoxSizer(wxHORIZONTAL); // holds buttons |
---|
[79c239e] | 408 | |
---|
[583c17d] | 409 | if (!printing) { |
---|
| 410 | wxStaticText* label; |
---|
| 411 | label = new wxStaticText(this, -1, wxString(wmsg(/*Export format*/410))); |
---|
[9feb252] | 412 | const size_t n_formats = sizeof(formats) / sizeof(formats[0]); |
---|
| 413 | m_format = new wxChoice(this, svx_FORMAT, |
---|
| 414 | wxDefaultPosition, wxDefaultSize, |
---|
| 415 | n_formats, formats); |
---|
[a322a09] | 416 | unsigned current_format = 0; |
---|
[3972b26] | 417 | wxConfigBase * cfg = wxConfigBase::Get(); |
---|
| 418 | wxString s; |
---|
| 419 | if (cfg->Read(wxT("export_format"), &s, wxString())) { |
---|
[9feb252] | 420 | for (unsigned i = 0; i != n_formats; ++i) { |
---|
[3972b26] | 421 | if (s == formats[i]) { |
---|
[a322a09] | 422 | current_format = i; |
---|
[3972b26] | 423 | break; |
---|
| 424 | } |
---|
| 425 | } |
---|
| 426 | } |
---|
[a322a09] | 427 | m_format->SetSelection(current_format); |
---|
[583c17d] | 428 | wxBoxSizer* formatbox = new wxBoxSizer(wxHORIZONTAL); |
---|
| 429 | formatbox->Add(label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
---|
| 430 | formatbox->Add(m_format, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
---|
| 431 | |
---|
| 432 | v1->Add(formatbox, 0, wxALIGN_LEFT|wxALL, 0); |
---|
| 433 | } |
---|
[5940815] | 434 | |
---|
[7b55ac2] | 435 | wxStaticText* label; |
---|
| 436 | label = new wxStaticText(this, -1, wxString(wmsg(/*Scale*/154)) + wxT(" 1:")); |
---|
| 437 | if (scales[0].empty()) { |
---|
| 438 | if (printing) { |
---|
[736f7df] | 439 | /* TRANSLATORS: used in the scale drop down selector in the print |
---|
| 440 | * dialog the implicit meaning is "choose a suitable scale to fit |
---|
| 441 | * the plot on a single page", but we need something shorter */ |
---|
[7b55ac2] | 442 | scales[0].assign(wmsg(/*One page*/258)); |
---|
| 443 | } else { |
---|
| 444 | scales[0].assign(wxT("1000")); |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | m_scale = new wxComboBox(this, svx_SCALE, scales[0], wxDefaultPosition, |
---|
| 448 | wxDefaultSize, sizeof(scales) / sizeof(scales[0]), |
---|
| 449 | scales); |
---|
| 450 | m_scalebox = new wxBoxSizer(wxHORIZONTAL); |
---|
| 451 | m_scalebox->Add(label, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
---|
| 452 | m_scalebox->Add(m_scale, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); |
---|
| 453 | |
---|
| 454 | m_viewbox->Add(m_scalebox, 0, wxALIGN_LEFT|wxALL, 0); |
---|
[5940815] | 455 | |
---|
[7b55ac2] | 456 | if (printing) { |
---|
[5940815] | 457 | // Make the dummy string wider than any sane value and use that to |
---|
| 458 | // fix the width of the control so the sizers allow space for bigger |
---|
| 459 | // page layouts. |
---|
[5627cbb] | 460 | m_printSize = new wxStaticText(this, -1, wxString::Format(wmsg(/*%d pages (%dx%d)*/257), 9604, 98, 98)); |
---|
[7b55ac2] | 461 | m_viewbox->Add(m_printSize, 0, wxALIGN_LEFT|wxALL, 5); |
---|
[79c239e] | 462 | } |
---|
| 463 | |
---|
[bc1fac5] | 464 | /* FIXME: |
---|
[9b5a5fd] | 465 | * svx_GRID, // double - spacing, default: 100m |
---|
| 466 | * svx_TEXT_HEIGHT, // default 0.6 |
---|
| 467 | * svx_MARKER_SIZE // default 0.8 |
---|
| 468 | */ |
---|
[7b55ac2] | 469 | |
---|
[79c239e] | 470 | if (m_layout.view != layout::EXTELEV) { |
---|
[eef68f9] | 471 | wxFlexGridSizer* anglebox = new wxFlexGridSizer(2); |
---|
| 472 | wxStaticText * brg_label, * tilt_label; |
---|
[5627cbb] | 473 | brg_label = new wxStaticText(this, -1, wmsg(/*Bearing*/259)); |
---|
[eef68f9] | 474 | anglebox->Add(brg_label, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALL, 5); |
---|
[4a66219] | 475 | m_bearing = new wxSpinCtrlDouble(this, svx_BEARING); |
---|
| 476 | m_bearing->SetRange(0.0, 360.0); |
---|
| 477 | m_bearing->SetDigits(ANGLE_DP); |
---|
[eef68f9] | 478 | anglebox->Add(m_bearing, 0, wxALIGN_CENTER|wxALL, 5); |
---|
[736f7df] | 479 | /* TRANSLATORS: Used in the print dialog: */ |
---|
[5627cbb] | 480 | tilt_label = new wxStaticText(this, -1, wmsg(/*Tilt angle*/263)); |
---|
[eef68f9] | 481 | anglebox->Add(tilt_label, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALL, 5); |
---|
[4a66219] | 482 | m_tilt = new wxSpinCtrlDouble(this, svx_TILT); |
---|
| 483 | m_tilt->SetRange(-90.0, 90.0); |
---|
| 484 | m_tilt->SetDigits(ANGLE_DP); |
---|
[eef68f9] | 485 | anglebox->Add(m_tilt, 0, wxALIGN_CENTER|wxALL, 5); |
---|
| 486 | |
---|
[7b55ac2] | 487 | m_viewbox->Add(anglebox, 0, wxALIGN_LEFT|wxALL, 0); |
---|
[eef68f9] | 488 | |
---|
[79c239e] | 489 | wxBoxSizer * planelevsizer = new wxBoxSizer(wxHORIZONTAL); |
---|
[8a78ca1] | 490 | planelevsizer->Add(new wxButton(this, svx_PLAN, wmsg(/*P&lan view*/117)), |
---|
[79c239e] | 491 | 0, wxALIGN_CENTRE_VERTICAL|wxALL, 5); |
---|
[8a78ca1] | 492 | planelevsizer->Add(new wxButton(this, svx_ELEV, wmsg(/*&Elevation*/285)), |
---|
[79c239e] | 493 | 0, wxALIGN_CENTRE_VERTICAL|wxALL, 5); |
---|
| 494 | |
---|
[7b55ac2] | 495 | m_viewbox->Add(planelevsizer, 0, wxALIGN_LEFT|wxALL, 5); |
---|
[79c239e] | 496 | } |
---|
| 497 | |
---|
[736f7df] | 498 | /* TRANSLATORS: Here a "survey leg" is a set of measurements between two |
---|
| 499 | * "survey stations". */ |
---|
[256c4c8] | 500 | v3->Add(new wxCheckBox(this, svx_LEGS, wmsg(/*Underground Survey Legs*/262), |
---|
| 501 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 502 | BitValidator(&m_layout.show_mask, LEGS)), |
---|
| 503 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
[736f7df] | 504 | /* TRANSLATORS: Here a "survey leg" is a set of measurements between two |
---|
| 505 | * "survey stations". */ |
---|
[256c4c8] | 506 | v3->Add(new wxCheckBox(this, svx_SURFACE, wmsg(/*Sur&face Survey Legs*/403), |
---|
| 507 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 508 | BitValidator(&m_layout.show_mask, SURF)), |
---|
| 509 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
| 510 | v3->Add(new wxCheckBox(this, svx_STATIONS, wmsg(/*Crosses*/261), |
---|
| 511 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 512 | BitValidator(&m_layout.show_mask, STNS)), |
---|
| 513 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
| 514 | v3->Add(new wxCheckBox(this, svx_NAMES, wmsg(/*Station Names*/260), |
---|
| 515 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 516 | BitValidator(&m_layout.show_mask, LABELS)), |
---|
| 517 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
[7b55ac2] | 518 | v3->Add(new wxCheckBox(this, svx_ENTS, wmsg(/*Entrances*/418), |
---|
| 519 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 520 | BitValidator(&m_layout.show_mask, ENTS)), |
---|
| 521 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
| 522 | v3->Add(new wxCheckBox(this, svx_FIXES, wmsg(/*Fixed Points*/419), |
---|
| 523 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 524 | BitValidator(&m_layout.show_mask, FIXES)), |
---|
| 525 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
[da6367cd] | 526 | v3->Add(new wxCheckBox(this, svx_EXPORTS, wmsg(/*Exported Stations*/420), |
---|
[7b55ac2] | 527 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 528 | BitValidator(&m_layout.show_mask, EXPORTS)), |
---|
| 529 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
[256c4c8] | 530 | v3->Add(new wxCheckBox(this, svx_XSECT, wmsg(/*Cross-sections*/393), |
---|
| 531 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 532 | BitValidator(&m_layout.show_mask, XSECT)), |
---|
| 533 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
| 534 | if (!printing) { |
---|
| 535 | v3->Add(new wxCheckBox(this, svx_WALLS, wmsg(/*Walls*/394), |
---|
| 536 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 537 | BitValidator(&m_layout.show_mask, WALLS)), |
---|
| 538 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
| 539 | v3->Add(new wxCheckBox(this, svx_PASSAGES, wmsg(/*Passages*/395), |
---|
| 540 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 541 | BitValidator(&m_layout.show_mask, PASG)), |
---|
| 542 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
[bc1fac5] | 543 | v3->Add(new wxCheckBox(this, svx_CENTRED, wmsg(/*Origin in centre*/421), |
---|
| 544 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 545 | BitValidator(&m_layout.show_mask, CENTRED)), |
---|
| 546 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
| 547 | v3->Add(new wxCheckBox(this, svx_FULLCOORDS, wmsg(/*Full coordinates*/422), |
---|
| 548 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 549 | BitValidator(&m_layout.show_mask, FULL_COORDS)), |
---|
| 550 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
[256c4c8] | 551 | } |
---|
[5940815] | 552 | if (printing) { |
---|
[736f7df] | 553 | /* TRANSLATORS: used in the print dialog - controls drawing lines |
---|
| 554 | * around each page */ |
---|
[256c4c8] | 555 | v3->Add(new wxCheckBox(this, svx_BORDERS, wmsg(/*Page Borders*/264), |
---|
| 556 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 557 | wxGenericValidator(&m_layout.Border)), |
---|
| 558 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
[736f7df] | 559 | /* TRANSLATORS: will be used in the print dialog - check this to print |
---|
| 560 | * blank pages (otherwise they’ll be skipped to save paper) */ |
---|
[5627cbb] | 561 | // m_blanks = new wxCheckBox(this, svx_BLANKS, wmsg(/*Blank Pages*/266)); |
---|
[5940815] | 562 | // v3->Add(m_blanks, 0, wxALIGN_LEFT|wxALL, 2); |
---|
[736f7df] | 563 | /* TRANSLATORS: As in the legend on a map. Used in the print dialog - |
---|
| 564 | * controls drawing the box at the lower left with survey name, view |
---|
| 565 | * angles, etc */ |
---|
[08e858b] | 566 | v3->Add(new wxCheckBox(this, svx_LEGEND, wmsg(/*Legend*/265), |
---|
[256c4c8] | 567 | wxDefaultPosition, wxDefaultSize, 0, |
---|
| 568 | wxGenericValidator(&m_layout.Legend)), |
---|
| 569 | 0, wxALIGN_LEFT|wxALL, 2); |
---|
[5940815] | 570 | } |
---|
[ee05463] | 571 | |
---|
[79c239e] | 572 | h1->Add(v3, 0, wxALIGN_LEFT|wxALL, 5); |
---|
[6d3938b] | 573 | h1->Add(m_viewbox, 0, wxALIGN_LEFT|wxLEFT, 5); |
---|
[79c239e] | 574 | |
---|
[736f7df] | 575 | /* TRANSLATORS: The PROJ library is used to do coordinate transformations |
---|
[6d3938b] | 576 | * (https://trac.osgeo.org/proj/) - if the .3d file doesn't contain details |
---|
| 577 | * of the coordinate projection in use, the user must specify it here for |
---|
| 578 | * export formats which need to know it (e.g. GPX). |
---|
[736f7df] | 579 | */ |
---|
[6d3938b] | 580 | h2->Add(new wxStaticText(this, svx_PROJ_LABEL, wmsg(/*Coordinate projection*/440)), |
---|
| 581 | 0, wxLEFT|wxALIGN_CENTRE_VERTICAL, 5); |
---|
| 582 | long style = 0; |
---|
| 583 | if (!m_layout.cs_proj.empty()) { |
---|
| 584 | // If the input file specified the coordinate system, don't let the |
---|
| 585 | // user mess with it. |
---|
| 586 | style = wxTE_READONLY; |
---|
| 587 | } else { |
---|
| 588 | #if 0 // FIXME: Is it a good idea to save this? |
---|
| 589 | wxConfigBase * cfg = wxConfigBase::Get(); |
---|
| 590 | wxString input_projection; |
---|
| 591 | cfg->Read(wxT("input_projection"), &input_projection); |
---|
| 592 | if (!input_projection.empty()) |
---|
| 593 | proj_edit.SetValue(input_projection); |
---|
[9b5a5fd] | 594 | #endif |
---|
[6d3938b] | 595 | } |
---|
| 596 | wxTextCtrl * proj_edit = new wxTextCtrl(this, svx_PROJ, m_layout.cs_proj, |
---|
| 597 | wxDefaultPosition, wxDefaultSize, |
---|
| 598 | style); |
---|
| 599 | h2->Add(proj_edit, 1, wxALL|wxEXPAND|wxALIGN_CENTRE_VERTICAL, 5); |
---|
| 600 | v1->Add(h2, 0, wxALIGN_LEFT|wxEXPAND, 5); |
---|
| 601 | |
---|
| 602 | v1->Add(h1, 0, wxALIGN_LEFT|wxALL, 5); |
---|
[9b5a5fd] | 603 | |
---|
[583c17d] | 604 | // When we enable/disable checkboxes in the export dialog, ideally we'd |
---|
| 605 | // like the dialog to resize, but not sure how to achieve that, so we |
---|
| 606 | // add a stretchable spacer here so at least the buttons stay in the |
---|
| 607 | // lower right corner. |
---|
| 608 | v1->AddStretchSpacer(); |
---|
| 609 | |
---|
[79c239e] | 610 | wxButton * but; |
---|
[73b3388] | 611 | but = new wxButton(this, wxID_CANCEL); |
---|
[9b5a5fd] | 612 | h3->Add(but, 0, wxALIGN_RIGHT|wxALL, 5); |
---|
[5940815] | 613 | if (printing) { |
---|
[cca2ce1] | 614 | #ifdef AVEN_PRINT_PREVIEW |
---|
[de8488a6] | 615 | but = new wxButton(this, wxID_PREVIEW); |
---|
[9b5a5fd] | 616 | h3->Add(but, 0, wxALIGN_RIGHT|wxALL, 5); |
---|
[de8488a6] | 617 | but = new wxButton(this, wxID_PRINT); |
---|
[b72f4b5] | 618 | #else |
---|
[ee7511a] | 619 | but = new wxButton(this, wxID_PRINT, wmsg(/*&Print…*/400)); |
---|
[b72f4b5] | 620 | #endif |
---|
[5940815] | 621 | } else { |
---|
[736f7df] | 622 | /* TRANSLATORS: The text on the action button in the "Export" settings |
---|
| 623 | * dialog */ |
---|
[ee7511a] | 624 | but = new wxButton(this, svx_EXPORT, wmsg(/*&Export…*/230)); |
---|
[5940815] | 625 | } |
---|
[79c239e] | 626 | but->SetDefault(); |
---|
[9b5a5fd] | 627 | h3->Add(but, 0, wxALIGN_RIGHT|wxALL, 5); |
---|
| 628 | v1->Add(h3, 0, wxALIGN_RIGHT|wxALL, 5); |
---|
[ee05463] | 629 | |
---|
[79c239e] | 630 | SetAutoLayout(true); |
---|
| 631 | SetSizer(v1); |
---|
| 632 | v1->SetSizeHints(this); |
---|
| 633 | |
---|
| 634 | LayoutToUI(); |
---|
[583c17d] | 635 | SomethingChanged(0); |
---|
[79c239e] | 636 | } |
---|
| 637 | |
---|
[ee05463] | 638 | void |
---|
[79c239e] | 639 | svxPrintDlg::OnPrint(wxCommandEvent&) { |
---|
[583c17d] | 640 | SomethingChanged(0); |
---|
[0056ee1] | 641 | TransferDataFromWindow(); |
---|
[e0ffc2c] | 642 | wxPageSetupDialogData * psdd = wxGetApp().GetPageSetupDialogData(); |
---|
| 643 | wxPrintDialogData pd(psdd->GetPrintData()); |
---|
[79c239e] | 644 | wxPrinter pr(&pd); |
---|
[e0ffc2c] | 645 | svxPrintout po(mainfrm, &m_layout, psdd, m_File); |
---|
[79c239e] | 646 | if (pr.Print(this, &po, true)) { |
---|
| 647 | // Close the print dialog if printing succeeded. |
---|
| 648 | Destroy(); |
---|
| 649 | } |
---|
| 650 | } |
---|
| 651 | |
---|
[5940815] | 652 | void |
---|
| 653 | svxPrintDlg::OnExport(wxCommandEvent&) { |
---|
| 654 | UIToLayout(); |
---|
[54b7650] | 655 | TransferDataFromWindow(); |
---|
[583c17d] | 656 | wxString leaf; |
---|
| 657 | wxFileName::SplitPath(m_File, NULL, NULL, &leaf, NULL, wxPATH_NATIVE); |
---|
| 658 | unsigned format_idx = ((wxChoice*)FindWindow(svx_FORMAT))->GetSelection(); |
---|
| 659 | leaf += wxString::FromUTF8(extension[format_idx]); |
---|
| 660 | |
---|
| 661 | wxString filespec = wmsg(msg_filetype[format_idx]); |
---|
| 662 | filespec += wxT("|*"); |
---|
| 663 | filespec += wxString::FromUTF8(extension[format_idx]); |
---|
| 664 | filespec += wxT("|"); |
---|
| 665 | filespec += wmsg(/*All files*/208); |
---|
| 666 | filespec += wxT("|"); |
---|
| 667 | filespec += wxFileSelectorDefaultWildcardStr; |
---|
| 668 | |
---|
[736f7df] | 669 | /* TRANSLATORS: Title of file dialog to choose name and type of exported |
---|
| 670 | * file. */ |
---|
[583c17d] | 671 | wxFileDialog dlg(this, wmsg(/*Export as:*/401), wxString(), leaf, |
---|
| 672 | filespec, wxFD_SAVE|wxFD_OVERWRITE_PROMPT); |
---|
[5940815] | 673 | if (dlg.ShowModal() == wxID_OK) { |
---|
[6d3938b] | 674 | wxString input_projection = ((wxTextCtrl*)FindWindow(svx_PROJ))->GetValue(); |
---|
[7b55ac2] | 675 | double grid = 100; // metres |
---|
| 676 | double text_height = 0.6; |
---|
| 677 | double marker_size = 0.8; |
---|
| 678 | |
---|
[6d3938b] | 679 | try { |
---|
| 680 | if (!Export(dlg.GetPath(), m_layout.title, |
---|
| 681 | m_layout.datestamp, m_layout.datestamp_numeric, mainfrm, |
---|
| 682 | m_layout.rot, m_layout.tilt, m_layout.show_mask, |
---|
| 683 | export_format(format_idx), input_projection.mb_str(), |
---|
[18ff765] | 684 | grid, text_height, marker_size, m_layout.Scale)) { |
---|
[6d3938b] | 685 | wxString m = wxString::Format(wmsg(/*Couldn’t write file “%s”*/402).c_str(), |
---|
| 686 | m_File.c_str()); |
---|
| 687 | wxGetApp().ReportError(m); |
---|
| 688 | } |
---|
| 689 | } catch (const wxString & m) { |
---|
[6e63fd3] | 690 | wxGetApp().ReportError(m); |
---|
[5940815] | 691 | } |
---|
| 692 | } |
---|
| 693 | Destroy(); |
---|
| 694 | } |
---|
| 695 | |
---|
[cca2ce1] | 696 | #ifdef AVEN_PRINT_PREVIEW |
---|
[ee05463] | 697 | void |
---|
[79c239e] | 698 | svxPrintDlg::OnPreview(wxCommandEvent&) { |
---|
[583c17d] | 699 | SomethingChanged(0); |
---|
[54b7650] | 700 | TransferDataFromWindow(); |
---|
[e0ffc2c] | 701 | wxPageSetupDialogData * psdd = wxGetApp().GetPageSetupDialogData(); |
---|
| 702 | wxPrintDialogData pd(psdd->GetPrintData()); |
---|
[79c239e] | 703 | wxPrintPreview* pv; |
---|
[e0ffc2c] | 704 | pv = new wxPrintPreview(new svxPrintout(mainfrm, &m_layout, psdd, m_File), |
---|
| 705 | new svxPrintout(mainfrm, &m_layout, psdd, m_File), |
---|
[79c239e] | 706 | &pd); |
---|
[736f7df] | 707 | // TRANSLATORS: Title of the print preview dialog |
---|
[5627cbb] | 708 | wxPreviewFrame *frame = new wxPreviewFrame(pv, mainfrm, wmsg(/*Print Preview*/398)); |
---|
[79c239e] | 709 | frame->Initialize(); |
---|
| 710 | |
---|
| 711 | // Size preview frame so that all of the controlbar and canvas can be seen |
---|
| 712 | // if possible. |
---|
| 713 | int w, h; |
---|
| 714 | // GetBestSize gives us the width needed to show the whole controlbar. |
---|
| 715 | frame->GetBestSize(&w, &h); |
---|
| 716 | #ifdef __WXMAC__ |
---|
| 717 | // wxMac opens the preview window at minimum size by default. |
---|
| 718 | // 360x480 is apparently enough to show A4 portrait. |
---|
| 719 | if (h < 480 || w < 360) { |
---|
| 720 | if (h < 480) h = 480; |
---|
| 721 | if (w < 360) w = 360; |
---|
| 722 | } |
---|
| 723 | #else |
---|
| 724 | if (h < w) { |
---|
| 725 | // On wxGTK at least, GetBestSize() returns much too small a height. |
---|
| 726 | h = w * 6 / 5; |
---|
| 727 | } |
---|
| 728 | #endif |
---|
| 729 | // Ensure that we don't make the window bigger than the screen. |
---|
| 730 | // Use wxGetClientDisplayRect() so we don't cover the MS Windows |
---|
| 731 | // task bar either. |
---|
| 732 | wxRect disp = wxGetClientDisplayRect(); |
---|
| 733 | if (w > disp.GetWidth()) w = disp.GetWidth(); |
---|
| 734 | if (h > disp.GetHeight()) h = disp.GetHeight(); |
---|
| 735 | // Centre the window within the "ClientDisplayRect". |
---|
| 736 | int x = disp.GetLeft() + (disp.GetWidth() - w) / 2; |
---|
| 737 | int y = disp.GetTop() + (disp.GetHeight() - h) / 2; |
---|
| 738 | frame->SetSize(x, y, w, h); |
---|
| 739 | |
---|
| 740 | frame->Show(); |
---|
| 741 | } |
---|
[cca2ce1] | 742 | #endif |
---|
[79c239e] | 743 | |
---|
[ee05463] | 744 | void |
---|
[79c239e] | 745 | svxPrintDlg::OnPlan(wxCommandEvent&) { |
---|
[4a66219] | 746 | m_tilt->SetValue(-90.0); |
---|
[583c17d] | 747 | SomethingChanged(svx_TILT); |
---|
[79c239e] | 748 | } |
---|
| 749 | |
---|
[ee05463] | 750 | void |
---|
[79c239e] | 751 | svxPrintDlg::OnElevation(wxCommandEvent&) { |
---|
[4a66219] | 752 | m_tilt->SetValue(0.0); |
---|
[583c17d] | 753 | SomethingChanged(svx_TILT); |
---|
[79c239e] | 754 | } |
---|
| 755 | |
---|
[102ba1d] | 756 | void |
---|
| 757 | svxPrintDlg::OnPlanUpdate(wxUpdateUIEvent& e) { |
---|
[4a66219] | 758 | e.Enable(m_tilt->GetValue() != -90.0); |
---|
[102ba1d] | 759 | } |
---|
| 760 | |
---|
| 761 | void |
---|
| 762 | svxPrintDlg::OnElevationUpdate(wxUpdateUIEvent& e) { |
---|
[4a66219] | 763 | e.Enable(m_tilt->GetValue() != 0.0); |
---|
[102ba1d] | 764 | } |
---|
| 765 | |
---|
[ee05463] | 766 | void |
---|
[583c17d] | 767 | svxPrintDlg::OnChangeSpin(wxSpinEvent& e) { |
---|
| 768 | SomethingChanged(e.GetId()); |
---|
[79c239e] | 769 | } |
---|
| 770 | |
---|
[ee05463] | 771 | void |
---|
[583c17d] | 772 | svxPrintDlg::OnChange(wxCommandEvent& e) { |
---|
| 773 | SomethingChanged(e.GetId()); |
---|
[79c239e] | 774 | } |
---|
| 775 | |
---|
[4ed8154] | 776 | void |
---|
| 777 | svxPrintDlg::OnCancel(wxCommandEvent&) { |
---|
| 778 | if (close_after) |
---|
| 779 | mainfrm->Close(); |
---|
[d4885c3] | 780 | Destroy(); |
---|
[4ed8154] | 781 | } |
---|
| 782 | |
---|
[79c239e] | 783 | void |
---|
[583c17d] | 784 | svxPrintDlg::SomethingChanged(int control_id) { |
---|
[7b55ac2] | 785 | if ((control_id == 0 || control_id == svx_FORMAT) && m_format) { |
---|
[583c17d] | 786 | // Update the shown/hidden fields for the newly selected export filter. |
---|
[a322a09] | 787 | int new_filter_idx = m_format->GetSelection(); |
---|
| 788 | if (new_filter_idx != wxNOT_FOUND) { |
---|
| 789 | unsigned mask = format_info[new_filter_idx]; |
---|
[9feb252] | 790 | static const struct { int id; unsigned mask; } controls[] = { |
---|
| 791 | { svx_LEGS, LEGS }, |
---|
| 792 | { svx_SURFACE, SURF }, |
---|
| 793 | { svx_STATIONS, STNS }, |
---|
| 794 | { svx_NAMES, LABELS }, |
---|
| 795 | { svx_XSECT, XSECT }, |
---|
| 796 | { svx_WALLS, WALLS }, |
---|
| 797 | { svx_PASSAGES, PASG }, |
---|
| 798 | { svx_ENTS, ENTS }, |
---|
| 799 | { svx_FIXES, FIXES }, |
---|
| 800 | { svx_EXPORTS, EXPORTS }, |
---|
| 801 | { svx_CENTRED, CENTRED }, |
---|
| 802 | { svx_FULLCOORDS, FULL_COORDS }, |
---|
[6d3938b] | 803 | { svx_PROJ_LABEL, PROJ }, |
---|
[9feb252] | 804 | { svx_PROJ, PROJ }, |
---|
| 805 | }; |
---|
| 806 | static unsigned n_controls = sizeof(controls) / sizeof(controls[0]); |
---|
| 807 | for (unsigned i = 0; i != n_controls; ++i) { |
---|
| 808 | wxWindow * control = FindWindow(controls[i].id); |
---|
| 809 | if (control) control->Show(mask & controls[i].mask); |
---|
| 810 | } |
---|
[7b55ac2] | 811 | m_scalebox->Show(bool(mask & SCALE)); |
---|
| 812 | m_viewbox->Show(!bool(mask & EXPORT_3D)); |
---|
[a322a09] | 813 | GetSizer()->Layout(); |
---|
| 814 | if (control_id == svx_FORMAT) { |
---|
| 815 | wxConfigBase * cfg = wxConfigBase::Get(); |
---|
| 816 | cfg->Write(wxT("export_format"), formats[new_filter_idx]); |
---|
| 817 | } |
---|
| 818 | } |
---|
[583c17d] | 819 | } |
---|
| 820 | |
---|
[79c239e] | 821 | UIToLayout(); |
---|
[18ff765] | 822 | |
---|
| 823 | if (m_printSize || m_scale) { |
---|
| 824 | // Update the bounding box. |
---|
| 825 | RecalcBounds(); |
---|
| 826 | |
---|
| 827 | if (m_scale) { |
---|
| 828 | (m_scale->GetValue()).ToDouble(&(m_layout.Scale)); |
---|
| 829 | if (m_layout.Scale == 0.0) { |
---|
| 830 | m_layout.pick_scale(1, 1); |
---|
| 831 | } |
---|
[6ca9f08] | 832 | } |
---|
| 833 | } |
---|
| 834 | |
---|
[18ff765] | 835 | if (m_printSize && m_layout.xMax >= m_layout.xMin) { |
---|
[79c239e] | 836 | m_layout.pages_required(); |
---|
[5627cbb] | 837 | m_printSize->SetLabel(wxString::Format(wmsg(/*%d pages (%dx%d)*/257), m_layout.pages, m_layout.pagesX, m_layout.pagesY)); |
---|
[79c239e] | 838 | } |
---|
| 839 | } |
---|
| 840 | |
---|
[ee05463] | 841 | void |
---|
[79c239e] | 842 | svxPrintDlg::LayoutToUI(){ |
---|
| 843 | // m_blanks->SetValue(m_layout.SkipBlank); |
---|
[eef68f9] | 844 | if (m_layout.view != layout::EXTELEV) { |
---|
| 845 | m_tilt->SetValue(m_layout.tilt); |
---|
| 846 | m_bearing->SetValue(m_layout.rot); |
---|
[79c239e] | 847 | } |
---|
| 848 | |
---|
| 849 | // Do this last as it causes an OnChange message which calls UIToLayout |
---|
[5940815] | 850 | if (m_scale) { |
---|
| 851 | if (m_layout.Scale != 0) { |
---|
| 852 | wxString temp; |
---|
| 853 | temp << m_layout.Scale; |
---|
| 854 | m_scale->SetValue(temp); |
---|
| 855 | } else { |
---|
[5627cbb] | 856 | if (scales[0].empty()) scales[0].assign(wmsg(/*One page*/258)); |
---|
[5940815] | 857 | m_scale->SetValue(scales[0]); |
---|
| 858 | } |
---|
[79c239e] | 859 | } |
---|
| 860 | } |
---|
| 861 | |
---|
[ee05463] | 862 | void |
---|
[79c239e] | 863 | svxPrintDlg::UIToLayout(){ |
---|
| 864 | // m_layout.SkipBlank = m_blanks->IsChecked(); |
---|
| 865 | |
---|
[de9aa88] | 866 | if (m_layout.view != layout::EXTELEV && m_tilt) { |
---|
[79c239e] | 867 | m_layout.tilt = m_tilt->GetValue(); |
---|
[4a66219] | 868 | if (m_layout.tilt == -90.0) { |
---|
[79c239e] | 869 | m_layout.view = layout::PLAN; |
---|
[4a66219] | 870 | } else if (m_layout.tilt == 0.0) { |
---|
[79c239e] | 871 | m_layout.view = layout::ELEV; |
---|
| 872 | } else { |
---|
| 873 | m_layout.view = layout::TILT; |
---|
| 874 | } |
---|
[256c4c8] | 875 | |
---|
| 876 | bool enable_passage_opts = (m_layout.view != layout::TILT); |
---|
| 877 | wxWindow * win; |
---|
| 878 | win = FindWindow(svx_XSECT); |
---|
| 879 | if (win) win->Enable(enable_passage_opts); |
---|
| 880 | win = FindWindow(svx_WALLS); |
---|
| 881 | if (win) win->Enable(enable_passage_opts); |
---|
| 882 | win = FindWindow(svx_PASSAGES); |
---|
| 883 | if (win) win->Enable(enable_passage_opts); |
---|
| 884 | |
---|
[79c239e] | 885 | m_layout.rot = m_bearing->GetValue(); |
---|
| 886 | } |
---|
| 887 | } |
---|
| 888 | |
---|
| 889 | void |
---|
| 890 | svxPrintDlg::RecalcBounds() |
---|
| 891 | { |
---|
| 892 | m_layout.yMax = m_layout.xMax = -DBL_MAX; |
---|
| 893 | m_layout.yMin = m_layout.xMin = DBL_MAX; |
---|
| 894 | |
---|
[5940815] | 895 | double SIN = sin(rad(m_layout.rot)); |
---|
| 896 | double COS = cos(rad(m_layout.rot)); |
---|
| 897 | double SINT = sin(rad(m_layout.tilt)); |
---|
| 898 | double COST = cos(rad(m_layout.tilt)); |
---|
[79c239e] | 899 | |
---|
[d713e5d] | 900 | if (m_layout.show_mask & LEGS) { |
---|
[c61aa79] | 901 | list<traverse>::const_iterator trav = mainfrm->traverses_begin(); |
---|
| 902 | list<traverse>::const_iterator tend = mainfrm->traverses_end(); |
---|
[ce403f1] | 903 | for ( ; trav != tend; ++trav) { |
---|
[d4650b3] | 904 | vector<PointInfo>::const_iterator pos = trav->begin(); |
---|
| 905 | vector<PointInfo>::const_iterator end = trav->end(); |
---|
[ce403f1] | 906 | for ( ; pos != end; ++pos) { |
---|
| 907 | double x = pos->GetX(); |
---|
| 908 | double y = pos->GetY(); |
---|
| 909 | double z = pos->GetZ(); |
---|
| 910 | double X = x * COS - y * SIN; |
---|
| 911 | if (X > m_layout.xMax) m_layout.xMax = X; |
---|
| 912 | if (X < m_layout.xMin) m_layout.xMin = X; |
---|
[7a57dc7] | 913 | double Y = z * COST - (x * SIN + y * COS) * SINT; |
---|
[ce403f1] | 914 | if (Y > m_layout.yMax) m_layout.yMax = Y; |
---|
| 915 | if (Y < m_layout.yMin) m_layout.yMin = Y; |
---|
| 916 | } |
---|
| 917 | } |
---|
| 918 | } |
---|
[d713e5d] | 919 | if (m_layout.show_mask & SURF) { |
---|
[c61aa79] | 920 | list<traverse>::const_iterator trav = mainfrm->surface_traverses_begin(); |
---|
| 921 | list<traverse>::const_iterator tend = mainfrm->surface_traverses_end(); |
---|
[ce403f1] | 922 | for ( ; trav != tend; ++trav) { |
---|
[d4650b3] | 923 | vector<PointInfo>::const_iterator pos = trav->begin(); |
---|
| 924 | vector<PointInfo>::const_iterator end = trav->end(); |
---|
[ce403f1] | 925 | for ( ; pos != end; ++pos) { |
---|
| 926 | double x = pos->GetX(); |
---|
| 927 | double y = pos->GetY(); |
---|
| 928 | double z = pos->GetZ(); |
---|
| 929 | double X = x * COS - y * SIN; |
---|
| 930 | if (X > m_layout.xMax) m_layout.xMax = X; |
---|
| 931 | if (X < m_layout.xMin) m_layout.xMin = X; |
---|
[7a57dc7] | 932 | double Y = z * COST - (x * SIN + y * COS) * SINT; |
---|
[ce403f1] | 933 | if (Y > m_layout.yMax) m_layout.yMax = Y; |
---|
| 934 | if (Y < m_layout.yMin) m_layout.yMin = Y; |
---|
[79c239e] | 935 | } |
---|
| 936 | } |
---|
| 937 | } |
---|
[d713e5d] | 938 | if (m_layout.show_mask & (LABELS|STNS)) { |
---|
[ce403f1] | 939 | list<LabelInfo*>::const_iterator label = mainfrm->GetLabels(); |
---|
| 940 | while (label != mainfrm->GetLabelsEnd()) { |
---|
[79c239e] | 941 | double x = (*label)->GetX(); |
---|
| 942 | double y = (*label)->GetY(); |
---|
| 943 | double z = (*label)->GetZ(); |
---|
[d713e5d] | 944 | if ((m_layout.show_mask & SURF) || (*label)->IsUnderground()) { |
---|
[79c239e] | 945 | double X = x * COS - y * SIN; |
---|
| 946 | if (X > m_layout.xMax) m_layout.xMax = X; |
---|
| 947 | if (X < m_layout.xMin) m_layout.xMin = X; |
---|
[7a57dc7] | 948 | double Y = z * COST - (x * SIN + y * COS) * SINT; |
---|
[79c239e] | 949 | if (Y > m_layout.yMax) m_layout.yMax = Y; |
---|
| 950 | if (Y < m_layout.yMin) m_layout.yMin = Y; |
---|
| 951 | } |
---|
| 952 | ++label; |
---|
| 953 | } |
---|
| 954 | } |
---|
| 955 | } |
---|
| 956 | |
---|
| 957 | static int xpPageWidth, ypPageDepth; |
---|
| 958 | static long MarginLeft, MarginRight, MarginTop, MarginBottom; |
---|
| 959 | static long x_offset, y_offset; |
---|
| 960 | static wxFont *font_labels, *font_default; |
---|
| 961 | static int fontsize, fontsize_labels; |
---|
| 962 | |
---|
| 963 | /* FIXME: allow the font to be set */ |
---|
| 964 | |
---|
| 965 | static const char *fontname = "Arial", *fontname_labels = "Arial"; |
---|
| 966 | |
---|
| 967 | // wx <-> prcore (calls to print_page etc...) |
---|
[5627cbb] | 968 | svxPrintout::svxPrintout(MainFrm *mainfrm_, layout *l, |
---|
| 969 | wxPageSetupDialogData *data, const wxString & title) |
---|
[79c239e] | 970 | : wxPrintout(title) |
---|
| 971 | { |
---|
[ce403f1] | 972 | mainfrm = mainfrm_; |
---|
[79c239e] | 973 | m_layout = l; |
---|
| 974 | m_data = data; |
---|
| 975 | } |
---|
| 976 | |
---|
| 977 | void |
---|
| 978 | svxPrintout::draw_info_box() |
---|
| 979 | { |
---|
| 980 | layout *l = m_layout; |
---|
[995cf6a] | 981 | int boxwidth = 70; |
---|
[79c239e] | 982 | int boxheight = 30; |
---|
| 983 | |
---|
| 984 | SetColour(PR_COLOUR_FRAME); |
---|
| 985 | |
---|
[995cf6a] | 986 | int div = boxwidth; |
---|
[79c239e] | 987 | if (l->view != layout::EXTELEV) { |
---|
[995cf6a] | 988 | boxwidth += boxheight; |
---|
| 989 | MOVEMM(div, boxheight); |
---|
| 990 | DRAWMM(div, 0); |
---|
| 991 | MOVEMM(0, 30); DRAWMM(div, 30); |
---|
[79c239e] | 992 | } |
---|
| 993 | |
---|
| 994 | MOVEMM(0, boxheight); |
---|
| 995 | DRAWMM(boxwidth, boxheight); |
---|
| 996 | DRAWMM(boxwidth, 0); |
---|
| 997 | if (!l->Border) { |
---|
| 998 | DRAWMM(0, 0); |
---|
| 999 | DRAWMM(0, boxheight); |
---|
| 1000 | } |
---|
| 1001 | |
---|
[995cf6a] | 1002 | MOVEMM(0, 20); DRAWMM(div, 20); |
---|
| 1003 | MOVEMM(0, 10); DRAWMM(div, 10); |
---|
[79c239e] | 1004 | |
---|
| 1005 | switch (l->view) { |
---|
| 1006 | case layout::PLAN: { |
---|
| 1007 | long ax, ay, bx, by, cx, cy, dx, dy; |
---|
| 1008 | |
---|
[995cf6a] | 1009 | long xc = boxwidth - boxheight / 2; |
---|
| 1010 | long yc = boxheight / 2; |
---|
[725cd74d] | 1011 | const double RADIUS = boxheight / 3; |
---|
[995cf6a] | 1012 | DrawEllipse(long(xc * l->scX), long(yc * l->scY), |
---|
| 1013 | long(RADIUS * l->scX), long(RADIUS * l->scY)); |
---|
| 1014 | |
---|
| 1015 | ax = (long)((xc - (RADIUS - 1) * sin(rad(000.0 + l->rot))) * l->scX); |
---|
| 1016 | ay = (long)((yc + (RADIUS - 1) * cos(rad(000.0 + l->rot))) * l->scY); |
---|
| 1017 | bx = (long)((xc - RADIUS * 0.5 * sin(rad(180.0 + l->rot))) * l->scX); |
---|
| 1018 | by = (long)((yc + RADIUS * 0.5 * cos(rad(180.0 + l->rot))) * l->scY); |
---|
| 1019 | cx = (long)((xc - (RADIUS - 1) * sin(rad(160.0 + l->rot))) * l->scX); |
---|
| 1020 | cy = (long)((yc + (RADIUS - 1) * cos(rad(160.0 + l->rot))) * l->scY); |
---|
| 1021 | dx = (long)((xc - (RADIUS - 1) * sin(rad(200.0 + l->rot))) * l->scX); |
---|
| 1022 | dy = (long)((yc + (RADIUS - 1) * cos(rad(200.0 + l->rot))) * l->scY); |
---|
[79c239e] | 1023 | |
---|
| 1024 | MoveTo(ax, ay); |
---|
| 1025 | DrawTo(bx, by); |
---|
| 1026 | DrawTo(cx, cy); |
---|
| 1027 | DrawTo(ax, ay); |
---|
| 1028 | DrawTo(dx, dy); |
---|
| 1029 | DrawTo(bx, by); |
---|
| 1030 | |
---|
| 1031 | SetColour(PR_COLOUR_TEXT); |
---|
[725cd74d] | 1032 | MOVEMM(div + 0.5, boxheight - 5.5); |
---|
[5627cbb] | 1033 | WriteString(wmsg(/*North*/115)); |
---|
[79c239e] | 1034 | |
---|
[4a66219] | 1035 | wxString angle = format_angle(ANGLE_FMT, l->rot); |
---|
[995cf6a] | 1036 | wxString s; |
---|
[736f7df] | 1037 | /* TRANSLATORS: This is used on printouts of plans, with %s replaced by |
---|
| 1038 | * something like "123°". The bearing is up the page. */ |
---|
[995cf6a] | 1039 | s.Printf(wmsg(/*Plan view, %s up page*/168), angle.c_str()); |
---|
| 1040 | MOVEMM(2, 12); WriteString(s); |
---|
[79c239e] | 1041 | break; |
---|
| 1042 | } |
---|
[995cf6a] | 1043 | case layout::ELEV: case layout::TILT: { |
---|
| 1044 | const int L = div + 2; |
---|
| 1045 | const int R = boxwidth - 2; |
---|
[725cd74d] | 1046 | const int H = boxheight / 2; |
---|
[995cf6a] | 1047 | MOVEMM(L, H); DRAWMM(L + 5, H - 3); DRAWMM(L + 3, H); DRAWMM(L + 5, H + 3); |
---|
[79c239e] | 1048 | |
---|
[995cf6a] | 1049 | DRAWMM(L, H); DRAWMM(R, H); |
---|
[79c239e] | 1050 | |
---|
[995cf6a] | 1051 | DRAWMM(R - 5, H + 3); DRAWMM(R - 3, H); DRAWMM(R - 5, H - 3); DRAWMM(R, H); |
---|
[79c239e] | 1052 | |
---|
[995cf6a] | 1053 | MOVEMM((L + R) / 2, H - 2); DRAWMM((L + R) / 2, H + 2); |
---|
[79c239e] | 1054 | |
---|
| 1055 | SetColour(PR_COLOUR_TEXT); |
---|
[725cd74d] | 1056 | MOVEMM(div + 2, boxheight - 8); |
---|
[736f7df] | 1057 | /* TRANSLATORS: "Elevation on" 020 <-> 200 degrees */ |
---|
[5627cbb] | 1058 | WriteString(wmsg(/*Elevation on*/116)); |
---|
| 1059 | |
---|
[725cd74d] | 1060 | MOVEMM(L, 2); |
---|
[4a66219] | 1061 | WriteString(format_angle(ANGLE_FMT, fmod(l->rot + 270.0, 360.0))); |
---|
[725cd74d] | 1062 | MOVEMM(R - 10, 2); |
---|
[4a66219] | 1063 | WriteString(format_angle(ANGLE_FMT, fmod(l->rot + 90.0, 360.0))); |
---|
[995cf6a] | 1064 | |
---|
[4a66219] | 1065 | wxString angle = format_angle(ANGLE_FMT, l->rot); |
---|
[995cf6a] | 1066 | wxString s; |
---|
| 1067 | if (l->view == layout::ELEV) { |
---|
[736f7df] | 1068 | /* TRANSLATORS: This is used on printouts of elevations, with %s |
---|
| 1069 | * replaced by something like "123°". The bearing is the direction |
---|
| 1070 | * we’re looking. */ |
---|
[995cf6a] | 1071 | s.Printf(wmsg(/*Elevation facing %s*/169), angle.c_str()); |
---|
| 1072 | } else { |
---|
[4a66219] | 1073 | wxString a2 = format_angle(ANGLE2_FMT, l->tilt); |
---|
[736f7df] | 1074 | /* TRANSLATORS: This is used on printouts of tilted elevations, with |
---|
| 1075 | * the first %s replaced by something like "123°", and the second by |
---|
| 1076 | * something like "-45°". The bearing is the direction we’re |
---|
| 1077 | * looking. */ |
---|
[995cf6a] | 1078 | s.Printf(wmsg(/*Elevation facing %s, tilted %s*/284), angle.c_str(), a2.c_str()); |
---|
| 1079 | } |
---|
| 1080 | MOVEMM(2, 12); WriteString(s); |
---|
[79c239e] | 1081 | break; |
---|
[995cf6a] | 1082 | } |
---|
[79c239e] | 1083 | case layout::EXTELEV: |
---|
| 1084 | SetColour(PR_COLOUR_TEXT); |
---|
[f6dff8b] | 1085 | MOVEMM(2, 12); |
---|
[736f7df] | 1086 | /* TRANSLATORS: This is used on printouts of extended elevations. */ |
---|
[5627cbb] | 1087 | WriteString(wmsg(/*Extended elevation*/191)); |
---|
[79c239e] | 1088 | break; |
---|
| 1089 | } |
---|
| 1090 | |
---|
[f6dff8b] | 1091 | MOVEMM(2, boxheight - 8); WriteString(l->title); |
---|
[79c239e] | 1092 | |
---|
[995cf6a] | 1093 | MOVEMM(2, 2); |
---|
| 1094 | // FIXME: "Original Scale" better? |
---|
[5627cbb] | 1095 | WriteString(wxString::Format(wmsg(/*Scale*/154) + wxT(" 1:%.0f"), |
---|
| 1096 | l->Scale)); |
---|
[79c239e] | 1097 | |
---|
| 1098 | /* This used to be a copyright line, but it was occasionally |
---|
| 1099 | * mis-interpreted as us claiming copyright on the survey, so let's |
---|
| 1100 | * give the website URL instead */ |
---|
| 1101 | MOVEMM(boxwidth + 2, 2); |
---|
[1671258] | 1102 | WriteString(wxT("Survex "VERSION" - http://survex.com/")); |
---|
[79c239e] | 1103 | |
---|
| 1104 | draw_scale_bar(boxwidth + 10.0, 17.0, l->PaperWidth - boxwidth - 18.0); |
---|
| 1105 | } |
---|
| 1106 | |
---|
| 1107 | /* Draw fancy scale bar with bottom left at (x,y) (both in mm) and at most */ |
---|
| 1108 | /* MaxLength mm long. The scaling in use is 1:scale */ |
---|
| 1109 | void |
---|
| 1110 | svxPrintout::draw_scale_bar(double x, double y, double MaxLength) |
---|
| 1111 | { |
---|
| 1112 | double StepEst, d; |
---|
[5627cbb] | 1113 | int E, Step, n, c; |
---|
| 1114 | wxString buf; |
---|
[79c239e] | 1115 | /* Limit scalebar to 20cm to stop people with A0 plotters complaining */ |
---|
| 1116 | if (MaxLength > 200.0) MaxLength = 200.0; |
---|
| 1117 | |
---|
| 1118 | #define dmin 10.0 /* each division >= dmin mm long */ |
---|
| 1119 | #define StepMax 5 /* number in steps of at most StepMax (x 10^N) */ |
---|
| 1120 | #define epsilon (1e-4) /* fudge factor to prevent rounding problems */ |
---|
| 1121 | |
---|
| 1122 | E = (int)ceil(log10((dmin * 0.001 * m_layout->Scale) / StepMax)); |
---|
| 1123 | StepEst = pow(10.0, -(double)E) * (dmin * 0.001) * m_layout->Scale - epsilon; |
---|
| 1124 | |
---|
| 1125 | /* Force labelling to be in multiples of 1, 2, or 5 */ |
---|
| 1126 | Step = (StepEst <= 1.0 ? 1 : (StepEst <= 2.0 ? 2 : 5)); |
---|
| 1127 | |
---|
| 1128 | /* Work out actual length of each scale bar division */ |
---|
| 1129 | d = Step * pow(10.0, (double)E) / m_layout->Scale * 1000.0; |
---|
| 1130 | |
---|
[ccb83b7] | 1131 | /* FIXME: Non-metric units here... */ |
---|
[79c239e] | 1132 | /* Choose appropriate units, s.t. if possible E is >=0 and minimized */ |
---|
[ccb83b7] | 1133 | int units; |
---|
| 1134 | if (E >= 3) { |
---|
| 1135 | E -= 3; |
---|
| 1136 | units = /*km*/423; |
---|
| 1137 | } else if (E >= 0) { |
---|
| 1138 | units = /*m*/424; |
---|
| 1139 | } else { |
---|
| 1140 | E += 2; |
---|
| 1141 | units = /*cm*/425; |
---|
| 1142 | } |
---|
[79c239e] | 1143 | |
---|
[5627cbb] | 1144 | buf = wmsg(/*Scale*/154); |
---|
[79c239e] | 1145 | |
---|
| 1146 | /* Add units used - eg. "Scale (10m)" */ |
---|
[ccb83b7] | 1147 | double pow10_E = pow(10.0, (double)E); |
---|
| 1148 | if (E >= 0) { |
---|
| 1149 | buf += wxString::Format(wxT(" (%.f%s)"), pow10_E, wmsg(units).c_str()); |
---|
| 1150 | } else { |
---|
| 1151 | int sf = -(int)floor(E); |
---|
| 1152 | buf += wxString::Format(wxT(" (%.*f%s)"), sf, pow10_E, wmsg(units).c_str()); |
---|
| 1153 | } |
---|
[79c239e] | 1154 | SetColour(PR_COLOUR_TEXT); |
---|
| 1155 | MOVEMM(x, y + 4); WriteString(buf); |
---|
| 1156 | |
---|
| 1157 | /* Work out how many divisions there will be */ |
---|
| 1158 | n = (int)(MaxLength / d); |
---|
| 1159 | |
---|
| 1160 | SetColour(PR_COLOUR_FRAME); |
---|
| 1161 | |
---|
| 1162 | long Y = long(y * m_layout->scY); |
---|
| 1163 | long Y2 = long((y + 3) * m_layout->scY); |
---|
| 1164 | long X = long(x * m_layout->scX); |
---|
| 1165 | long X2 = long((x + n * d) * m_layout->scX); |
---|
| 1166 | |
---|
| 1167 | /* Draw top of scale bar */ |
---|
| 1168 | MoveTo(X2, Y2); |
---|
| 1169 | DrawTo(X, Y2); |
---|
| 1170 | #if 0 |
---|
| 1171 | DrawTo(X2, Y); |
---|
| 1172 | DrawTo(X, Y); |
---|
| 1173 | MOVEMM(x + n * d, y); DRAWMM(x, y); |
---|
| 1174 | #endif |
---|
| 1175 | /* Draw divisions and label them */ |
---|
| 1176 | for (c = 0; c <= n; c++) { |
---|
| 1177 | SetColour(PR_COLOUR_FRAME); |
---|
| 1178 | X = long((x + c * d) * m_layout->scX); |
---|
| 1179 | MoveTo(X, Y); |
---|
| 1180 | DrawTo(X, Y2); |
---|
| 1181 | #if 0 // Don't waste toner! |
---|
| 1182 | /* Draw a "zebra crossing" scale bar. */ |
---|
| 1183 | if (c < n && (c & 1) == 0) { |
---|
| 1184 | X2 = long((x + (c + 1) * d) * m_layout->scX); |
---|
| 1185 | SolidRectangle(X, Y, X2 - X, Y2 - Y); |
---|
| 1186 | } |
---|
| 1187 | #endif |
---|
[5627cbb] | 1188 | buf.Printf(wxT("%d"), c * Step); |
---|
[79c239e] | 1189 | SetColour(PR_COLOUR_TEXT); |
---|
[30f1caa] | 1190 | MOVEMM(x + c * d - buf.length(), y - 5); |
---|
[79c239e] | 1191 | WriteString(buf); |
---|
| 1192 | } |
---|
| 1193 | } |
---|
| 1194 | |
---|
| 1195 | #if 0 |
---|
[ee05463] | 1196 | void |
---|
[79c239e] | 1197 | make_calibration(layout *l) { |
---|
| 1198 | img_point pt = { 0.0, 0.0, 0.0 }; |
---|
| 1199 | l->xMax = l->yMax = 0.1; |
---|
| 1200 | l->xMin = l->yMin = 0; |
---|
| 1201 | |
---|
| 1202 | stack(l,img_MOVE, NULL, &pt); |
---|
| 1203 | pt.x = 0.1; |
---|
| 1204 | stack(l,img_LINE, NULL, &pt); |
---|
| 1205 | pt.y = 0.1; |
---|
| 1206 | stack(l,img_LINE, NULL, &pt); |
---|
| 1207 | pt.x = 0.0; |
---|
| 1208 | stack(l,img_LINE, NULL, &pt); |
---|
| 1209 | pt.y = 0.0; |
---|
| 1210 | stack(l,img_LINE, NULL, &pt); |
---|
| 1211 | pt.x = 0.05; |
---|
| 1212 | pt.y = 0.001; |
---|
| 1213 | stack(l,img_LABEL, "10cm", &pt); |
---|
| 1214 | pt.x = 0.001; |
---|
| 1215 | pt.y = 0.05; |
---|
| 1216 | stack(l,img_LABEL, "10cm", &pt); |
---|
| 1217 | l->Scale = 1.0; |
---|
| 1218 | } |
---|
| 1219 | #endif |
---|
| 1220 | |
---|
| 1221 | int |
---|
| 1222 | svxPrintout::next_page(int *pstate, char **q, int pageLim) |
---|
| 1223 | { |
---|
| 1224 | char *p; |
---|
| 1225 | int page; |
---|
| 1226 | int c; |
---|
| 1227 | p = *q; |
---|
| 1228 | if (*pstate > 0) { |
---|
| 1229 | /* doing a range */ |
---|
| 1230 | (*pstate)++; |
---|
| 1231 | SVX_ASSERT(*p == '-'); |
---|
| 1232 | p++; |
---|
| 1233 | while (isspace((unsigned char)*p)) p++; |
---|
| 1234 | if (sscanf(p, "%u%n", &page, &c) > 0) { |
---|
| 1235 | p += c; |
---|
| 1236 | } else { |
---|
| 1237 | page = pageLim; |
---|
| 1238 | } |
---|
| 1239 | if (*pstate > page) goto err; |
---|
| 1240 | if (*pstate < page) return *pstate; |
---|
| 1241 | *q = p; |
---|
| 1242 | *pstate = 0; |
---|
| 1243 | return page; |
---|
| 1244 | } |
---|
| 1245 | |
---|
| 1246 | while (isspace((unsigned char)*p) || *p == ',') p++; |
---|
| 1247 | |
---|
| 1248 | if (!*p) return 0; /* done */ |
---|
| 1249 | |
---|
| 1250 | if (*p == '-') { |
---|
| 1251 | *q = p; |
---|
| 1252 | *pstate = 1; |
---|
| 1253 | return 1; /* range with initial parameter omitted */ |
---|
| 1254 | } |
---|
| 1255 | if (sscanf(p, "%u%n", &page, &c) > 0) { |
---|
| 1256 | p += c; |
---|
| 1257 | while (isspace((unsigned char)*p)) p++; |
---|
| 1258 | *q = p; |
---|
| 1259 | if (0 < page && page <= pageLim) { |
---|
| 1260 | if (*p == '-') *pstate = page; /* range with start */ |
---|
| 1261 | return page; |
---|
| 1262 | } |
---|
| 1263 | } |
---|
| 1264 | err: |
---|
| 1265 | *pstate = -1; |
---|
| 1266 | return 0; |
---|
| 1267 | } |
---|
| 1268 | |
---|
| 1269 | /* Draws in alignment marks on each page or borders on edge pages */ |
---|
| 1270 | void |
---|
| 1271 | svxPrintout::drawticks(border clip, int tsize, int x, int y) |
---|
| 1272 | { |
---|
| 1273 | long i; |
---|
| 1274 | int s = tsize * 4; |
---|
| 1275 | int o = s / 8; |
---|
| 1276 | bool fAtCorner = fFalse; |
---|
| 1277 | SetColour(PR_COLOUR_FRAME); |
---|
| 1278 | if (x == 0 && m_layout->Border) { |
---|
| 1279 | /* solid left border */ |
---|
| 1280 | MoveTo(clip.x_min, clip.y_min); |
---|
| 1281 | DrawTo(clip.x_min, clip.y_max); |
---|
| 1282 | fAtCorner = fTrue; |
---|
| 1283 | } else { |
---|
| 1284 | if (x > 0 || y > 0) { |
---|
| 1285 | MoveTo(clip.x_min, clip.y_min); |
---|
| 1286 | DrawTo(clip.x_min, clip.y_min + tsize); |
---|
| 1287 | } |
---|
| 1288 | if (s && x > 0 && m_layout->Cutlines) { |
---|
| 1289 | /* dashed left border */ |
---|
| 1290 | i = (clip.y_max - clip.y_min) - |
---|
| 1291 | (tsize + ((clip.y_max - clip.y_min - tsize * 2L) % s) / 2); |
---|
| 1292 | for ( ; i > tsize; i -= s) { |
---|
| 1293 | MoveTo(clip.x_min, clip.y_max - (i + o)); |
---|
| 1294 | DrawTo(clip.x_min, clip.y_max - (i - o)); |
---|
| 1295 | } |
---|
| 1296 | } |
---|
| 1297 | if (x > 0 || y < m_layout->pagesY - 1) { |
---|
| 1298 | MoveTo(clip.x_min, clip.y_max - tsize); |
---|
| 1299 | DrawTo(clip.x_min, clip.y_max); |
---|
| 1300 | fAtCorner = fTrue; |
---|
| 1301 | } |
---|
| 1302 | } |
---|
| 1303 | |
---|
| 1304 | if (y == m_layout->pagesY - 1 && m_layout->Border) { |
---|
| 1305 | /* solid top border */ |
---|
| 1306 | if (!fAtCorner) MoveTo(clip.x_min, clip.y_max); |
---|
| 1307 | DrawTo(clip.x_max, clip.y_max); |
---|
| 1308 | fAtCorner = fTrue; |
---|
| 1309 | } else { |
---|
| 1310 | if (y < m_layout->pagesY - 1 || x > 0) { |
---|
| 1311 | if (!fAtCorner) MoveTo(clip.x_min, clip.y_max); |
---|
| 1312 | DrawTo(clip.x_min + tsize, clip.y_max); |
---|
| 1313 | } |
---|
| 1314 | if (s && y < m_layout->pagesY - 1 && m_layout->Cutlines) { |
---|
| 1315 | /* dashed top border */ |
---|
| 1316 | i = (clip.x_max - clip.x_min) - |
---|
| 1317 | (tsize + ((clip.x_max - clip.x_min - tsize * 2L) % s) / 2); |
---|
| 1318 | for ( ; i > tsize; i -= s) { |
---|
| 1319 | MoveTo(clip.x_max - (i + o), clip.y_max); |
---|
| 1320 | DrawTo(clip.x_max - (i - o), clip.y_max); |
---|
| 1321 | } |
---|
| 1322 | } |
---|
| 1323 | if (y < m_layout->pagesY - 1 || x < m_layout->pagesX - 1) { |
---|
| 1324 | MoveTo(clip.x_max - tsize, clip.y_max); |
---|
| 1325 | DrawTo(clip.x_max, clip.y_max); |
---|
| 1326 | fAtCorner = fTrue; |
---|
| 1327 | } else { |
---|
| 1328 | fAtCorner = fFalse; |
---|
| 1329 | } |
---|
| 1330 | } |
---|
| 1331 | |
---|
| 1332 | if (x == m_layout->pagesX - 1 && m_layout->Border) { |
---|
| 1333 | /* solid right border */ |
---|
| 1334 | if (!fAtCorner) MoveTo(clip.x_max, clip.y_max); |
---|
| 1335 | DrawTo(clip.x_max, clip.y_min); |
---|
| 1336 | fAtCorner = fTrue; |
---|
| 1337 | } else { |
---|
| 1338 | if (x < m_layout->pagesX - 1 || y < m_layout->pagesY - 1) { |
---|
| 1339 | if (!fAtCorner) MoveTo(clip.x_max, clip.y_max); |
---|
| 1340 | DrawTo(clip.x_max, clip.y_max - tsize); |
---|
| 1341 | } |
---|
| 1342 | if (s && x < m_layout->pagesX - 1 && m_layout->Cutlines) { |
---|
| 1343 | /* dashed right border */ |
---|
| 1344 | i = (clip.y_max - clip.y_min) - |
---|
| 1345 | (tsize + ((clip.y_max - clip.y_min - tsize * 2L) % s) / 2); |
---|
| 1346 | for ( ; i > tsize; i -= s) { |
---|
| 1347 | MoveTo(clip.x_max, clip.y_min + (i + o)); |
---|
| 1348 | DrawTo(clip.x_max, clip.y_min + (i - o)); |
---|
| 1349 | } |
---|
| 1350 | } |
---|
| 1351 | if (x < m_layout->pagesX - 1 || y > 0) { |
---|
| 1352 | MoveTo(clip.x_max, clip.y_min + tsize); |
---|
| 1353 | DrawTo(clip.x_max, clip.y_min); |
---|
| 1354 | fAtCorner = fTrue; |
---|
| 1355 | } else { |
---|
| 1356 | fAtCorner = fFalse; |
---|
| 1357 | } |
---|
| 1358 | } |
---|
| 1359 | |
---|
| 1360 | if (y == 0 && m_layout->Border) { |
---|
| 1361 | /* solid bottom border */ |
---|
| 1362 | if (!fAtCorner) MoveTo(clip.x_max, clip.y_min); |
---|
| 1363 | DrawTo(clip.x_min, clip.y_min); |
---|
| 1364 | } else { |
---|
| 1365 | if (y > 0 || x < m_layout->pagesX - 1) { |
---|
| 1366 | if (!fAtCorner) MoveTo(clip.x_max, clip.y_min); |
---|
| 1367 | DrawTo(clip.x_max - tsize, clip.y_min); |
---|
| 1368 | } |
---|
| 1369 | if (s && y > 0 && m_layout->Cutlines) { |
---|
| 1370 | /* dashed bottom border */ |
---|
| 1371 | i = (clip.x_max - clip.x_min) - |
---|
| 1372 | (tsize + ((clip.x_max - clip.x_min - tsize * 2L) % s) / 2); |
---|
| 1373 | for ( ; i > tsize; i -= s) { |
---|
| 1374 | MoveTo(clip.x_min + (i + o), clip.y_min); |
---|
| 1375 | DrawTo(clip.x_min + (i - o), clip.y_min); |
---|
| 1376 | } |
---|
| 1377 | } |
---|
| 1378 | if (y > 0 || x > 0) { |
---|
| 1379 | MoveTo(clip.x_min + tsize, clip.y_min); |
---|
| 1380 | DrawTo(clip.x_min, clip.y_min); |
---|
| 1381 | } |
---|
| 1382 | } |
---|
| 1383 | } |
---|
| 1384 | |
---|
[ee05463] | 1385 | bool |
---|
[79c239e] | 1386 | svxPrintout::OnPrintPage(int pageNum) { |
---|
| 1387 | GetPageSizePixels(&xpPageWidth, &ypPageDepth); |
---|
| 1388 | pdc = GetDC(); |
---|
[cca2ce1] | 1389 | #ifdef AVEN_PRINT_PREVIEW |
---|
[79c239e] | 1390 | if (IsPreview()) { |
---|
| 1391 | int dcx, dcy; |
---|
| 1392 | pdc->GetSize(&dcx, &dcy); |
---|
| 1393 | pdc->SetUserScale((double)dcx / xpPageWidth, (double)dcy / ypPageDepth); |
---|
| 1394 | } |
---|
[cca2ce1] | 1395 | #endif |
---|
[79c239e] | 1396 | |
---|
| 1397 | layout * l = m_layout; |
---|
| 1398 | { |
---|
| 1399 | int pwidth, pdepth; |
---|
| 1400 | GetPageSizeMM(&pwidth, &pdepth); |
---|
| 1401 | l->scX = (double)xpPageWidth / pwidth; |
---|
| 1402 | l->scY = (double)ypPageDepth / pdepth; |
---|
| 1403 | font_scaling_x = l->scX * (25.4 / 72.0); |
---|
| 1404 | font_scaling_y = l->scY * (25.4 / 72.0); |
---|
| 1405 | MarginLeft = m_data->GetMarginTopLeft().x; |
---|
| 1406 | MarginTop = m_data->GetMarginTopLeft().y; |
---|
| 1407 | MarginBottom = m_data->GetMarginBottomRight().y; |
---|
| 1408 | MarginRight = m_data->GetMarginBottomRight().x; |
---|
| 1409 | xpPageWidth -= (int)(l->scX * (MarginLeft + MarginRight)); |
---|
| 1410 | ypPageDepth -= (int)(l->scY * (10 + MarginBottom + MarginRight)); |
---|
| 1411 | // xpPageWidth -= 1; |
---|
| 1412 | pdepth -= 10; |
---|
| 1413 | x_offset = (long)(l->scX * MarginLeft); |
---|
| 1414 | y_offset = (long)(l->scY * MarginTop); |
---|
| 1415 | l->PaperWidth = pwidth -= MarginLeft + MarginRight; |
---|
| 1416 | l->PaperDepth = pdepth -= MarginTop + MarginBottom; |
---|
| 1417 | } |
---|
| 1418 | |
---|
[5940815] | 1419 | double SIN = sin(rad(l->rot)); |
---|
| 1420 | double COS = cos(rad(l->rot)); |
---|
| 1421 | double SINT = sin(rad(l->tilt)); |
---|
| 1422 | double COST = cos(rad(l->tilt)); |
---|
[79c239e] | 1423 | |
---|
| 1424 | NewPage(pageNum, l->pagesX, l->pagesY); |
---|
| 1425 | |
---|
[256c4c8] | 1426 | if (l->Legend && pageNum == (l->pagesY - 1) * l->pagesX + 1) { |
---|
[79c239e] | 1427 | SetFont(PR_FONT_DEFAULT); |
---|
| 1428 | draw_info_box(); |
---|
| 1429 | } |
---|
| 1430 | |
---|
[55918ca] | 1431 | pdc->SetClippingRegion(x_offset, y_offset,xpPageWidth+1, ypPageDepth+1); |
---|
| 1432 | |
---|
[741d94f] | 1433 | const double Sc = 1000 / l->Scale; |
---|
[79c239e] | 1434 | |
---|
[d713e5d] | 1435 | if (l->show_mask & LEGS) { |
---|
[ce403f1] | 1436 | SetColour(PR_COLOUR_LEG); |
---|
[c61aa79] | 1437 | list<traverse>::const_iterator trav = mainfrm->traverses_begin(); |
---|
| 1438 | list<traverse>::const_iterator tend = mainfrm->traverses_end(); |
---|
[ce403f1] | 1439 | for ( ; trav != tend; ++trav) { |
---|
[d4650b3] | 1440 | vector<PointInfo>::const_iterator pos = trav->begin(); |
---|
| 1441 | vector<PointInfo>::const_iterator end = trav->end(); |
---|
[ce403f1] | 1442 | for ( ; pos != end; ++pos) { |
---|
| 1443 | double x = pos->GetX(); |
---|
| 1444 | double y = pos->GetY(); |
---|
| 1445 | double z = pos->GetZ(); |
---|
| 1446 | double X = x * COS - y * SIN; |
---|
[7a57dc7] | 1447 | double Y = z * COST - (x * SIN + y * COS) * SINT; |
---|
[ce403f1] | 1448 | long px = (long)((X * Sc + l->xOrg) * l->scX); |
---|
| 1449 | long py = (long)((Y * Sc + l->yOrg) * l->scY); |
---|
| 1450 | if (pos == trav->begin()) { |
---|
| 1451 | MoveTo(px, py); |
---|
| 1452 | } else { |
---|
| 1453 | DrawTo(px, py); |
---|
| 1454 | } |
---|
| 1455 | } |
---|
[ee05463] | 1456 | } |
---|
| 1457 | } |
---|
| 1458 | |
---|
[d713e5d] | 1459 | if ((l->show_mask & XSECT) && |
---|
| 1460 | (l->tilt == 0.0 || l->tilt == 90.0 || l->tilt == -90.0)) { |
---|
[ee05463] | 1461 | list<vector<XSect> >::const_iterator trav = mainfrm->tubes_begin(); |
---|
| 1462 | list<vector<XSect> >::const_iterator tend = mainfrm->tubes_end(); |
---|
| 1463 | for ( ; trav != tend; ++trav) { |
---|
| 1464 | if (l->tilt == 90.0 || l->tilt == -90.0) PlotLR(*trav); |
---|
[0fdd3aa] | 1465 | if (l->tilt == 0.0) PlotUD(*trav); |
---|
[ce403f1] | 1466 | } |
---|
| 1467 | } |
---|
| 1468 | |
---|
[d713e5d] | 1469 | if (l->show_mask & SURF) { |
---|
[ce403f1] | 1470 | SetColour(PR_COLOUR_SURFACE_LEG); |
---|
[c61aa79] | 1471 | list<traverse>::const_iterator trav = mainfrm->surface_traverses_begin(); |
---|
| 1472 | list<traverse>::const_iterator tend = mainfrm->surface_traverses_end(); |
---|
[ce403f1] | 1473 | for ( ; trav != tend; ++trav) { |
---|
[d4650b3] | 1474 | vector<PointInfo>::const_iterator pos = trav->begin(); |
---|
| 1475 | vector<PointInfo>::const_iterator end = trav->end(); |
---|
[ce403f1] | 1476 | for ( ; pos != end; ++pos) { |
---|
| 1477 | double x = pos->GetX(); |
---|
| 1478 | double y = pos->GetY(); |
---|
| 1479 | double z = pos->GetZ(); |
---|
| 1480 | double X = x * COS - y * SIN; |
---|
[1b2e819] | 1481 | double Y = z * COST - (x * SIN + y * COS) * SINT; |
---|
[ce403f1] | 1482 | long px = (long)((X * Sc + l->xOrg) * l->scX); |
---|
| 1483 | long py = (long)((Y * Sc + l->yOrg) * l->scY); |
---|
| 1484 | if (pos == trav->begin()) { |
---|
| 1485 | MoveTo(px, py); |
---|
[79c239e] | 1486 | } else { |
---|
[ce403f1] | 1487 | DrawTo(px, py); |
---|
[79c239e] | 1488 | } |
---|
| 1489 | } |
---|
| 1490 | } |
---|
| 1491 | } |
---|
| 1492 | |
---|
[d713e5d] | 1493 | if (l->show_mask & (LABELS|STNS)) { |
---|
| 1494 | if (l->show_mask & LABELS) SetFont(PR_FONT_LABELS); |
---|
[ce403f1] | 1495 | list<LabelInfo*>::const_iterator label = mainfrm->GetLabels(); |
---|
| 1496 | while (label != mainfrm->GetLabelsEnd()) { |
---|
[79c239e] | 1497 | double px = (*label)->GetX(); |
---|
| 1498 | double py = (*label)->GetY(); |
---|
| 1499 | double pz = (*label)->GetZ(); |
---|
[d713e5d] | 1500 | if ((l->show_mask & SURF) || (*label)->IsUnderground()) { |
---|
[79c239e] | 1501 | double X = px * COS - py * SIN; |
---|
[7a57dc7] | 1502 | double Y = pz * COST - (px * SIN + py * COS) * SINT; |
---|
[79c239e] | 1503 | long xnew, ynew; |
---|
| 1504 | xnew = (long)((X * Sc + l->xOrg) * l->scX); |
---|
| 1505 | ynew = (long)((Y * Sc + l->yOrg) * l->scY); |
---|
[d713e5d] | 1506 | if (l->show_mask & STNS) { |
---|
[79c239e] | 1507 | SetColour(PR_COLOUR_CROSS); |
---|
| 1508 | DrawCross(xnew, ynew); |
---|
| 1509 | } |
---|
[d713e5d] | 1510 | if (l->show_mask & LABELS) { |
---|
[79c239e] | 1511 | SetColour(PR_COLOUR_LABELS); |
---|
| 1512 | MoveTo(xnew, ynew); |
---|
| 1513 | WriteString((*label)->GetText()); |
---|
| 1514 | } |
---|
| 1515 | } |
---|
| 1516 | ++label; |
---|
| 1517 | } |
---|
| 1518 | } |
---|
| 1519 | |
---|
| 1520 | return true; |
---|
| 1521 | } |
---|
| 1522 | |
---|
[13da582] | 1523 | void |
---|
| 1524 | svxPrintout::GetPageInfo(int *minPage, int *maxPage, |
---|
| 1525 | int *pageFrom, int *pageTo) |
---|
| 1526 | { |
---|
| 1527 | *minPage = *pageFrom = 1; |
---|
| 1528 | *maxPage = *pageTo = m_layout->pages; |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | bool |
---|
| 1532 | svxPrintout::HasPage(int pageNum) { |
---|
| 1533 | return (pageNum <= m_layout->pages); |
---|
| 1534 | } |
---|
| 1535 | |
---|
[ee05463] | 1536 | void |
---|
[79c239e] | 1537 | svxPrintout::OnBeginPrinting() { |
---|
[ee05463] | 1538 | FILE *fh_list[4]; |
---|
[79c239e] | 1539 | |
---|
| 1540 | FILE **pfh = fh_list; |
---|
| 1541 | FILE *fh; |
---|
| 1542 | const char *pth_cfg; |
---|
| 1543 | char *print_ini; |
---|
| 1544 | |
---|
| 1545 | /* ini files searched in this order: |
---|
| 1546 | * ~/.survex/print.ini [unix only] |
---|
| 1547 | * /etc/survex/print.ini [unix only] |
---|
| 1548 | * <support file directory>/myprint.ini [not unix] |
---|
| 1549 | * <support file directory>/print.ini [must exist] |
---|
| 1550 | */ |
---|
| 1551 | |
---|
[affaeee] | 1552 | #ifdef __UNIX__ |
---|
[79c239e] | 1553 | pth_cfg = getenv("HOME"); |
---|
| 1554 | if (pth_cfg) { |
---|
| 1555 | fh = fopenWithPthAndExt(pth_cfg, ".survex/print."EXT_INI, NULL, |
---|
| 1556 | "rb", NULL); |
---|
| 1557 | if (fh) *pfh++ = fh; |
---|
| 1558 | } |
---|
| 1559 | pth_cfg = msg_cfgpth(); |
---|
| 1560 | fh = fopenWithPthAndExt(NULL, "/etc/survex/print."EXT_INI, NULL, "rb", |
---|
| 1561 | NULL); |
---|
| 1562 | if (fh) *pfh++ = fh; |
---|
| 1563 | #else |
---|
| 1564 | pth_cfg = msg_cfgpth(); |
---|
| 1565 | print_ini = add_ext("myprint", EXT_INI); |
---|
| 1566 | fh = fopenWithPthAndExt(pth_cfg, print_ini, NULL, "rb", NULL); |
---|
| 1567 | if (fh) *pfh++ = fh; |
---|
| 1568 | #endif |
---|
| 1569 | print_ini = add_ext("print", EXT_INI); |
---|
| 1570 | fh = fopenWithPthAndExt(pth_cfg, print_ini, NULL, "rb", NULL); |
---|
[98cf5b5] | 1571 | if (!fh) fatalerror(/*Couldn’t open file “%s”*/24, print_ini); |
---|
[79c239e] | 1572 | *pfh++ = fh; |
---|
| 1573 | *pfh = NULL; |
---|
| 1574 | Init(pfh, false); |
---|
| 1575 | for (pfh = fh_list; *pfh; pfh++) (void)fclose(*pfh); |
---|
| 1576 | Pre(); |
---|
[0804fbe] | 1577 | m_layout->footer = wmsg(/*Survey “%s” Page %d (of %d) Processed on %s*/167); |
---|
[79c239e] | 1578 | } |
---|
| 1579 | |
---|
| 1580 | void |
---|
| 1581 | svxPrintout::OnEndPrinting() { |
---|
[03e2031] | 1582 | delete font_labels; |
---|
| 1583 | delete font_default; |
---|
| 1584 | delete pen_frame; |
---|
| 1585 | delete pen_leg; |
---|
| 1586 | delete pen_surface_leg; |
---|
| 1587 | delete pen_cross; |
---|
[79c239e] | 1588 | } |
---|
| 1589 | |
---|
| 1590 | |
---|
| 1591 | // prcore -> wx.grafx (calls to move pens around and stuff - low level) |
---|
| 1592 | // this seems to have been done... |
---|
| 1593 | |
---|
| 1594 | |
---|
| 1595 | |
---|
| 1596 | static border clip; |
---|
| 1597 | |
---|
| 1598 | |
---|
| 1599 | int |
---|
| 1600 | svxPrintout::check_intersection(long x_p, long y_p) |
---|
| 1601 | { |
---|
| 1602 | #define U 1 |
---|
| 1603 | #define D 2 |
---|
| 1604 | #define L 4 |
---|
| 1605 | #define R 8 |
---|
| 1606 | int mask_p = 0, mask_t = 0; |
---|
| 1607 | if (x_p < 0) |
---|
| 1608 | mask_p = L; |
---|
| 1609 | else if (x_p > xpPageWidth) |
---|
| 1610 | mask_p = R; |
---|
| 1611 | |
---|
| 1612 | if (y_p < 0) |
---|
| 1613 | mask_p |= D; |
---|
| 1614 | else if (y_p > ypPageDepth) |
---|
| 1615 | mask_p |= U; |
---|
| 1616 | |
---|
| 1617 | if (x_t < 0) |
---|
| 1618 | mask_t = L; |
---|
| 1619 | else if (x_t > xpPageWidth) |
---|
| 1620 | mask_t = R; |
---|
| 1621 | |
---|
| 1622 | if (y_t < 0) |
---|
| 1623 | mask_t |= D; |
---|
| 1624 | else if (y_t > ypPageDepth) |
---|
| 1625 | mask_t |= U; |
---|
| 1626 | |
---|
| 1627 | #if 0 |
---|
| 1628 | /* approximation to correct answer */ |
---|
| 1629 | return !(mask_t & mask_p); |
---|
| 1630 | #else |
---|
| 1631 | /* One end of the line is on the page */ |
---|
| 1632 | if (!mask_t || !mask_p) return 1; |
---|
| 1633 | |
---|
| 1634 | /* whole line is above, left, right, or below page */ |
---|
| 1635 | if (mask_t & mask_p) return 0; |
---|
| 1636 | |
---|
| 1637 | if (mask_t == 0) mask_t = mask_p; |
---|
| 1638 | if (mask_t & U) { |
---|
| 1639 | double v = (double)(y_p - ypPageDepth) / (y_p - y_t); |
---|
| 1640 | return v >= 0 && v <= 1; |
---|
| 1641 | } |
---|
| 1642 | if (mask_t & D) { |
---|
| 1643 | double v = (double)y_p / (y_p - y_t); |
---|
| 1644 | return v >= 0 && v <= 1; |
---|
| 1645 | } |
---|
| 1646 | if (mask_t & R) { |
---|
| 1647 | double v = (double)(x_p - xpPageWidth) / (x_p - x_t); |
---|
| 1648 | return v >= 0 && v <= 1; |
---|
| 1649 | } |
---|
| 1650 | SVX_ASSERT(mask_t & L); |
---|
| 1651 | { |
---|
| 1652 | double v = (double)x_p / (x_p - x_t); |
---|
| 1653 | return v >= 0 && v <= 1; |
---|
| 1654 | } |
---|
| 1655 | #endif |
---|
| 1656 | #undef U |
---|
| 1657 | #undef D |
---|
| 1658 | #undef L |
---|
| 1659 | #undef R |
---|
| 1660 | } |
---|
| 1661 | |
---|
| 1662 | void |
---|
| 1663 | svxPrintout::MoveTo(long x, long y) |
---|
| 1664 | { |
---|
| 1665 | x_t = x_offset + x - clip.x_min; |
---|
| 1666 | y_t = y_offset + clip.y_max - y; |
---|
| 1667 | } |
---|
| 1668 | |
---|
| 1669 | void |
---|
| 1670 | svxPrintout::DrawTo(long x, long y) |
---|
| 1671 | { |
---|
| 1672 | long x_p = x_t, y_p = y_t; |
---|
| 1673 | x_t = x_offset + x - clip.x_min; |
---|
| 1674 | y_t = y_offset + clip.y_max - y; |
---|
| 1675 | if (cur_pass != -1) { |
---|
[5940815] | 1676 | pdc->DrawLine(x_p, y_p, x_t, y_t); |
---|
[79c239e] | 1677 | } else { |
---|
| 1678 | if (check_intersection(x_p, y_p)) fBlankPage = fFalse; |
---|
| 1679 | } |
---|
| 1680 | } |
---|
| 1681 | |
---|
| 1682 | #define POINTS_PER_INCH 72.0 |
---|
| 1683 | #define POINTS_PER_MM (POINTS_PER_INCH / MM_PER_INCH) |
---|
| 1684 | #define PWX_CROSS_SIZE (int)(2 * m_layout->scX / POINTS_PER_MM) |
---|
| 1685 | |
---|
| 1686 | void |
---|
| 1687 | svxPrintout::DrawCross(long x, long y) |
---|
| 1688 | { |
---|
| 1689 | if (cur_pass != -1) { |
---|
| 1690 | MoveTo(x - PWX_CROSS_SIZE, y - PWX_CROSS_SIZE); |
---|
| 1691 | DrawTo(x + PWX_CROSS_SIZE, y + PWX_CROSS_SIZE); |
---|
| 1692 | MoveTo(x + PWX_CROSS_SIZE, y - PWX_CROSS_SIZE); |
---|
| 1693 | DrawTo(x - PWX_CROSS_SIZE, y + PWX_CROSS_SIZE); |
---|
| 1694 | MoveTo(x, y); |
---|
| 1695 | } else { |
---|
| 1696 | if ((x + PWX_CROSS_SIZE > clip.x_min && |
---|
| 1697 | x - PWX_CROSS_SIZE < clip.x_max) || |
---|
| 1698 | (y + PWX_CROSS_SIZE > clip.y_min && |
---|
| 1699 | y - PWX_CROSS_SIZE < clip.y_max)) { |
---|
| 1700 | fBlankPage = fFalse; |
---|
| 1701 | } |
---|
| 1702 | } |
---|
| 1703 | } |
---|
| 1704 | |
---|
| 1705 | void |
---|
| 1706 | svxPrintout::SetFont(int fontcode) |
---|
| 1707 | { |
---|
| 1708 | switch (fontcode) { |
---|
| 1709 | case PR_FONT_DEFAULT: |
---|
| 1710 | current_font = font_default; |
---|
| 1711 | break; |
---|
| 1712 | case PR_FONT_LABELS: |
---|
| 1713 | current_font = font_labels; |
---|
| 1714 | break; |
---|
| 1715 | default: |
---|
| 1716 | BUG("unknown font code"); |
---|
| 1717 | } |
---|
| 1718 | } |
---|
| 1719 | |
---|
| 1720 | void |
---|
| 1721 | svxPrintout::SetColour(int colourcode) |
---|
| 1722 | { |
---|
| 1723 | switch (colourcode) { |
---|
| 1724 | case PR_COLOUR_TEXT: |
---|
| 1725 | pdc->SetTextForeground(colour_text); |
---|
| 1726 | break; |
---|
| 1727 | case PR_COLOUR_LABELS: |
---|
| 1728 | pdc->SetTextForeground(colour_labels); |
---|
| 1729 | pdc->SetBackgroundMode(wxTRANSPARENT); |
---|
| 1730 | break; |
---|
| 1731 | case PR_COLOUR_FRAME: |
---|
| 1732 | pdc->SetPen(*pen_frame); |
---|
| 1733 | break; |
---|
| 1734 | case PR_COLOUR_LEG: |
---|
| 1735 | pdc->SetPen(*pen_leg); |
---|
| 1736 | break; |
---|
| 1737 | case PR_COLOUR_CROSS: |
---|
| 1738 | pdc->SetPen(*pen_cross); |
---|
| 1739 | break; |
---|
| 1740 | case PR_COLOUR_SURFACE_LEG: |
---|
| 1741 | pdc->SetPen(*pen_surface_leg); |
---|
| 1742 | break; |
---|
| 1743 | default: |
---|
| 1744 | BUG("unknown colour code"); |
---|
| 1745 | } |
---|
| 1746 | } |
---|
| 1747 | |
---|
| 1748 | void |
---|
[5627cbb] | 1749 | svxPrintout::WriteString(const wxString & s) |
---|
[79c239e] | 1750 | { |
---|
| 1751 | double xsc, ysc; |
---|
| 1752 | pdc->GetUserScale(&xsc, &ysc); |
---|
| 1753 | pdc->SetUserScale(xsc * font_scaling_x, ysc * font_scaling_y); |
---|
| 1754 | pdc->SetFont(*current_font); |
---|
| 1755 | int w, h; |
---|
| 1756 | if (cur_pass != -1) { |
---|
[5627cbb] | 1757 | pdc->GetTextExtent(wxT("My"), &w, &h); |
---|
[ee05463] | 1758 | pdc->DrawText(s, |
---|
[79c239e] | 1759 | long(x_t / font_scaling_x), |
---|
| 1760 | long(y_t / font_scaling_y) - h); |
---|
| 1761 | } else { |
---|
| 1762 | pdc->GetTextExtent(s, &w, &h); |
---|
| 1763 | if ((y_t + h > 0 && y_t - h < clip.y_max - clip.y_min) || |
---|
| 1764 | (x_t < clip.x_max - clip.x_min && x_t + w > 0)) { |
---|
| 1765 | fBlankPage = fFalse; |
---|
| 1766 | } |
---|
| 1767 | } |
---|
| 1768 | pdc->SetUserScale(xsc, ysc); |
---|
| 1769 | } |
---|
| 1770 | |
---|
| 1771 | void |
---|
| 1772 | svxPrintout::DrawEllipse(long x, long y, long r, long R) |
---|
| 1773 | { |
---|
| 1774 | /* Don't need to check in first-pass - circle is only used in title box */ |
---|
| 1775 | if (cur_pass != -1) { |
---|
| 1776 | x_t = x_offset + x - clip.x_min; |
---|
| 1777 | y_t = y_offset + clip.y_max - y; |
---|
[2bf75f3] | 1778 | const wxBrush & save_brush = pdc->GetBrush(); |
---|
[79c239e] | 1779 | pdc->SetBrush(*wxTRANSPARENT_BRUSH); |
---|
| 1780 | pdc->DrawEllipse(x_t - r, y_t - R, 2 * r, 2 * R); |
---|
[2bf75f3] | 1781 | pdc->SetBrush(save_brush); |
---|
[79c239e] | 1782 | } |
---|
| 1783 | } |
---|
| 1784 | |
---|
| 1785 | void |
---|
| 1786 | svxPrintout::SolidRectangle(long x, long y, long w, long h) |
---|
| 1787 | { |
---|
| 1788 | long X = x_offset + x - clip.x_min; |
---|
| 1789 | long Y = y_offset + clip.y_max - y; |
---|
| 1790 | pdc->SetBrush(*wxBLACK_BRUSH); |
---|
| 1791 | pdc->DrawRectangle(X, Y - h, w, h); |
---|
| 1792 | } |
---|
| 1793 | |
---|
| 1794 | int |
---|
| 1795 | svxPrintout::Pre() |
---|
| 1796 | { |
---|
[5627cbb] | 1797 | font_labels = new wxFont(fontsize_labels, wxDEFAULT, wxNORMAL, wxNORMAL, |
---|
| 1798 | false, wxString(fontname_labels, wxConvUTF8), |
---|
| 1799 | wxFONTENCODING_ISO8859_1); |
---|
| 1800 | font_default = new wxFont(fontsize, wxDEFAULT, wxNORMAL, wxNORMAL, |
---|
| 1801 | false, wxString(fontname, wxConvUTF8), |
---|
| 1802 | wxFONTENCODING_ISO8859_1); |
---|
[79c239e] | 1803 | current_font = font_default; |
---|
[2bf75f3] | 1804 | pen_leg = new wxPen(colour_leg); |
---|
| 1805 | pen_surface_leg = new wxPen(colour_surface_leg); |
---|
| 1806 | pen_cross = new wxPen(colour_cross); |
---|
| 1807 | pen_frame = new wxPen(colour_frame); |
---|
[79c239e] | 1808 | return 1; /* only need 1 pass */ |
---|
| 1809 | } |
---|
| 1810 | |
---|
| 1811 | void |
---|
| 1812 | svxPrintout::NewPage(int pg, int pagesX, int pagesY) |
---|
| 1813 | { |
---|
| 1814 | int x, y; |
---|
| 1815 | x = (pg - 1) % pagesX; |
---|
| 1816 | y = pagesY - 1 - ((pg - 1) / pagesX); |
---|
| 1817 | |
---|
| 1818 | clip.x_min = (long)x * xpPageWidth; |
---|
| 1819 | clip.y_min = (long)y * ypPageDepth; |
---|
| 1820 | clip.x_max = clip.x_min + xpPageWidth; /* dm/pcl/ps had -1; */ |
---|
| 1821 | clip.y_max = clip.y_min + ypPageDepth; /* dm/pcl/ps had -1; */ |
---|
| 1822 | |
---|
| 1823 | //we have to write the footer here. PostScript is being weird. Really weird. |
---|
| 1824 | pdc->SetFont(*font_labels); |
---|
[0f8ab4d] | 1825 | MoveTo(clip.x_min, clip.y_min - (long)(7 * m_layout->scY)); |
---|
| 1826 | wxString footer; |
---|
| 1827 | footer.Printf(m_layout->footer, |
---|
| 1828 | m_layout->title.c_str(), |
---|
| 1829 | pg, |
---|
| 1830 | m_layout->pagesX * m_layout->pagesY, |
---|
| 1831 | m_layout->datestamp.c_str()); |
---|
| 1832 | WriteString(footer); |
---|
[79c239e] | 1833 | pdc->DestroyClippingRegion(); |
---|
| 1834 | drawticks(clip, (int)(9 * m_layout->scX / POINTS_PER_MM), x, y); |
---|
| 1835 | } |
---|
| 1836 | |
---|
[741d94f] | 1837 | void |
---|
[ee05463] | 1838 | svxPrintout::PlotLR(const vector<XSect> & centreline) |
---|
[741d94f] | 1839 | { |
---|
| 1840 | assert(centreline.size() > 1); |
---|
[ee05463] | 1841 | XSect prev_pt_v; |
---|
[741d94f] | 1842 | Vector3 last_right(1.0, 0.0, 0.0); |
---|
| 1843 | |
---|
| 1844 | const double Sc = 1000 / m_layout->Scale; |
---|
[0fdd3aa] | 1845 | const double SIN = sin(rad(m_layout->rot)); |
---|
| 1846 | const double COS = cos(rad(m_layout->rot)); |
---|
[741d94f] | 1847 | |
---|
[ee05463] | 1848 | vector<XSect>::const_iterator i = centreline.begin(); |
---|
| 1849 | vector<XSect>::size_type segment = 0; |
---|
[741d94f] | 1850 | while (i != centreline.end()) { |
---|
| 1851 | // get the coordinates of this vertex |
---|
[ee05463] | 1852 | const XSect & pt_v = *i++; |
---|
[741d94f] | 1853 | |
---|
| 1854 | Vector3 right; |
---|
| 1855 | |
---|
| 1856 | const Vector3 up_v(0.0, 0.0, 1.0); |
---|
| 1857 | |
---|
| 1858 | if (segment == 0) { |
---|
| 1859 | assert(i != centreline.end()); |
---|
| 1860 | // first segment |
---|
| 1861 | |
---|
| 1862 | // get the coordinates of the next vertex |
---|
[ee05463] | 1863 | const XSect & next_pt_v = *i; |
---|
[741d94f] | 1864 | |
---|
| 1865 | // calculate vector from this pt to the next one |
---|
[d67450e] | 1866 | Vector3 leg_v = next_pt_v - pt_v; |
---|
[741d94f] | 1867 | |
---|
| 1868 | // obtain a vector in the LRUD plane |
---|
| 1869 | right = leg_v * up_v; |
---|
| 1870 | if (right.magnitude() == 0) { |
---|
| 1871 | right = last_right; |
---|
| 1872 | } else { |
---|
| 1873 | last_right = right; |
---|
| 1874 | } |
---|
| 1875 | } else if (segment + 1 == centreline.size()) { |
---|
| 1876 | // last segment |
---|
| 1877 | |
---|
| 1878 | // Calculate vector from the previous pt to this one. |
---|
[d67450e] | 1879 | Vector3 leg_v = pt_v - prev_pt_v; |
---|
[741d94f] | 1880 | |
---|
| 1881 | // Obtain a horizontal vector in the LRUD plane. |
---|
| 1882 | right = leg_v * up_v; |
---|
| 1883 | if (right.magnitude() == 0) { |
---|
[d67450e] | 1884 | right = Vector3(last_right.GetX(), last_right.GetY(), 0.0); |
---|
[741d94f] | 1885 | } else { |
---|
| 1886 | last_right = right; |
---|
| 1887 | } |
---|
| 1888 | } else { |
---|
| 1889 | assert(i != centreline.end()); |
---|
| 1890 | // Intermediate segment. |
---|
| 1891 | |
---|
| 1892 | // Get the coordinates of the next vertex. |
---|
[ee05463] | 1893 | const XSect & next_pt_v = *i; |
---|
[741d94f] | 1894 | |
---|
| 1895 | // Calculate vectors from this vertex to the |
---|
| 1896 | // next vertex, and from the previous vertex to |
---|
| 1897 | // this one. |
---|
[d67450e] | 1898 | Vector3 leg1_v = pt_v - prev_pt_v; |
---|
| 1899 | Vector3 leg2_v = next_pt_v - pt_v; |
---|
[741d94f] | 1900 | |
---|
| 1901 | // Obtain horizontal vectors perpendicular to |
---|
| 1902 | // both legs, then normalise and average to get |
---|
| 1903 | // a horizontal bisector. |
---|
| 1904 | Vector3 r1 = leg1_v * up_v; |
---|
| 1905 | Vector3 r2 = leg2_v * up_v; |
---|
| 1906 | r1.normalise(); |
---|
| 1907 | r2.normalise(); |
---|
| 1908 | right = r1 + r2; |
---|
| 1909 | if (right.magnitude() == 0) { |
---|
| 1910 | // This is the "mid-pitch" case... |
---|
| 1911 | right = last_right; |
---|
| 1912 | } |
---|
| 1913 | last_right = right; |
---|
| 1914 | } |
---|
| 1915 | |
---|
| 1916 | // Scale to unit vectors in the LRUD plane. |
---|
| 1917 | right.normalise(); |
---|
| 1918 | |
---|
| 1919 | Double l = pt_v.GetL(); |
---|
| 1920 | Double r = pt_v.GetR(); |
---|
| 1921 | |
---|
| 1922 | if (l >= 0) { |
---|
[d67450e] | 1923 | Vector3 p = pt_v - right * l; |
---|
| 1924 | double X = p.GetX() * COS - p.GetY() * SIN; |
---|
| 1925 | double Y = (p.GetX() * SIN + p.GetY() * COS); |
---|
[741d94f] | 1926 | long x = (long)((X * Sc + m_layout->xOrg) * m_layout->scX); |
---|
| 1927 | long y = (long)((Y * Sc + m_layout->yOrg) * m_layout->scY); |
---|
| 1928 | MoveTo(x - PWX_CROSS_SIZE, y - PWX_CROSS_SIZE); |
---|
| 1929 | DrawTo(x, y); |
---|
| 1930 | DrawTo(x - PWX_CROSS_SIZE, y + PWX_CROSS_SIZE); |
---|
| 1931 | } |
---|
| 1932 | if (r >= 0) { |
---|
[d67450e] | 1933 | Vector3 p = pt_v + right * r; |
---|
| 1934 | double X = p.GetX() * COS - p.GetY() * SIN; |
---|
| 1935 | double Y = (p.GetX() * SIN + p.GetY() * COS); |
---|
[741d94f] | 1936 | long x = (long)((X * Sc + m_layout->xOrg) * m_layout->scX); |
---|
| 1937 | long y = (long)((Y * Sc + m_layout->yOrg) * m_layout->scY); |
---|
| 1938 | MoveTo(x + PWX_CROSS_SIZE, y - PWX_CROSS_SIZE); |
---|
| 1939 | DrawTo(x, y); |
---|
| 1940 | DrawTo(x + PWX_CROSS_SIZE, y + PWX_CROSS_SIZE); |
---|
| 1941 | } |
---|
| 1942 | |
---|
| 1943 | prev_pt_v = pt_v; |
---|
| 1944 | |
---|
| 1945 | ++segment; |
---|
| 1946 | } |
---|
| 1947 | } |
---|
| 1948 | |
---|
[0fdd3aa] | 1949 | void |
---|
[ee05463] | 1950 | svxPrintout::PlotUD(const vector<XSect> & centreline) |
---|
[0fdd3aa] | 1951 | { |
---|
| 1952 | assert(centreline.size() > 1); |
---|
| 1953 | const double Sc = 1000 / m_layout->Scale; |
---|
| 1954 | |
---|
[ee05463] | 1955 | vector<XSect>::const_iterator i = centreline.begin(); |
---|
[0fdd3aa] | 1956 | while (i != centreline.end()) { |
---|
| 1957 | // get the coordinates of this vertex |
---|
[ee05463] | 1958 | const XSect & pt_v = *i++; |
---|
[0fdd3aa] | 1959 | |
---|
[4f40e6c] | 1960 | Double u = pt_v.GetU(); |
---|
| 1961 | Double d = pt_v.GetD(); |
---|
[0fdd3aa] | 1962 | |
---|
| 1963 | if (u >= 0 || d >= 0) { |
---|
[d67450e] | 1964 | Vector3 p = pt_v; |
---|
[0fdd3aa] | 1965 | double SIN = sin(rad(m_layout->rot)); |
---|
| 1966 | double COS = cos(rad(m_layout->rot)); |
---|
[d67450e] | 1967 | double X = p.GetX() * COS - p.GetY() * SIN; |
---|
| 1968 | double Y = p.GetZ(); |
---|
[0fdd3aa] | 1969 | long x = (long)((X * Sc + m_layout->xOrg) * m_layout->scX); |
---|
| 1970 | if (u >= 0) { |
---|
| 1971 | long y = (long)(((Y + u) * Sc + m_layout->yOrg) * m_layout->scY); |
---|
| 1972 | MoveTo(x - PWX_CROSS_SIZE, y + PWX_CROSS_SIZE); |
---|
| 1973 | DrawTo(x, y); |
---|
| 1974 | DrawTo(x + PWX_CROSS_SIZE, y + PWX_CROSS_SIZE); |
---|
| 1975 | } |
---|
| 1976 | if (d >= 0) { |
---|
| 1977 | long y = (long)(((Y - d) * Sc + m_layout->yOrg) * m_layout->scY); |
---|
| 1978 | MoveTo(x - PWX_CROSS_SIZE, y - PWX_CROSS_SIZE); |
---|
| 1979 | DrawTo(x, y); |
---|
| 1980 | DrawTo(x + PWX_CROSS_SIZE, y - PWX_CROSS_SIZE); |
---|
| 1981 | } |
---|
| 1982 | } |
---|
| 1983 | } |
---|
| 1984 | } |
---|
| 1985 | |
---|
[79c239e] | 1986 | static wxColour |
---|
| 1987 | to_rgb(const char *var, char *val) |
---|
| 1988 | { |
---|
| 1989 | unsigned long rgb; |
---|
| 1990 | if (!val) return *wxBLACK; |
---|
| 1991 | rgb = as_colour(var, val); |
---|
| 1992 | return wxColour((rgb & 0xff0000) >> 16, (rgb & 0xff00) >> 8, rgb & 0xff); |
---|
| 1993 | } |
---|
| 1994 | |
---|
| 1995 | /* Initialise printer routines */ |
---|
| 1996 | char * |
---|
| 1997 | svxPrintout::Init(FILE **fh_list, bool fCalibrate) |
---|
| 1998 | { |
---|
| 1999 | static const char *vars[] = { |
---|
| 2000 | "font_size_labels", |
---|
| 2001 | "colour_text", |
---|
| 2002 | "colour_labels", |
---|
| 2003 | "colour_frame", |
---|
| 2004 | "colour_legs", |
---|
| 2005 | "colour_crosses", |
---|
| 2006 | "colour_surface_legs", |
---|
| 2007 | NULL |
---|
| 2008 | }; |
---|
| 2009 | char **vals; |
---|
| 2010 | |
---|
[9185847] | 2011 | (void)fCalibrate; /* suppress unused argument warning */ |
---|
[79c239e] | 2012 | |
---|
[9577fcc] | 2013 | vals = ini_read(fh_list, "aven", vars); |
---|
[79c239e] | 2014 | fontsize_labels = 10; |
---|
[9f6ea6c] | 2015 | if (vals[0]) fontsize_labels = as_int(vars[0], vals[0], 1, INT_MAX); |
---|
[79c239e] | 2016 | fontsize = 10; |
---|
| 2017 | |
---|
| 2018 | colour_text = colour_labels = colour_frame = colour_leg = colour_cross = colour_surface_leg = *wxBLACK; |
---|
[9f6ea6c] | 2019 | if (vals[1]) colour_text = to_rgb(vars[1], vals[1]); |
---|
| 2020 | if (vals[2]) colour_labels = to_rgb(vars[2], vals[2]); |
---|
| 2021 | if (vals[3]) colour_frame = to_rgb(vars[3], vals[3]); |
---|
| 2022 | if (vals[4]) colour_leg = to_rgb(vars[4], vals[4]); |
---|
| 2023 | if (vals[5]) colour_cross = to_rgb(vars[5], vals[5]); |
---|
| 2024 | if (vals[6]) colour_surface_leg = to_rgb(vars[6], vals[6]); |
---|
[79c239e] | 2025 | m_layout->scX = 1; |
---|
| 2026 | m_layout->scY = 1; |
---|
| 2027 | return NULL; |
---|
| 2028 | } |
---|