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 "chart1.h" 29 #include "LLRegion.h" 30 #include "OCPNRegion.h" 31 //#include "chcanv.h" 32 33 extern bool g_bopengl; 34 35 struct ChartTableEntry; 36 37 class QuiltPatch 38 { 39 public: QuiltPatch()40 QuiltPatch() 41 { 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 55 class QuiltCandidate 56 { 57 public: QuiltCandidate()58 QuiltCandidate() 59 { 60 b_include = false; 61 b_eclipsed = false; 62 b_locked = false; 63 last_factor = -1; 64 } 65 66 const LLRegion &GetCandidateRegion(); 67 LLRegion &GetReducedCandidateRegion(double factor); 68 void SetScale(int scale); Scale_eq(int b)69 bool Scale_eq( int b ) const { return abs ( ChartScale - b) <= rounding; } Scale_ge(int b)70 bool Scale_ge( int b ) const { return Scale_eq( b ) || ChartScale > b; } 71 72 int dbIndex; 73 int ChartScale; 74 int rounding; 75 bool b_include; 76 bool b_eclipsed; 77 bool b_locked; 78 79 private: 80 double last_factor; 81 LLRegion reduced_candidate_region; 82 83 }; 84 85 WX_DECLARE_LIST( QuiltPatch, PatchList ); 86 WX_DEFINE_SORTED_ARRAY( QuiltCandidate *, ArrayOfSortedQuiltCandidates ); 87 88 class Quilt 89 { 90 public: 91 92 Quilt( ChartCanvas *parent); 93 ~Quilt(); 94 SetQuiltParameters(double CanvasScaleFactor,int CanvasWidth)95 void SetQuiltParameters( double CanvasScaleFactor, int CanvasWidth ) 96 { 97 m_canvas_scale_factor = CanvasScaleFactor; 98 m_canvas_width = CanvasWidth; 99 } 100 EnableHighDefinitionZoom(bool value)101 void EnableHighDefinitionZoom( bool value ) { m_b_hidef = value;} 102 103 void UnlockQuilt(); 104 bool Compose( const ViewPort &vp ); IsComposed()105 bool IsComposed() { 106 return m_bcomposed; 107 } 108 ChartBase *GetFirstChart(); 109 ChartBase *GetNextChart(); 110 ChartBase *GetLargestScaleChart(); 111 ChartBase *GetNextSmallerScaleChart(); 112 113 std::vector<int> GetQuiltIndexArray( void ); 114 bool IsQuiltDelta( ViewPort &vp ); 115 bool IsChartQuiltableRef( int db_index ); GetQuiltVP()116 ViewPort &GetQuiltVP() { 117 return m_vp_quilt; 118 } GetQuiltDepthUnit()119 wxString GetQuiltDepthUnit() { 120 return m_quilt_depth_unit; 121 } SetRenderedVP(ViewPort & vp)122 void SetRenderedVP( ViewPort &vp ) { 123 m_vp_rendered = vp; 124 } HasOverlays(void)125 bool HasOverlays( void ) { 126 return m_bquilt_has_overlays; 127 } 128 GetExtendedStackCount(void)129 int GetExtendedStackCount(void) { 130 return m_extended_stack_array.size(); 131 } 132 GetnCharts()133 int GetnCharts() { 134 return m_PatchList.GetCount(); 135 } 136 double GetBestStartScale(int dbi_ref_hint, const ViewPort &vp_in); 137 138 139 void ComputeRenderRegion( ViewPort &vp, OCPNRegion &chart_region ); 140 bool RenderQuiltRegionViewOnDCNoText( wxMemoryDC &dc, ViewPort &vp, OCPNRegion &chart_region ); 141 bool RenderQuiltRegionViewOnDCTextOnly( wxMemoryDC &dc, ViewPort &vp, OCPNRegion &chart_region ); 142 143 bool IsVPBlittable( ViewPort &VPoint, int dx, int dy, bool b_allow_vector = false ); 144 ChartBase *GetChartAtPix( ViewPort &VPoint, wxPoint p ); 145 ChartBase *GetOverlayChartAtPix( ViewPort &VPoint, wxPoint p ); 146 int GetChartdbIndexAtPix( ViewPort &VPoint, wxPoint p ); 147 void InvalidateAllQuiltPatchs( void ); Invalidate(void)148 void Invalidate( void ) 149 { 150 m_bcomposed = false; 151 m_vp_quilt.Invalidate(); 152 m_zout_dbindex = -1; 153 154 // Quilting of skewed raster charts is allowed for OpenGL only 155 m_bquiltskew = g_bopengl; 156 // Quilting of different projections is allowed for OpenGL only 157 m_bquiltanyproj = g_bopengl; 158 } 159 void AdjustQuiltVP( ViewPort &vp_last, ViewPort &vp_proposed ); 160 GetFullQuiltRegion(void)161 LLRegion &GetFullQuiltRegion( void ) { 162 return m_covered_region; 163 } GetFullQuiltRenderedRegion(void)164 OCPNRegion &GetFullQuiltRenderedRegion( void ) { 165 return m_rendered_region; 166 } 167 bool IsChartSmallestScale( int dbIndex ); 168 169 int AdjustRefOnZoomOut( double proposed_scale_onscreen ); 170 int AdjustRefOnZoomIn( double proposed_scale_onscreen ); 171 // int AdjustRefOnZoom( bool b_zin, ChartFamilyEnum family, ChartTypeEnum type, double proposed_scale_onscreen ); 172 int AdjustRefSelection(const ViewPort &vp_in); 173 SetHiliteIndex(int index)174 void SetHiliteIndex( int index ) { 175 m_nHiLiteIndex = index; 176 } SetReferenceChart(int dbIndex)177 void SetReferenceChart( int dbIndex ) { 178 m_refchart_dbIndex = dbIndex; 179 if (dbIndex >= 0) { 180 m_zout_family = -1; 181 } 182 } GetRefChartdbIndex(void)183 int GetRefChartdbIndex( void ) { 184 return m_refchart_dbIndex; 185 } 186 187 ChartBase *GetRefChart(); 188 GetQuiltProj(void)189 int GetQuiltProj( void ) 190 { 191 return m_quilt_proj; 192 } GetMaxErrorFactor()193 double GetMaxErrorFactor() 194 { 195 return m_max_error_factor; 196 } GetRefScale()197 double GetRefScale() 198 { 199 return m_reference_scale; 200 } 201 GetRefFamily()202 ChartFamilyEnum GetRefFamily(){ return (ChartFamilyEnum)m_reference_family; } 203 SetPreferrefFamily(ChartFamilyEnum family)204 void SetPreferrefFamily(ChartFamilyEnum family) { m_preferred_family = family; } 205 206 double GetRefNativeScale(); 207 208 std::vector<int> GetCandidatedbIndexArray( bool from_ref_chart, bool exclude_user_hidden ); GetExtendedStackIndexArray()209 std::vector<int> GetExtendedStackIndexArray() 210 { 211 return m_extended_stack_array; 212 } GetEclipsedStackIndexArray()213 std::vector<int> GetEclipsedStackIndexArray() 214 { 215 return m_eclipsed_stack_array; 216 } 217 GetXStackHash()218 unsigned long GetXStackHash() { 219 return m_xa_hash; 220 } 221 IsBusy()222 bool IsBusy() 223 { 224 return m_bbusy; 225 } 226 QuiltPatch *GetCurrentPatch(); 227 bool IsChartInQuilt( ChartBase *pc ); 228 bool IsChartInQuilt( wxString &full_path); 229 230 bool IsQuiltVector( void ); 231 bool DoesQuiltContainPlugins( void ); 232 233 LLRegion GetHiliteRegion( ); 234 static LLRegion GetChartQuiltRegion( const ChartTableEntry &cte, ViewPort &vp ); 235 236 int GetNomScaleMin(int scale, ChartTypeEnum type, ChartFamilyEnum family); 237 int GetNomScaleMax(int scale, ChartTypeEnum type, ChartFamilyEnum family); GetPreferredFamily(void)238 ChartFamilyEnum GetPreferredFamily( void ){ return m_preferred_family; } 239 240 private: 241 bool BuildExtendedChartStackAndCandidateArray(int ref_db_index, ViewPort &vp_in); 242 int AdjustRefOnZoom( bool b_zin, ChartFamilyEnum family, ChartTypeEnum type, double proposed_scale_onscreen ); 243 244 bool DoRenderQuiltRegionViewOnDC( wxMemoryDC &dc, ViewPort &vp, OCPNRegion &chart_region ); 245 bool DoRenderQuiltRegionViewOnDCTextOnly( wxMemoryDC& dc, ViewPort &vp, OCPNRegion &chart_region ); 246 247 void EmptyCandidateArray( void ); 248 void SubstituteClearDC( wxMemoryDC &dc, ViewPort &vp ); 249 int GetNewRefChart( void ); 250 const LLRegion &GetTilesetRegion( int dbIndex); 251 252 253 bool IsChartS57Overlay( int db_index ); 254 255 LLRegion m_covered_region; 256 OCPNRegion m_rendered_region; // used only in dc mode 257 258 PatchList m_PatchList; 259 wxBitmap *m_pBM; 260 261 bool m_bcomposed; 262 wxPatchListNode *cnode; 263 bool m_bbusy; 264 int m_quilt_proj; 265 266 ArrayOfSortedQuiltCandidates *m_pcandidate_array; 267 std::vector<int> m_last_index_array; 268 std::vector<int> m_index_array; 269 std::vector<int> m_extended_stack_array; 270 std::vector<int> m_eclipsed_stack_array; 271 272 ViewPort m_vp_quilt; 273 ViewPort m_vp_rendered; // last VP rendered 274 275 int m_nHiLiteIndex; 276 int m_refchart_dbIndex; 277 int m_reference_scale; 278 int m_reference_type; 279 int m_reference_family; 280 bool m_bneed_clear; 281 LLRegion m_back_region; 282 wxString m_quilt_depth_unit; 283 double m_max_error_factor; 284 double m_canvas_scale_factor; 285 int m_canvas_width; 286 bool m_bquilt_has_overlays; 287 unsigned long m_xa_hash; 288 int m_zout_dbindex; 289 int m_zout_family; 290 int m_zout_type; 291 292 int m_lost_refchart_dbIndex; 293 bool m_b_hidef; 294 295 bool m_bquiltskew; 296 bool m_bquiltanyproj; 297 ChartFamilyEnum m_preferred_family; 298 ChartCanvas *m_parent; 299 300 }; 301 302 #endif 303