Commit 93688872e96c6843b65f2fdaae7e3273ecb47ece
1 parent
b169b88b18
Exists in
master
2036 : Update draw Restriction
Showing 2 changed files with 77 additions and 40 deletions Inline Diff
sources/RoboforkApp/DesignerCanvas.cs
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Linq; | 3 | using System.Linq; |
4 | using System.Windows; | 4 | using System.Windows; |
5 | using System.Windows.Controls; | 5 | using System.Windows.Controls; |
6 | using System.Windows.Documents; | 6 | using System.Windows.Documents; |
7 | using System.Windows.Input; | 7 | using System.Windows.Input; |
8 | using System.Windows.Markup; | 8 | using System.Windows.Markup; |
9 | using System.Windows.Media; | 9 | using System.Windows.Media; |
10 | using System.Windows.Shapes; | 10 | using System.Windows.Shapes; |
11 | using System.Xml; | 11 | using System.Xml; |
12 | 12 | ||
13 | namespace RoboforkApp | 13 | namespace RoboforkApp |
14 | { | 14 | { |
15 | public class DesignerCanvas : Canvas | 15 | public class DesignerCanvas : Canvas |
16 | { | 16 | { |
17 | const double RADIUS_NODE = 8d; | 17 | const double RADIUS_NODE = 8d; |
18 | const double RADIUS_CURVER_LINE = 130d; | 18 | const double RADIUS_CURVER_LINE = 130d; |
19 | const double DISTANCE_AUTO_NODES = 100d; | 19 | const double DISTANCE_AUTO_NODES = 100d; |
20 | const double DISTANCE_START_NODES = 30d; | 20 | const double DISTANCE_START_NODES = 30d; |
21 | const double DISTANCE_END_NODES = 30d; | 21 | const double DISTANCE_END_NODES = 30d; |
22 | const double DISTANCE_FREE_NODES = 40d; | 22 | const double DISTANCE_FREE_NODES = 40d; |
23 | const double STROKE_ROOT_LINE = 6d; | 23 | const double STROKE_ROOT_LINE = 6d; |
24 | const double STROKE_LINE = 4d; | 24 | const double STROKE_LINE = 4d; |
25 | const double STROKE_NODE = 1d; | 25 | const double STROKE_NODE = 1d; |
26 | const double DISTANCE_RATIO = 100; | 26 | const double DISTANCE_RATIO = 100; |
27 | 27 | ||
28 | private List<Rectangle> shapeList = new List<Rectangle>(); | 28 | private List<Rectangle> shapeList = new List<Rectangle>(); |
29 | private TextBlock shapePosIndicator; | 29 | private TextBlock shapePosIndicator; |
30 | private TextBlock shapeSizeIndicator; | 30 | private TextBlock shapeSizeIndicator; |
31 | private int currentLine; | 31 | private int currentLine; |
32 | private ucStartEndButton _startPoint; | 32 | private ucStartEndButton _startPoint; |
33 | private ucStartEndButton _goalPoint; | 33 | private ucStartEndButton _goalPoint; |
34 | private ucDisplayCoordinate _displayAxiPosition; | 34 | private ucDisplayCoordinate _displayAxiPosition; |
35 | 35 | ||
36 | // Add variable for draw route | 36 | // Add variable for draw route |
37 | public Path pLine = new Path(); | 37 | public Path pLine = new Path(); |
38 | public Path pRootLine = new Path(); | 38 | public Path pRootLine = new Path(); |
39 | public Path pCurverLine = new Path(); | 39 | public Path pCurverLine = new Path(); |
40 | public Path pRedNode = new Path(); | 40 | public Path pRedNode = new Path(); |
41 | public Path pYellowNode = new Path(); | 41 | public Path pYellowNode = new Path(); |
42 | public GeometryGroup gGrpLine = new GeometryGroup(); | 42 | public GeometryGroup gGrpLine = new GeometryGroup(); |
43 | public GeometryGroup gGrpRootLine = new GeometryGroup(); | 43 | public GeometryGroup gGrpRootLine = new GeometryGroup(); |
44 | public GeometryGroup gGrpCurverLine = new GeometryGroup(); | 44 | public GeometryGroup gGrpCurverLine = new GeometryGroup(); |
45 | public GeometryGroup gGrpRedNode = new GeometryGroup(); | 45 | public GeometryGroup gGrpRedNode = new GeometryGroup(); |
46 | public GeometryGroup gGrpYellowNode = new GeometryGroup(); | 46 | public GeometryGroup gGrpYellowNode = new GeometryGroup(); |
47 | public int currentShape; | 47 | public int currentShape; |
48 | public static bool isStartDrawRoute = false; | 48 | public static bool isStartDrawRoute = false; |
49 | public static bool isGoalDrawRoute = false; | 49 | public static bool isGoalDrawRoute = false; |
50 | 50 | ||
51 | public struct NodeInfo | 51 | public struct NodeInfo |
52 | { | 52 | { |
53 | public double X; | 53 | public double X; |
54 | public double Y; | 54 | public double Y; |
55 | public String Mode1; | 55 | public String Mode1; |
56 | public String Mode2; | 56 | public String Mode2; |
57 | public String Mode3; | 57 | public String Mode3; |
58 | } | 58 | } |
59 | List<NodeInfo> NodeInfo_List = new List<NodeInfo>(); | 59 | List<NodeInfo> NodeInfo_List = new List<NodeInfo>(); |
60 | 60 | ||
61 | // Add variable for Set Auto Nodes | 61 | // Add variable for Set Auto Nodes |
62 | public Path pBlueNode = new Path(); | 62 | public Path pBlueNode = new Path(); |
63 | private GeometryGroup gGrpBlueNode = new GeometryGroup(); | 63 | private GeometryGroup gGrpBlueNode = new GeometryGroup(); |
64 | 64 | ||
65 | // Add variable for Set Free Nodes | 65 | // Add variable for Set Free Nodes |
66 | public Path pFreeNode = new Path(); | 66 | public Path pFreeNode = new Path(); |
67 | //private GeometryGroup gGrpFreeNode = new GeometryGroup(); | 67 | //private GeometryGroup gGrpFreeNode = new GeometryGroup(); |
68 | 68 | ||
69 | // The part of the rectangle the mouse is over. | 69 | // The part of the rectangle the mouse is over. |
70 | private enum HitType | 70 | private enum HitType |
71 | { | 71 | { |
72 | None, Body, UL, UR, LR, LL, L, R, T, B | 72 | None, Body, UL, UR, LR, LL, L, R, T, B |
73 | }; | 73 | }; |
74 | public enum OperationState | 74 | public enum OperationState |
75 | { | 75 | { |
76 | None, DrawObstract, DrawRoute, DrawSetFreeNode, EditNode | 76 | None, DrawObstract, DrawRoute, DrawSetFreeNode, EditNode |
77 | }; | 77 | }; |
78 | public enum MouseState | 78 | public enum MouseState |
79 | { | 79 | { |
80 | None, Draw, Drag, | 80 | None, Draw, Drag, |
81 | } | 81 | } |
82 | public OperationState Operation = OperationState.None; | 82 | public OperationState Operation = OperationState.None; |
83 | public MouseState mouseState = MouseState.None; | 83 | public MouseState mouseState = MouseState.None; |
84 | 84 | ||
85 | // The draw start point. | 85 | // The draw start point. |
86 | private Point StartDrawPoint; | 86 | private Point StartDrawPoint; |
87 | 87 | ||
88 | // The drag's last point. | 88 | // The drag's last point. |
89 | private Point LastPoint; | 89 | private Point LastPoint; |
90 | 90 | ||
91 | // The part of the rectangle under the mouse. | 91 | // The part of the rectangle under the mouse. |
92 | HitType MouseHitType = HitType.None; | 92 | HitType MouseHitType = HitType.None; |
93 | 93 | ||
94 | public void Init() { | 94 | public void Init() { |
95 | if (shapePosIndicator == null) | 95 | if (shapePosIndicator == null) |
96 | { | 96 | { |
97 | shapePosIndicator = new TextBlock() | 97 | shapePosIndicator = new TextBlock() |
98 | { | 98 | { |
99 | Foreground = Brushes.Black, | 99 | Foreground = Brushes.Black, |
100 | Background = Brushes.Transparent, | 100 | Background = Brushes.Transparent, |
101 | FontSize = 20, | 101 | FontSize = 20, |
102 | }; | 102 | }; |
103 | } | 103 | } |
104 | if (shapeSizeIndicator == null) | 104 | if (shapeSizeIndicator == null) |
105 | { | 105 | { |
106 | shapeSizeIndicator = new TextBlock() | 106 | shapeSizeIndicator = new TextBlock() |
107 | { | 107 | { |
108 | Foreground = Brushes.Black, | 108 | Foreground = Brushes.Black, |
109 | Background = Brushes.Transparent, | 109 | Background = Brushes.Transparent, |
110 | FontSize = 20, | 110 | FontSize = 20, |
111 | }; | 111 | }; |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | // Return a HitType value to indicate what is at the point. | 115 | // Return a HitType value to indicate what is at the point. |
116 | private HitType SetHitType(Point point) | 116 | private HitType SetHitType(Point point) |
117 | { | 117 | { |
118 | if (shapeList.Count == 0) | 118 | if (shapeList.Count == 0) |
119 | { | 119 | { |
120 | currentShape = 0; | 120 | currentShape = 0; |
121 | return HitType.None; | 121 | return HitType.None; |
122 | } | 122 | } |
123 | for (int i = 0; i < shapeList.Count; i++) | 123 | for (int i = 0; i < shapeList.Count; i++) |
124 | { | 124 | { |
125 | Rectangle rect = shapeList[i]; | 125 | Rectangle rect = shapeList[i]; |
126 | double left = Canvas.GetLeft(rect); | 126 | double left = Canvas.GetLeft(rect); |
127 | double top = Canvas.GetTop(rect); | 127 | double top = Canvas.GetTop(rect); |
128 | double right = left + rect.Width; | 128 | double right = left + rect.Width; |
129 | double bottom = top + rect.Height; | 129 | double bottom = top + rect.Height; |
130 | if (point.X < left) continue; | 130 | if (point.X < left) continue; |
131 | if (point.X > right) continue; | 131 | if (point.X > right) continue; |
132 | if (point.Y < top) continue; | 132 | if (point.Y < top) continue; |
133 | if (point.Y > bottom) continue; | 133 | if (point.Y > bottom) continue; |
134 | currentShape = i; | 134 | currentShape = i; |
135 | 135 | ||
136 | const double GAP = 10; | 136 | const double GAP = 10; |
137 | if (point.X - left < GAP) | 137 | if (point.X - left < GAP) |
138 | { | 138 | { |
139 | // Left edge. | 139 | // Left edge. |
140 | if (point.Y - top < GAP) return HitType.UL; | 140 | if (point.Y - top < GAP) return HitType.UL; |
141 | if (bottom - point.Y < GAP) return HitType.LL; | 141 | if (bottom - point.Y < GAP) return HitType.LL; |
142 | return HitType.L; | 142 | return HitType.L; |
143 | } | 143 | } |
144 | if (right - point.X < GAP) | 144 | if (right - point.X < GAP) |
145 | { | 145 | { |
146 | // Right edge. | 146 | // Right edge. |
147 | if (point.Y - top < GAP) return HitType.UR; | 147 | if (point.Y - top < GAP) return HitType.UR; |
148 | if (bottom - point.Y < GAP) return HitType.LR; | 148 | if (bottom - point.Y < GAP) return HitType.LR; |
149 | return HitType.R; | 149 | return HitType.R; |
150 | } | 150 | } |
151 | if (point.Y - top < GAP) return HitType.T; | 151 | if (point.Y - top < GAP) return HitType.T; |
152 | if (bottom - point.Y < GAP) return HitType.B; | 152 | if (bottom - point.Y < GAP) return HitType.B; |
153 | return HitType.Body; | 153 | return HitType.Body; |
154 | } | 154 | } |
155 | currentShape = 0; | 155 | currentShape = 0; |
156 | return HitType.None; | 156 | return HitType.None; |
157 | } | 157 | } |
158 | 158 | ||
159 | // Set a mouse cursor appropriate for the current hit type. | 159 | // Set a mouse cursor appropriate for the current hit type. |
160 | private void SetMouseCursor() | 160 | private void SetMouseCursor() |
161 | { | 161 | { |
162 | // See what cursor we should display. | 162 | // See what cursor we should display. |
163 | Cursor desired_cursor = Cursors.Arrow; | 163 | Cursor desired_cursor = Cursors.Arrow; |
164 | switch (MouseHitType) | 164 | switch (MouseHitType) |
165 | { | 165 | { |
166 | case HitType.None: | 166 | case HitType.None: |
167 | desired_cursor = Cursors.Arrow; | 167 | desired_cursor = Cursors.Arrow; |
168 | break; | 168 | break; |
169 | case HitType.Body: | 169 | case HitType.Body: |
170 | desired_cursor = Cursors.ScrollAll; | 170 | desired_cursor = Cursors.ScrollAll; |
171 | break; | 171 | break; |
172 | case HitType.UL: | 172 | case HitType.UL: |
173 | case HitType.LR: | 173 | case HitType.LR: |
174 | desired_cursor = Cursors.SizeNWSE; | 174 | desired_cursor = Cursors.SizeNWSE; |
175 | break; | 175 | break; |
176 | case HitType.LL: | 176 | case HitType.LL: |
177 | case HitType.UR: | 177 | case HitType.UR: |
178 | desired_cursor = Cursors.SizeNESW; | 178 | desired_cursor = Cursors.SizeNESW; |
179 | break; | 179 | break; |
180 | case HitType.T: | 180 | case HitType.T: |
181 | case HitType.B: | 181 | case HitType.B: |
182 | desired_cursor = Cursors.SizeNS; | 182 | desired_cursor = Cursors.SizeNS; |
183 | break; | 183 | break; |
184 | case HitType.L: | 184 | case HitType.L: |
185 | case HitType.R: | 185 | case HitType.R: |
186 | desired_cursor = Cursors.SizeWE; | 186 | desired_cursor = Cursors.SizeWE; |
187 | break; | 187 | break; |
188 | } | 188 | } |
189 | 189 | ||
190 | // Display the desired cursor. | 190 | // Display the desired cursor. |
191 | if (Cursor != desired_cursor) Cursor = desired_cursor; | 191 | if (Cursor != desired_cursor) Cursor = desired_cursor; |
192 | } | 192 | } |
193 | 193 | ||
194 | // constance | 194 | // constance |
195 | int indicatorAligment = 2; | 195 | int indicatorAligment = 2; |
196 | 196 | ||
197 | /* | 197 | /* |
198 | private Point? dragStartPoint = null; | 198 | private Point? dragStartPoint = null; |
199 | 199 | ||
200 | */ | 200 | */ |
201 | public IEnumerable<DesignerItem> SelectedItems | 201 | public IEnumerable<DesignerItem> SelectedItems |
202 | { | 202 | { |
203 | get | 203 | get |
204 | { | 204 | { |
205 | var selectedItems = from item in this.Children.OfType<DesignerItem>() | 205 | var selectedItems = from item in this.Children.OfType<DesignerItem>() |
206 | where item.IsSelected == true | 206 | where item.IsSelected == true |
207 | select item; | 207 | select item; |
208 | 208 | ||
209 | return selectedItems; | 209 | return selectedItems; |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
213 | public void DeselectAll() | 213 | public void DeselectAll() |
214 | { | 214 | { |
215 | /* | 215 | /* |
216 | foreach (DesignerItem item in this.SelectedItems) | 216 | foreach (DesignerItem item in this.SelectedItems) |
217 | { | 217 | { |
218 | item.IsSelected = false; | 218 | item.IsSelected = false; |
219 | }*/ | 219 | }*/ |
220 | } | 220 | } |
221 | 221 | ||
222 | protected override void OnMouseDown(MouseButtonEventArgs e) | 222 | protected override void OnMouseDown(MouseButtonEventArgs e) |
223 | { | 223 | { |
224 | base.OnMouseDown(e); | 224 | base.OnMouseDown(e); |
225 | 225 | ||
226 | MouseHitType = SetHitType(Mouse.GetPosition(this)); | 226 | MouseHitType = SetHitType(Mouse.GetPosition(this)); |
227 | SetMouseCursor(); | 227 | SetMouseCursor(); |
228 | if (Operation == OperationState.DrawRoute && isStartDrawRoute) | 228 | if (Operation == OperationState.DrawRoute && isStartDrawRoute) |
229 | { | 229 | { |
230 | if (isGoalDrawRoute) | 230 | if (isGoalDrawRoute) |
231 | { | 231 | { |
232 | return; | 232 | return; |
233 | } | 233 | } |
234 | 234 | ||
235 | // Check state draw | 235 | // Check state draw |
236 | if (MouseHitType == HitType.None) | 236 | if (MouseHitType == HitType.None) |
237 | { | 237 | { |
238 | if (gGrpLine.Children.Count == 1) | 238 | if (gGrpLine.Children.Count == 1) |
239 | { | 239 | { |
240 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[0]; | 240 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[0]; |
241 | lineGeometry.EndPoint = LastPoint; | 241 | lineGeometry.EndPoint = LastPoint; |
242 | 242 | ||
243 | // Check end route | 243 | // Check end route |
244 | if (IsEndRoute(_goalPoint, lineGeometry)) | 244 | if (IsEndRoute(_goalPoint, lineGeometry)) |
245 | { | 245 | { |
246 | isGoalDrawRoute = true; | 246 | isGoalDrawRoute = true; |
247 | ProcessEndRoute(); | 247 | ProcessEndRoute(); |
248 | return; | 248 | return; |
249 | } | 249 | } |
250 | } | 250 | } |
251 | else if (IsCurverNode((LineGeometry)gGrpLine.Children[currentLine - 1] | 251 | else if (IsCurverNode((LineGeometry)gGrpLine.Children[currentLine - 1] |
252 | , (LineGeometry)gGrpLine.Children[currentLine])) | 252 | , (LineGeometry)gGrpLine.Children[currentLine])) |
253 | { | 253 | { |
254 | // Set end point to finish draw line | 254 | // Set end point to finish draw line |
255 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine]; | 255 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine]; |
256 | lineGeometry.EndPoint = LastPoint; | 256 | lineGeometry.EndPoint = LastPoint; |
257 | 257 | ||
258 | // Add node to curver postion | ||
259 | AddNode(lineGeometry.StartPoint, gGrpRedNode); | ||
260 | |||
258 | // Check end route | 261 | // Check end route |
259 | if (IsEndRoute(_goalPoint, lineGeometry)) | 262 | if (IsEndRoute(_goalPoint, lineGeometry)) |
260 | { | 263 | { |
261 | isGoalDrawRoute = true; | 264 | isGoalDrawRoute = true; |
262 | ProcessEndRoute(); | 265 | ProcessEndRoute(); |
263 | return; | 266 | return; |
264 | } | 267 | } |
265 | 268 | ||
266 | // Add node to curver postion | ||
267 | AddNode(lineGeometry.StartPoint, gGrpRedNode); | ||
268 | |||
269 | // Draw curver line | 269 | // Draw curver line |
270 | DrawCurver((LineGeometry)gGrpLine.Children[currentLine - 1], (LineGeometry)gGrpLine.Children[currentLine]); | 270 | //DrawCurver((LineGeometry)gGrpLine.Children[currentLine - 1], (LineGeometry)gGrpLine.Children[currentLine]); |
271 | } | 271 | } |
272 | else | 272 | else |
273 | { | 273 | { |
274 | // Remove current line | 274 | // Remove current line |
275 | gGrpLine.Children.RemoveAt(currentLine); | 275 | gGrpLine.Children.RemoveAt(currentLine); |
276 | // Remove yellow node | 276 | // Remove yellow node |
277 | if (gGrpYellowNode.Children.Count > 0) | 277 | //if (gGrpYellowNode.Children.Count > 0) |
278 | { | 278 | //{ |
279 | gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); | 279 | // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); |
280 | gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); | 280 | // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); |
281 | } | 281 | //} |
282 | // Remove curver line | 282 | //// Remove curver line |
283 | if (gGrpCurverLine.Children.Count > 0) | 283 | //if (gGrpCurverLine.Children.Count > 0) |
284 | { | 284 | //{ |
285 | gGrpCurverLine.Children.RemoveAt(gGrpCurverLine.Children.Count - 1); | 285 | // gGrpCurverLine.Children.RemoveAt(gGrpCurverLine.Children.Count - 1); |
286 | } | 286 | //} |
287 | 287 | ||
288 | // Set end point to finish draw line | 288 | // Set end point to finish draw line |
289 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine - 1]; | 289 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine - 1]; |
290 | lineGeometry.EndPoint = LastPoint; | 290 | lineGeometry.EndPoint = LastPoint; |
291 | 291 | ||
292 | // Check end route | 292 | // Check end route |
293 | if (IsEndRoute(_goalPoint, lineGeometry)) | 293 | if (IsEndRoute(_goalPoint, lineGeometry)) |
294 | { | 294 | { |
295 | isGoalDrawRoute = true; | 295 | isGoalDrawRoute = true; |
296 | ProcessEndRoute(); | 296 | ProcessEndRoute(); |
297 | return; | 297 | return; |
298 | } | 298 | } |
299 | 299 | ||
300 | // Re-draw cuver line | 300 | //// Re-draw cuver line |
301 | if (currentLine > 1) | 301 | //if (currentLine > 1) |
302 | { | 302 | //{ |
303 | if (IsCurverNode((LineGeometry)gGrpLine.Children[currentLine - 2] | 303 | // if (IsCurverNode((LineGeometry)gGrpLine.Children[currentLine - 2] |
304 | , (LineGeometry)gGrpLine.Children[currentLine - 1])) | 304 | // , (LineGeometry)gGrpLine.Children[currentLine - 1])) |
305 | DrawCurver((LineGeometry)gGrpLine.Children[currentLine - 2], (LineGeometry)gGrpLine.Children[currentLine - 1]); | 305 | // DrawCurver((LineGeometry)gGrpLine.Children[currentLine - 2], (LineGeometry)gGrpLine.Children[currentLine - 1]); |
306 | } | 306 | //} |
307 | } | 307 | } |
308 | 308 | ||
309 | // Draw new line | 309 | // Draw new line |
310 | DrawLine(LastPoint, LastPoint, gGrpLine); | 310 | DrawLine(LastPoint, LastPoint, gGrpLine); |
311 | // Setting start point for new line | 311 | // Setting start point for new line |
312 | StartDrawPoint = LastPoint; | 312 | StartDrawPoint = LastPoint; |
313 | 313 | ||
314 | mouseState = MouseState.Draw; | 314 | mouseState = MouseState.Draw; |
315 | currentLine = gGrpLine.Children.Count - 1; | 315 | currentLine = gGrpLine.Children.Count - 1; |
316 | return; | 316 | return; |
317 | } | 317 | } |
318 | } | 318 | } |
319 | else if (Operation == OperationState.DrawSetFreeNode) | 319 | else if (Operation == OperationState.DrawSetFreeNode) |
320 | { | 320 | { |
321 | bool RightClick = false; | 321 | bool RightClick = false; |
322 | if (IsStopDrawRoute(e)) | 322 | if (IsStopDrawRoute(e)) |
323 | RightClick = true; | 323 | RightClick = true; |
324 | 324 | ||
325 | StartDrawPoint = e.MouseDevice.GetPosition(this); | 325 | StartDrawPoint = e.MouseDevice.GetPosition(this); |
326 | SetFreeNodes(StartDrawPoint, RightClick); | 326 | SetFreeNodes(StartDrawPoint, RightClick); |
327 | } | 327 | } |
328 | else if (Operation == OperationState.EditNode) | 328 | else if (Operation == OperationState.EditNode) |
329 | { | 329 | { |
330 | Point node_edited = e.MouseDevice.GetPosition(this); | 330 | Point node_edited = e.MouseDevice.GetPosition(this); |
331 | 331 | ||
332 | // start Edit Node Infor | 332 | // start Edit Node Infor |
333 | EditNode(node_edited); | 333 | EditNode(node_edited); |
334 | 334 | ||
335 | } | 335 | } |
336 | else if (Operation == OperationState.DrawObstract) | 336 | else if (Operation == OperationState.DrawObstract) |
337 | { | 337 | { |
338 | if (MouseHitType == HitType.None) | 338 | if (MouseHitType == HitType.None) |
339 | { | 339 | { |
340 | Rectangle shape = new Rectangle(); | 340 | Rectangle shape = new Rectangle(); |
341 | shape.Width = 1; | 341 | shape.Width = 1; |
342 | shape.Height = 1; | 342 | shape.Height = 1; |
343 | // Create a SolidColorBrush and use it to | 343 | // Create a SolidColorBrush and use it to |
344 | // paint the rectangle. | 344 | // paint the rectangle. |
345 | shape.Stroke = Brushes.Blue; | 345 | shape.Stroke = Brushes.Blue; |
346 | shape.StrokeThickness = 1; | 346 | shape.StrokeThickness = 1; |
347 | shape.Fill = new SolidColorBrush(Colors.LightCyan); | 347 | shape.Fill = new SolidColorBrush(Colors.LightCyan); |
348 | StartDrawPoint = e.MouseDevice.GetPosition(this); | 348 | StartDrawPoint = e.MouseDevice.GetPosition(this); |
349 | shape.SetValue(Canvas.LeftProperty, StartDrawPoint.X); | 349 | shape.SetValue(Canvas.LeftProperty, StartDrawPoint.X); |
350 | shape.SetValue(Canvas.TopProperty, StartDrawPoint.Y); | 350 | shape.SetValue(Canvas.TopProperty, StartDrawPoint.Y); |
351 | this.Children.Add(shape); | 351 | this.Children.Add(shape); |
352 | shapeList.Add(shape); | 352 | shapeList.Add(shape); |
353 | 353 | ||
354 | mouseState = MouseState.Draw; | 354 | mouseState = MouseState.Draw; |
355 | currentShape = shapeList.Count() - 1; | 355 | currentShape = shapeList.Count() - 1; |
356 | 356 | ||
357 | double shapeX = Canvas.GetLeft(shapeList[currentShape]); | 357 | double shapeX = Canvas.GetLeft(shapeList[currentShape]); |
358 | double shapeY = Canvas.GetTop(shapeList[currentShape]); | 358 | double shapeY = Canvas.GetTop(shapeList[currentShape]); |
359 | shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; | 359 | shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; |
360 | shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); | 360 | shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); |
361 | shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); | 361 | shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); |
362 | 362 | ||
363 | double width = (int)shapeList[currentShape].Width; | 363 | double width = (int)shapeList[currentShape].Width; |
364 | double height = (int)shapeList[currentShape].Height; | 364 | double height = (int)shapeList[currentShape].Height; |
365 | shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; | 365 | shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; |
366 | shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); | 366 | shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); |
367 | shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); | 367 | shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); |
368 | 368 | ||
369 | this.Children.Add(shapePosIndicator); | 369 | this.Children.Add(shapePosIndicator); |
370 | this.Children.Add(shapeSizeIndicator); | 370 | this.Children.Add(shapeSizeIndicator); |
371 | 371 | ||
372 | 372 | ||
373 | return; | 373 | return; |
374 | } | 374 | } |
375 | else | 375 | else |
376 | { | 376 | { |
377 | if (shapeList.Count() != 0) | 377 | if (shapeList.Count() != 0) |
378 | shapeList[currentShape].Fill = new SolidColorBrush(Colors.LightCyan); | 378 | shapeList[currentShape].Fill = new SolidColorBrush(Colors.LightCyan); |
379 | 379 | ||
380 | double shapeX = Canvas.GetLeft(shapeList[currentShape]); | 380 | double shapeX = Canvas.GetLeft(shapeList[currentShape]); |
381 | double shapeY = Canvas.GetTop(shapeList[currentShape]); | 381 | double shapeY = Canvas.GetTop(shapeList[currentShape]); |
382 | shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; | 382 | shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; |
383 | shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); | 383 | shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); |
384 | shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); | 384 | shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); |
385 | 385 | ||
386 | double width = (int)shapeList[currentShape].Width; | 386 | double width = (int)shapeList[currentShape].Width; |
387 | double height = (int)shapeList[currentShape].Height; | 387 | double height = (int)shapeList[currentShape].Height; |
388 | shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; | 388 | shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; |
389 | shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); | 389 | shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); |
390 | shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); | 390 | shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); |
391 | 391 | ||
392 | this.Children.Add(shapePosIndicator); | 392 | this.Children.Add(shapePosIndicator); |
393 | this.Children.Add(shapeSizeIndicator); | 393 | this.Children.Add(shapeSizeIndicator); |
394 | } | 394 | } |
395 | 395 | ||
396 | LastPoint = Mouse.GetPosition(this); | 396 | LastPoint = Mouse.GetPosition(this); |
397 | mouseState = MouseState.Drag; | 397 | mouseState = MouseState.Drag; |
398 | } | 398 | } |
399 | e.Handled = true; | 399 | e.Handled = true; |
400 | } | 400 | } |
401 | 401 | ||
402 | protected override void OnMouseMove(MouseEventArgs e) | 402 | protected override void OnMouseMove(MouseEventArgs e) |
403 | { | 403 | { |
404 | base.OnMouseMove(e); | 404 | base.OnMouseMove(e); |
405 | 405 | ||
406 | if (mouseState == MouseState.None) | 406 | if (mouseState == MouseState.None) |
407 | { | 407 | { |
408 | MouseHitType = SetHitType(Mouse.GetPosition(this)); | 408 | MouseHitType = SetHitType(Mouse.GetPosition(this)); |
409 | SetMouseCursor(); | 409 | SetMouseCursor(); |
410 | } | 410 | } |
411 | else if (Operation == OperationState.DrawRoute && isStartDrawRoute) | 411 | else if (Operation == OperationState.DrawRoute && isStartDrawRoute) |
412 | { | 412 | { |
413 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine]; | 413 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine]; |
414 | 414 | ||
415 | // See how much the mouse has moved. | 415 | // See how much the mouse has moved. |
416 | Point point = Mouse.GetPosition(this); | 416 | Point point = Mouse.GetPosition(this); |
417 | double offset_x = point.X - StartDrawPoint.X; | 417 | double offset_x = point.X - StartDrawPoint.X; |
418 | double offset_y = point.Y - StartDrawPoint.Y; | 418 | double offset_y = point.Y - StartDrawPoint.Y; |
419 | 419 | ||
420 | // Get the line's current position. | 420 | // Get the line's current position. |
421 | double new_x = lineGeometry.StartPoint.X; | 421 | double new_x = lineGeometry.StartPoint.X; |
422 | double new_y = lineGeometry.StartPoint.Y; | 422 | double new_y = lineGeometry.StartPoint.Y; |
423 | 423 | ||
424 | if (offset_x != 0 || offset_y != 0) | 424 | if (offset_x != 0 || offset_y != 0) |
425 | { | 425 | { |
426 | if (Math.Abs(offset_x) >= Math.Abs(offset_y)) | 426 | if (Math.Abs(offset_x) >= Math.Abs(offset_y)) |
427 | { | 427 | { |
428 | new_x = point.X; | 428 | new_x = point.X; |
429 | } | 429 | } |
430 | else | 430 | else |
431 | { | 431 | { |
432 | new_y = point.Y; | 432 | new_y = point.Y; |
433 | } | 433 | } |
434 | } | 434 | } |
435 | 435 | ||
436 | // Set end point of current line | 436 | // Set end point of current line |
437 | LastPoint = new Point(new_x, new_y); | 437 | LastPoint = new Point(new_x, new_y); |
438 | lineGeometry.EndPoint = LastPoint; | 438 | lineGeometry.EndPoint = LastPoint; |
439 | DisplayCoordinate(LastPoint); | 439 | DisplayCoordinate(LastPoint); |
440 | } | 440 | } |
441 | else if (Operation == OperationState.DrawObstract) | 441 | else if (Operation == OperationState.DrawObstract) |
442 | { | 442 | { |
443 | if (mouseState == MouseState.Drag) | 443 | if (mouseState == MouseState.Drag) |
444 | { | 444 | { |
445 | // See how much the mouse has moved. | 445 | // See how much the mouse has moved. |
446 | Point point = Mouse.GetPosition(this); | 446 | Point point = Mouse.GetPosition(this); |
447 | double offset_x = point.X - LastPoint.X; | 447 | double offset_x = point.X - LastPoint.X; |
448 | double offset_y = point.Y - LastPoint.Y; | 448 | double offset_y = point.Y - LastPoint.Y; |
449 | 449 | ||
450 | // Get the rectangle's current position. | 450 | // Get the rectangle's current position. |
451 | double new_x = Canvas.GetLeft(shapeList[currentShape]); | 451 | double new_x = Canvas.GetLeft(shapeList[currentShape]); |
452 | double new_y = Canvas.GetTop(shapeList[currentShape]); | 452 | double new_y = Canvas.GetTop(shapeList[currentShape]); |
453 | double new_width = shapeList[currentShape].Width; | 453 | double new_width = shapeList[currentShape].Width; |
454 | double new_height = shapeList[currentShape].Height; | 454 | double new_height = shapeList[currentShape].Height; |
455 | 455 | ||
456 | // Update the rectangle. | 456 | // Update the rectangle. |
457 | switch (MouseHitType) | 457 | switch (MouseHitType) |
458 | { | 458 | { |
459 | case HitType.Body: | 459 | case HitType.Body: |
460 | new_x += offset_x; | 460 | new_x += offset_x; |
461 | new_y += offset_y; | 461 | new_y += offset_y; |
462 | break; | 462 | break; |
463 | case HitType.UL: | 463 | case HitType.UL: |
464 | new_x += offset_x; | 464 | new_x += offset_x; |
465 | new_y += offset_y; | 465 | new_y += offset_y; |
466 | new_width -= offset_x; | 466 | new_width -= offset_x; |
467 | new_height -= offset_y; | 467 | new_height -= offset_y; |
468 | break; | 468 | break; |
469 | case HitType.UR: | 469 | case HitType.UR: |
470 | new_y += offset_y; | 470 | new_y += offset_y; |
471 | new_width += offset_x; | 471 | new_width += offset_x; |
472 | new_height -= offset_y; | 472 | new_height -= offset_y; |
473 | break; | 473 | break; |
474 | case HitType.LR: | 474 | case HitType.LR: |
475 | new_width += offset_x; | 475 | new_width += offset_x; |
476 | new_height += offset_y; | 476 | new_height += offset_y; |
477 | break; | 477 | break; |
478 | case HitType.LL: | 478 | case HitType.LL: |
479 | new_x += offset_x; | 479 | new_x += offset_x; |
480 | new_width -= offset_x; | 480 | new_width -= offset_x; |
481 | new_height += offset_y; | 481 | new_height += offset_y; |
482 | break; | 482 | break; |
483 | case HitType.L: | 483 | case HitType.L: |
484 | new_x += offset_x; | 484 | new_x += offset_x; |
485 | new_width -= offset_x; | 485 | new_width -= offset_x; |
486 | break; | 486 | break; |
487 | case HitType.R: | 487 | case HitType.R: |
488 | new_width += offset_x; | 488 | new_width += offset_x; |
489 | break; | 489 | break; |
490 | case HitType.B: | 490 | case HitType.B: |
491 | new_height += offset_y; | 491 | new_height += offset_y; |
492 | break; | 492 | break; |
493 | case HitType.T: | 493 | case HitType.T: |
494 | new_y += offset_y; | 494 | new_y += offset_y; |
495 | new_height -= offset_y; | 495 | new_height -= offset_y; |
496 | break; | 496 | break; |
497 | } | 497 | } |
498 | // Don't use negative width or height. | 498 | // Don't use negative width or height. |
499 | if ((new_width > 0) && (new_height > 0)) | 499 | if ((new_width > 0) && (new_height > 0)) |
500 | { | 500 | { |
501 | // Update the rectangle. | 501 | // Update the rectangle. |
502 | Canvas.SetLeft(shapeList[currentShape], new_x); | 502 | Canvas.SetLeft(shapeList[currentShape], new_x); |
503 | Canvas.SetTop(shapeList[currentShape], new_y); | 503 | Canvas.SetTop(shapeList[currentShape], new_y); |
504 | shapeList[currentShape].Width = new_width; | 504 | shapeList[currentShape].Width = new_width; |
505 | shapeList[currentShape].Height = new_height; | 505 | shapeList[currentShape].Height = new_height; |
506 | 506 | ||
507 | // Save the mouse's new location. | 507 | // Save the mouse's new location. |
508 | LastPoint = point; | 508 | LastPoint = point; |
509 | 509 | ||
510 | } | 510 | } |
511 | } | 511 | } |
512 | else if (mouseState == MouseState.Draw) | 512 | else if (mouseState == MouseState.Draw) |
513 | { | 513 | { |
514 | 514 | ||
515 | // See how much the mouse has moved. | 515 | // See how much the mouse has moved. |
516 | Point point = Mouse.GetPosition(this); | 516 | Point point = Mouse.GetPosition(this); |
517 | 517 | ||
518 | 518 | ||
519 | double offset_x = point.X - StartDrawPoint.X; | 519 | double offset_x = point.X - StartDrawPoint.X; |
520 | double offset_y = point.Y - StartDrawPoint.Y; | 520 | double offset_y = point.Y - StartDrawPoint.Y; |
521 | 521 | ||
522 | // Get the rectangle's current position. | 522 | // Get the rectangle's current position. |
523 | double start_x = Canvas.GetLeft(shapeList[currentShape]); | 523 | double start_x = Canvas.GetLeft(shapeList[currentShape]); |
524 | double start_y = Canvas.GetTop(shapeList[currentShape]); | 524 | double start_y = Canvas.GetTop(shapeList[currentShape]); |
525 | double new_x = Canvas.GetLeft(shapeList[currentShape]); | 525 | double new_x = Canvas.GetLeft(shapeList[currentShape]); |
526 | double new_y = Canvas.GetTop(shapeList[currentShape]); | 526 | double new_y = Canvas.GetTop(shapeList[currentShape]); |
527 | double new_width = offset_x; | 527 | double new_width = offset_x; |
528 | double new_height = offset_y; | 528 | double new_height = offset_y; |
529 | if (offset_x < 0) | 529 | if (offset_x < 0) |
530 | { | 530 | { |
531 | new_x = point.X; | 531 | new_x = point.X; |
532 | new_width = -offset_x; | 532 | new_width = -offset_x; |
533 | } | 533 | } |
534 | if (offset_y < 0) | 534 | if (offset_y < 0) |
535 | { | 535 | { |
536 | new_y = point.Y; | 536 | new_y = point.Y; |
537 | new_height = -offset_y; | 537 | new_height = -offset_y; |
538 | } | 538 | } |
539 | Canvas.SetLeft(shapeList[currentShape], new_x); | 539 | Canvas.SetLeft(shapeList[currentShape], new_x); |
540 | Canvas.SetTop(shapeList[currentShape], new_y); | 540 | Canvas.SetTop(shapeList[currentShape], new_y); |
541 | shapeList[currentShape].Width = new_width; | 541 | shapeList[currentShape].Width = new_width; |
542 | shapeList[currentShape].Height = new_height; | 542 | shapeList[currentShape].Height = new_height; |
543 | 543 | ||
544 | } | 544 | } |
545 | 545 | ||
546 | double shapeX = Canvas.GetLeft(shapeList[currentShape]); | 546 | double shapeX = Canvas.GetLeft(shapeList[currentShape]); |
547 | double shapeY = Canvas.GetTop(shapeList[currentShape]); | 547 | double shapeY = Canvas.GetTop(shapeList[currentShape]); |
548 | shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; | 548 | shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; |
549 | shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); | 549 | shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); |
550 | shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); | 550 | shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); |
551 | 551 | ||
552 | double width = (int)shapeList[currentShape].Width; | 552 | double width = (int)shapeList[currentShape].Width; |
553 | double height = (int)shapeList[currentShape].Height; | 553 | double height = (int)shapeList[currentShape].Height; |
554 | shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; | 554 | shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; |
555 | shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); | 555 | shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); |
556 | shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); | 556 | shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); |
557 | } | 557 | } |
558 | e.Handled = true; | 558 | e.Handled = true; |
559 | } | 559 | } |
560 | 560 | ||
561 | protected override void OnMouseUp(MouseButtonEventArgs e) | 561 | protected override void OnMouseUp(MouseButtonEventArgs e) |
562 | { | 562 | { |
563 | base.OnMouseUp(e); | 563 | base.OnMouseUp(e); |
564 | if (Operation == OperationState.DrawObstract) | 564 | if (Operation == OperationState.DrawObstract) |
565 | { | 565 | { |
566 | if (shapeList.Count() != 0) | 566 | if (shapeList.Count() != 0) |
567 | shapeList[currentShape].Fill = new SolidColorBrush(Colors.Blue); | 567 | shapeList[currentShape].Fill = new SolidColorBrush(Colors.Blue); |
568 | shapePosIndicator.Text = ""; | 568 | shapePosIndicator.Text = ""; |
569 | shapeSizeIndicator.Text = ""; | 569 | shapeSizeIndicator.Text = ""; |
570 | this.Children.Remove(shapePosIndicator); | 570 | this.Children.Remove(shapePosIndicator); |
571 | this.Children.Remove(shapeSizeIndicator); | 571 | this.Children.Remove(shapeSizeIndicator); |
572 | 572 | ||
573 | mouseState = MouseState.None; | 573 | mouseState = MouseState.None; |
574 | currentShape = 0; | 574 | currentShape = 0; |
575 | } | 575 | } |
576 | e.Handled = true; | 576 | e.Handled = true; |
577 | } | 577 | } |
578 | 578 | ||
579 | /// <summary> | 579 | /// <summary> |
580 | /// On Preview Mouse Down | 580 | /// On Preview Mouse Down |
581 | /// </summary> | 581 | /// </summary> |
582 | /// <param name="e"></param> | 582 | /// <param name="e"></param> |
583 | protected override void OnPreviewMouseDown(MouseButtonEventArgs e) | 583 | protected override void OnPreviewMouseDown(MouseButtonEventArgs e) |
584 | { | 584 | { |
585 | base.OnPreviewMouseDown(e); | 585 | base.OnPreviewMouseDown(e); |
586 | if (Operation != OperationState.DrawRoute) | 586 | if (Operation != OperationState.DrawRoute) |
587 | { | 587 | { |
588 | return; | 588 | return; |
589 | } | 589 | } |
590 | 590 | ||
591 | Point currentPoint = e.MouseDevice.GetPosition(this); | 591 | Point currentPoint = e.MouseDevice.GetPosition(this); |
592 | bool _isStart = IsStartEndRoute(_startPoint, currentPoint); | 592 | bool _isStart = IsStartEndRoute(_startPoint, currentPoint); |
593 | 593 | ||
594 | if (_isStart && isStartDrawRoute == false) | 594 | if (_isStart && isStartDrawRoute == false) |
595 | { | 595 | { |
596 | double centerY = Canvas.GetTop(_startPoint); | 596 | double centerY = Canvas.GetTop(_startPoint); |
597 | double centerX = Canvas.GetLeft(_startPoint); | 597 | double centerX = Canvas.GetLeft(_startPoint); |
598 | 598 | ||
599 | isStartDrawRoute = true; | 599 | isStartDrawRoute = true; |
600 | InitDrawRoute(); | 600 | InitDrawRoute(); |
601 | DrawLine(new Point(centerX + 25, centerY + 25), new Point(centerX + 25, centerY + 25), gGrpLine); | 601 | DrawLine(new Point(centerX + 25, centerY + 25), new Point(centerX + 25, centerY + 25), gGrpLine); |
602 | mouseState = MouseState.Draw; | 602 | mouseState = MouseState.Draw; |
603 | currentLine = gGrpLine.Children.Count - 1; | 603 | currentLine = gGrpLine.Children.Count - 1; |
604 | StartDrawPoint = new Point(centerX + 25, centerY + 25); | 604 | StartDrawPoint = new Point(centerX + 25, centerY + 25); |
605 | 605 | ||
606 | this.Children.Remove(_startPoint); | 606 | this.Children.Remove(_startPoint); |
607 | this.Children.Add(_startPoint); | 607 | this.Children.Add(_startPoint); |
608 | 608 | ||
609 | return; | 609 | return; |
610 | } | 610 | } |
611 | 611 | ||
612 | bool _isgoal = IsStartEndRoute(_goalPoint, LastPoint); | 612 | bool _isgoal = IsStartEndRoute(_goalPoint, LastPoint); |
613 | if (_isgoal && isGoalDrawRoute == false) | 613 | if (_isgoal && isGoalDrawRoute == false) |
614 | { | 614 | { |
615 | isGoalDrawRoute = true; | 615 | isGoalDrawRoute = true; |
616 | ProcessEndRoute(); | 616 | ProcessEndRoute(); |
617 | } | 617 | } |
618 | } | 618 | } |
619 | 619 | ||
620 | #region Functions for draw route | 620 | #region Functions for draw route |
621 | 621 | ||
622 | /// <summary> | 622 | /// <summary> |
623 | /// Check start or end draw route | 623 | /// Check start or end draw route |
624 | /// </summary> | 624 | /// </summary> |
625 | /// <param name="_ucStartEndButton">Button start</param> | 625 | /// <param name="_ucStartEndButton">Button start</param> |
626 | /// <param name="currentPoint">Position for check</param> | 626 | /// <param name="currentPoint">Position for check</param> |
627 | /// <returns>true: start, false: not start</returns> | 627 | /// <returns>true: start, false: not start</returns> |
628 | private bool IsStartEndRoute(ucStartEndButton _ucStartEndButton, Point currentPoint) | 628 | private bool IsStartEndRoute(ucStartEndButton _ucStartEndButton, Point currentPoint) |
629 | { | 629 | { |
630 | if(_ucStartEndButton == null) | 630 | if(_ucStartEndButton == null) |
631 | { | 631 | { |
632 | return false; | 632 | return false; |
633 | } | 633 | } |
634 | 634 | ||
635 | double centerX = Canvas.GetLeft(_ucStartEndButton); | 635 | double centerX = Canvas.GetLeft(_ucStartEndButton); |
636 | double centerY = Canvas.GetTop(_ucStartEndButton); | 636 | double centerY = Canvas.GetTop(_ucStartEndButton); |
637 | 637 | ||
638 | if (currentPoint.X < centerX + 50 && currentPoint.X > centerX | 638 | if (currentPoint.X < centerX + 50 && currentPoint.X > centerX |
639 | && currentPoint.Y < centerY + 50 && currentPoint.Y > centerY) | 639 | && currentPoint.Y < centerY + 50 && currentPoint.Y > centerY) |
640 | { | 640 | { |
641 | return true; | 641 | return true; |
642 | } | 642 | } |
643 | return false; | 643 | return false; |
644 | } | 644 | } |
645 | 645 | ||
646 | /// <summary> | 646 | /// <summary> |
647 | /// Process when end draw route | 647 | /// Process when end draw route |
648 | /// </summary> | 648 | /// </summary> |
649 | private void ProcessEndRoute() | 649 | private void ProcessEndRoute() |
650 | { | 650 | { |
651 | Operation = OperationState.None; | 651 | Operation = OperationState.None; |
652 | AutoEditLine(); | 652 | AutoEditLine(); |
653 | this.Children.Remove(_displayAxiPosition); | 653 | this.Children.Remove(_displayAxiPosition); |
654 | this.Children.Remove(_goalPoint); | 654 | this.Children.Remove(_goalPoint); |
655 | this.Children.Add(_goalPoint); | 655 | this.Children.Add(_goalPoint); |
656 | } | 656 | } |
657 | 657 | ||
658 | /// <summary> | 658 | /// <summary> |
659 | /// Check end draw route | 659 | /// Check end draw route |
660 | /// </summary> | 660 | /// </summary> |
661 | /// <param name="_ucStartEndButton">Button end</param> | 661 | /// <param name="_ucStartEndButton">Button end</param> |
662 | /// <param name="currentPoint">Position for check</param> | 662 | /// <param name="currentPoint">Position for check</param> |
663 | /// <returns>true: end, false: not end</returns> | 663 | /// <returns>true: end, false: not end</returns> |
664 | private bool IsEndRoute(ucStartEndButton _ucStartEndButton, LineGeometry lineGeometry) | 664 | private bool IsEndRoute(ucStartEndButton _ucStartEndButton, LineGeometry lineGeometry) |
665 | { | 665 | { |
666 | if (_ucStartEndButton == null) | 666 | if (_ucStartEndButton == null) |
667 | { | 667 | { |
668 | return false; | 668 | return false; |
669 | } | 669 | } |
670 | 670 | ||
671 | double centerX = Canvas.GetLeft(_ucStartEndButton); | 671 | double centerX = Canvas.GetLeft(_ucStartEndButton); |
672 | double centerY = Canvas.GetTop(_ucStartEndButton); | 672 | double centerY = Canvas.GetTop(_ucStartEndButton); |
673 | Point startPoint = lineGeometry.StartPoint; | 673 | Point startPoint = lineGeometry.StartPoint; |
674 | Point endPoint = lineGeometry.EndPoint; | 674 | Point endPoint = lineGeometry.EndPoint; |
675 | 675 | ||
676 | if(IsVerticalLine(lineGeometry)) | 676 | if(IsVerticalLine(lineGeometry)) |
677 | { | 677 | { |
678 | if(endPoint.X < centerX || endPoint.X > centerX + 50) | 678 | if(endPoint.X < centerX || endPoint.X > centerX + 50) |
679 | return false; | 679 | return false; |
680 | 680 | ||
681 | if (startPoint.Y > centerY + 50 && endPoint.Y > centerY + 50) | 681 | if (startPoint.Y > centerY + 50 && endPoint.Y > centerY + 50) |
682 | return false; | 682 | return false; |
683 | 683 | ||
684 | if (startPoint.Y < centerY && endPoint.Y < centerY) | 684 | if (startPoint.Y < centerY && endPoint.Y < centerY) |
685 | return false; | 685 | return false; |
686 | }else | 686 | }else |
687 | { | 687 | { |
688 | if (endPoint.Y < centerY || endPoint.Y > centerY + 50) | 688 | if (endPoint.Y < centerY || endPoint.Y > centerY + 50) |
689 | return false; | 689 | return false; |
690 | 690 | ||
691 | if (startPoint.X > centerX + 50 && endPoint.X > centerX + 50) | 691 | if (startPoint.X > centerX + 50 && endPoint.X > centerX + 50) |
692 | return false; | 692 | return false; |
693 | 693 | ||
694 | if (startPoint.X < centerX && endPoint.X < centerX) | 694 | if (startPoint.X < centerX && endPoint.X < centerX) |
695 | return false; | 695 | return false; |
696 | } | 696 | } |
697 | 697 | ||
698 | return true; | 698 | return true; |
699 | } | 699 | } |
700 | 700 | ||
701 | /// <summary> | 701 | /// <summary> |
702 | /// Make root | 702 | /// Make root |
703 | /// </summary> | 703 | /// </summary> |
704 | public void MakeRoot() | 704 | public void MakeRoot() |
705 | { | 705 | { |
706 | //LineGeometry lineGeometry; | 706 | //LineGeometry lineGeometry; |
707 | //EllipseGeometry ellipseGeometry; | 707 | //EllipseGeometry ellipseGeometry; |
708 | //Point startPoint; | 708 | //Point startPoint; |
709 | //Point endPoint; | 709 | //Point endPoint; |
710 | 710 | ||
711 | // If still not route | 711 | // If still not route |
712 | if (gGrpLine.Children.Count == 0) | 712 | if (gGrpLine.Children.Count == 0) |
713 | return; | 713 | return; |
714 | 714 | ||
715 | pLine.Stroke = new SolidColorBrush(Colors.Red); | 715 | pLine.Stroke = new SolidColorBrush(Colors.Red); |
716 | pLine.StrokeThickness = STROKE_ROOT_LINE; | 716 | pLine.StrokeThickness = STROKE_ROOT_LINE; |
717 | 717 | ||
718 | //// Setting for path line | 718 | //// Setting for path line |
719 | //pRootLine.Stroke = new SolidColorBrush(Colors.Red); | 719 | //pRootLine.Stroke = new SolidColorBrush(Colors.Red); |
720 | //pRootLine.StrokeThickness = STROKE_ROOT_LINE; | 720 | //pRootLine.StrokeThickness = STROKE_ROOT_LINE; |
721 | //pRootLine.Data = gGrpRootLine; | 721 | //pRootLine.Data = gGrpRootLine; |
722 | //this.Children.Add(pRootLine); | 722 | //this.Children.Add(pRootLine); |
723 | 723 | ||
724 | // Setting for path curver line | 724 | // Setting for path curver line |
725 | //pCurverLine.StrokeThickness = STROKE_ROOT_LINE; | 725 | //pCurverLine.StrokeThickness = STROKE_ROOT_LINE; |
726 | 726 | ||
727 | //// Get start point | 727 | //// Get start point |
728 | //lineGeometry = (LineGeometry)gGrpLine.Children[0]; | 728 | //lineGeometry = (LineGeometry)gGrpLine.Children[0]; |
729 | //startPoint = lineGeometry.StartPoint; | 729 | //startPoint = lineGeometry.StartPoint; |
730 | 730 | ||
731 | //for (int i = 0; i < gGrpYellowNode.Children.Count; i = i + 2) | 731 | //for (int i = 0; i < gGrpYellowNode.Children.Count; i = i + 2) |
732 | //{ | 732 | //{ |
733 | // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i]; | 733 | // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i]; |
734 | // endPoint = ellipseGeometry.Center; | 734 | // endPoint = ellipseGeometry.Center; |
735 | 735 | ||
736 | // DrawLine(startPoint, endPoint, gGrpRootLine); | 736 | // DrawLine(startPoint, endPoint, gGrpRootLine); |
737 | 737 | ||
738 | // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i + 1]; | 738 | // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i + 1]; |
739 | // startPoint = ellipseGeometry.Center; | 739 | // startPoint = ellipseGeometry.Center; |
740 | //} | 740 | //} |
741 | 741 | ||
742 | //lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count - 1]; | 742 | //lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count - 1]; |
743 | //endPoint = lineGeometry.EndPoint; | 743 | //endPoint = lineGeometry.EndPoint; |
744 | 744 | ||
745 | //DrawLine(startPoint, endPoint, gGrpRootLine); | 745 | //DrawLine(startPoint, endPoint, gGrpRootLine); |
746 | 746 | ||
747 | //this.Children.Remove(pYellowNode); | 747 | //this.Children.Remove(pYellowNode); |
748 | //this.Children.Remove(pBlueNode); | 748 | //this.Children.Remove(pBlueNode); |
749 | //this.Children.Remove(_startPoint); | 749 | //this.Children.Remove(_startPoint); |
750 | //this.Children.Remove(_goalPoint); | 750 | //this.Children.Remove(_goalPoint); |
751 | //this.Children.Add(pYellowNode); | 751 | //this.Children.Add(pYellowNode); |
752 | //this.Children.Add(pBlueNode); | 752 | //this.Children.Add(pBlueNode); |
753 | //this.Children.Add(_startPoint); | 753 | //this.Children.Add(_startPoint); |
754 | //this.Children.Add(_goalPoint); | 754 | //this.Children.Add(_goalPoint); |
755 | } | 755 | } |
756 | 756 | ||
757 | /// <summary> | 757 | /// <summary> |
758 | /// Auto edit leght of line | 758 | /// Auto edit leght of line |
759 | /// </summary> | 759 | /// </summary> |
760 | private void AutoEditLine() | 760 | private void AutoEditLine() |
761 | { | 761 | { |
762 | double temp; | 762 | double temp; |
763 | int index = gGrpLine.Children.Count - 1; | 763 | int index = gGrpLine.Children.Count - 1; |
764 | double centerY = Canvas.GetTop(_goalPoint) + 25; | 764 | double centerY = Canvas.GetTop(_goalPoint) + 25; |
765 | double centerX = Canvas.GetLeft(_goalPoint) + 25; | 765 | double centerX = Canvas.GetLeft(_goalPoint) + 25; |
766 | LineGeometry lastLine = (LineGeometry)gGrpLine.Children[index]; | 766 | LineGeometry lastLine = (LineGeometry)gGrpLine.Children[index]; |
767 | LineGeometry beforeLastLine = (LineGeometry)gGrpLine.Children[index]; | 767 | LineGeometry beforeLastLine = (LineGeometry)gGrpLine.Children[index]; |
768 | 768 | ||
769 | if(gGrpLine.Children.Count > 1) | 769 | if(gGrpLine.Children.Count > 1) |
770 | { | 770 | { |
771 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; | 771 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; |
772 | 772 | ||
773 | if (!IsCurverNode(beforeLastLine, lastLine)) | 773 | if (!IsCurverNode(beforeLastLine, lastLine)) |
774 | { | 774 | { |
775 | beforeLastLine.EndPoint = lastLine.EndPoint; | 775 | beforeLastLine.EndPoint = lastLine.EndPoint; |
776 | gGrpLine.Children.RemoveAt(index); | 776 | gGrpLine.Children.RemoveAt(index); |
777 | // Remove yellow node | 777 | //// Remove yellow node |
778 | if (gGrpYellowNode.Children.Count > 0) | 778 | //if (gGrpYellowNode.Children.Count > 0) |
779 | { | 779 | //{ |
780 | gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); | 780 | // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); |
781 | gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); | 781 | // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); |
782 | } | 782 | //} |
783 | // Remove curver line | 783 | //// Remove curver line |
784 | if (gGrpCurverLine.Children.Count > 0) | 784 | //if (gGrpCurverLine.Children.Count > 0) |
785 | { | 785 | //{ |
786 | gGrpCurverLine.Children.RemoveAt(gGrpCurverLine.Children.Count - 1); | 786 | // gGrpCurverLine.Children.RemoveAt(gGrpCurverLine.Children.Count - 1); |
787 | } | 787 | //} |
788 | index = index - 1; | 788 | index = index - 1; |
789 | lastLine = (LineGeometry)gGrpLine.Children[index]; | 789 | lastLine = (LineGeometry)gGrpLine.Children[index]; |
790 | } | 790 | } |
791 | } | 791 | } |
792 | 792 | ||
793 | if (index == gGrpRedNode.Children.Count + 1) | ||
794 | { | ||
795 | AddNode(lastLine.StartPoint, gGrpRedNode); | ||
796 | } | ||
797 | |||
793 | if (lastLine.EndPoint.X == centerX && lastLine.EndPoint.Y == centerY) | 798 | if (lastLine.EndPoint.X == centerX && lastLine.EndPoint.Y == centerY) |
794 | return; | 799 | return; |
795 | 800 | ||
796 | if(IsVerticalLine(lastLine)) | 801 | if(IsVerticalLine(lastLine)) |
797 | { | 802 | { |
798 | temp = lastLine.StartPoint.Y; | 803 | temp = lastLine.StartPoint.Y; |
799 | lastLine.StartPoint = new Point(centerX, temp); | 804 | lastLine.StartPoint = new Point(centerX, temp); |
800 | lastLine.EndPoint = new Point(centerX, centerY); | 805 | lastLine.EndPoint = new Point(centerX, centerY); |
801 | 806 | ||
802 | if(gGrpLine.Children.Count > 1){ | 807 | if(gGrpLine.Children.Count > 1){ |
803 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; | 808 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; |
804 | temp = beforeLastLine.EndPoint.Y; | 809 | temp = beforeLastLine.EndPoint.Y; |
805 | beforeLastLine.EndPoint = new Point(centerX, temp); | 810 | beforeLastLine.EndPoint = new Point(centerX, temp); |
806 | } | 811 | } |
807 | }else | 812 | }else |
808 | { | 813 | { |
809 | temp = lastLine.StartPoint.X; | 814 | temp = lastLine.StartPoint.X; |
810 | lastLine.StartPoint = new Point(temp, centerY); | 815 | lastLine.StartPoint = new Point(temp, centerY); |
811 | lastLine.EndPoint = new Point(centerX, centerY); | 816 | lastLine.EndPoint = new Point(centerX, centerY); |
812 | if (gGrpLine.Children.Count > 1) | 817 | if (gGrpLine.Children.Count > 1) |
813 | { | 818 | { |
814 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; | 819 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; |
815 | temp = beforeLastLine.EndPoint.X; | 820 | temp = beforeLastLine.EndPoint.X; |
816 | beforeLastLine.EndPoint = new Point(temp, centerY); | 821 | beforeLastLine.EndPoint = new Point(temp, centerY); |
817 | } | 822 | } |
818 | } | 823 | } |
819 | 824 | ||
820 | // Draw curver line | 825 | // Draw curver line |
821 | if (IsCurverNode(beforeLastLine, lastLine)) | 826 | if (IsCurverNode(beforeLastLine, lastLine)) |
822 | { | 827 | { |
823 | AddNode(beforeLastLine.EndPoint, gGrpRedNode); | 828 | EllipseGeometry ellipseGeometry = (EllipseGeometry)gGrpRedNode.Children[gGrpRedNode.Children.Count - 1]; |
824 | if (GetDistance(lastLine.StartPoint, lastLine.EndPoint) > RADIUS_CURVER_LINE + 25) | 829 | ellipseGeometry.Center = lastLine.StartPoint; |
825 | { | 830 | // |
826 | DrawCurver(beforeLastLine, lastLine); | 831 | //if (GetDistance(lastLine.StartPoint, lastLine.EndPoint) > RADIUS_CURVER_LINE + 25) |
827 | } | 832 | //{ |
833 | //DrawCurver(beforeLastLine, lastLine); | ||
834 | //} | ||
828 | } | 835 | } |
829 | } | 836 | } |
830 | 837 | ||
831 | /// <summary> | 838 | /// <summary> |
832 | /// Check draw curver node | 839 | /// Check draw curver node |
833 | /// </summary> | 840 | /// </summary> |
834 | /// <param name="oldLine">Old line</param> | 841 | /// <param name="oldLine">Old line</param> |
835 | /// <param name="newLine">New line</param> | 842 | /// <param name="newLine">New line</param> |
836 | /// <returns>true:is curver, fasle: not curver</returns> | 843 | /// <returns>true:is curver, fasle: not curver</returns> |
837 | private bool IsCurverNode(LineGeometry oldLine, LineGeometry newLine) | 844 | private bool IsCurverNode(LineGeometry oldLine, LineGeometry newLine) |
838 | { | 845 | { |
839 | if (oldLine.StartPoint.Y == oldLine.EndPoint.Y && oldLine.StartPoint.Y == newLine.EndPoint.Y) | 846 | if (oldLine.StartPoint.Y == oldLine.EndPoint.Y && oldLine.StartPoint.Y == newLine.EndPoint.Y) |
840 | { | 847 | { |
841 | return false; | 848 | return false; |
842 | } | 849 | } |
843 | 850 | ||
844 | if (oldLine.StartPoint.X == oldLine.EndPoint.X && oldLine.StartPoint.X == newLine.EndPoint.X) | 851 | if (oldLine.StartPoint.X == oldLine.EndPoint.X && oldLine.StartPoint.X == newLine.EndPoint.X) |
845 | { | 852 | { |
846 | return false; | 853 | return false; |
847 | } | 854 | } |
848 | 855 | ||
849 | return true; | 856 | return true; |
850 | } | 857 | } |
851 | 858 | ||
852 | /// <summary> | 859 | /// <summary> |
853 | /// Check timming to stop draw route | 860 | /// Check timming to stop draw route |
854 | /// </summary> | 861 | /// </summary> |
855 | /// <param name="e"></param> | 862 | /// <param name="e"></param> |
856 | /// <returns>true:stop; false:continue</returns> | 863 | /// <returns>true:stop; false:continue</returns> |
857 | private bool IsStopDrawRoute(MouseEventArgs e) | 864 | private bool IsStopDrawRoute(MouseEventArgs e) |
858 | { | 865 | { |
859 | if(e.RightButton == MouseButtonState.Pressed) | 866 | if(e.RightButton == MouseButtonState.Pressed) |
860 | { | 867 | { |
861 | return true; | 868 | return true; |
862 | } | 869 | } |
863 | 870 | ||
864 | return false; | 871 | return false; |
865 | } | 872 | } |
866 | 873 | ||
867 | /// <summary> | 874 | /// <summary> |
868 | /// Draw curver line and yellow node | 875 | /// Draw curver line and yellow node |
869 | /// </summary> | 876 | /// </summary> |
870 | /// <param name="oldLine">Old line</param> | 877 | /// <param name="oldLine">Old line</param> |
871 | /// <param name="newLine">New line</param> | 878 | /// <param name="newLine">New line</param> |
872 | private void DrawCurver(LineGeometry oldLine, LineGeometry newLine) | 879 | private void DrawCurver(LineGeometry oldLine, LineGeometry newLine) |
873 | { | 880 | { |
874 | double radius = RADIUS_CURVER_LINE; | 881 | double radius = RADIUS_CURVER_LINE; |
875 | 882 | ||
876 | Point startPoint ; | 883 | Point startPoint ; |
877 | Point endPoint ; | 884 | Point endPoint ; |
878 | 885 | ||
879 | // Get postion of yellow node on old line | 886 | // Get postion of yellow node on old line |
880 | if(IsVerticalLine(oldLine)) | 887 | if(IsVerticalLine(oldLine)) |
881 | { | 888 | { |
882 | if (oldLine.StartPoint.Y > oldLine.EndPoint.Y) | 889 | if (oldLine.StartPoint.Y > oldLine.EndPoint.Y) |
883 | startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y + radius); | 890 | startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y + radius); |
884 | else | 891 | else |
885 | startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y - radius); | 892 | startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y - radius); |
886 | }else | 893 | }else |
887 | { | 894 | { |
888 | if (oldLine.StartPoint.X > oldLine.EndPoint.X) | 895 | if (oldLine.StartPoint.X > oldLine.EndPoint.X) |
889 | startPoint = new Point(oldLine.EndPoint.X + radius, oldLine.EndPoint.Y); | 896 | startPoint = new Point(oldLine.EndPoint.X + radius, oldLine.EndPoint.Y); |
890 | else | 897 | else |
891 | startPoint = new Point(oldLine.EndPoint.X - radius, oldLine.EndPoint.Y); | 898 | startPoint = new Point(oldLine.EndPoint.X - radius, oldLine.EndPoint.Y); |
892 | } | 899 | } |
893 | 900 | ||
894 | // Get postion of yellow node on new line | 901 | // Get postion of yellow node on new line |
895 | if (IsVerticalLine(newLine)) | 902 | if (IsVerticalLine(newLine)) |
896 | { | 903 | { |
897 | if (newLine.StartPoint.Y > newLine.EndPoint.Y) | 904 | if (newLine.StartPoint.Y > newLine.EndPoint.Y) |
898 | endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y - radius); | 905 | endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y - radius); |
899 | else | 906 | else |
900 | endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y + radius); | 907 | endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y + radius); |
901 | } | 908 | } |
902 | else | 909 | else |
903 | { | 910 | { |
904 | if (newLine.StartPoint.X > newLine.EndPoint.X) | 911 | if (newLine.StartPoint.X > newLine.EndPoint.X) |
905 | endPoint = new Point(newLine.StartPoint.X - radius, newLine.StartPoint.Y); | 912 | endPoint = new Point(newLine.StartPoint.X - radius, newLine.StartPoint.Y); |
906 | else | 913 | else |
907 | endPoint = new Point(newLine.StartPoint.X + radius, newLine.StartPoint.Y); | 914 | endPoint = new Point(newLine.StartPoint.X + radius, newLine.StartPoint.Y); |
908 | } | 915 | } |
909 | 916 | ||
910 | //// Setting sweep direction | 917 | //// Setting sweep direction |
911 | //SweepDirection sweepDirection = SweepDirection.Clockwise; | 918 | //SweepDirection sweepDirection = SweepDirection.Clockwise; |
912 | //if (IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) > 0) | 919 | //if (IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) > 0) |
913 | //{ | 920 | //{ |
914 | // sweepDirection = SweepDirection.Counterclockwise; | 921 | // sweepDirection = SweepDirection.Counterclockwise; |
915 | //} | 922 | //} |
916 | 923 | ||
917 | //if (!IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) < 0) | 924 | //if (!IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) < 0) |
918 | //{ | 925 | //{ |
919 | // sweepDirection = SweepDirection.Counterclockwise; | 926 | // sweepDirection = SweepDirection.Counterclockwise; |
920 | //} | 927 | //} |
921 | 928 | ||
922 | //// Add curver line | 929 | //// Add curver line |
923 | //DrawCurverLine(startPoint, endPoint, sweepDirection, gGrpCurverLine); | 930 | //DrawCurverLine(startPoint, endPoint, sweepDirection, gGrpCurverLine); |
924 | 931 | ||
925 | // Add node to postion distance 1300mm | 932 | // Add node to postion distance 1300mm |
926 | AddNode(startPoint, gGrpYellowNode); | 933 | if (GetDistance(oldLine.StartPoint, oldLine.EndPoint) > RADIUS_CURVER_LINE) |
927 | AddNode(endPoint, gGrpYellowNode); | 934 | { |
935 | AddNode(startPoint, gGrpYellowNode); | ||
936 | } | ||
937 | |||
938 | if (GetDistance(newLine.StartPoint, newLine.EndPoint) > RADIUS_CURVER_LINE) | ||
939 | { | ||
940 | AddNode(endPoint, gGrpYellowNode); | ||
941 | } | ||
928 | } | 942 | } |
929 | 943 | ||
930 | /// <summary> | 944 | /// <summary> |
931 | /// Init data for draw route | 945 | /// Init data for draw route |
932 | /// </summary> | 946 | /// </summary> |
933 | private void InitDrawRoute() | 947 | private void InitDrawRoute() |
934 | { | 948 | { |
935 | // Setting for path line | 949 | // Setting for path line |
936 | pLine.Stroke = new SolidColorBrush(Colors.Blue); | 950 | pLine.Stroke = new SolidColorBrush(Colors.Blue); |
937 | pLine.StrokeThickness = STROKE_LINE; | 951 | pLine.StrokeThickness = STROKE_LINE; |
938 | pLine.Data = gGrpLine; | 952 | pLine.Data = gGrpLine; |
939 | 953 | ||
940 | // Setting for path of curver line | 954 | // Setting for path of curver line |
941 | pCurverLine.Stroke = Brushes.Red; | 955 | pCurverLine.Stroke = Brushes.Red; |
942 | pCurverLine.StrokeThickness = STROKE_LINE; | 956 | pCurverLine.StrokeThickness = STROKE_LINE; |
943 | pCurverLine.Data = gGrpCurverLine; | 957 | pCurverLine.Data = gGrpCurverLine; |
944 | 958 | ||
945 | // Setting for path of red node | 959 | // Setting for path of red node |
946 | pRedNode.Stroke = new SolidColorBrush(Colors.Blue); | 960 | pRedNode.Stroke = new SolidColorBrush(Colors.Blue); |
947 | pRedNode.Fill = new SolidColorBrush(Colors.Red); | 961 | pRedNode.Fill = new SolidColorBrush(Colors.Red); |
948 | pRedNode.StrokeThickness = STROKE_NODE; | 962 | pRedNode.StrokeThickness = STROKE_NODE; |
949 | pRedNode.Data = gGrpRedNode; | 963 | pRedNode.Data = gGrpRedNode; |
950 | 964 | ||
951 | // Setting for path of yellow node | 965 | // Setting for path of yellow node |
952 | pYellowNode.Stroke = new SolidColorBrush(Colors.Blue); | 966 | pYellowNode.Stroke = new SolidColorBrush(Colors.Blue); |
953 | pYellowNode.Fill = new SolidColorBrush(Colors.Yellow); | 967 | pYellowNode.Fill = new SolidColorBrush(Colors.Yellow); |
954 | pYellowNode.StrokeThickness = STROKE_NODE; | 968 | pYellowNode.StrokeThickness = STROKE_NODE; |
955 | pYellowNode.Data = gGrpYellowNode; | 969 | pYellowNode.Data = gGrpYellowNode; |
956 | 970 | ||
957 | // Setting for path of Blue node | 971 | // Setting for path of Blue node |
958 | pBlueNode.Stroke = new SolidColorBrush(Colors.Blue); | 972 | pBlueNode.Stroke = new SolidColorBrush(Colors.Blue); |
959 | pBlueNode.Fill = new SolidColorBrush(Colors.LightBlue); | 973 | pBlueNode.Fill = new SolidColorBrush(Colors.LightBlue); |
960 | pBlueNode.StrokeThickness = STROKE_NODE; | 974 | pBlueNode.StrokeThickness = STROKE_NODE; |
961 | pBlueNode.Data = gGrpBlueNode; | 975 | pBlueNode.Data = gGrpBlueNode; |
962 | 976 | ||
963 | // Setting for path of Free node | 977 | // Setting for path of Free node |
964 | //pFreeNode.Stroke = new SolidColorBrush(Colors.Blue); | 978 | //pFreeNode.Stroke = new SolidColorBrush(Colors.Blue); |
965 | //pFreeNode.Fill = new SolidColorBrush(Colors.LightBlue); | 979 | //pFreeNode.Fill = new SolidColorBrush(Colors.LightBlue); |
966 | //pFreeNode.StrokeThickness = STROKE_NODE; | 980 | //pFreeNode.StrokeThickness = STROKE_NODE; |
967 | //pFreeNode.Data = gGrpFreeNode; | 981 | //pFreeNode.Data = gGrpFreeNode; |
968 | 982 | ||
969 | // Add paths to canvas | 983 | // Add paths to canvas |
970 | this.Children.Add(pLine); | 984 | this.Children.Add(pLine); |
971 | this.Children.Add(pCurverLine); | 985 | this.Children.Add(pCurverLine); |
972 | this.Children.Add(pRedNode); | 986 | this.Children.Add(pRedNode); |
973 | this.Children.Add(pYellowNode); | 987 | this.Children.Add(pYellowNode); |
974 | this.Children.Add(pBlueNode); | 988 | this.Children.Add(pBlueNode); |
975 | } | 989 | } |
976 | 990 | ||
977 | /// <summary> | 991 | /// <summary> |
978 | /// Clear all route | 992 | /// Clear all route |
979 | /// </summary> | 993 | /// </summary> |
980 | public void ClearRoute() | 994 | public void ClearRoute() |
981 | { | 995 | { |
982 | isStartDrawRoute = false; | 996 | isStartDrawRoute = false; |
983 | isGoalDrawRoute = false; | 997 | isGoalDrawRoute = false; |
984 | 998 | ||
985 | gGrpLine.Children.Clear(); | 999 | gGrpLine.Children.Clear(); |
986 | gGrpRootLine.Children.Clear(); | 1000 | gGrpRootLine.Children.Clear(); |
987 | gGrpCurverLine.Children.Clear(); | 1001 | gGrpCurverLine.Children.Clear(); |
988 | gGrpRedNode.Children.Clear(); | 1002 | gGrpRedNode.Children.Clear(); |
989 | gGrpYellowNode.Children.Clear(); | 1003 | gGrpYellowNode.Children.Clear(); |
990 | gGrpBlueNode.Children.Clear(); | 1004 | gGrpBlueNode.Children.Clear(); |
991 | 1005 | ||
992 | this.Children.Remove(pLine); | 1006 | this.Children.Remove(pLine); |
993 | this.Children.Remove(pRootLine); | 1007 | this.Children.Remove(pRootLine); |
994 | this.Children.Remove(pCurverLine); | 1008 | this.Children.Remove(pCurverLine); |
995 | this.Children.Remove(pRedNode); | 1009 | this.Children.Remove(pRedNode); |
996 | this.Children.Remove(pYellowNode); | 1010 | this.Children.Remove(pYellowNode); |
997 | this.Children.Remove(pBlueNode); | 1011 | this.Children.Remove(pBlueNode); |
998 | } | 1012 | } |
999 | 1013 | ||
1000 | /// <summary> | 1014 | /// <summary> |
1001 | /// Draw line for route | 1015 | /// Draw line for route |
1002 | /// </summary> | 1016 | /// </summary> |
1003 | /// <param name="startPoint">Start point</param> | 1017 | /// <param name="startPoint">Start point</param> |
1004 | /// <param name="endPoint">End point</param> | 1018 | /// <param name="endPoint">End point</param> |
1005 | /// <param name="geometryGroup">Geometry Group</param> | 1019 | /// <param name="geometryGroup">Geometry Group</param> |
1006 | private void DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup) | 1020 | private void DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup) |
1007 | { | 1021 | { |
1008 | LineGeometry lineGeometry = new LineGeometry(); | 1022 | LineGeometry lineGeometry = new LineGeometry(); |
1009 | lineGeometry.StartPoint = startPoint; | 1023 | lineGeometry.StartPoint = startPoint; |
1010 | lineGeometry.EndPoint = endPoint; | 1024 | lineGeometry.EndPoint = endPoint; |
1011 | geometryGroup.Children.Add(lineGeometry); | 1025 | geometryGroup.Children.Add(lineGeometry); |
1012 | } | 1026 | } |
1013 | 1027 | ||
1014 | /// <summary> | 1028 | /// <summary> |
1015 | /// Draw curver line | 1029 | /// Draw curver line |
1016 | /// </summary> | 1030 | /// </summary> |
1017 | /// <param name="startPoint">Point start curver line</param> | 1031 | /// <param name="startPoint">Point start curver line</param> |
1018 | /// <param name="endPoint">Point end curver line</param> | 1032 | /// <param name="endPoint">Point end curver line</param> |
1019 | /// <param name="radius">Radius</param> | 1033 | /// <param name="radius">Radius</param> |
1020 | /// <param name="geometryGroup">Geometry Group</param> | 1034 | /// <param name="geometryGroup">Geometry Group</param> |
1021 | private void DrawCurverLine(Point startPoint, Point endPoint, SweepDirection sweepDirection, GeometryGroup geometryGroup) | 1035 | private void DrawCurverLine(Point startPoint, Point endPoint, SweepDirection sweepDirection, GeometryGroup geometryGroup) |
1022 | { | 1036 | { |
1023 | PathGeometry pathGeometry = new PathGeometry(); | 1037 | PathGeometry pathGeometry = new PathGeometry(); |
1024 | PathFigure figure = new PathFigure(); | 1038 | PathFigure figure = new PathFigure(); |
1025 | figure.StartPoint = startPoint; | 1039 | figure.StartPoint = startPoint; |
1026 | figure.Segments.Add(new ArcSegment(endPoint, new Size(RADIUS_CURVER_LINE, RADIUS_CURVER_LINE), 90, false, sweepDirection, true)); | 1040 | figure.Segments.Add(new ArcSegment(endPoint, new Size(RADIUS_CURVER_LINE, RADIUS_CURVER_LINE), 90, false, sweepDirection, true)); |
1027 | pathGeometry.Figures.Add(figure); | 1041 | pathGeometry.Figures.Add(figure); |
1028 | geometryGroup.Children.Add(pathGeometry); | 1042 | geometryGroup.Children.Add(pathGeometry); |
1029 | } | 1043 | } |
1030 | 1044 | ||
1031 | /// <summary> | 1045 | /// <summary> |
1032 | /// Setting node | 1046 | /// Setting node |
1033 | /// </summary> | 1047 | /// </summary> |
1034 | /// <param name="centerPoit">Position of center node</param> | 1048 | /// <param name="centerPoit">Position of center node</param> |
1035 | /// <param name="geometryGroup">Geometry Group</param> | 1049 | /// <param name="geometryGroup">Geometry Group</param> |
1036 | private void AddNode(Point centerPoit, GeometryGroup geometryGroup) | 1050 | private void AddNode(Point centerPoit, GeometryGroup geometryGroup) |
1037 | { | 1051 | { |
1038 | double radius = RADIUS_NODE; | 1052 | double radius = RADIUS_NODE; |
1039 | geometryGroup.Children.Add(new EllipseGeometry(centerPoit, radius, radius)); | 1053 | geometryGroup.Children.Add(new EllipseGeometry(centerPoit, radius, radius)); |
1040 | } | 1054 | } |
1041 | 1055 | ||
1042 | /// <summary> | 1056 | /// <summary> |
1043 | /// Check line is vertical or horizontal | 1057 | /// Check line is vertical or horizontal |
1044 | /// </summary> | 1058 | /// </summary> |
1045 | /// <param name="line"></param> | 1059 | /// <param name="line"></param> |
1046 | /// <returns>true:Vertical, false:Horizontal</returns> | 1060 | /// <returns>true:Vertical, false:Horizontal</returns> |
1047 | private bool IsVerticalLine(LineGeometry line) | 1061 | private bool IsVerticalLine(LineGeometry line) |
1048 | { | 1062 | { |
1049 | if (line.StartPoint.X == line.EndPoint.X) | 1063 | if (line.StartPoint.X == line.EndPoint.X) |
1050 | { | 1064 | { |
1051 | // Vertical line | 1065 | // Vertical line |
1052 | return true; | 1066 | return true; |
1053 | } | 1067 | } |
1054 | 1068 | ||
1055 | // Horizontal line | 1069 | // Horizontal line |
1056 | return false; | 1070 | return false; |
1057 | } | 1071 | } |
1058 | 1072 | ||
1059 | /// <summary> | 1073 | /// <summary> |
1060 | /// Get distance between two point | 1074 | /// Get distance between two point |
1061 | /// </summary> | 1075 | /// </summary> |
1062 | /// <param name="point1">Point 1</param> | 1076 | /// <param name="point1">Point 1</param> |
1063 | /// <param name="point2">Point 2</param> | 1077 | /// <param name="point2">Point 2</param> |
1064 | /// <returns>Distance between two point</returns> | 1078 | /// <returns>Distance between two point</returns> |
1065 | private double GetDistance(Point point1, Point point2) | 1079 | private double GetDistance(Point point1, Point point2) |
1066 | { | 1080 | { |
1067 | //pythagorean theorem c^2 = a^2 + b^2 | 1081 | //pythagorean theorem c^2 = a^2 + b^2 |
1068 | //thus c = square root(a^2 + b^2) | 1082 | //thus c = square root(a^2 + b^2) |
1069 | double a = (double)(point2.X - point1.X); | 1083 | double a = (double)(point2.X - point1.X); |
1070 | double b = (double)(point2.Y - point1.Y); | 1084 | double b = (double)(point2.Y - point1.Y); |
1071 | 1085 | ||
1072 | return Math.Sqrt(a * a + b * b); | 1086 | return Math.Sqrt(a * a + b * b); |
1073 | } | 1087 | } |
1074 | 1088 | ||
1075 | /// <summary> | 1089 | /// <summary> |
1076 | /// Check point is valid for draw | 1090 | /// Check point is valid for draw |
1077 | /// </summary> | 1091 | /// </summary> |
1078 | /// <param name="point">Poit need check</param> | 1092 | /// <param name="point">Poit need check</param> |
1079 | /// <returns>true:Valid, false:Invalid</returns> | 1093 | /// <returns>true:Valid, false:Invalid</returns> |
1080 | private bool IsValidPoint(Point point) | 1094 | private bool IsValidPoint(Point point) |
1081 | { | 1095 | { |
1082 | return true; | 1096 | return true; |
1083 | } | 1097 | } |
1084 | 1098 | ||
1085 | /// <summary> | 1099 | /// <summary> |
1086 | /// Display coordinate position | 1100 | /// Display coordinate position |
1087 | /// </summary> | 1101 | /// </summary> |
1088 | /// <param name="point">Position to display</param> | 1102 | /// <param name="point">Position to display</param> |
1089 | private void DisplayCoordinate(Point point) | 1103 | private void DisplayCoordinate(Point point) |
1090 | { | 1104 | { |
1091 | if (_displayAxiPosition == null) | 1105 | if (_displayAxiPosition == null) |
1092 | { | 1106 | { |
1093 | _displayAxiPosition = new ucDisplayCoordinate(); | 1107 | _displayAxiPosition = new ucDisplayCoordinate(); |
1094 | this.Children.Add(_displayAxiPosition); | 1108 | this.Children.Add(_displayAxiPosition); |
1095 | } | 1109 | } |
1096 | _displayAxiPosition.Display(point); | 1110 | _displayAxiPosition.Display(point); |
1097 | } | 1111 | } |
1098 | 1112 | ||
1099 | #endregion | 1113 | #endregion |
1100 | 1114 | ||
1101 | #region Functions for Set Auto Nodes | 1115 | #region Functions for Set Auto Nodes |
1102 | 1116 | ||
1103 | /// <summary> | 1117 | /// <summary> |
1104 | /// SetAutoNodes | 1118 | /// SetAutoNodes |
1105 | /// </summary> | 1119 | /// </summary> |
1106 | public void SetAutoNodes() | 1120 | public void SetAutoNodes() |
1107 | { | 1121 | { |
1108 | double radiusStart = DISTANCE_START_NODES; | 1122 | double radiusStart = DISTANCE_START_NODES; |
1109 | double radiusEnd = DISTANCE_END_NODES; | 1123 | double radiusEnd = DISTANCE_END_NODES; |
1110 | double radiusCurver = RADIUS_CURVER_LINE; | 1124 | double radiusCurver = RADIUS_CURVER_LINE; |
1111 | 1125 | ||
1112 | Point startNode; | 1126 | Point startNode; |
1113 | Point endNode; | 1127 | Point endNode; |
1114 | 1128 | ||
1115 | gGrpBlueNode.Children.Clear(); | 1129 | gGrpBlueNode.Children.Clear(); |
1116 | 1130 | ||
1117 | if (gGrpLine.Children.Count == 1) | 1131 | if (gGrpLine.Children.Count == 1) |
1118 | radiusCurver = radiusEnd; | 1132 | radiusCurver = radiusEnd; |
1119 | 1133 | ||
1120 | if (gGrpLine.Children.Count > 0) | 1134 | if (gGrpLine.Children.Count > 0) |
1121 | { | 1135 | { |
1122 | for (int i = 0; i < gGrpLine.Children.Count; i++) | 1136 | for (int i = 0; i < gGrpLine.Children.Count; i++) |
1123 | { | 1137 | { |
1124 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i]; | 1138 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i]; |
1125 | if (i == 0) | 1139 | if (i == 0) |
1126 | { | 1140 | { |
1127 | startNode = lineGeometry.EndPoint; | 1141 | startNode = lineGeometry.EndPoint; |
1128 | endNode = lineGeometry.StartPoint; | 1142 | endNode = lineGeometry.StartPoint; |
1129 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusStart); | 1143 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusStart); |
1130 | } | 1144 | } |
1131 | else if (i == gGrpLine.Children.Count - 1 && i > 0) | 1145 | else if (i == gGrpLine.Children.Count - 1 && i > 0) |
1132 | { | 1146 | { |
1133 | startNode = lineGeometry.StartPoint; | 1147 | startNode = lineGeometry.StartPoint; |
1134 | endNode = lineGeometry.EndPoint; | 1148 | endNode = lineGeometry.EndPoint; |
1135 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusEnd); | 1149 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusEnd); |
1136 | } | 1150 | } |
1137 | else | 1151 | else |
1138 | { | 1152 | { |
1139 | startNode = lineGeometry.StartPoint; | 1153 | startNode = lineGeometry.StartPoint; |
1140 | endNode = lineGeometry.EndPoint; | 1154 | endNode = lineGeometry.EndPoint; |
1141 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusCurver); | 1155 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusCurver); |
1142 | } | 1156 | } |
1143 | } | 1157 | } |
1144 | } | 1158 | } |
1145 | } | 1159 | } |
1146 | 1160 | ||
1147 | 1161 | ||
1148 | /// <summary> | 1162 | /// <summary> |
1149 | /// DrawAutoNodes | 1163 | /// DrawAutoNodes |
1150 | /// </summary> | 1164 | /// </summary> |
1151 | /// <param name="startNode"></param> | 1165 | /// <param name="startNode"></param> |
1152 | /// <param name="endNode"></param> | 1166 | /// <param name="endNode"></param> |
1153 | /// <param name="radiusStart"></param> | 1167 | /// <param name="radiusStart"></param> |
1154 | /// <param name="radiusEnd"></param> | 1168 | /// <param name="radiusEnd"></param> |
1155 | private void DrawAutoNodes(Point startNode, Point endNode, double radiusStart, double radiusEnd) | 1169 | private void DrawAutoNodes(Point startNode, Point endNode, double radiusStart, double radiusEnd) |
1156 | { | 1170 | { |
1157 | double distance = DISTANCE_AUTO_NODES; | 1171 | double distance = DISTANCE_AUTO_NODES; |
1158 | double i; | 1172 | double i; |
1159 | 1173 | ||
1160 | Point node; | 1174 | Point node; |
1161 | 1175 | ||
1162 | // Get postion of blue node on line | 1176 | // Get postion of blue node on line |
1163 | if (startNode.X == endNode.X) | 1177 | if (startNode.X == endNode.X) |
1164 | { | 1178 | { |
1165 | if (startNode.Y > endNode.Y) | 1179 | if (startNode.Y > endNode.Y) |
1166 | { | 1180 | { |
1167 | i = startNode.Y - radiusStart; | 1181 | i = startNode.Y - radiusStart; |
1168 | if (i - distance > endNode.Y + radiusEnd) | 1182 | if (i - distance > endNode.Y + radiusEnd) |
1169 | { | 1183 | { |
1170 | do | 1184 | do |
1171 | { | 1185 | { |
1172 | i = i - distance; | 1186 | i = i - distance; |
1173 | node = new Point(endNode.X, i); | 1187 | node = new Point(endNode.X, i); |
1174 | // Add node to postion distance 1000mm | 1188 | // Add node to postion distance 1000mm |
1175 | AddNode(node, gGrpBlueNode); | 1189 | AddNode(node, gGrpBlueNode); |
1176 | 1190 | ||
1177 | } while (i > endNode.Y + radiusEnd + distance); | 1191 | } while (i > endNode.Y + radiusEnd + distance); |
1178 | } | 1192 | } |
1179 | } | 1193 | } |
1180 | else | 1194 | else |
1181 | { | 1195 | { |
1182 | i = startNode.Y + radiusStart; | 1196 | i = startNode.Y + radiusStart; |
1183 | if (i + distance < endNode.Y - radiusEnd) | 1197 | if (i + distance < endNode.Y - radiusEnd) |
1184 | { | 1198 | { |
1185 | do | 1199 | do |
1186 | { | 1200 | { |
1187 | i = i + distance; | 1201 | i = i + distance; |
1188 | node = new Point(endNode.X, i); | 1202 | node = new Point(endNode.X, i); |
1189 | // Add node to postion distance 1000mm | 1203 | // Add node to postion distance 1000mm |
1190 | AddNode(node, gGrpBlueNode); | 1204 | AddNode(node, gGrpBlueNode); |
1191 | } while (i < endNode.Y - radiusEnd - distance); | 1205 | } while (i < endNode.Y - radiusEnd - distance); |
1192 | } | 1206 | } |
1193 | } | 1207 | } |
1194 | } | 1208 | } |
1195 | else | 1209 | else |
1196 | { | 1210 | { |
1197 | if (startNode.X > endNode.X) | 1211 | if (startNode.X > endNode.X) |
1198 | { | 1212 | { |
1199 | i = startNode.X - radiusStart; | 1213 | i = startNode.X - radiusStart; |
1200 | if (i - distance > endNode.X + radiusEnd) | 1214 | if (i - distance > endNode.X + radiusEnd) |
1201 | { | 1215 | { |
1202 | do | 1216 | do |
1203 | { | 1217 | { |
1204 | i = i - distance; | 1218 | i = i - distance; |
1205 | node = new Point(i, endNode.Y); | 1219 | node = new Point(i, endNode.Y); |
1206 | // Add node to postion distance 1000mm | 1220 | // Add node to postion distance 1000mm |
1207 | AddNode(node, gGrpBlueNode); | 1221 | AddNode(node, gGrpBlueNode); |
1208 | } while (i > endNode.X + radiusEnd + distance); | 1222 | } while (i > endNode.X + radiusEnd + distance); |
1209 | } | 1223 | } |
1210 | } | 1224 | } |
1211 | else | 1225 | else |
1212 | { | 1226 | { |
1213 | i = startNode.X + radiusStart; | 1227 | i = startNode.X + radiusStart; |
1214 | if (i + distance < endNode.X - radiusEnd) | 1228 | if (i + distance < endNode.X - radiusEnd) |
1215 | { | 1229 | { |
1216 | do | 1230 | do |
1217 | { | 1231 | { |
1218 | i = i + distance; | 1232 | i = i + distance; |
1219 | node = new Point(i, endNode.Y); | 1233 | node = new Point(i, endNode.Y); |
1220 | // Add node to postion distance 1000mm | 1234 | // Add node to postion distance 1000mm |
1221 | AddNode(node, gGrpBlueNode); | 1235 | AddNode(node, gGrpBlueNode); |
1222 | } while (i < endNode.X - radiusEnd - distance); | 1236 | } while (i < endNode.X - radiusEnd - distance); |
1223 | } | 1237 | } |
1224 | } | 1238 | } |
1225 | } | 1239 | } |
1226 | 1240 | ||
1227 | } | 1241 | } |
1228 | 1242 | ||
1229 | #endregion | 1243 | #endregion |
1230 | 1244 | ||
1231 | #region Functions for Set Free Nodes | 1245 | #region Functions for Set Free Nodes |
1232 | /// <summary> | 1246 | /// <summary> |
1233 | /// Draw Auto Blue node | 1247 | /// Draw Auto Blue node |
1234 | /// </summary> | 1248 | /// </summary> |
1235 | public void SetFreeNodes(Point FreeNode, bool RightClick) | 1249 | public void SetFreeNodes(Point FreeNode, bool RightClick) |
1236 | { | 1250 | { |
1237 | double radiusStart = DISTANCE_START_NODES; | 1251 | double radiusStart = DISTANCE_START_NODES; |
1238 | double radiusEnd = DISTANCE_END_NODES; | 1252 | double radiusEnd = DISTANCE_END_NODES; |
1239 | double radiusNode = RADIUS_NODE; | 1253 | double radiusNode = RADIUS_NODE; |
1240 | double radiusCurver = RADIUS_CURVER_LINE + RADIUS_NODE; | 1254 | double radiusCurver = RADIUS_CURVER_LINE + RADIUS_NODE; |
1241 | 1255 | ||
1242 | EllipseGeometry ellipseGeometry; | 1256 | EllipseGeometry ellipseGeometry; |
1243 | Point node; | 1257 | Point node; |
1244 | bool deleteFlag = false; | 1258 | bool deleteFlag = false; |
1245 | 1259 | ||
1246 | if (RightClick) | 1260 | if (RightClick) |
1247 | { | 1261 | { |
1248 | if (gGrpBlueNode.Children.Count > 0) | 1262 | if (gGrpBlueNode.Children.Count > 0) |
1249 | { | 1263 | { |
1250 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 1264 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
1251 | { | 1265 | { |
1252 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 1266 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
1253 | node = ellipseGeometry.Center; | 1267 | node = ellipseGeometry.Center; |
1254 | if (FreeNode.X == node.X) | 1268 | if (FreeNode.X == node.X) |
1255 | { | 1269 | { |
1256 | if (CheckIsNode(FreeNode, node, radiusNode)) | 1270 | if (CheckIsNode(FreeNode, node, radiusNode)) |
1257 | { | 1271 | { |
1258 | deleteFlag = true; | 1272 | deleteFlag = true; |
1259 | } | 1273 | } |
1260 | } | 1274 | } |
1261 | else | 1275 | else |
1262 | { | 1276 | { |
1263 | if (CheckIsNode(FreeNode, node, radiusNode)) | 1277 | if (CheckIsNode(FreeNode, node, radiusNode)) |
1264 | { | 1278 | { |
1265 | deleteFlag = true; | 1279 | deleteFlag = true; |
1266 | } | 1280 | } |
1267 | } | 1281 | } |
1268 | if (deleteFlag) | 1282 | if (deleteFlag) |
1269 | { | 1283 | { |
1270 | MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); | 1284 | MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); |
1271 | if (result == MessageBoxResult.OK) | 1285 | if (result == MessageBoxResult.OK) |
1272 | { | 1286 | { |
1273 | gGrpBlueNode.Children.RemoveAt(i); | 1287 | gGrpBlueNode.Children.RemoveAt(i); |
1274 | return; | 1288 | return; |
1275 | } | 1289 | } |
1276 | else | 1290 | else |
1277 | { | 1291 | { |
1278 | return; | 1292 | return; |
1279 | } | 1293 | } |
1280 | } | 1294 | } |
1281 | } | 1295 | } |
1282 | } | 1296 | } |
1283 | } | 1297 | } |
1284 | 1298 | ||
1285 | if (gGrpLine.Children.Count > 0) | 1299 | if (gGrpLine.Children.Count > 0) |
1286 | { | 1300 | { |
1287 | for (int i = 0; i < gGrpLine.Children.Count; i++) | 1301 | for (int i = 0; i < gGrpLine.Children.Count; i++) |
1288 | { | 1302 | { |
1289 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i]; | 1303 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i]; |
1290 | 1304 | ||
1291 | // Get postion of node on line | 1305 | // Get postion of node on line |
1292 | if (IsVerticalLine(lineGeometry)) | 1306 | if (IsVerticalLine(lineGeometry)) |
1293 | { | 1307 | { |
1294 | if (FreeNode.X < lineGeometry.EndPoint.X + radiusNode && FreeNode.X > lineGeometry.EndPoint.X - radiusNode) | 1308 | if (FreeNode.X < lineGeometry.EndPoint.X + radiusNode && FreeNode.X > lineGeometry.EndPoint.X - radiusNode) |
1295 | { | 1309 | { |
1296 | FreeNode.X = lineGeometry.EndPoint.X; | 1310 | FreeNode.X = lineGeometry.EndPoint.X; |
1297 | 1311 | ||
1298 | if (i == 0) | 1312 | if (i == 0) |
1299 | { | 1313 | { |
1300 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver)) | 1314 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver)) |
1301 | { | 1315 | { |
1302 | 1316 | ||
1303 | AddNode(FreeNode, gGrpBlueNode); | 1317 | AddNode(FreeNode, gGrpBlueNode); |
1304 | } | 1318 | } |
1305 | } | 1319 | } |
1306 | else if (i == gGrpLine.Children.Count - 1 && i > 0) | 1320 | else if (i == gGrpLine.Children.Count - 1 && i > 0) |
1307 | { | 1321 | { |
1308 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd)) | 1322 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd)) |
1309 | { | 1323 | { |
1310 | 1324 | ||
1311 | AddNode(FreeNode, gGrpBlueNode); | 1325 | AddNode(FreeNode, gGrpBlueNode); |
1312 | } | 1326 | } |
1313 | } | 1327 | } |
1314 | else | 1328 | else |
1315 | { | 1329 | { |
1316 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver)) | 1330 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver)) |
1317 | { | 1331 | { |
1318 | 1332 | ||
1319 | AddNode(FreeNode, gGrpBlueNode); | 1333 | AddNode(FreeNode, gGrpBlueNode); |
1320 | } | 1334 | } |
1321 | } | 1335 | } |
1322 | 1336 | ||
1323 | } | 1337 | } |
1324 | } | 1338 | } |
1325 | else | 1339 | else |
1326 | { | 1340 | { |
1327 | if (FreeNode.Y < lineGeometry.EndPoint.Y + radiusNode && FreeNode.Y > lineGeometry.EndPoint.Y - radiusNode) | 1341 | if (FreeNode.Y < lineGeometry.EndPoint.Y + radiusNode && FreeNode.Y > lineGeometry.EndPoint.Y - radiusNode) |
1328 | { | 1342 | { |
1329 | FreeNode.Y = lineGeometry.EndPoint.Y; | 1343 | FreeNode.Y = lineGeometry.EndPoint.Y; |
1330 | if (i == 0) | 1344 | if (i == 0) |
1331 | { | 1345 | { |
1332 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver)) | 1346 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver)) |
1333 | { | 1347 | { |
1334 | 1348 | ||
1335 | AddNode(FreeNode, gGrpBlueNode); | 1349 | AddNode(FreeNode, gGrpBlueNode); |
1336 | } | 1350 | } |
1337 | } | 1351 | } |
1338 | else if (i == gGrpLine.Children.Count - 1 && i > 0) | 1352 | else if (i == gGrpLine.Children.Count - 1 && i > 0) |
1339 | { | 1353 | { |
1340 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd)) | 1354 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd)) |
1341 | { | 1355 | { |
1342 | 1356 | ||
1343 | AddNode(FreeNode, gGrpBlueNode); | 1357 | AddNode(FreeNode, gGrpBlueNode); |
1344 | } | 1358 | } |
1345 | } | 1359 | } |
1346 | else | 1360 | else |
1347 | { | 1361 | { |
1348 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver)) | 1362 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver)) |
1349 | { | 1363 | { |
1350 | 1364 | ||
1351 | AddNode(FreeNode, gGrpBlueNode); | 1365 | AddNode(FreeNode, gGrpBlueNode); |
1352 | } | 1366 | } |
1353 | } | 1367 | } |
1354 | 1368 | ||
1355 | } | 1369 | } |
1356 | } | 1370 | } |
1357 | } | 1371 | } |
1358 | } | 1372 | } |
1359 | } | 1373 | } |
1360 | 1374 | ||
1361 | 1375 | ||
1362 | public bool CheckFreeNodes(LineGeometry lineNode, Point Freenode, double radiusStart, double radiusEnd) | 1376 | public bool CheckFreeNodes(LineGeometry lineNode, Point Freenode, double radiusStart, double radiusEnd) |
1363 | { | 1377 | { |
1364 | 1378 | ||
1365 | double distanceFreeNode = DISTANCE_FREE_NODES; | 1379 | double distanceFreeNode = DISTANCE_FREE_NODES; |
1366 | double radiusNode = RADIUS_NODE; | 1380 | double radiusNode = RADIUS_NODE; |
1367 | EllipseGeometry ellipseGeometry; | 1381 | EllipseGeometry ellipseGeometry; |
1368 | Point node; | 1382 | Point node; |
1369 | 1383 | ||
1370 | if (IsVerticalLine(lineNode)) | 1384 | if (IsVerticalLine(lineNode)) |
1371 | { | 1385 | { |
1372 | if (lineNode.StartPoint.Y < lineNode.EndPoint.Y) | 1386 | if (lineNode.StartPoint.Y < lineNode.EndPoint.Y) |
1373 | { | 1387 | { |
1374 | if (Freenode.Y < lineNode.StartPoint.Y + radiusStart || Freenode.Y > lineNode.EndPoint.Y - radiusEnd) | 1388 | if (Freenode.Y < lineNode.StartPoint.Y + radiusStart || Freenode.Y > lineNode.EndPoint.Y - radiusEnd) |
1375 | { | 1389 | { |
1376 | return false; | 1390 | return false; |
1377 | } | 1391 | } |
1378 | } | 1392 | } |
1379 | else | 1393 | else |
1380 | { | 1394 | { |
1381 | if (Freenode.Y > lineNode.StartPoint.Y - radiusStart || Freenode.Y < lineNode.EndPoint.Y + radiusEnd) | 1395 | if (Freenode.Y > lineNode.StartPoint.Y - radiusStart || Freenode.Y < lineNode.EndPoint.Y + radiusEnd) |
1382 | { | 1396 | { |
1383 | return false; | 1397 | return false; |
1384 | } | 1398 | } |
1385 | } | 1399 | } |
1386 | } | 1400 | } |
1387 | else | 1401 | else |
1388 | { | 1402 | { |
1389 | if (lineNode.StartPoint.X < lineNode.EndPoint.X) | 1403 | if (lineNode.StartPoint.X < lineNode.EndPoint.X) |
1390 | { | 1404 | { |
1391 | if (Freenode.X < lineNode.StartPoint.X + radiusStart || Freenode.X > lineNode.EndPoint.X - radiusEnd) | 1405 | if (Freenode.X < lineNode.StartPoint.X + radiusStart || Freenode.X > lineNode.EndPoint.X - radiusEnd) |
1392 | { | 1406 | { |
1393 | return false; | 1407 | return false; |
1394 | } | 1408 | } |
1395 | } | 1409 | } |
1396 | else | 1410 | else |
1397 | { | 1411 | { |
1398 | if (Freenode.X > lineNode.StartPoint.X - radiusStart || Freenode.X < lineNode.EndPoint.X + radiusEnd) | 1412 | if (Freenode.X > lineNode.StartPoint.X - radiusStart || Freenode.X < lineNode.EndPoint.X + radiusEnd) |
1399 | { | 1413 | { |
1400 | return false; | 1414 | return false; |
1401 | } | 1415 | } |
1402 | } | 1416 | } |
1403 | } | 1417 | } |
1404 | 1418 | ||
1405 | if (gGrpBlueNode.Children.Count > 0) | 1419 | if (gGrpBlueNode.Children.Count > 0) |
1406 | { | 1420 | { |
1407 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 1421 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
1408 | { | 1422 | { |
1409 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 1423 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
1410 | node = ellipseGeometry.Center; | 1424 | node = ellipseGeometry.Center; |
1411 | if (Freenode.X == node.X) | 1425 | if (Freenode.X == node.X) |
1412 | { | 1426 | { |
1413 | if (CheckIsNode(Freenode, node, radiusNode)) | 1427 | if (CheckIsNode(Freenode, node, radiusNode)) |
1414 | { | 1428 | { |
1415 | return false; | 1429 | return false; |
1416 | } | 1430 | } |
1417 | else if (Freenode.Y < node.Y + distanceFreeNode && Freenode.Y > node.Y - distanceFreeNode) | 1431 | else if (Freenode.Y < node.Y + distanceFreeNode && Freenode.Y > node.Y - distanceFreeNode) |
1418 | { | 1432 | { |
1419 | return false; | 1433 | return false; |
1420 | } | 1434 | } |
1421 | } | 1435 | } |
1422 | else if (Freenode.Y == node.Y) | 1436 | else if (Freenode.Y == node.Y) |
1423 | { | 1437 | { |
1424 | if (CheckIsNode(Freenode, node, radiusNode)) | 1438 | if (CheckIsNode(Freenode, node, radiusNode)) |
1425 | { | 1439 | { |
1426 | return false; | 1440 | return false; |
1427 | } | 1441 | } |
1428 | else if (Freenode.X < node.X + distanceFreeNode && Freenode.X > node.X - distanceFreeNode) | 1442 | else if (Freenode.X < node.X + distanceFreeNode && Freenode.X > node.X - distanceFreeNode) |
1429 | { | 1443 | { |
1430 | return false; | 1444 | return false; |
1431 | } | 1445 | } |
1432 | } | 1446 | } |
1433 | } | 1447 | } |
1434 | } | 1448 | } |
1435 | 1449 | ||
1436 | return true; | 1450 | return true; |
1437 | } | 1451 | } |
1438 | 1452 | ||
1439 | public bool CheckIsNode(Point FreeNode, Point Node, double radiusNode) | 1453 | public bool CheckIsNode(Point FreeNode, Point Node, double radiusNode) |
1440 | { | 1454 | { |
1441 | if (FreeNode.X < Node.X + radiusNode && FreeNode.X > Node.X - radiusNode && FreeNode.Y < Node.Y + radiusNode && FreeNode.Y > Node.Y - radiusNode) | 1455 | if (FreeNode.X < Node.X + radiusNode && FreeNode.X > Node.X - radiusNode && FreeNode.Y < Node.Y + radiusNode && FreeNode.Y > Node.Y - radiusNode) |
1442 | { | 1456 | { |
1443 | return true; | 1457 | return true; |
1444 | } | 1458 | } |
1445 | return false; | 1459 | return false; |
1446 | } | 1460 | } |
1447 | 1461 | ||
1448 | #endregion | 1462 | #endregion |
1449 | 1463 | ||
1450 | #region Edit Node | 1464 | #region Edit Node |
1451 | public void InitNodeInfo_List() | 1465 | public void InitNodeInfo_List() |
1452 | { | 1466 | { |
1453 | //Reset List | 1467 | //Reset List |
1454 | NodeInfo_List = new List<NodeInfo>(); | 1468 | NodeInfo_List = new List<NodeInfo>(); |
1455 | 1469 | ||
1456 | if (gGrpBlueNode.Children.Count > 0) | 1470 | if (gGrpBlueNode.Children.Count > 0) |
1457 | { | 1471 | { |
1458 | // Get start point | 1472 | // Get start point |
1459 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[0]; | 1473 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[0]; |
1460 | Point startPoint = lineGeometry.StartPoint; | 1474 | Point startPoint = lineGeometry.StartPoint; |
1461 | 1475 | ||
1462 | NodeInfo n1 = new NodeInfo(); | 1476 | NodeInfo n1 = new NodeInfo(); |
1463 | n1.X = startPoint.X; | 1477 | n1.X = startPoint.X; |
1464 | n1.Y = startPoint.Y; | 1478 | n1.Y = startPoint.Y; |
1465 | n1.Mode1 = ""; | 1479 | n1.Mode1 = ""; |
1466 | n1.Mode2 = ""; | 1480 | n1.Mode2 = ""; |
1467 | n1.Mode3 = ""; | 1481 | n1.Mode3 = ""; |
1468 | NodeInfo_List.Add(n1); | 1482 | NodeInfo_List.Add(n1); |
1469 | 1483 | ||
1470 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 1484 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
1471 | { | 1485 | { |
1472 | Point point; | 1486 | Point point; |
1473 | EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 1487 | EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
1474 | point = eGeometry.Center; | 1488 | point = eGeometry.Center; |
1475 | 1489 | ||
1476 | NodeInfo Ninfo = new NodeInfo(); | 1490 | NodeInfo Ninfo = new NodeInfo(); |
1477 | Ninfo.X = point.X; | 1491 | Ninfo.X = point.X; |
1478 | Ninfo.Y = point.Y; | 1492 | Ninfo.Y = point.Y; |
1479 | 1493 | ||
1480 | Ninfo.Mode1 = ""; | 1494 | Ninfo.Mode1 = ""; |
1481 | Ninfo.Mode2 = ""; | 1495 | Ninfo.Mode2 = ""; |
1482 | Ninfo.Mode3 = ""; | 1496 | Ninfo.Mode3 = ""; |
1483 | 1497 | ||
1484 | NodeInfo_List.Add(Ninfo); | 1498 | NodeInfo_List.Add(Ninfo); |
1485 | } | 1499 | } |
1486 | 1500 | ||
1487 | // Get end point | 1501 | // Get end point |
1488 | lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count -1]; | 1502 | lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count -1]; |
1489 | Point endPoint = lineGeometry.EndPoint; | 1503 | Point endPoint = lineGeometry.EndPoint; |
1490 | 1504 | ||
1491 | NodeInfo n2 = new NodeInfo(); | 1505 | NodeInfo n2 = new NodeInfo(); |
1492 | n2.X = startPoint.X; | 1506 | n2.X = startPoint.X; |
1493 | n2.Y = startPoint.Y; | 1507 | n2.Y = startPoint.Y; |
1494 | n2.Mode1 = ""; | 1508 | n2.Mode1 = ""; |
1495 | n2.Mode2 = ""; | 1509 | n2.Mode2 = ""; |
1496 | n2.Mode3 = ""; | 1510 | n2.Mode3 = ""; |
1497 | NodeInfo_List.Add(n2); | 1511 | NodeInfo_List.Add(n2); |
1498 | 1512 | ||
1499 | // Resort NodeInfo_List From Start to Goal | 1513 | // Resort NodeInfo_List From Start to Goal |
1500 | LineGeometry firstLine = (LineGeometry)gGrpLine.Children[0]; | 1514 | LineGeometry firstLine = (LineGeometry)gGrpLine.Children[0]; |
1501 | Point startNode = firstLine.StartPoint; | 1515 | Point startNode = firstLine.StartPoint; |
1502 | Point endNode = firstLine.EndPoint; | 1516 | Point endNode = firstLine.EndPoint; |
1503 | 1517 | ||
1504 | 1518 | ||
1505 | List<NodeInfo> tmpLst = new List<NodeInfo>(); | 1519 | List<NodeInfo> tmpLst = new List<NodeInfo>(); |
1506 | 1520 | ||
1507 | // Create temp List | 1521 | // Create temp List |
1508 | if(startNode.X == endNode.X) | 1522 | if(startNode.X == endNode.X) |
1509 | { | 1523 | { |
1510 | for (int i = 1; i < NodeInfo_List.Count; i++) | 1524 | for (int i = 1; i < NodeInfo_List.Count; i++) |
1511 | { | 1525 | { |
1512 | if (NodeInfo_List[i].X != endNode.X) | 1526 | if (NodeInfo_List[i].X != endNode.X) |
1513 | { | 1527 | { |
1514 | break; | 1528 | break; |
1515 | } | 1529 | } |
1516 | else | 1530 | else |
1517 | { | 1531 | { |
1518 | tmpLst.Add(NodeInfo_List[i]); | 1532 | tmpLst.Add(NodeInfo_List[i]); |
1519 | } | 1533 | } |
1520 | } | 1534 | } |
1521 | } | 1535 | } |
1522 | 1536 | ||
1523 | if (startNode.Y == endNode.Y) | 1537 | if (startNode.Y == endNode.Y) |
1524 | { | 1538 | { |
1525 | for (int i = 1; i < NodeInfo_List.Count; i++) | 1539 | for (int i = 1; i < NodeInfo_List.Count; i++) |
1526 | { | 1540 | { |
1527 | if (NodeInfo_List[i].Y != endNode.Y) | 1541 | if (NodeInfo_List[i].Y != endNode.Y) |
1528 | { | 1542 | { |
1529 | break; | 1543 | break; |
1530 | } | 1544 | } |
1531 | else | 1545 | else |
1532 | { | 1546 | { |
1533 | tmpLst.Add(NodeInfo_List[i]); | 1547 | tmpLst.Add(NodeInfo_List[i]); |
1534 | } | 1548 | } |
1535 | } | 1549 | } |
1536 | } | 1550 | } |
1537 | 1551 | ||
1538 | // Sort NodeInfo_List | 1552 | // Sort NodeInfo_List |
1539 | for (int i = 0; i < tmpLst.Count; i++) | 1553 | for (int i = 0; i < tmpLst.Count; i++) |
1540 | { | 1554 | { |
1541 | NodeInfo_List[i + 1] = tmpLst[tmpLst.Count -1 - i]; | 1555 | NodeInfo_List[i + 1] = tmpLst[tmpLst.Count -1 - i]; |
1542 | } | 1556 | } |
1543 | 1557 | ||
1544 | } | 1558 | } |
1545 | } | 1559 | } |
1546 | 1560 | ||
1547 | 1561 | ||
1548 | public void EditNode(Point node_edited) | 1562 | public void EditNode(Point node_edited) |
1549 | { | 1563 | { |
1550 | EllipseGeometry ellipseGeometry; | 1564 | EllipseGeometry ellipseGeometry; |
1551 | Point node; | 1565 | Point node; |
1552 | double radiusNode = RADIUS_NODE; | 1566 | double radiusNode = RADIUS_NODE; |
1553 | 1567 | ||
1554 | bool flag = false; | 1568 | bool flag = false; |
1555 | 1569 | ||
1556 | if (gGrpBlueNode.Children.Count > 0) | 1570 | if (gGrpBlueNode.Children.Count > 0) |
1557 | { | 1571 | { |
1558 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 1572 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
1559 | { | 1573 | { |
1560 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 1574 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
1561 | node = ellipseGeometry.Center; | 1575 | node = ellipseGeometry.Center; |
1562 | 1576 | ||
1563 | if (CheckIsNode(node_edited, node, radiusNode)) | 1577 | if (CheckIsNode(node_edited, node, radiusNode)) |
1564 | { | 1578 | { |
1565 | flag = true; | 1579 | flag = true; |
1566 | } | 1580 | } |
1567 | 1581 | ||
1568 | if (flag) | 1582 | if (flag) |
1569 | { | 1583 | { |
1570 | node_edited.X = node.X; | 1584 | node_edited.X = node.X; |
1571 | node_edited.Y = node.Y; | 1585 | node_edited.Y = node.Y; |
1572 | 1586 | ||
1573 | // show form edit node | 1587 | // show form edit node |
1574 | EditNodeWindow edtNodeWindow = new EditNodeWindow(); | 1588 | EditNodeWindow edtNodeWindow = new EditNodeWindow(); |
1575 | edtNodeWindow.ShowDialog(); | 1589 | edtNodeWindow.ShowDialog(); |
1576 | 1590 | ||
1577 | string result1 = edtNodeWindow._txtMode1; | 1591 | string result1 = edtNodeWindow._txtMode1; |
1578 | string result2 = edtNodeWindow._txtMode2; | 1592 | string result2 = edtNodeWindow._txtMode2; |
1579 | string result3 = edtNodeWindow._txtMode3; | 1593 | string result3 = edtNodeWindow._txtMode3; |
1580 | bool exit = edtNodeWindow._ExitFlg; | 1594 | bool exit = edtNodeWindow._ExitFlg; |
1581 | 1595 | ||
1582 | if (!exit) { | 1596 | if (!exit) { |
1583 | SaveChanged(node_edited.X, node_edited.Y, result1, result2, result3); | 1597 | SaveChanged(node_edited.X, node_edited.Y, result1, result2, result3); |
1584 | } | 1598 | } |
1585 | 1599 | ||
1586 | return; | 1600 | return; |
1587 | } | 1601 | } |
1588 | } | 1602 | } |
1589 | } | 1603 | } |
1590 | } | 1604 | } |
1591 | 1605 | ||
1592 | public void SaveChanged(double x, double y, string st1, string st2, string st3) | 1606 | public void SaveChanged(double x, double y, string st1, string st2, string st3) |
1593 | { | 1607 | { |
1594 | for (int i = 0; i < NodeInfo_List.Count; i++) | 1608 | for (int i = 0; i < NodeInfo_List.Count; i++) |
1595 | { | 1609 | { |
1596 | NodeInfo ni = new NodeInfo(); | 1610 | NodeInfo ni = new NodeInfo(); |
1597 | ni = NodeInfo_List[i]; | 1611 | ni = NodeInfo_List[i]; |
1598 | 1612 | ||
1599 | if (ni.X == x && ni.Y == y) | 1613 | if (ni.X == x && ni.Y == y) |
1600 | { | 1614 | { |
1601 | 1615 | ||
1602 | ni.Mode1 = st1; | 1616 | ni.Mode1 = st1; |
1603 | ni.Mode2 = st2; | 1617 | ni.Mode2 = st2; |
1604 | ni.Mode3 = st3; | 1618 | ni.Mode3 = st3; |
1605 | 1619 | ||
1606 | NodeInfo_List[i] = ni; | 1620 | NodeInfo_List[i] = ni; |
1607 | return; | 1621 | return; |
1608 | } | 1622 | } |
1609 | } | 1623 | } |
1610 | } | 1624 | } |
1611 | #endregion | 1625 | #endregion |
1612 | 1626 | ||
1613 | #region Display RouteInfo | 1627 | #region Display RouteInfo |
1614 | public void DspRouteInfo() | 1628 | public void DspRouteInfo() |
1615 | { | 1629 | { |
1616 | //Clear Route Info Table | 1630 | //Clear Route Info Table |
1617 | ((MainWindow)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear(); | 1631 | ((MainWindow)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear(); |
1618 | 1632 | ||
1619 | if (NodeInfo_List.Count != 0) { | 1633 | if (NodeInfo_List.Count != 0) { |
1620 | int _RowIdx = 0; | 1634 | int _RowIdx = 0; |
1621 | string _Content = ""; | 1635 | string _Content = ""; |
1622 | 1636 | ||
1623 | for (int i = 0; i < NodeInfo_List.Count; i++) { | 1637 | for (int i = 0; i < NodeInfo_List.Count; i++) { |
1624 | 1638 | ||
1625 | NodeInfo ni = new NodeInfo(); | 1639 | NodeInfo ni = new NodeInfo(); |
1626 | ni = NodeInfo_List[i]; | 1640 | ni = NodeInfo_List[i]; |
1627 | 1641 | ||
1628 | //column 1 | 1642 | //column 1 |
1629 | if (i == 0) | 1643 | if (i == 0) |
1630 | { | 1644 | { |
1631 | _Content = "S"; | 1645 | _Content = "S"; |
1632 | } | 1646 | } |
1633 | else if (i == NodeInfo_List.Count - 1) | 1647 | else if (i == NodeInfo_List.Count - 1) |
1634 | { | 1648 | { |
1635 | _Content = "G"; | 1649 | _Content = "G"; |
1636 | } | 1650 | } |
1637 | else | 1651 | else |
1638 | { | 1652 | { |
1639 | _Content = i.ToString(); | 1653 | _Content = i.ToString(); |
1640 | } | 1654 | } |
1641 | AddLabeltoGrid(_RowIdx, 0, _Content); | 1655 | AddLabeltoGrid(_RowIdx, 0, _Content); |
1642 | 1656 | ||
1643 | //column 2 | 1657 | //column 2 |
1644 | // Display Node's Position | 1658 | // Display Node's Position |
1645 | _Content = ni.X + ", " + ni.Y; | 1659 | _Content = ni.X + ", " + ni.Y; |
1646 | AddLabeltoGrid(_RowIdx, 1, _Content); | 1660 | AddLabeltoGrid(_RowIdx, 1, _Content); |
1647 | 1661 | ||
1648 | // Display Node's Field | 1662 | // Display Node's Field |
1649 | if (ni.Mode1 != "" && ni.Mode1 != null) | 1663 | if (ni.Mode1 != "" && ni.Mode1 != null) |
1650 | { | 1664 | { |
1651 | char delimiterChars = '_'; | 1665 | char delimiterChars = '_'; |
1652 | string[] tmp = ni.Mode1.Split(delimiterChars); | 1666 | string[] tmp = ni.Mode1.Split(delimiterChars); |
1653 | foreach (string s in tmp) | 1667 | foreach (string s in tmp) |
1654 | { | 1668 | { |
1655 | _RowIdx++; | 1669 | _RowIdx++; |
1656 | delimiterChars = ':'; | 1670 | delimiterChars = ':'; |
1657 | 1671 | ||
1658 | if (s.Split(delimiterChars)[0] == "Mode") | 1672 | if (s.Split(delimiterChars)[0] == "Mode") |
1659 | { | 1673 | { |
1660 | double distance = 0; | 1674 | double distance = 0; |
1661 | if (i == NodeInfo_List.Count - 1) | 1675 | if (i == NodeInfo_List.Count - 1) |
1662 | { | 1676 | { |
1663 | distance = 0; | 1677 | distance = 0; |
1664 | } | 1678 | } |
1665 | else | 1679 | else |
1666 | { | 1680 | { |
1667 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); | 1681 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); |
1668 | } | 1682 | } |
1669 | _Content = "MOVE " + distance.ToString() + "mm"; | 1683 | _Content = "MOVE " + distance.ToString() + "mm"; |
1670 | } | 1684 | } |
1671 | else | 1685 | else |
1672 | { | 1686 | { |
1673 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; | 1687 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; |
1674 | } | 1688 | } |
1675 | 1689 | ||
1676 | AddLabeltoGrid(_RowIdx, 1, _Content); | 1690 | AddLabeltoGrid(_RowIdx, 1, _Content); |
1677 | } | 1691 | } |
1678 | } | 1692 | } |
1679 | 1693 | ||
1680 | if (ni.Mode2 != "" && ni.Mode2 != null) | 1694 | if (ni.Mode2 != "" && ni.Mode2 != null) |
1681 | { | 1695 | { |
1682 | char delimiterChars = '_'; | 1696 | char delimiterChars = '_'; |
1683 | string[] tmp = ni.Mode2.Split(delimiterChars); | 1697 | string[] tmp = ni.Mode2.Split(delimiterChars); |
1684 | foreach (string s in tmp) | 1698 | foreach (string s in tmp) |
1685 | { | 1699 | { |
1686 | _RowIdx++; | 1700 | _RowIdx++; |
1687 | delimiterChars = ':'; | 1701 | delimiterChars = ':'; |
1688 | 1702 | ||
1689 | if (s.Split(delimiterChars)[0] == "Mode") | 1703 | if (s.Split(delimiterChars)[0] == "Mode") |
1690 | { | 1704 | { |
1691 | double distance = 0; | 1705 | double distance = 0; |
1692 | if (i == NodeInfo_List.Count - 1) | 1706 | if (i == NodeInfo_List.Count - 1) |
1693 | { | 1707 | { |
1694 | distance = 0; | 1708 | distance = 0; |
1695 | } | 1709 | } |
1696 | else | 1710 | else |
1697 | { | 1711 | { |
1698 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); | 1712 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); |
1699 | } | 1713 | } |
1700 | _Content = "MOVE " + distance.ToString() + "mm"; | 1714 | _Content = "MOVE " + distance.ToString() + "mm"; |
1701 | } | 1715 | } |
1702 | else | 1716 | else |
1703 | { | 1717 | { |
1704 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; | 1718 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; |
1705 | } | 1719 | } |
1706 | 1720 | ||
1707 | AddLabeltoGrid(_RowIdx, 1, _Content); | 1721 | AddLabeltoGrid(_RowIdx, 1, _Content); |
1708 | } | 1722 | } |
1709 | } | 1723 | } |
1710 | 1724 | ||
1711 | if (ni.Mode3 != "" && ni.Mode3 != null) | 1725 | if (ni.Mode3 != "" && ni.Mode3 != null) |
1712 | { | 1726 | { |
1713 | char delimiterChars = '_'; | 1727 | char delimiterChars = '_'; |
1714 | string[] tmp = ni.Mode3.Split(delimiterChars); | 1728 | string[] tmp = ni.Mode3.Split(delimiterChars); |
1715 | foreach (string s in tmp) | 1729 | foreach (string s in tmp) |
1716 | { | 1730 | { |
1717 | _RowIdx++; | 1731 | _RowIdx++; |
1718 | delimiterChars = ':'; | 1732 | delimiterChars = ':'; |
1719 | 1733 | ||
1720 | if (s.Split(delimiterChars)[0] == "Mode") | 1734 | if (s.Split(delimiterChars)[0] == "Mode") |
1721 | { | 1735 | { |
1722 | double distance = 0; | 1736 | double distance = 0; |
1723 | if (i == NodeInfo_List.Count - 1) | 1737 | if (i == NodeInfo_List.Count - 1) |
1724 | { | 1738 | { |
1725 | distance = 0; | 1739 | distance = 0; |
1726 | } | 1740 | } |
1727 | else | 1741 | else |
1728 | { | 1742 | { |
1729 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); | 1743 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); |
1730 | } | 1744 | } |
1731 | _Content = "MOVE " + distance.ToString() + "mm"; | 1745 | _Content = "MOVE " + distance.ToString() + "mm"; |
1732 | } | 1746 | } |
1733 | else | 1747 | else |
1734 | { | 1748 | { |
1735 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; | 1749 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; |
1736 | } | 1750 | } |
1737 | 1751 | ||
1738 | AddLabeltoGrid(_RowIdx, 1, _Content); | 1752 | AddLabeltoGrid(_RowIdx, 1, _Content); |
1739 | } | 1753 | } |
1740 | } | 1754 | } |
1741 | _RowIdx ++; | 1755 | _RowIdx ++; |
1742 | } | 1756 | } |
1743 | } | 1757 | } |
1744 | } | 1758 | } |
1745 | 1759 | ||
1746 | public double DistanceCalculate(double _X1, double _Y1, double _X2, double _Y2) | 1760 | public double DistanceCalculate(double _X1, double _Y1, double _X2, double _Y2) |
1747 | { | 1761 | { |
1748 | double dist = 0; | 1762 | double dist = 0; |
1749 | 1763 | ||
1750 | if (_X1 == _X2) | 1764 | if (_X1 == _X2) |
1751 | { | 1765 | { |
1752 | dist = System.Math.Abs(_Y1 - _Y2) * DISTANCE_RATIO; | 1766 | dist = System.Math.Abs(_Y1 - _Y2) * DISTANCE_RATIO; |
1753 | } | 1767 | } |
1754 | else if (_Y1 == _Y2) | 1768 | else if (_Y1 == _Y2) |
1755 | { | 1769 | { |
1756 | dist = System.Math.Abs(_X1 - _X2) * DISTANCE_RATIO; | 1770 | dist = System.Math.Abs(_X1 - _X2) * DISTANCE_RATIO; |
1757 | } | 1771 | } |
1758 | return dist; | 1772 | return dist; |
1759 | } | 1773 | } |
1760 | 1774 | ||
1761 | public void AddLabeltoGrid(int RowIdx, int ColIdx, string Content) | 1775 | public void AddLabeltoGrid(int RowIdx, int ColIdx, string Content) |
1762 | { | 1776 | { |
1763 | //Add Row to Grid | 1777 | //Add Row to Grid |
1764 | RowDefinition _rd = new RowDefinition(); | 1778 | RowDefinition _rd = new RowDefinition(); |
1765 | ((MainWindow)System.Windows.Application.Current.MainWindow).grdRouteInfo.RowDefinitions.Add(_rd); | 1779 | ((MainWindow)System.Windows.Application.Current.MainWindow).grdRouteInfo.RowDefinitions.Add(_rd); |
1766 | 1780 | ||
1767 | // Add data to Grid | 1781 | // Add data to Grid |
1768 | Label dynamicLabel = new Label(); | 1782 | Label dynamicLabel = new Label(); |
1769 | 1783 | ||
1770 | dynamicLabel.Content = Content; | 1784 | dynamicLabel.Content = Content; |
1771 | dynamicLabel.Margin = new Thickness(0, 0, 0, 0); | 1785 | dynamicLabel.Margin = new Thickness(0, 0, 0, 0); |
1772 | dynamicLabel.Foreground = new SolidColorBrush(Colors.Black); | 1786 | dynamicLabel.Foreground = new SolidColorBrush(Colors.Black); |
1773 | dynamicLabel.Background = new SolidColorBrush(Colors.White); | 1787 | dynamicLabel.Background = new SolidColorBrush(Colors.White); |
1774 | dynamicLabel.BorderBrush = new SolidColorBrush(Colors.LightGray); | 1788 | dynamicLabel.BorderBrush = new SolidColorBrush(Colors.LightGray); |
1775 | dynamicLabel.BorderThickness = new Thickness(1); | 1789 | dynamicLabel.BorderThickness = new Thickness(1); |
1776 | 1790 | ||
1777 | Grid.SetRow(dynamicLabel, RowIdx); | 1791 | Grid.SetRow(dynamicLabel, RowIdx); |
1778 | Grid.SetColumn(dynamicLabel, ColIdx); | 1792 | Grid.SetColumn(dynamicLabel, ColIdx); |
1779 | ((MainWindow)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Add(dynamicLabel); | 1793 | ((MainWindow)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Add(dynamicLabel); |
1780 | } | 1794 | } |
1781 | #endregion | 1795 | #endregion |
1782 | 1796 | ||
1783 | 1797 | ||
1784 | public void CreateGoalPoint() | 1798 | public void CreateGoalPoint() |
1785 | { | 1799 | { |
1800 | if (isGoalDrawRoute) | ||
1801 | { | ||
1802 | return; | ||
1803 | } | ||
1804 | |||
1786 | isStartDrawRoute = false; | 1805 | isStartDrawRoute = false; |
1787 | if (_goalPoint == null) | 1806 | if (_goalPoint == null) |
1788 | { | 1807 | { |
1789 | _goalPoint = new ucStartEndButton(); | 1808 | _goalPoint = new ucStartEndButton(); |
1790 | _goalPoint.btnWidth = 50.0; | 1809 | _goalPoint.btnWidth = 50.0; |
1791 | _goalPoint.btnHeight = 50.0; | 1810 | _goalPoint.btnHeight = 50.0; |
1792 | _goalPoint.buttText = "G"; | 1811 | _goalPoint.buttText = "G"; |
1793 | Canvas.SetLeft(_goalPoint, 675); | 1812 | Canvas.SetLeft(_goalPoint, 675); |
1794 | Canvas.SetTop(_goalPoint, 75); | 1813 | Canvas.SetTop(_goalPoint, 75); |
1795 | this.Children.Add(_goalPoint); | 1814 | this.Children.Add(_goalPoint); |
1796 | } | 1815 | } |
1797 | } | 1816 | } |
1798 | 1817 | ||
1799 | public void CreateStartPoint() | 1818 | public void CreateStartPoint() |
1800 | { | 1819 | { |
1820 | if (isGoalDrawRoute) | ||
1821 | { | ||
1822 | return; | ||
1823 | } | ||
1824 | |||
1801 | isStartDrawRoute = false; | 1825 | isStartDrawRoute = false; |
1802 | if (_startPoint == null) | 1826 | if (_startPoint == null) |
1803 | { | 1827 | { |
1804 | _startPoint = new ucStartEndButton(); | 1828 | _startPoint = new ucStartEndButton(); |
1805 | _startPoint.btnWidth = 50.0; | 1829 | _startPoint.btnWidth = 50.0; |
1806 | _startPoint.btnHeight = 50.0; | 1830 | _startPoint.btnHeight = 50.0; |
1807 | _startPoint.buttText = "S"; | 1831 | _startPoint.buttText = "S"; |
1808 | Canvas.SetLeft(_startPoint, 75); | 1832 | Canvas.SetLeft(_startPoint, 75); |
1809 | Canvas.SetTop(_startPoint, 675); | 1833 | Canvas.SetTop(_startPoint, 675); |
1810 | this.Children.Add(_startPoint); | 1834 | this.Children.Add(_startPoint); |
1811 | } | 1835 | } |
1812 | } | 1836 | } |
sources/RoboforkApp/RoboforkMenu.xaml.cs
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Linq; | 3 | using System.Linq; |
4 | using System.Text; | 4 | using System.Text; |
5 | using System.Threading.Tasks; | 5 | using System.Threading.Tasks; |
6 | using System.Windows; | 6 | using System.Windows; |
7 | using System.Windows.Controls; | 7 | using System.Windows.Controls; |
8 | using System.Windows.Data; | 8 | using System.Windows.Data; |
9 | using System.Windows.Documents; | 9 | using System.Windows.Documents; |
10 | using System.Windows.Input; | 10 | using System.Windows.Input; |
11 | using System.Windows.Media; | 11 | using System.Windows.Media; |
12 | using System.Windows.Media.Imaging; | 12 | using System.Windows.Media.Imaging; |
13 | using System.Windows.Shapes; | 13 | using System.Windows.Shapes; |
14 | 14 | ||
15 | namespace RoboforkApp | 15 | namespace RoboforkApp |
16 | { | 16 | { |
17 | /// <summary> | 17 | /// <summary> |
18 | /// Interaction logic for RoboforkMenu.xaml | 18 | /// Interaction logic for RoboforkMenu.xaml |
19 | /// </summary> | 19 | /// </summary> |
20 | public partial class RoboforkMenu : Window | 20 | public partial class RoboforkMenu : Window |
21 | { | 21 | { |
22 | public RoboforkMenu() | 22 | public RoboforkMenu() |
23 | { | 23 | { |
24 | InitializeComponent(); | 24 | InitializeComponent(); |
25 | Load_Form(); | 25 | Load_Form(); |
26 | } | 26 | } |
27 | 27 | ||
28 | private void Load_Form() | 28 | private void Load_Form() |
29 | { | 29 | { |
30 | //PassplanTree.IsEnabled = false; | 30 | //PassplanTree.IsEnabled = false; |
31 | //NodeTree.IsEnabled = false; | 31 | //NodeTree.IsEnabled = false; |
32 | 32 | ||
33 | } | 33 | } |
34 | 34 | ||
35 | private void btnMenu_Selected(object sender, RoutedEventArgs e) | 35 | private void btnMenu_Selected(object sender, RoutedEventArgs e) |
36 | { | 36 | { |
37 | if (((TreeViewItem)sender) == null) | 37 | if (((TreeViewItem)sender) == null) |
38 | { | 38 | { |
39 | return; | 39 | return; |
40 | } | 40 | } |
41 | 41 | ||
42 | string tag = ((TreeViewItem)sender).Tag.ToString(); | 42 | string tag = ((TreeViewItem)sender).Tag.ToString(); |
43 | switch (tag) | 43 | switch (tag) |
44 | { | 44 | { |
45 | case "SetupRestriction": | ||
46 | DoBeginSetupRestriction(); | ||
47 | break; | ||
48 | |||
45 | case "SetStart": | 49 | case "SetStart": |
46 | DoBeginSetStart(); | 50 | DoBeginSetStart(); |
47 | break; | 51 | break; |
48 | 52 | ||
49 | case "SetGoal": | 53 | case "SetGoal": |
50 | DoBeginSetGoal(); | 54 | DoBeginSetGoal(); |
51 | break; | 55 | break; |
52 | 56 | ||
53 | case "SetupRoute": | 57 | case "SetupRoute": |
54 | DoBeginSetupRoute(); | 58 | DoBeginSetupRoute(); |
55 | break; | 59 | break; |
56 | 60 | ||
57 | case "MakeRoot": | 61 | case "MakeRoot": |
58 | DoBeginMakeRoot(); | 62 | DoBeginMakeRoot(); |
59 | break; | 63 | break; |
60 | 64 | ||
61 | case "DeleteRoute": | 65 | case "DeleteRoute": |
62 | DoBeginDeleteRoute(); | 66 | DoBeginDeleteRoute(); |
63 | break; | 67 | break; |
64 | 68 | ||
65 | case "SetAutoNodes": | 69 | case "SetAutoNodes": |
66 | DoBeginSetAutoNotes(); | 70 | DoBeginSetAutoNotes(); |
67 | break; | 71 | break; |
68 | 72 | ||
69 | case "SetFreeNodes": | 73 | case "SetFreeNodes": |
70 | DoBeginSetFreeNotes(); | 74 | DoBeginSetFreeNotes(); |
71 | break; | 75 | break; |
72 | default: | 76 | default: |
73 | break; | 77 | break; |
74 | } | 78 | } |
75 | } | 79 | } |
76 | 80 | ||
77 | private void btnMenu_UnselectedSet(object sender, RoutedEventArgs e) | 81 | private void btnMenu_UnselectedSet(object sender, RoutedEventArgs e) |
78 | { | 82 | { |
79 | if (((TreeViewItem)sender) == null) | 83 | if (((TreeViewItem)sender) == null) |
80 | { | 84 | { |
81 | return; | 85 | return; |
82 | } | 86 | } |
83 | 87 | ||
84 | string tag = ((TreeViewItem)sender).Tag.ToString(); | 88 | string tag = ((TreeViewItem)sender).Tag.ToString(); |
85 | switch (tag) | 89 | switch (tag) |
86 | { | 90 | { |
91 | case "SetupRestriction": | ||
92 | //DoBeginSetStart(); | ||
93 | break; | ||
94 | |||
87 | case "SetStart": | 95 | case "SetStart": |
88 | //DoBeginSetStart(); | 96 | //DoBeginSetStart(); |
89 | break; | 97 | break; |
90 | 98 | ||
91 | case "SetGoal": | 99 | case "SetGoal": |
92 | //DoBeginSetGoal(); | 100 | //DoBeginSetGoal(); |
93 | break; | 101 | break; |
94 | 102 | ||
95 | case "DeleteRoute": | 103 | case "DeleteRoute": |
96 | //DoBeginDeleteRoute(); | 104 | //DoBeginDeleteRoute(); |
97 | break; | 105 | break; |
98 | 106 | ||
99 | case "SetupRoute": | 107 | case "SetupRoute": |
100 | //DoBeginSetupRoute(); | 108 | //DoBeginSetupRoute(); |
101 | break; | 109 | break; |
102 | 110 | ||
103 | case "MakeRoot": | 111 | case "MakeRoot": |
104 | //DoBeginMakeRoot(); | 112 | //DoBeginMakeRoot(); |
105 | break; | 113 | break; |
106 | 114 | ||
107 | default: | 115 | default: |
108 | break; | 116 | break; |
109 | } | 117 | } |
110 | } | 118 | } |
111 | 119 | ||
112 | 120 | ||
113 | private void DoBeginSetAutoNotes() | 121 | private void DoBeginSetAutoNotes() |
114 | { | 122 | { |
115 | MyDesignerCanvas.SetAutoNodes(); | 123 | MyDesignerCanvas.SetAutoNodes(); |
116 | } | 124 | } |
117 | 125 | ||
118 | private void DoBeginSetFreeNotes() | 126 | private void DoBeginSetFreeNotes() |
119 | { | 127 | { |
120 | MyDesignerCanvas.Init(); | 128 | MyDesignerCanvas.Init(); |
121 | MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawSetFreeNode; | 129 | MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawSetFreeNode; |
122 | } | 130 | } |
123 | 131 | ||
124 | 132 | private void DoBeginSetupRestriction() | |
133 | { | ||
134 | MyDesignerCanvas.Init(); | ||
135 | MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawObstract; | ||
136 | MyDesignerCanvas.mouseState = DesignerCanvas.MouseState.None; | ||
137 | } | ||
125 | 138 | ||
126 | private void DoBeginSetStart() | 139 | private void DoBeginSetStart() |
127 | { | 140 | { |
128 | MyDesignerCanvas.CreateStartPoint(); | 141 | MyDesignerCanvas.CreateStartPoint(); |
129 | } | 142 | } |
130 | 143 | ||
131 | private void DoBeginSetGoal() | 144 | private void DoBeginSetGoal() |
132 | { | 145 | { |
133 | MyDesignerCanvas.CreateGoalPoint(); | 146 | MyDesignerCanvas.CreateGoalPoint(); |
134 | } | 147 | } |
135 | 148 | ||
136 | private void DoBeginSetupRoute() | 149 | private void DoBeginSetupRoute() |
137 | { | 150 | { |
138 | MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawRoute; | 151 | MyDesignerCanvas.Operation = DesignerCanvas.OperationState.DrawRoute; |
139 | } | 152 | } |
140 | 153 | ||
141 | private void DoBeginMakeRoot() | 154 | private void DoBeginMakeRoot() |
142 | { | 155 | { |
143 | MyDesignerCanvas.Children.Remove(MyDesignerCanvas.pRootLine); | 156 | MyDesignerCanvas.Children.Remove(MyDesignerCanvas.pRootLine); |
144 | MyDesignerCanvas.MakeRoot(); | 157 | MyDesignerCanvas.MakeRoot(); |
145 | } | 158 | } |
146 | 159 | ||
147 | private void DoBeginDeleteRoute() | 160 | private void DoBeginDeleteRoute() |
148 | { | 161 | { |
149 | MessageBoxResult result = MessageBox.Show("Do you want delete route?", "Delete route", MessageBoxButton.OKCancel); | 162 | MessageBoxResult result = MessageBox.Show("Do you want delete route?", "Delete route", MessageBoxButton.OKCancel); |
150 | if (result == MessageBoxResult.OK) | 163 | if (result == MessageBoxResult.OK) |
151 | { | 164 | { |
152 | MyDesignerCanvas.ClearRoute(); | 165 | MyDesignerCanvas.ClearRoute(); |
153 | } | 166 | } |
154 | } | 167 | } |
155 | 168 | ||
156 | private void GetPassplanTree(object sender, RoutedEventArgs e) | 169 | private void GetPassplanTree(object sender, RoutedEventArgs e) |
157 | { | 170 | { |
158 | MessageBoxResult result = MessageBox.Show("Selected PassplanTree", "", MessageBoxButton.OKCancel); | 171 | MessageBoxResult result = MessageBox.Show("Selected PassplanTree", "", MessageBoxButton.OKCancel); |
159 | } | 172 | } |
160 | 173 | ||
161 | private void SetPassplanTree(object sender, RoutedEventArgs e) | 174 | private void SetPassplanTree(object sender, RoutedEventArgs e) |
162 | { | 175 | { |
163 | 176 | ||
164 | } | 177 | } |
165 | 178 | ||
166 | private void GetNodeTree(object sender, RoutedEventArgs e) | 179 | private void GetNodeTree(object sender, RoutedEventArgs e) |
167 | { | 180 | { |
168 | MessageBoxResult result = MessageBox.Show("Selected NodeTree", "", MessageBoxButton.OKCancel); | 181 | MessageBoxResult result = MessageBox.Show("Selected NodeTree", "", MessageBoxButton.OKCancel); |
169 | } | 182 | } |
170 | 183 | ||
171 | private void SetNodeTree(object sender, RoutedEventArgs e) | 184 | private void SetNodeTree(object sender, RoutedEventArgs e) |
172 | { | 185 | { |
173 | 186 | ||
174 | } | 187 | } |
175 | 188 | ||
176 | private void GetFK15Tree(object sender, RoutedEventArgs e) | 189 | private void GetFK15Tree(object sender, RoutedEventArgs e) |
177 | { | 190 | { |
178 | MessageBoxResult result = MessageBox.Show("Selected FK15Tree", "", MessageBoxButton.OKCancel); | 191 | MessageBoxResult result = MessageBox.Show("Selected FK15Tree", "", MessageBoxButton.OKCancel); |
179 | } | 192 | } |
180 | 193 | ||
181 | private void SetFK15Tree(object sender, RoutedEventArgs e) | 194 | private void SetFK15Tree(object sender, RoutedEventArgs e) |
182 | { | 195 | { |
183 | 196 | ||
184 | } | 197 | } |
185 | 198 | ||
186 | private void GetVehicleAddTree(object sender, RoutedEventArgs e) | 199 | private void GetVehicleAddTree(object sender, RoutedEventArgs e) |
187 | { | 200 | { |
188 | MessageBoxResult result = MessageBox.Show("Selected VehicleAddTree", "", MessageBoxButton.OKCancel); | 201 | MessageBoxResult result = MessageBox.Show("Selected VehicleAddTree", "", MessageBoxButton.OKCancel); |
189 | } | 202 | } |
190 | 203 | ||
191 | private void SetVehicleAddTree(object sender, RoutedEventArgs e) | 204 | private void SetVehicleAddTree(object sender, RoutedEventArgs e) |
192 | { | 205 | { |
193 | 206 | ||
194 | } | 207 | } |
195 | 208 | ||
196 | private void GetTaskpattermTree(object sender, RoutedEventArgs e) | 209 | private void GetTaskpattermTree(object sender, RoutedEventArgs e) |
197 | { | 210 | { |
198 | 211 | ||
199 | } | 212 | } |
200 | 213 | ||
201 | private void SetTaskpattermTree(object sender, RoutedEventArgs e) | 214 | private void SetTaskpattermTree(object sender, RoutedEventArgs e) |
202 | { | 215 | { |
203 | 216 | ||
204 | } | 217 | } |
205 | 218 | ||
206 | private void GetWorkAddTree(object sender, RoutedEventArgs e) | 219 | private void GetWorkAddTree(object sender, RoutedEventArgs e) |
207 | { | 220 | { |
208 | 221 | ||
209 | } | 222 | } |
210 | 223 | ||
211 | private void SetWorkAddTree(object sender, RoutedEventArgs e) | 224 | private void SetWorkAddTree(object sender, RoutedEventArgs e) |
212 | { | 225 | { |
213 | 226 | ||
214 | } | 227 | } |
215 | 228 | ||
216 | private void GetConnectTree(object sender, RoutedEventArgs e) | 229 | private void GetConnectTree(object sender, RoutedEventArgs e) |
217 | { | 230 | { |
218 | 231 | ||
219 | } | 232 | } |
220 | 233 | ||
221 | private void SetConnectTree(object sender, RoutedEventArgs e) | 234 | private void SetConnectTree(object sender, RoutedEventArgs e) |
222 | { | 235 | { |
223 | 236 | ||
224 | } | 237 | } |
225 | 238 | ||
226 | private void GetParameterTree(object sender, RoutedEventArgs e) | 239 | private void GetParameterTree(object sender, RoutedEventArgs e) |
227 | { | 240 | { |
228 | 241 | ||
229 | } | 242 | } |
230 | 243 | ||
231 | private void SetParameterTree(object sender, RoutedEventArgs e) | 244 | private void SetParameterTree(object sender, RoutedEventArgs e) |
232 | { | 245 | { |
233 | 246 | ||
234 | } | 247 | } |
235 | 248 | ||
236 | private void GetScheduleTree(object sender, RoutedEventArgs e) | 249 | private void GetScheduleTree(object sender, RoutedEventArgs e) |
237 | { | 250 | { |
238 | 251 | ||
239 | } | 252 | } |
240 | 253 | ||
241 | private void SetScheduleTree(object sender, RoutedEventArgs e) | 254 | private void SetScheduleTree(object sender, RoutedEventArgs e) |
242 | { | 255 | { |
243 | 256 | ||
244 | } | 257 | } |
245 | 258 | ||
246 | private void GetLoggingTree(object sender, RoutedEventArgs e) | 259 | private void GetLoggingTree(object sender, RoutedEventArgs e) |
247 | { | 260 | { |
248 | 261 | ||
249 | } | 262 | } |
250 | 263 | ||
251 | private void SetLoggingTree(object sender, RoutedEventArgs e) | 264 | private void SetLoggingTree(object sender, RoutedEventArgs e) |
252 | { | 265 | { |
253 | 266 | ||
254 | } | 267 | } |
255 | 268 | ||
256 | private void GetAlertTree(object sender, RoutedEventArgs e) | 269 | private void GetAlertTree(object sender, RoutedEventArgs e) |
257 | { | 270 | { |
258 | 271 | ||
259 | } | 272 | } |
260 | 273 | ||
261 | private void SetAlertTree(object sender, RoutedEventArgs e) | 274 | private void SetAlertTree(object sender, RoutedEventArgs e) |
262 | { | 275 | { |
263 | 276 | ||
264 | } | 277 | } |
265 | 278 | ||
266 | private void GetHelpTree(object sender, RoutedEventArgs e) | 279 | private void GetHelpTree(object sender, RoutedEventArgs e) |
267 | { | 280 | { |
268 | 281 | ||
269 | } | 282 | } |
270 | 283 | ||
271 | private void SetHelpTree(object sender, RoutedEventArgs e) | 284 | private void SetHelpTree(object sender, RoutedEventArgs e) |
272 | { | 285 | { |
273 | 286 | ||
274 | } | 287 | } |
275 | 288 | ||
276 | private void GetNewProjectTree(object sender, RoutedEventArgs e) | 289 | private void GetNewProjectTree(object sender, RoutedEventArgs e) |
277 | { | 290 | { |
278 | 291 | ||
279 | } | 292 | } |
280 | 293 | ||
281 | private void SetNewProjectTree(object sender, RoutedEventArgs e) | 294 | private void SetNewProjectTree(object sender, RoutedEventArgs e) |
282 | { | 295 | { |
283 | 296 | ||
284 | } | 297 | } |
285 | 298 | ||
286 | 299 | ||
287 | } | 300 | } |
288 | } | 301 | } |
289 | 302 |