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