OpenCPN Partial API docs
Quilt.h
1 /******************************************************************************
2  *
3  * Project: OpenCPN
4  *
5  ***************************************************************************
6  * Copyright (C) 2013 by David S. Register *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22  ***************************************************************************
23  */
24 
25 #ifndef __QUIT_H__
26 #define __QUIT_H__
27 
28 #include <vector>
29 #include "LLRegion.h"
30 #include "OCPNRegion.h"
31 #include "chcanv.h"
32 #include "viewport.h"
33 #include "chartdb.h"
34 
35 extern bool g_bopengl;
36 
37 struct ChartTableEntry;
38 
39 class QuiltPatch {
40 public:
41  QuiltPatch() {
42  b_Valid = false;
43  b_eclipsed = false;
44  b_overlay = false;
45  }
46  int dbIndex;
47  LLRegion ActiveRegion;
48  int ProjType;
49  bool b_Valid;
50  bool b_eclipsed;
51  bool b_overlay;
52  LLRegion quilt_region;
53 };
54 
56 public:
57  QuiltCandidate() {
58  b_include = false;
59  b_eclipsed = false;
60  last_factor = -1;
61  }
62 
63  const LLRegion &GetCandidateRegion();
64  LLRegion &GetReducedCandidateRegion(double factor);
65  void SetScale(int scale);
66  bool Scale_eq(int b) const { return abs(ChartScale - b) <= rounding; }
67  bool Scale_ge(int b) const { return Scale_eq(b) || ChartScale > b; }
68 
69  int dbIndex;
70  int ChartScale;
71  int rounding;
72  bool b_include;
73  bool b_eclipsed;
74 
75 private:
76  double last_factor;
77  LLRegion reduced_candidate_region;
78 };
79 
80 WX_DECLARE_LIST(QuiltPatch, PatchList);
81 WX_DEFINE_SORTED_ARRAY(QuiltCandidate *, ArrayOfSortedQuiltCandidates);
82 
83 class Quilt {
84 public:
85  Quilt(ChartCanvas *parent);
86  ~Quilt();
87 
88  void SetQuiltParameters(double CanvasScaleFactor, int CanvasWidth) {
89  m_canvas_scale_factor = CanvasScaleFactor;
90  m_canvas_width = CanvasWidth;
91  }
92 
93  void EnableHighDefinitionZoom(bool value) { m_b_hidef = value; }
94 
95  void UnlockQuilt();
96  bool Compose(const ViewPort &vp);
97  bool IsComposed() { return m_bcomposed; }
98  ChartBase *GetFirstChart();
99  ChartBase *GetNextChart();
100  ChartBase *GetLargestScaleChart();
101  ChartBase *GetNextSmallerScaleChart();
102 
103  std::vector<int> GetQuiltIndexArray(void);
104  bool IsQuiltDelta(ViewPort &vp);
105  bool IsChartQuiltableRef(int db_index);
106  ViewPort &GetQuiltVP() { return m_vp_quilt; }
107  wxString GetQuiltDepthUnit() { return m_quilt_depth_unit; }
108  void SetRenderedVP(ViewPort &vp) { m_vp_rendered = vp; }
109  bool HasOverlays(void) { return m_bquilt_has_overlays; }
110 
111  int GetExtendedStackCount(void) { return m_extended_stack_array.size(); }
112  int GetFullScreenIndexCount(void) { return m_fullscreen_index_array.size(); }
113 
114  int GetnCharts() { return m_PatchList.GetCount(); }
115  double GetBestStartScale(int dbi_ref_hint, const ViewPort &vp_in);
116 
117  void ComputeRenderRegion(ViewPort &vp, OCPNRegion &chart_region);
118  bool RenderQuiltRegionViewOnDCNoText(wxMemoryDC &dc, ViewPort &vp,
119  OCPNRegion &chart_region);
120  bool RenderQuiltRegionViewOnDCTextOnly(wxMemoryDC &dc, ViewPort &vp,
121  OCPNRegion &chart_region);
122 
123  bool IsVPBlittable(ViewPort &VPoint, int dx, int dy,
124  bool b_allow_vector = false);
125  ChartBase *GetChartAtPix(ViewPort &VPoint, wxPoint p);
126  ChartBase *GetOverlayChartAtPix(ViewPort &VPoint, wxPoint p);
127  int GetChartdbIndexAtPix(ViewPort &VPoint, wxPoint p);
128  void InvalidateAllQuiltPatchs(void);
129  void Invalidate(void) {
130  m_bcomposed = false;
131  m_vp_quilt.Invalidate();
132  m_zout_dbindex = -1;
133 
134  // Quilting of skewed raster charts is allowed for OpenGL only
135  m_bquiltskew = g_bopengl;
136  // Quilting of different projections is allowed for OpenGL only
137  m_bquiltanyproj = g_bopengl;
138  }
139  void AdjustQuiltVP(ViewPort &vp_last, ViewPort &vp_proposed);
140 
141  LLRegion &GetFullQuiltRegion(void) { return m_covered_region; }
142  OCPNRegion &GetFullQuiltRenderedRegion(void) { return m_rendered_region; }
143  bool IsChartSmallestScale(int dbIndex);
144 
145  int AdjustRefOnZoomOut(double proposed_scale_onscreen);
146  int AdjustRefOnZoomIn(double proposed_scale_onscreen);
147  // int AdjustRefOnZoom( bool b_zin, ChartFamilyEnum family, ChartTypeEnum
148  // type, double proposed_scale_onscreen );
149  int AdjustRefSelection(const ViewPort &vp_in);
150 
151  void SetHiliteIndex(int index) { m_nHiLiteIndex = index; }
152  void SetHiliteIndexArray(const std::vector<int> &index_array) {
153  m_HiLiteIndexArray = index_array; }
154  void ClearHiliteIndexArray() { m_HiLiteIndexArray.clear(); }
155 
156  void SetReferenceChart(int dbIndex) {
157  m_refchart_dbIndex = dbIndex;
158  if (dbIndex >= 0) {
159  m_zout_family = -1;
160  }
161  }
162  int GetRefChartdbIndex(void) { return m_refchart_dbIndex; }
163 
164  ChartBase *GetRefChart();
165 
166  int GetQuiltProj(void) { return m_quilt_proj; }
167  double GetMaxErrorFactor() { return m_max_error_factor; }
168  double GetRefScale() { return m_reference_scale; }
169 
170  ChartFamilyEnum GetRefFamily() { return (ChartFamilyEnum)m_reference_family; }
171 
172  void SetPreferrefFamily(ChartFamilyEnum family) {
173  m_preferred_family = family;
174  }
175 
176  double GetRefNativeScale();
177 
178  std::vector<int> GetCandidatedbIndexArray(bool from_ref_chart,
179  bool exclude_user_hidden);
180  std::vector<int> &GetExtendedStackIndexArray() {
181  return m_extended_stack_array;
182  }
183  std::vector<int> GetEclipsedStackIndexArray() {
184  return m_eclipsed_stack_array;
185  }
186  std::vector<int> &GetFullscreenIndexArray() {
187  return m_fullscreen_index_array;
188  }
189 
190  unsigned long GetXStackHash() { return m_xa_hash; }
191 
192  bool IsBusy() { return m_bbusy; }
193  QuiltPatch *GetCurrentPatch();
194  bool IsChartInQuilt(ChartBase *pc);
195  bool IsChartInQuilt(wxString &full_path);
196 
197  bool IsQuiltVector(void);
198  bool DoesQuiltContainPlugins(void);
199 
200  LLRegion GetHiliteRegion();
201  std::vector<int> &GetHiLiteIndexArray(){ return m_HiLiteIndexArray; }
202 
203  static LLRegion GetChartQuiltRegion(const ChartTableEntry &cte, ViewPort &vp);
204 
205  int GetNomScaleMin(int scale, ChartTypeEnum type, ChartFamilyEnum family);
206  int GetNomScaleMax(int scale, ChartTypeEnum type, ChartFamilyEnum family);
207  ChartFamilyEnum GetPreferredFamily(void) { return m_preferred_family; }
208 
209 private:
210  bool BuildExtendedChartStackAndCandidateArray(int ref_db_index,
211  ViewPort &vp_in);
212  int AdjustRefOnZoom(bool b_zin, ChartFamilyEnum family, ChartTypeEnum type,
213  double proposed_scale_onscreen);
214 
215  bool DoRenderQuiltRegionViewOnDC(wxMemoryDC &dc, ViewPort &vp,
216  OCPNRegion &chart_region);
217  bool DoRenderQuiltRegionViewOnDCTextOnly(wxMemoryDC &dc, ViewPort &vp,
218  OCPNRegion &chart_region);
219 
220  void EmptyCandidateArray(void);
221  void SubstituteClearDC(wxMemoryDC &dc, ViewPort &vp);
222  int GetNewRefChart(void);
223  const LLRegion &GetTilesetRegion(int dbIndex);
224 
225  bool IsChartS57Overlay(int db_index);
226 
227  LLRegion m_covered_region;
228  OCPNRegion m_rendered_region; // used only in dc mode
229 
230  PatchList m_PatchList;
231  wxBitmap *m_pBM;
232 
233  bool m_bcomposed;
234  wxPatchListNode *cnode;
235  bool m_bbusy;
236  int m_quilt_proj;
237 
238  ArrayOfSortedQuiltCandidates *m_pcandidate_array;
239  std::vector<int> m_last_index_array;
240  std::vector<int> m_index_array;
241  std::vector<int> m_extended_stack_array;
242  std::vector<int> m_eclipsed_stack_array;
243  std::vector<int> m_fullscreen_index_array;
244 
245  ViewPort m_vp_quilt;
246  ViewPort m_vp_rendered; // last VP rendered
247 
248  int m_nHiLiteIndex;
249  std::vector<int> m_HiLiteIndexArray;
250  int m_refchart_dbIndex;
251  int m_reference_scale;
252  int m_reference_type;
253  int m_reference_family;
254  bool m_bneed_clear;
255  LLRegion m_back_region;
256  wxString m_quilt_depth_unit;
257  double m_max_error_factor;
258  double m_canvas_scale_factor;
259  int m_canvas_width;
260  bool m_bquilt_has_overlays;
261  unsigned long m_xa_hash;
262  int m_zout_dbindex;
263  int m_zout_family;
264  int m_zout_type;
265 
266  int m_lost_refchart_dbIndex;
267  bool m_b_hidef;
268 
269  bool m_bquiltskew;
270  bool m_bquiltanyproj;
271  ChartFamilyEnum m_preferred_family;
272  ChartCanvas *m_parent;
273 };
274 
275 #endif
Definition: Quilt.h:83
bool Compose(const ViewPort &vp)
Definition: Quilt.cpp:1694
Definition: Quilt.cpp:867