Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
RoadMapEdit.h
1 //
2 // RoadMapEdit.h
3 //
4 // Copyright (c) 2001-2008 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #ifndef ROADMAPEDIT
9 #define ROADMAPEDIT
10 
11 #include "vtdata/RoadMap.h"
12 #include "vtdata/Selectable.h"
13 
14 class vtScaledView;
15 class vtRoadLayer;
16 class vtScaledView;
17 class vtDLGFile;
18 class OGRLayer;
19 class OGRLineString;
20 
21 enum VisualIntersectionType {
22  VIT_UNKNOWN, //uncontrolled
23  VIT_NONE, //uncontrolled
24  VIT_ALLLIGHTS, //controlled intersection with all lights
25  VIT_ALLSTOPS, //controlled intersection with all stop signs
26  VIT_LIGHTS, //controlled intersection with at least one, but not all, traffic light
27  VIT_STOPSIGN, //controlled intersection with at least one, but not all, stop sign
28  VIT_SELECTED,
29  VIT_TOTAL
30 };
31 
32 
33 class NodeEdit : public TNode, public Selectable
34 {
35 public:
36  NodeEdit();
37 
38  // compare one node to another
39  bool operator==(NodeEdit &ref);
40 
41  //copies this node's properties to parameter node.
42  void Copy(NodeEdit *node);
43  //draws the node
44  bool Draw(wxDC *pDC, vtScaledView *pView);
45  //brings up a node dialog to edit road properties
46  bool EditProperties(vtScaledView *pView, vtRoadLayer *pLayer);
47 
48  //move the node
49  void Translate(const DPoint2 &offset);
50  //makes sure road endpoints match the node's position
51  void EnforceLinkEndpoints();
52 
53  NodeEdit *GetNext() { return (NodeEdit *)m_pNext; }
54  class LinkEdit *GetLink(int n);
55 
56  VisualIntersectionType GetVisual() { return m_iVisual; }
57  void SetVisual(VisualIntersectionType v) { m_iVisual = v; }
58 
59  void DetermineVisualFromLinks();
60 
61  //use to find shortest path
62  int m_iPathIndex; //index to the array of the priorty queue. (yeah, not exactly pretty.)
63  NodeEdit *m_pPrevPathNode; //prev node in the shortest path
64  LinkEdit *m_pPrevPathLink; //road to take to the prev node.
65 
66 protected:
67  VisualIntersectionType m_iVisual; //what to display the node as
68 };
69 
70 class LinkEdit : public TLink, public Selectable
71 {
72 public:
73  LinkEdit();
74 
75  // compare one road to another
76  bool operator==(LinkEdit &ref);
77 
78  // determine bounding box
79  void ComputeExtent();
80  //is target in the bounding box?
81  bool WithinExtent(const DRECT &target);
82  bool WithinExtent(const DPoint2 &target);
83 
84  //is extent of the road in "bound"
85  bool InBounds(const DRECT &bound);
86  //if only part of road is in "bound"
87  bool PartiallyInBounds(const DRECT &bound);
88 
89  //draw the road
90  bool Draw(wxDC *pDC, vtScaledView *pView, bool bShowDirection = false,
91  bool bShowWidth = false);
92  // prepare to draw the road (estimate the left and right edges)
93  void ComputeDisplayedLinkWidth(const DPoint2 &ToMeters);
94  //edit the road - brings up a road dialog box
95  bool EditProperties(vtRoadLayer *pLayer);
96 
97  // override because we need to update width when flags change
98  virtual void SetFlag(int flag, bool value);
99  // call whenever the link's geometry is changed
100  void Dirtied();
101 
102  NodeEdit *GetNode(int n) { return (NodeEdit *)m_pNode[n]; }
103  LinkEdit *GetNext() { return (LinkEdit *)m_pNext; }
104 
105  DRECT m_extent; // bounding box in world coordinates
106  int m_iPriority; // used to determine intersection behavior. lower number => higher priority
107  float m_fLength; // length of the road
108  bool m_bDrawPoints; // draw each point in the road individually
109 
110  DLine2 m_WidthOffset; // offset from each point to its left edge
111  bool m_bSidesComputed; // true when m_Left and m_Right are up-to-date
112 };
113 
114 class RoadMapEdit : public vtRoadMap
115 {
116 public:
117  RoadMapEdit();
118  ~RoadMapEdit();
119 
120  // overrides for virtual methods
121  LinkEdit *GetFirstLink() { return (LinkEdit *)m_pFirstLink; }
122  NodeEdit *GetFirstNode() { return (NodeEdit *)m_pFirstNode; }
123  NodeEdit *NewNode() { return new NodeEdit; }
124  LinkEdit *NewLink() { return new LinkEdit; }
125 
126  // Import from DLG
127  void AddElementsFromDLG(vtDLGFile *pDlg);
128 
129  // Import from SHP
130  bool ApplyCFCC(LinkEdit *pR, const char *str);
131  void AddElementsFromSHP(const wxString &filename, const vtProjection &proj,
132  bool progress_callback(int) = NULL);
133 
134  // Import from OGR, for formats like SDTS
135  void AddElementsFromOGR(class OGRDataSource *datasource,
136  bool progress_callback(int) = NULL);
137  LinkEdit *AddRoadSegment(class OGRLineString *pLineString);
138 
139  // Import from OpenStreetMap
140  bool ImportFromOSM(const char *fname, bool progress_callback(int) = NULL);
141 
142  //cleaning functions-------------------------
143  // merge nodes that are near each other
144  int MergeRedundantNodes(bool bDegrees, bool progress_callback(int) = NULL);
145  // remove BAD roads
146  int RemoveDegenerateLinks();
147  // remove nodes and merge roads if 2 adjacent roads have the same properties and the node is uncontrolled.
148  int RemoveUnnecessaryNodes();
149  // fix road points so that the end nodes do not have same coordinates as their adjacent nodes.
150  int CleanLinkPoints();
151  // deletes roads that either:
152  // have the same start and end nodes and have less than 4 points
153  // have less than 2 points, regardless of start or end nodes.
154  int DeleteDanglingLinks();
155  // fix when two road meet at the same node along the same path
156  int FixOverlappedLinks(bool bDegrees);
157  // delete roads that are really close to another road, but go nowhere coming out of a node
158  int FixExtraneousParallels();
159  //----------------------------------------------
160 
161  // draw the road network in window, given size of drawing area
162  void Draw(wxDC *pDC, vtScaledView *pView, bool bNodes);
163 
164  // look at the road properties to guess what the intersections might be
165  void GuessIntersectionTypes();
166 
167  // delete selected roads.
168  DRECT* DeleteSelected(int &nBounds);
169 
170  // find which road is within a given distance of a given point
171  LinkEdit *FindLink(DPoint2 point, float error);
172  // inverts m_bSelect value of road within error of utmCoord
173  bool SelectLink(DPoint2 point, float error, DRECT &bound);
174  // if bval true, select roads within bound. otherwise deselect roads
175  int SelectLinks(DRECT bound, bool bval);
176 
177  // selects a road, as well as any adjacent roads that is an extension of that road.
178  bool SelectAndExtendLink(DPoint2 point, float error, DRECT &bound);
179 
180  //selects all roads with given highway number
181  bool SelectHwyNum(int num);
182 
183  //selects road if it is only partially in the box.
184  bool CrossSelectLinks(DRECT bound, bool bval);
185  //inverts selection values on all roads and nodes.
186  void InvertSelection();
187 
188  //inverts m_bSelect value of node within epsilon of point
189  bool SelectNode(const DPoint2 &point, float epsilon, DRECT &bound);
190  //if bval true, select nodes within bound. otherwise deselect nodes
191  int SelectNodes(DRECT bound, bool bval);
192 
193  //return the number of selected nodes.
194  int NumSelectedNodes();
195  //return the number of selected roads
196  int NumSelectedLinks();
197  //deselect all (nodes and roads.
198  DRECT *DeSelectAll(int &numRegions);
199 
200 protected:
201  void ApplyDLGAttributes(int road_type, int &lanes, SurfaceType &stype, int &priority);
202  bool extract_road_attributes(const char *strEntity, int &lanes,
203  SurfaceType &stype, int &priority);
204 
205  bool attribute_filter_roads(DLGLine *pLine, int &lanes, SurfaceType &stype, int &priority);
206  bool AppendFromOGRLayer(OGRLayer *pLayer);
207  void AddLinkFromLineString(OGRLineString *pLineString);
208 
209  //delete one road.
210  void DeleteSingleLink(LinkEdit *pLink);
211  //replace a node
212  void ReplaceNode(NodeEdit *pN, NodeEdit *pN2);
213 };
214 
215 typedef NodeEdit *NodeEditPtr;
216 
217 #endif