source: git/src/model.h @ e49b289

RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereo-2025walls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since e49b289 was d7078b4, checked in by Olly Betts <olly@…>, 7 years ago

Make use of C++11 to avoid needing to write > >

  • Property mode set to 100644
File size: 7.6 KB
Line 
1//
2//  model.h
3//
4//  Cave survey model.
5//
6//  Copyright (C) 2000-2003,2005 Mark R. Shinwell
7//  Copyright (C) 2001-2003,2004,2005,2006,2010,2011,2012,2013,2014,2015,2016 Olly Betts
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>
34#include <set>
35#include <vector>
36
37using namespace std;
38
39class MainFrm;
40
41class PointInfo : public Point {
42    int date;
43
44public:
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
52class XSect {
53    friend class MainFrm;
54    const LabelInfo* stn;
55    int date;
56    double l, r, u, d;
57    double right_bearing;
58
59public:
60    XSect(const LabelInfo* stn_, int date_,
61          double l_, double r_, double u_, double d_)
62        : stn(stn_), date(date_), l(l_), r(r_), u(u_), d(d_), right_bearing(0) { }
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    }
71    int GetDate() const { return date; }
72    wxString GetLabel() const { return stn->GetText(); }
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);
78};
79
80inline Vector3 operator-(const XSect& a, const XSect& b) {
81    return *(a.stn) - *(b.stn);
82}
83
84class traverse : public vector<PointInfo> {
85  public:
86    int n_legs;
87    // Bitmask of img_FLAG_SURFACE, img_FLAG_SPLAY and img_FLAG_DUPLICATE.
88    int flags;
89    double length;
90    double E, H, V;
91    wxString name;
92
93    explicit
94    traverse(const char* name_)
95        : n_legs(0), flags(0),
96          length(0), E(-1), H(-1), V(-1),
97          name(name_, wxConvUTF8) {
98        if (name.empty() && !name_[0]) {
99            // If name isn't valid UTF-8 then this conversion will
100            // give an empty string.  In this case, assume that the
101            // label is CP1252 (the Microsoft superset of ISO8859-1).
102            static wxCSConv ConvCP1252(wxFONTENCODING_CP1252);
103            name = wxString(name_, ConvCP1252);
104            if (name.empty()) {
105                // Or if that doesn't work (ConvCP1252 doesn't like
106                // strings with some bytes in) let's just go for
107                // ISO8859-1.
108                name = wxString(name_, wxConvISO8859_1);
109            }
110        }
111    }
112};
113
114class SurveyFilter {
115    std::set<wxString, std::greater<wxString>> filters;
116    wxChar separator = 0;
117
118  public:
119    SurveyFilter() {}
120
121    void add(const wxString& survey) { filters.insert(survey); }
122
123    void remove(const wxString& survey) { filters.erase(survey); }
124
125    void clear() { filters.clear(); }
126
127    bool empty() const { return filters.empty(); }
128
129    void SetSeparator(wxChar separator_) { separator = separator_; }
130
131    bool CheckVisible(const wxString& name) const;
132};
133
134/// Cave model.
135class Model {
136    list<traverse> traverses[8];
137    list<vector<XSect>> tubes;
138
139  public: // FIXME
140    list<LabelInfo*> m_Labels;
141
142  private:
143    Vector3 m_Ext;
144    double m_DepthMin, m_DepthExt;
145    int m_DateMin, m_DateExt;
146    bool complete_dateinfo;
147    int m_NumEntrances = 0;
148    int m_NumFixedPts = 0;
149    int m_NumExportedPts = 0;
150    bool m_HasUndergroundLegs = false;
151    bool m_HasSplays = false;
152    bool m_HasDupes = false;
153    bool m_HasSurfaceLegs = false;
154    bool m_HasErrorInformation = false;
155    bool m_IsExtendedElevation = false;
156
157    // Character separating survey levels (often '.')
158    wxChar m_separator;
159
160    wxString m_Title, m_cs_proj, m_DateStamp;
161
162    time_t m_DateStamp_numeric;
163
164    Vector3 m_Offset;
165
166  public:
167    int Load(const wxString& file, const wxString& prefix);
168
169    void CentreDataset(const Vector3& vmin);
170
171    const Vector3& GetExtent() const { return m_Ext; }
172
173    const wxString& GetSurveyTitle() const { return m_Title; }
174
175    const wxString& GetDateString() const { return m_DateStamp; }
176
177    time_t GetDateStamp() const { return m_DateStamp_numeric; }
178
179    double GetDepthExtent() const { return m_DepthExt; }
180    double GetDepthMin() const { return m_DepthMin; }
181
182    bool HasCompleteDateInfo() const { return complete_dateinfo; }
183    int GetDateExtent() const { return m_DateExt; }
184    int GetDateMin() const { return m_DateMin; }
185
186    int GetNumFixedPts() const { return m_NumFixedPts; }
187    int GetNumExportedPts() const { return m_NumExportedPts; }
188    int GetNumEntrances() const { return m_NumEntrances; }
189
190    bool HasUndergroundLegs() const { return m_HasUndergroundLegs; }
191    bool HasSplays() const { return m_HasSplays; }
192    bool HasDupes() const { return m_HasDupes; }
193    bool HasSurfaceLegs() const { return m_HasSurfaceLegs; }
194    bool HasTubes() const { return !tubes.empty(); }
195    bool HasErrorInformation() const { return m_HasErrorInformation; }
196
197    bool IsExtendedElevation() const { return m_IsExtendedElevation; }
198
199    wxChar GetSeparator() const { return m_separator; }
200
201    const wxString& GetCSProj() const { return m_cs_proj; }
202
203    const Vector3& GetOffset() const { return m_Offset; }
204
205    list<traverse>::const_iterator
206    traverses_begin(unsigned flags, const SurveyFilter* filter) const {
207        if (flags >= sizeof(traverses)) return traverses[0].end();
208        auto it = traverses[flags].begin();
209        if (filter) {
210            while (it != traverses[flags].end() &&
211                   !filter->CheckVisible(it->name)) {
212                ++it;
213            }
214        }
215        return it;
216    }
217
218    list<traverse>::const_iterator
219    traverses_next(unsigned flags, const SurveyFilter* filter,
220                   list<traverse>::const_iterator it) const {
221        ++it;
222        if (filter) {
223            while (it != traverses[flags].end() &&
224                   !filter->CheckVisible(it->name)) {
225                ++it;
226            }
227        }
228        return it;
229    }
230
231    list<traverse>::const_iterator traverses_end(unsigned flags) const {
232        if (flags >= sizeof(traverses)) flags = 0;
233        return traverses[flags].end();
234    }
235
236    list<vector<XSect>>::const_iterator tubes_begin() const {
237        return tubes.begin();
238    }
239
240    list<vector<XSect>>::const_iterator tubes_end() const {
241        return tubes.end();
242    }
243
244    list<vector<XSect>>::iterator tubes_begin() {
245        return tubes.begin();
246    }
247
248    list<vector<XSect>>::iterator tubes_end() {
249        return tubes.end();
250    }
251
252    list<LabelInfo*>::const_iterator GetLabels() const {
253        return m_Labels.begin();
254    }
255
256    list<LabelInfo*>::const_iterator GetLabelsEnd() const {
257        return m_Labels.end();
258    }
259
260    list<LabelInfo*>::const_reverse_iterator GetRevLabels() const {
261        return m_Labels.rbegin();
262    }
263
264    list<LabelInfo*>::const_reverse_iterator GetRevLabelsEnd() const {
265        return m_Labels.rend();
266    }
267
268    list<LabelInfo*>::iterator GetLabelsNC() {
269        return m_Labels.begin();
270    }
271
272    list<LabelInfo*>::iterator GetLabelsNCEnd() {
273        return m_Labels.end();
274    }
275};
276
277#endif
Note: See TracBrowser for help on using the repository browser.