Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
ScaledView.h
1 //
2 // ScaledView.h
3 //
4 // Copyright (c) 2001-2008 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef SCALEDVIEWH
9 #define SCALEDVIEWH
10 
11 #include "vtdata/MathTypes.h"
12 #include "ogr_geometry.h"
13 
14 class vtScaledView : public wxScrolledWindow
15 {
16 public:
17  vtScaledView(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
18  const wxSize& size = wxDefaultSize, long style = wxHSCROLL | wxVSCROLL, const wxString& name = _T(""));
19 
20  void SetScale(double scale);
21  double GetScale();
22 
23  void ZoomToPoint(const DPoint2 &p);
24  void ZoomToRect(const DRECT &geo_rect, float margin);
25  void ZoomOutToRect(const DRECT &geo_rect);
26 
27  wxRect WorldToCanvas(const DRECT &r);
28  wxRect WorldToWindow(const DRECT &r);
29  DRECT CanvasToWorld(const wxRect &r);
30 
31  void GetCanvasPosition(const wxMouseEvent &event, wxPoint &pos);
32  DRECT GetWorldRect();
33  wxRect PointsToRect(const wxPoint &p1, const wxPoint &p2);
34 
35  // transform object space -> screen space
36  int sx(double x) { return (int)(x*m_fScale - m_limits.x); }
37  int sy(double y) { return (int)(-y*m_fScale - m_limits.y); }
38  void screen(const DPoint2 &p, wxPoint &sp) const
39  {
40  sp.x = (int)(p.x*m_fScale - m_limits.x);
41  sp.y = (int)(-p.y*m_fScale - m_limits.y);
42  }
43  void screen(const OGRPoint *p, wxPoint &sp) const
44  {
45  sp.x = (int)(p->getX()*m_fScale - m_limits.x);
46  sp.y = (int)(-(p->getY())*m_fScale - m_limits.y);
47  }
48  // transform object space -> screen space (relative delta)
49  int sdx(double x) { return (int)(x*m_fScale); }
50  int sdy(double y) { return (int)(-y*m_fScale); }
51 
52  wxPoint screen_delta(const DPoint2 &p) const
53  {
54  wxPoint sp;
55  sp.x = (int)(p.x*m_fScale);
56  sp.y = (int)(-p.y*m_fScale);
57  return sp;
58  }
59 
60  // transform screen space -> object space
61  double ox(int x) { return (x + m_limits.x) / m_fScale; }
62  double oy(int y) { return -(y + m_limits.y) / m_fScale; }
63  void object(const wxPoint &sp, DPoint2 &p) const
64  {
65  p.x = (sp.x + m_limits.x) / m_fScale;
66  p.y = -(sp.y + m_limits.y) / m_fScale;
67  }
68 
69  // transform screen space -> object space (relative delta)
70  double odx(int x) { return x/m_fScale; }
71  double ody(int y) { return -y/m_fScale; }
72 
73  void DrawLine(wxDC *pDC, const DPoint2 &p0, const DPoint2 &p1);
74  void DrawPolyLine(wxDC *pDC, const DLine2 &line, bool bClose);
75  void DrawDoubleLine(wxDC *pDC, const DLine2 &line, const DLine2 &width);
76  void DrawPolygon(wxDC *pDC, const DPolygon2 &poly, bool bFill);
77 
78  void DrawOGRLinearRing(wxDC *pDC, const OGRLinearRing *line, bool bCircles);
79  void DrawOGRPolygon(wxDC *pDC, const OGRPolygon &poly, bool bFill, bool bCircles);
80  void DrawDPolygon2(wxDC *pDC, const DPolygon2 &poly, bool bFill, bool bCircles);
81 
82 protected:
83  void UpdateRanges();
84 
85  double m_fScale; // pixels per UTM meter/pixel per degree
86  wxRect m_limits; // allowed range of m_offset
87 };
88 
89 #define SCREENBUF_SIZE 32000
90 extern wxPoint g_screenbuf[SCREENBUF_SIZE];
91 
92 #endif