Version: 0.6.0
gisdisplay.h
1 /******************************************************************************
2  * Project: wxGIS
3  * Purpose: wxGISDisplay class.
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2011-2014 Dmitry Baryshnikov
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, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 
23 #include "wxgis/display/color.h"
24 
25 #undef LT_OBJDIR
26 #include "ogrsf_frmts.h"
27 #include "gdal_priv.h"
28 
29 #include <cairo.h>
30 
31 #ifdef __WXMSW__
32  #include <cairo-win32.h>
33 #endif
34 
35 WX_DEFINE_ARRAY(wxRealPoint*, wxGISPointsArray);
36 
43 class WXDLLIMPEXP_GIS_DSP wxGISDisplay
44 {
45 public:
46  wxGISDisplay(void);
47  virtual ~wxGISDisplay(void);
48  //
49  virtual size_t AddCache(void);
50  virtual void Clear();
51  virtual size_t GetLastCacheID(void) const;
52  virtual size_t GetFlashCacheID(void) const;
53  virtual void SetDrawCache(size_t nCacheID, bool bNoDerty = false);
54  virtual size_t GetDrawCache(void) const;
55  virtual bool IsCacheDerty(size_t nCacheID) const;
56  virtual void SetCacheDerty(size_t nCacheID, bool bIsDerty);
57  virtual void SetAllCachesDerty(bool bIsDerty);
58  virtual void SetUpperCachesDerty(size_t nFromCacheNo, bool bIsDerty = true);
59  virtual bool IsDerty(void) const;
60  virtual size_t GetCacheCount(void) const {return m_saLayerCaches.size();};
61  virtual void ClearCache(size_t nCacheId);
62 
63  //frame
64  virtual void SetDeviceFrame(wxRect &rc);
65  virtual wxRect GetDeviceFrame(void) const;
66  //current draw bounds
67  virtual void SetBounds(const OGREnvelope &Env);
68  virtual OGREnvelope GetBounds(bool bRotated = true) const;
69  virtual wxRealPoint GetBoundsCenter(void) const {return wxRealPoint(m_dRotatedBoundsCenterX, m_dRotatedBoundsCenterY);};
70  //misc
71  virtual void SetRotate(double dAngleRad);
72  virtual double GetRotate(void) const {return m_dAngleRad;};
73  virtual void DC2World(double* pdX, double* pdY);
74  virtual void World2DC(double* pdX, double* pdY);
75  virtual void DC2WorldDist(double* pdX, double* pdY, bool bRotated = true);
76  virtual void World2DCDist(double* pdX, double* pdY, bool bRotated = true);
77  //
78  virtual void OnEraseBackground(void); //Fill #0 cache of background color
79  virtual void Output(wxDC* pDC);
80  virtual bool Output(GDALDataset *pGDALDataset);
81  //Styles
82  virtual void SetColor(const wxGISColor &Color);
83  virtual void SetLineCap(cairo_line_cap_t line_cap = CAIRO_LINE_CAP_BUTT);
84  virtual void SetLineJoin(cairo_line_join_t line_join = CAIRO_LINE_JOIN_MITER);
85  virtual void SetLineWidth(double dWidth);
86  virtual void SetMiterLimit(double dMiterLimit);
87  virtual void SetFillRule(cairo_fill_rule_t fill_rule = CAIRO_FILL_RULE_WINDING);
88  //Draw
89  virtual bool CanDraw(OGREnvelope &Env);
90  virtual void Stroke();
91  virtual void FillPreserve();
92  virtual void SetColor(double dRed, double dGreen, double dBlue, double dAlpha = 0);
93  virtual bool CheckDrawAsPoint(const OGREnvelope &Envelope, double dfLineWidth, bool bIsRing = true, double dOffsetX = 0, double dOffsetY = 0, bool bCheckEnvelope = false);
94  virtual bool DrawCircle(double dX, double dY, double dOffsetX = 0, double dOffsetY = 0, double dfRadius = 1.0, double angle1 = 0, double angle2 = 2 * M_PI);
95  virtual bool DrawEllipse(double dX, double dY, double dOffsetX = 0, double dOffsetY = 0, double dfWidth = 1.0, double dfHeight = 1.0);
96  virtual bool DrawPointFast(double dX, double dY, double dOffsetX = 0, double dOffsetY = 0);
97  virtual bool DrawLine(OGRRawPoint* pOGRRawPoints, int nPointCount, bool bOwn = true, double dOffsetX = 0, double dOffsetY = 0, bool bIsRing = false);
98  virtual void DrawRaster(cairo_surface_t *surface, const OGREnvelope& Envelope, bool bDrawEnvelope = false);
99  virtual void ZoomingDraw(const wxRect& rc, wxDC* pDC);
100  virtual void WheelingDraw(double dZoom, wxDC* pDC);
101  virtual void PanningDraw(wxCoord x, wxCoord y, wxDC* pDC);
102  virtual void RotatingDraw(double dAngle, wxDC* pDC);
103  virtual OGREnvelope TransformRect(wxRect &rect);
104  //Testing
105  virtual void TestDraw(void);
106 
107  typedef struct _layercachedata
108  {
109  bool bIsDerty;
110  cairo_surface_t *pCairoSurface;
111  cairo_t *pCairoContext;
112  } LAYERCACHEDATA;
113  virtual wxCriticalSection &GetLock();
114 protected:
115  virtual void Output(cairo_surface_t *pSurface, wxDC* pDC);
116  virtual cairo_t* CreateContext(wxDC* dc);
117  virtual void InitTransformMatrix(void);
118  virtual inline double GetScaledWidth(double nWidth)
119  {
120  double x_new, y_new;
121  x_new = y_new = nWidth;
122  DC2WorldDist(&x_new, &y_new);
123  return (fabs(x_new) + fabs(y_new)) / 2;
124  }
125 protected:
126  wxVector<LAYERCACHEDATA> m_saLayerCaches;
127  wxGISColor m_BackGroudnColour;
128  size_t m_nLastCacheID, m_nCurrentLayer;
129  int m_nMax_X, m_nMax_Y;
130  wxRect m_oDeviceFrameRect;
131  OGREnvelope m_RealBounds, m_CurrentBounds, m_CurrentBoundsRotated, m_CurrentBoundsX8;
132  double m_dRotatedBoundsCenterX, m_dRotatedBoundsCenterY;
133  //wxSize m_ppi;
134  double m_dAngleRad;
135  cairo_matrix_t *m_pMatrix, *m_pDisplayMatrix, *m_pDisplayMatrixNoRotate;
136  double m_dOrigin_X, m_dOrigin_Y;
137  double m_dFrameCenterX, m_dFrameCenterY;
138  double m_dCacheCenterX, m_dCacheCenterY;
139  double m_dFrameXShift, m_dFrameYShift;
140  wxCriticalSection m_CritSect;
141  bool m_bZeroCacheSet;
142  double m_dFrameRatio;
143  double m_dScale;
144  int m_nSysCacheCount;
145  double m_dfLineWidth;
146 
147  //temp cairo for output double buffering
148  cairo_surface_t *m_surface_tmp;
149  cairo_t *m_cr_tmp;
150 };
Definition: gisdisplay.h:43
Definition: gisdisplay.h:107
Definition: color.h:34