[bec42b2] | 1 | // |
---|
| 2 | // model.h |
---|
| 3 | // |
---|
| 4 | // Cave survey model. |
---|
| 5 | // |
---|
| 6 | // Copyright (C) 2000-2003,2005 Mark R. Shinwell |
---|
[16193ae] | 7 | // Copyright (C) 2001-2003,2004,2005,2006,2010,2011,2012,2013,2014,2015,2016,2018 Olly Betts |
---|
[bec42b2] | 8 | // |
---|
| 9 | // This program is free software; you can redistribute it and/or modify |
---|
| 10 | // it under the terms of the GNU General Public License as published by |
---|
| 11 | // the Free Software Foundation; either version 2 of the License, or |
---|
| 12 | // (at your option) any later version. |
---|
| 13 | // |
---|
| 14 | // This program is distributed in the hope that it will be useful, |
---|
| 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | // GNU General Public License for more details. |
---|
| 18 | // |
---|
| 19 | // You should have received a copy of the GNU General Public License |
---|
| 20 | // along with this program; if not, write to the Free Software |
---|
| 21 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | // |
---|
| 23 | |
---|
| 24 | #ifndef model_h |
---|
| 25 | #define model_h |
---|
| 26 | |
---|
| 27 | #include "wx.h" |
---|
| 28 | |
---|
| 29 | #include "labelinfo.h" |
---|
| 30 | #include "vector3.h" |
---|
| 31 | |
---|
| 32 | #include <ctime> |
---|
| 33 | #include <list> |
---|
[1a46879] | 34 | #include <set> |
---|
[bec42b2] | 35 | #include <vector> |
---|
| 36 | |
---|
| 37 | using namespace std; |
---|
| 38 | |
---|
| 39 | class MainFrm; |
---|
| 40 | |
---|
| 41 | class PointInfo : public Point { |
---|
| 42 | int date; |
---|
| 43 | |
---|
| 44 | public: |
---|
| 45 | PointInfo() : Point(), date(-1) { } |
---|
| 46 | explicit PointInfo(const img_point & pt) : Point(pt), date(-1) { } |
---|
| 47 | PointInfo(const img_point & pt, int date_) : Point(pt), date(date_) { } |
---|
| 48 | PointInfo(const Point & p, int date_) : Point(p), date(date_) { } |
---|
| 49 | int GetDate() const { return date; } |
---|
| 50 | }; |
---|
| 51 | |
---|
[672459c] | 52 | class XSect { |
---|
[bec42b2] | 53 | friend class MainFrm; |
---|
[672459c] | 54 | const LabelInfo* stn; |
---|
| 55 | int date; |
---|
[bec42b2] | 56 | double l, r, u, d; |
---|
| 57 | double right_bearing; |
---|
| 58 | |
---|
| 59 | public: |
---|
[672459c] | 60 | XSect(const LabelInfo* stn_, int date_, |
---|
[bec42b2] | 61 | double l_, double r_, double u_, double d_) |
---|
[672459c] | 62 | : stn(stn_), date(date_), l(l_), r(r_), u(u_), d(d_), right_bearing(0) { } |
---|
[bec42b2] | 63 | double GetL() const { return l; } |
---|
| 64 | double GetR() const { return r; } |
---|
| 65 | double GetU() const { return u; } |
---|
| 66 | double GetD() const { return d; } |
---|
| 67 | double get_right_bearing() const { return right_bearing; } |
---|
| 68 | void set_right_bearing(double right_bearing_) { |
---|
| 69 | right_bearing = right_bearing_; |
---|
| 70 | } |
---|
[672459c] | 71 | int GetDate() const { return date; } |
---|
[68fb07a] | 72 | const wxString& GetLabel() const { return stn->GetText(); } |
---|
[672459c] | 73 | const Point& GetPoint() const { return *stn; } |
---|
| 74 | double GetX() const { return stn->GetX(); } |
---|
| 75 | double GetY() const { return stn->GetY(); } |
---|
| 76 | double GetZ() const { return stn->GetZ(); } |
---|
| 77 | friend Vector3 operator-(const XSect& a, const XSect& b); |
---|
[bec42b2] | 78 | }; |
---|
| 79 | |
---|
[672459c] | 80 | inline Vector3 operator-(const XSect& a, const XSect& b) { |
---|
| 81 | return *(a.stn) - *(b.stn); |
---|
| 82 | } |
---|
| 83 | |
---|
[bec42b2] | 84 | class traverse : public vector<PointInfo> { |
---|
| 85 | public: |
---|
[fc43dda] | 86 | int n_legs = 0; |
---|
[bec42b2] | 87 | // Bitmask of img_FLAG_SURFACE, img_FLAG_SPLAY and img_FLAG_DUPLICATE. |
---|
[fc43dda] | 88 | int flags = 0; |
---|
| 89 | double length = 0.0; |
---|
| 90 | enum { ERROR_3D = 0, ERROR_H = 1, ERROR_V = 2 }; |
---|
| 91 | double errors[3] = {0, 0, 0}; |
---|
[49c58872] | 92 | wxString name; |
---|
[bec42b2] | 93 | |
---|
[49c58872] | 94 | explicit |
---|
[fc43dda] | 95 | traverse(const char* name_) : name(name_, wxConvUTF8) { |
---|
[49c58872] | 96 | if (name.empty() && !name_[0]) { |
---|
| 97 | // If name isn't valid UTF-8 then this conversion will |
---|
| 98 | // give an empty string. In this case, assume that the |
---|
| 99 | // label is CP1252 (the Microsoft superset of ISO8859-1). |
---|
| 100 | static wxCSConv ConvCP1252(wxFONTENCODING_CP1252); |
---|
| 101 | name = wxString(name_, ConvCP1252); |
---|
| 102 | if (name.empty()) { |
---|
| 103 | // Or if that doesn't work (ConvCP1252 doesn't like |
---|
| 104 | // strings with some bytes in) let's just go for |
---|
| 105 | // ISO8859-1. |
---|
| 106 | name = wxString(name_, wxConvISO8859_1); |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | } |
---|
[bec42b2] | 110 | }; |
---|
| 111 | |
---|
[1a46879] | 112 | class SurveyFilter { |
---|
| 113 | std::set<wxString, std::greater<wxString>> filters; |
---|
[09ad6d7] | 114 | std::set<wxString, std::greater<wxString>> redundant_filters; |
---|
[16193ae] | 115 | // Default to the Survex standard separator - then a filter created before |
---|
| 116 | // the survey separator is known is likely to not need rebuilding. |
---|
| 117 | wxChar separator = '.'; |
---|
[1a46879] | 118 | |
---|
| 119 | public: |
---|
| 120 | SurveyFilter() {} |
---|
| 121 | |
---|
[09ad6d7] | 122 | void add(const wxString& survey); |
---|
[1a46879] | 123 | |
---|
[09ad6d7] | 124 | void remove(const wxString& survey); |
---|
[1a46879] | 125 | |
---|
[09ad6d7] | 126 | void clear() { filters.clear(); redundant_filters.clear(); } |
---|
[1a46879] | 127 | |
---|
| 128 | bool empty() const { return filters.empty(); } |
---|
| 129 | |
---|
[16193ae] | 130 | void SetSeparator(wxChar separator_); |
---|
[1a46879] | 131 | |
---|
| 132 | bool CheckVisible(const wxString& name) const; |
---|
| 133 | }; |
---|
| 134 | |
---|
[bec42b2] | 135 | /// Cave model. |
---|
| 136 | class Model { |
---|
| 137 | list<traverse> traverses[8]; |
---|
[46a9883] | 138 | mutable list<vector<XSect>> tubes; |
---|
[bec42b2] | 139 | |
---|
| 140 | public: // FIXME |
---|
| 141 | list<LabelInfo*> m_Labels; |
---|
| 142 | |
---|
| 143 | private: |
---|
| 144 | Vector3 m_Ext; |
---|
| 145 | double m_DepthMin, m_DepthExt; |
---|
| 146 | int m_DateMin, m_DateExt; |
---|
| 147 | bool complete_dateinfo; |
---|
| 148 | int m_NumEntrances = 0; |
---|
| 149 | int m_NumFixedPts = 0; |
---|
| 150 | int m_NumExportedPts = 0; |
---|
| 151 | bool m_HasUndergroundLegs = false; |
---|
| 152 | bool m_HasSplays = false; |
---|
| 153 | bool m_HasDupes = false; |
---|
| 154 | bool m_HasSurfaceLegs = false; |
---|
| 155 | bool m_HasErrorInformation = false; |
---|
| 156 | bool m_IsExtendedElevation = false; |
---|
[46a9883] | 157 | mutable bool m_TubesPrepared = false; |
---|
[bec42b2] | 158 | |
---|
| 159 | // Character separating survey levels (often '.') |
---|
| 160 | wxChar m_separator; |
---|
| 161 | |
---|
| 162 | wxString m_Title, m_cs_proj, m_DateStamp; |
---|
| 163 | |
---|
| 164 | time_t m_DateStamp_numeric; |
---|
| 165 | |
---|
| 166 | Vector3 m_Offset; |
---|
| 167 | |
---|
[46a9883] | 168 | void do_prepare_tubes() const; |
---|
| 169 | |
---|
[bec42b2] | 170 | public: |
---|
| 171 | int Load(const wxString& file, const wxString& prefix); |
---|
| 172 | |
---|
| 173 | void CentreDataset(const Vector3& vmin); |
---|
| 174 | |
---|
| 175 | const Vector3& GetExtent() const { return m_Ext; } |
---|
| 176 | |
---|
| 177 | const wxString& GetSurveyTitle() const { return m_Title; } |
---|
| 178 | |
---|
| 179 | const wxString& GetDateString() const { return m_DateStamp; } |
---|
| 180 | |
---|
| 181 | time_t GetDateStamp() const { return m_DateStamp_numeric; } |
---|
| 182 | |
---|
| 183 | double GetDepthExtent() const { return m_DepthExt; } |
---|
| 184 | double GetDepthMin() const { return m_DepthMin; } |
---|
| 185 | |
---|
| 186 | bool HasCompleteDateInfo() const { return complete_dateinfo; } |
---|
| 187 | int GetDateExtent() const { return m_DateExt; } |
---|
| 188 | int GetDateMin() const { return m_DateMin; } |
---|
| 189 | |
---|
| 190 | int GetNumFixedPts() const { return m_NumFixedPts; } |
---|
| 191 | int GetNumExportedPts() const { return m_NumExportedPts; } |
---|
| 192 | int GetNumEntrances() const { return m_NumEntrances; } |
---|
| 193 | |
---|
| 194 | bool HasUndergroundLegs() const { return m_HasUndergroundLegs; } |
---|
| 195 | bool HasSplays() const { return m_HasSplays; } |
---|
| 196 | bool HasDupes() const { return m_HasDupes; } |
---|
| 197 | bool HasSurfaceLegs() const { return m_HasSurfaceLegs; } |
---|
| 198 | bool HasTubes() const { return !tubes.empty(); } |
---|
| 199 | bool HasErrorInformation() const { return m_HasErrorInformation; } |
---|
| 200 | |
---|
| 201 | bool IsExtendedElevation() const { return m_IsExtendedElevation; } |
---|
| 202 | |
---|
| 203 | wxChar GetSeparator() const { return m_separator; } |
---|
| 204 | |
---|
| 205 | const wxString& GetCSProj() const { return m_cs_proj; } |
---|
| 206 | |
---|
| 207 | const Vector3& GetOffset() const { return m_Offset; } |
---|
| 208 | |
---|
[1a46879] | 209 | list<traverse>::const_iterator |
---|
| 210 | traverses_begin(unsigned flags, const SurveyFilter* filter) const { |
---|
[bec42b2] | 211 | if (flags >= sizeof(traverses)) return traverses[0].end(); |
---|
[1a46879] | 212 | auto it = traverses[flags].begin(); |
---|
| 213 | if (filter) { |
---|
| 214 | while (it != traverses[flags].end() && |
---|
| 215 | !filter->CheckVisible(it->name)) { |
---|
| 216 | ++it; |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | return it; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | list<traverse>::const_iterator |
---|
| 223 | traverses_next(unsigned flags, const SurveyFilter* filter, |
---|
| 224 | list<traverse>::const_iterator it) const { |
---|
| 225 | ++it; |
---|
| 226 | if (filter) { |
---|
| 227 | while (it != traverses[flags].end() && |
---|
| 228 | !filter->CheckVisible(it->name)) { |
---|
| 229 | ++it; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | return it; |
---|
[bec42b2] | 233 | } |
---|
| 234 | |
---|
| 235 | list<traverse>::const_iterator traverses_end(unsigned flags) const { |
---|
| 236 | if (flags >= sizeof(traverses)) flags = 0; |
---|
| 237 | return traverses[flags].end(); |
---|
| 238 | } |
---|
| 239 | |
---|
[d7078b4] | 240 | list<vector<XSect>>::const_iterator tubes_begin() const { |
---|
[46a9883] | 241 | prepare_tubes(); |
---|
[bec42b2] | 242 | return tubes.begin(); |
---|
| 243 | } |
---|
| 244 | |
---|
[d7078b4] | 245 | list<vector<XSect>>::const_iterator tubes_end() const { |
---|
[bec42b2] | 246 | return tubes.end(); |
---|
| 247 | } |
---|
| 248 | |
---|
[d7078b4] | 249 | list<vector<XSect>>::iterator tubes_begin() { |
---|
[46a9883] | 250 | prepare_tubes(); |
---|
[bec42b2] | 251 | return tubes.begin(); |
---|
| 252 | } |
---|
| 253 | |
---|
[d7078b4] | 254 | list<vector<XSect>>::iterator tubes_end() { |
---|
[bec42b2] | 255 | return tubes.end(); |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | list<LabelInfo*>::const_iterator GetLabels() const { |
---|
| 259 | return m_Labels.begin(); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | list<LabelInfo*>::const_iterator GetLabelsEnd() const { |
---|
| 263 | return m_Labels.end(); |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | list<LabelInfo*>::const_reverse_iterator GetRevLabels() const { |
---|
| 267 | return m_Labels.rbegin(); |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | list<LabelInfo*>::const_reverse_iterator GetRevLabelsEnd() const { |
---|
| 271 | return m_Labels.rend(); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | list<LabelInfo*>::iterator GetLabelsNC() { |
---|
| 275 | return m_Labels.begin(); |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | list<LabelInfo*>::iterator GetLabelsNCEnd() { |
---|
| 279 | return m_Labels.end(); |
---|
| 280 | } |
---|
[46a9883] | 281 | |
---|
| 282 | void prepare_tubes() const { |
---|
| 283 | if (!m_TubesPrepared) { |
---|
| 284 | do_prepare_tubes(); |
---|
| 285 | m_TubesPrepared = true; |
---|
| 286 | } |
---|
| 287 | } |
---|
[bec42b2] | 288 | }; |
---|
| 289 | |
---|
| 290 | #endif |
---|