Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
BExtractorView.h
1 //
2 // BExtractorView.h : interface of the BExtractorView class
3 //
4 // Copyright (c) 2001-2008 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #if !defined(AFX_B_EXTRACTORVIEW_H)
9 #define AFX_B_EXTRACTORVIEW_H
10 
11 #if _MSC_VER >= 1000
12 #pragma once
13 #endif // _MSC_VER >= 1000
14 
15 #include "vtdata/Building.h"
16 
17 #define BLENGTH 6
18 
19 #define NODE_CAPTURE_THRESHOLD 10.0 // Metres
20 
21 enum LBMode {
22  LB_AddRemove, // click to add, drag to remove
23  LB_Hand, // drag to pan
24  LB_Footprint, // click to add footprints
25  LB_Rectangle, // click to add rectangular footprints
26  LB_Circle,
27  LB_EditShape,
28  LB_EditRoadNodes,
29  LB_EditRoad
30 };
31 
32 class BExtractorDoc;
33 class CBImage;
34 class TNode;
35 class TLink;
36 
37 class BExtractorView : public CView
38 {
39 protected: // create from serialization only
41  DECLARE_DYNCREATE(BExtractorView)
42 
43 // Attributes
44 public:
45  BExtractorDoc* GetDocument();
46  DPoint2 GetCurLocation() { return m_curLocation; }
47 
48 // Operations
49 public:
50  void ReadDataPath();
51 
52  void ZoomToImage(CBImage *pImage);
53  void DrawBuildings(CDC *pDC);
54  void DrawBuilding(CDC *pDC, vtBuilding *bld);
55  void DrawRoadNodes(CDC *pDC);
56  void DrawRoadNode(CDC *pDC, TNode *pNode);
57  void DrawRoads(CDC *pDC);
58  void DrawRoad(CDC *pDC, TLink *pLink);
59  bool FindNearestRoadNode(CPoint &point, TNode **pNearestNode);
60  bool ReadINIFile();
61  bool WriteINIFile();
62  bool SelectionOnPicture(DPoint2 point);
63 
64 // Overrides
65  // ClassWizard generated virtual function overrides
66  //{{AFX_VIRTUAL(BExtractorView)
67  public:
68  virtual void OnDraw(CDC* pDC); // overridden to draw this view
69  virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
70  virtual void OnInitialUpdate();
71  protected:
72  virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
73  //}}AFX_VIRTUAL
74 
75 // Implementation
76 protected:
77  virtual ~BExtractorView();
78 
79 #ifdef _DEBUG
80  virtual void AssertValid() const;
81  virtual void Dump(CDumpContext& dc) const;
82 #endif
83 
84 protected:
85  // For scaling and panning the view
86  CPoint m_offset; // pixel offset between UTM and screen origins
87  CPoint m_offset_base; // minimum value of m_offset
88  CPoint m_offset_size; // range m_offset
89  double m_fScale; // meters/screen_pixel
90  int m_scrollposH;
91  int m_scrollposV;
92 
93  // Left Mouse Button Mode
94  LBMode m_mode;
95 
96  CPoint m_old_offset; // saved to calculate new position for hand mode
97  CPoint m_oldPoint;
98  CPoint m_lastMousePoint;
99 
100  // Used for the space-bar zoom effect
101  bool m_zoomed;
102  CPoint m_SavedOffset; // used to save offset when we ZoomToBuilding
103  double m_fSavedScale; // used to save Scale when we ZoomToBuilding
104 
105  // Color used to draw the buildings
106  COLORREF m_buildingColor;
107 
108  // Color used to draw the roads
109  COLORREF m_roadColor;
110 
111  // Current road when plotting roads
112  TLink *m_pCurrentRoad;
113 
114  // Directory path at startup, used to locate the .ini file
115  char m_directory[MAX_PATH];
116 
117  // Used while defining a new building polygon
118  DLine2 m_poly;
119 
120  // Used while dragging the mouse
121  bool m_maybeRect;
122  bool m_bPanning; // true while panning
123  bool m_bRubber;
124  float m_fPixelRadius;
125  int m_iStep; // steps to a rectangle
126  CPoint m_p0, m_p1, m_p2, m_p3;
127  CPoint m_downPoint; // point at which mouse was clicked down (used in hand mode and mop-up mode
128  DPoint2 m_downLocation;
129  DPoint2 m_curLocation;
130  DPoint2 m_curBuildingCenter;
131 
132  // Used while editing buildings
133  vtBuilding *m_pCurBuilding, m_EditBuilding;
134  int m_iCurCorner;
135  bool m_bDragCenter;
136  bool m_bRotate;
137  bool m_bControl;
138  bool m_bShift;
139  bool m_bConstrain;
140 
141  // transform screen space -> UTM space
142  double s_UTMx(int sx) { return ((sx - m_offset.x) * m_fScale); }
143  double s_UTMy(int sy) { return -((sy - m_offset.y) * m_fScale); }
144  void s_UTM(CPoint &p, DPoint2 &utm)
145  {
146  utm.x = s_UTMx(p.x);
147  utm.y = s_UTMy(p.y);
148  }
149 
150  // transform UTM space -> screen space
151  int UTM_sx(double utm_x) { return (int)((utm_x / m_fScale) + m_offset.x); }
152  int UTM_sy(double utm_y) { return (int)((-utm_y / m_fScale) + m_offset.y); }
153  void UTM_s(const DPoint2 &utm, CPoint &p)
154  {
155  p.x = UTM_sx((float)utm.x);
156  p.y = UTM_sy((float)utm.y);
157  }
158 
159  // transform UTM space -> screen space
160  int UTM_sdx(double utm_x) { return (int)(utm_x / m_fScale); }
161  int UTM_sdy(double utm_y) { return (int)(-utm_y / m_fScale); }
162  CPoint UTM_sd(const DPoint2 &utm)
163  {
164  return CPoint((int)(utm.x / m_fScale),
165  (int)(-utm.y / m_fScale));
166  }
167  double s_UTMdx(double sx) { return (sx * m_fScale); }
168  double s_UTMdy(double sy) { return (-sy * m_fScale); }
169  CRect screen(const DRECT &r)
170  {
171  CRect r2;
172  r2.left = UTM_sx(r.left);
173  r2.top = UTM_sy(r.top);
174  r2.right = UTM_sx(r.right);
175  r2.bottom = UTM_sy(r.bottom);
176  return r2;
177  }
178 
179  void ChangeScale(double fFactor);
180  void MopRemove(const DPoint2 &start, const DPoint2 &end);
181  void MopRemoveRoadNodes(const DPoint2 &start, const DPoint2 &end);
182  void DrawRect(CDC *pDC, CPoint one, CPoint two);
183  void ZoomToBuilding();
184  void UpdateRanges();
185  void ClipOffset();
186  void UpdateScrollPos();
187  void OnLButtonDownEditShape(UINT nFlags, CPoint point);
188  void OnLButtonDownEditRoad(UINT nFlags, CPoint point);
189  void OnLButtonUpAddRemove(CPoint point);
190  void OnLButtonUpFootprint(CPoint point);
191  void OnLButtonUpRectangle(CPoint point);
192  void OnLButtonUpCircle(CPoint point);
193  void OnLButtonUpEditRoadNodes(CPoint point);
194  CDC *GetInvertDC();
195  void DoPan(CPoint point);
196  void DrawPoly(CDC *pDC);
197  void UpdateRectangle(CPoint point);
198  void DrawRectangle(CDC *pDC);
199  void InvalidatePolyExtent();
200  void UpdateCircle(CPoint point);
201  void DrawCircle(CDC *pDC);
202  void DrawCircle(CDC *pDC, CPoint &center, int iRadius);
203 
204  void UpdateMove();
205  void UpdateResizeScale();
206  void UpdateRotate();
207  void DrawCurrentBuilding(CDC *pDC);
208  void ContrainLocationForPoly();
209 
210  void SetMode(LBMode mode);
211  void CancelFootprint();
212  void CancelShape();
213 
214 // Generated message map functions
215 protected:
216  //{{AFX_MSG(BExtractorView)
217  afx_msg void OnColorChange();
218  afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
219  afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
220  afx_msg void OnFunctionsConvolve();
221  afx_msg void OnAddRemove();
222  afx_msg void OnUpdateAddRemove(CCmdUI* pCmdUI);
223  afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
224  afx_msg void OnFullres();
225  afx_msg void OnHand();
226  afx_msg void OnUpdateHand(CCmdUI* pCmdUI);
227  afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
228  afx_msg void OnMouseMove(UINT nFlags, CPoint point);
229  afx_msg void OnZoomIn();
230  afx_msg void OnZoomOut();
231  afx_msg void OnMButtonUp(UINT nFlags, CPoint point);
232  afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
233  afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
234  afx_msg void OnClearscreenofBuildings();
235  afx_msg void OnUndo();
236  afx_msg void OnViewViewfullcolorimage();
237  afx_msg void OnUpdateViewViewfullcolorimage(CCmdUI* pCmdUI);
238  afx_msg void OnModesFootprintMode();
239  afx_msg void OnUpdateModesFootprintmode(CCmdUI* pCmdUI);
240  afx_msg void OnModesRectangle();
241  afx_msg void OnUpdateModesRectangle(CCmdUI* pCmdUI);
242  afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
243  afx_msg void OnModesCircle();
244  afx_msg void OnUpdateModesCircle(CCmdUI* pCmdUI);
245  afx_msg void OnUpdateUndo(CCmdUI* pCmdUI);
246  afx_msg void OnUpdateFunctionsConvolve(CCmdUI* pCmdUI);
247  afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
248  afx_msg void OnModesMoveresize();
249  afx_msg void OnUpdateModesMoveresize(CCmdUI* pCmdUI);
250  afx_msg void OnModesRoadnode();
251  afx_msg void OnUpdateModesRoadnode(CCmdUI* pCmdUI);
252  afx_msg void OnChangeRoadColor();
253  afx_msg void OnModesRoadEdit();
254  afx_msg void OnUpdateModesRoadEdit(CCmdUI* pCmdUI);
255  afx_msg void OnConstrain();
256  afx_msg void OnUpdateConstrain(CCmdUI* pCmdUI);
257  //}}AFX_MSG
258  DECLARE_MESSAGE_MAP()
259 };
260 
261 #ifndef _DEBUG // debug version in BExtractorView.cpp
262 inline BExtractorDoc* BExtractorView::GetDocument()
263  { return (BExtractorDoc*)m_pDocument; }
264 #endif
265 
267 
268 //{{AFX_INSERT_LOCATION}}
269 // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
270 
271 #endif // !defined(AFX_B_EXTRACTORVIEW_H)