Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
BuilderView.h
1 //
2 // BuilderView.h
3 //
4 // Copyright (c) 2001-2008 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef BUILDERVIEWH
9 #define BUILDERVIEWH
10 
11 #include "ScaledView.h"
12 #include "vtdata/Projections.h"
13 #include "vtdata/Building.h"
14 #include "vtdata/Fence.h"
15 #include "vtdata/Icosa.h"
16 
17 class vtLayer;
18 class vtRoadLayer;
19 class vtElevLayer;
20 class vtImageLayer;
21 class vtStructureLayer;
22 class vtUtilityLayer;
23 class LinkEdit;
24 
25 //
26 // Left-button modes
27 //
28 enum LBMode {
29  LB_None, // none
30  LB_Link, // select/edit links
31  LB_Node, // select/edit nodes
32  LB_Move, // move selected nodes
33  LB_Pan, // pan the view
34  LB_Dist, // measure distance
35  LB_Mag, // zoom into rectangle
36  LB_Dir, // show/change road direction
37  LB_LinkEdit, // edit the points of a road centerline
38  LB_LinkExtend, //extend a link selection,
39  LB_TSelect, // select elevation layer
40  LB_Box, // set area box
41  LB_FSelect, // select feature
42  LB_BldEdit, // edit built structures
43  LB_BldAddPoints, // add footprint points
44  LB_BldDeletePoints, // delete footprint points
45  LB_AddLinear, // structures: add linear features
46  LB_EditLinear, // structures: add linear features
47  LB_AddInstance, // structures: add structure instances
48  LB_AddPoints, // add raw points
49  LB_TowerSelect, // selectTowers
50  LB_TowerAdd, // Add Tower to layer
51  LB_FeatInfo, // Get info about features by picking them
52  LB_TrimTIN // Trim TIN triangles by indicating them
53 };
54 
55 // A useful class to contain an array of bools
56 class BoolArray : public vtArray<bool> {};
57 
58 struct UIContext
59 {
60  bool m_bLMouseButton;
61  bool m_bMMouseButton;
62  bool m_bRMouseButton;
63 
64  bool m_bRubber;
65 
66  // Used while editing buildings
67  vtBuilding *m_pCurBuilding, m_EditBuilding;
68  int m_iCurCorner;
69  bool m_bDragCenter;
70  bool m_bRotate;
71  bool m_bControl;
72  bool m_bShift;
73  bool m_bAlt;
74 
75  // Used for linear structures
76  vtFence *m_pCurLinear, m_EditLinear;
77 
78  // Used while editing roads
79  LinkEdit *m_pEditingRoad;
80  int m_iEditingPoint;
81 
82  // Left Mouse Button Mode
83  LBMode mode;
84 
85  // Mouse in world coordinates
86  DPoint2 m_DownLocation;
87  DPoint2 m_CurLocation;
88  DPoint2 m_PrevLocation;
89 
90  // Mouse in canvas coords
91  wxPoint m_DownPoint;
92  wxPoint m_CurPoint; // current position of mouse
93  wxPoint m_LastPoint; // last position of mouse
94 
95  bool m_bDistanceToolMode;
96 };
97 
98 class BuilderView : public vtScaledView
99 {
100  friend class vtRoadLayer;
101 
102 public:
103  BuilderView(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition,
104  const wxSize& size = wxDefaultSize, const wxString& name = _T(""));
105  virtual ~BuilderView();
106 
107  virtual void OnDraw(wxDC& dc); // overridden to draw this view
108 
109  // Cursor
110  void SetCorrectCursor();
111 
112  // Mouse
113  void SetMode(LBMode m);
114  LBMode GetMode() { return m_ui.mode; }
115  void GetMouseLocation(DPoint2 &p);
116 
117  // UTM zone boundary display
118  void DrawUTMBounds(wxDC *pDC);
119  void DrawDymaxionOutline(wxDC *pDC);
120 
121  // World Map
122  void SetWMProj(const vtProjection &p);
123 
124  // Key handler
125  void OnChar(wxKeyEvent& event);
126  void OnKeyDown(wxKeyEvent& event);
127  void OnMouseWheel(wxMouseEvent& event);
128 
129  // More public methods
130  void DeselectAll();
131  void DeleteSelected(vtRoadLayer *pRL);
132  void SetActiveLayer(vtLayer *lp);
133  void MatchZoomToElev(vtElevLayer *pEL);
134  void MatchZoomToImage(vtImageLayer *pEL);
135  void SetShowMap(bool bShow);
136  bool GetShowMap() { return m_bShowMap; }
137  void SetShowScaleBar(bool bShow);
138  bool GetShowScaleBar() { return m_bScaleBar; }
139  void InvertAreaTool(const DRECT &rect);
140  void ShowGridMarks(const DRECT &area, int cols, int rows, int active_col, int active_row);
141  void HideGridMarks();
142  void SetDistanceToolMode(bool bPath);
143  bool GetDistanceToolMode();
144  void SetDistancePoints(const DPoint2 &p1, const DPoint2 &p2)
145  { m_distance_p1 = p1; m_distance_p2 = p2; }
146  void SetDistancePath(const DLine2 &path)
147  { m_distance_path = path; }
148  void ClearDistanceTool();
149  void UpdateDistance();
150  void DrawInvertedLine(const DPoint2 &ep1, const DPoint2 &ep2);
151 
152  void RunTest();
153 
154  bool m_bCrossSelect;
155  bool m_bShowUTMBounds;
156  bool m_bConstrain;
157 
158 protected:
159  // Edit
160  void UpdateResizeScale();
161  void UpdateRotate();
162  void OnDragDistance();
163 
164  // Elevation
165  void CheckForTerrainSelect(const DPoint2 &loc);
166  void HighlightArea(wxDC *pDC, const DRECT &rect);
167 
168  // Pan handlers
169  void BeginPan();
170  void EndPan();
171  void DoPan(wxPoint point);
172 
173  // Box handlers
174  void BeginBox();
175  void EndBox(const wxMouseEvent& event);
176  void EndBoxFeatureSelect(const wxMouseEvent& event);
177  void DoBox(wxPoint point);
178  void BeginArea();
179  void DoArea(wxPoint delta);
180 
181  // Mouse handlers
182  void OnLeftDown(wxMouseEvent& event);
183  void OnLeftUp(wxMouseEvent& event);
184  void OnLeftDoubleClick(wxMouseEvent& event);
185  void OnMiddleDown(wxMouseEvent& event);
186  void OnMiddleUp(wxMouseEvent& event);
187  void OnRightDown(wxMouseEvent& event);
188  void OnRightUp(wxMouseEvent& event);
189 
190  void OnLButtonClick(wxMouseEvent& event);
191  void OnLButtonDragRelease(wxMouseEvent& event);
192  void OnLButtonClickElement(vtRoadLayer *pRL);
193  void OnLButtonClickLinkEdit(vtRoadLayer *pRL);
194  void OnLButtonClickFeature(vtLayer *pL);
195  void OnRightUpStructure(vtStructureLayer *pSL);
196 
197  void OnMouseMove(wxMouseEvent& event);
198  void OnMouseMoveLButton(const wxPoint &point);
199 
200  void OnIdle(wxIdleEvent& event);
201  void OnSize(wxSizeEvent& event);
202  void OnEraseBackground(wxEraseEvent& event);
203 
204  void InvertRect(wxDC *pDC, const wxRect &r, bool bDashed = false);
205  void InvertRect(wxDC *pDC, const wxPoint &one, const wxPoint &two, bool bDashed = false);
206  void DrawAreaTool(wxDC *pDC, const DRECT &area);
207  void DrawDistanceTool(wxDC *pDC);
208  void DrawDistanceTool();
209  void BeginDistance();
210 
211  bool m_bGotFirstIdle;
212  bool m_bSkipNextDraw;
213  bool m_bSkipNextRefresh;
214  wxSize m_previous_size;
215  DRECT m_world_rect; // rectangle box drawn by mouse
216  DPoint2 m_distance_p1, m_distance_p2;
217  DLine2 m_distance_path;
218 
219  // Mouse in window coords
220  wxPoint m_DownClient;
221 
222  // Used while mouse button is down
223  bool m_bMouseMoved;
224  bool m_bPanning; // currently panning
225  bool m_bScrolling; // currently scrolling
226  bool m_bBoxing; // currently drawing a rubber box
227  int m_iDragSide; // which side of the area box being dragged
228 
229  // Used while editing roads
230  void RefreshRoad(LinkEdit *pRoad);
231 
232  wxCursor *m_pCursorPan;
233  bool m_bMouseCaptured;
234 
235  // World Map
236  bool m_bShowMap;
237  bool m_bScaleBar;
238  DLine2Array WMPoly; // Original data from SHP file
239  DLine2Array WMPolyDraw; // This is the WM that is drawn
240  std::vector<DRECT> WMPolyExtents;
241  uint m_iEntities;
242  bool m_bAttemptedLoad;
243  DymaxIcosa m_icosa;
244  OCT *m_pMapToCurrent, *m_pCurrentToMap;
245 
246  bool ImportWorldMap();
247  void DrawWorldMap(wxDC *pDC);
248 
249  // Grid marks
250  bool m_bShowGridMarks;
251  DRECT m_GridArea;
252  int m_iGridCols, m_iGridRows, m_iActiveCol, m_iActiveRow;
253  void DrawGridMarks(wxDC &dc);
254 
255  //--------------------------------
256  void DrawScaleBar(wxDC * dc);
257  void OnBeginScroll(wxScrollWinEvent & event);
258  void OnEndScroll(wxScrollWinEvent& event);
259  void OnOtherScrollEvents(wxScrollWinEvent & event);
260  wxRect m_ScaleBarArea;
261 
262  UIContext m_ui;
263 
264  DECLARE_EVENT_TABLE()
265 };
266 
267 #endif
268