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