Commit 8710ee1dbc5fef8941ba3ac2ba2064b577a4d2b8
1 parent
23c508ed23
Exists in
master
Update bug task 2045
Showing 2 changed files with 2 additions and 6 deletions Inline Diff
releases/RM2045/20170306_RM2045_NEW.rar
No preview for this file type
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 = 25d; //8d; | 17 | const double RADIUS_NODE = 25d; //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 Schedule | 61 | // Add variable for Set Schedule |
62 | public Path pScheduleNode = new Path(); | 62 | public Path pScheduleNode = new Path(); |
63 | public Path pScheduleLine = new Path(); | 63 | public Path pScheduleLine = new Path(); |
64 | public GeometryGroup gGrpScheduleNode = new GeometryGroup(); | 64 | public GeometryGroup gGrpScheduleNode = new GeometryGroup(); |
65 | public GeometryGroup gGrpScheduleLine = new GeometryGroup(); | 65 | public GeometryGroup gGrpScheduleLine = new GeometryGroup(); |
66 | 66 | ||
67 | 67 | ||
68 | //2017/03/04 NAM ADD START | 68 | //2017/03/04 NAM ADD START |
69 | public static bool isDrawingNode = false; | 69 | public static bool isDrawingNode = false; |
70 | public Path pNewLine = new Path(); | 70 | public Path pNewLine = new Path(); |
71 | public GeometryGroup gGrpNewLine = new GeometryGroup(); | 71 | public GeometryGroup gGrpNewLine = new GeometryGroup(); |
72 | 72 | ||
73 | public struct NewNodeInfo | 73 | public struct NewNodeInfo |
74 | { | 74 | { |
75 | public double X; | 75 | public double X; |
76 | public double Y; | 76 | public double Y; |
77 | public String Mode; | 77 | public String Mode; |
78 | } | 78 | } |
79 | List<NewNodeInfo> NewNodeInfo_List = new List<NewNodeInfo>(); | 79 | List<NewNodeInfo> NewNodeInfo_List = new List<NewNodeInfo>(); |
80 | List<TextBlock> NodeNo = new List<TextBlock>(); | 80 | List<TextBlock> NodeNo = new List<TextBlock>(); |
81 | List<ucNode> ucNode_Lst = new List<ucNode>(); | 81 | List<ucNode> ucNode_Lst = new List<ucNode>(); |
82 | List<ucNode> ucScheduleNode_Lst = new List<ucNode>(); | 82 | List<ucNode> ucScheduleNode_Lst = new List<ucNode>(); |
83 | int stt = 1; | 83 | int stt = 1; |
84 | //2017/03/04 NAM ADD END | 84 | //2017/03/04 NAM ADD END |
85 | 85 | ||
86 | 86 | ||
87 | public ScheduleCanvas scheduleCanvas; | 87 | public ScheduleCanvas scheduleCanvas; |
88 | 88 | ||
89 | 89 | ||
90 | // Add variable for Set Auto Nodes | 90 | // Add variable for Set Auto Nodes |
91 | public Path pBlueNode = new Path(); | 91 | public Path pBlueNode = new Path(); |
92 | private GeometryGroup gGrpBlueNode = new GeometryGroup(); | 92 | private GeometryGroup gGrpBlueNode = new GeometryGroup(); |
93 | 93 | ||
94 | // Add variable for Set Free Nodes | 94 | // Add variable for Set Free Nodes |
95 | public Path pFreeNode = new Path(); | 95 | public Path pFreeNode = new Path(); |
96 | //private GeometryGroup gGrpFreeNode = new GeometryGroup(); | 96 | //private GeometryGroup gGrpFreeNode = new GeometryGroup(); |
97 | 97 | ||
98 | // The part of the rectangle the mouse is over. | 98 | // The part of the rectangle the mouse is over. |
99 | private enum HitType | 99 | private enum HitType |
100 | { | 100 | { |
101 | None, Body, UL, UR, LR, LL, L, R, T, B | 101 | None, Body, UL, UR, LR, LL, L, R, T, B |
102 | }; | 102 | }; |
103 | public enum OperationState | 103 | public enum OperationState |
104 | { | 104 | { |
105 | None, DrawObstract, DrawRoute, DrawSetFreeNode, EditNode, NewDrawSetFreeNode | 105 | None, DrawObstract, DrawRoute, DrawSetFreeNode, EditNode, NewDrawSetFreeNode |
106 | }; | 106 | }; |
107 | public enum MouseState | 107 | public enum MouseState |
108 | { | 108 | { |
109 | None, Draw, Drag, | 109 | None, Draw, Drag, |
110 | } | 110 | } |
111 | public OperationState Operation = OperationState.None; | 111 | public OperationState Operation = OperationState.None; |
112 | public MouseState mouseState = MouseState.None; | 112 | public MouseState mouseState = MouseState.None; |
113 | 113 | ||
114 | // The draw start point. | 114 | // The draw start point. |
115 | private Point StartDrawPoint; | 115 | private Point StartDrawPoint; |
116 | 116 | ||
117 | // The drag's last point. | 117 | // The drag's last point. |
118 | private Point LastPoint; | 118 | private Point LastPoint; |
119 | 119 | ||
120 | // The part of the rectangle under the mouse. | 120 | // The part of the rectangle under the mouse. |
121 | HitType MouseHitType = HitType.None; | 121 | HitType MouseHitType = HitType.None; |
122 | 122 | ||
123 | public void Init() { | 123 | public void Init() { |
124 | if (shapePosIndicator == null) | 124 | if (shapePosIndicator == null) |
125 | { | 125 | { |
126 | shapePosIndicator = new TextBlock() | 126 | shapePosIndicator = new TextBlock() |
127 | { | 127 | { |
128 | Foreground = Brushes.Black, | 128 | Foreground = Brushes.Black, |
129 | Background = Brushes.Transparent, | 129 | Background = Brushes.Transparent, |
130 | FontSize = 20, | 130 | FontSize = 20, |
131 | }; | 131 | }; |
132 | } | 132 | } |
133 | if (shapeSizeIndicator == null) | 133 | if (shapeSizeIndicator == null) |
134 | { | 134 | { |
135 | shapeSizeIndicator = new TextBlock() | 135 | shapeSizeIndicator = new TextBlock() |
136 | { | 136 | { |
137 | Foreground = Brushes.Black, | 137 | Foreground = Brushes.Black, |
138 | Background = Brushes.Transparent, | 138 | Background = Brushes.Transparent, |
139 | FontSize = 20, | 139 | FontSize = 20, |
140 | }; | 140 | }; |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | // Return a HitType value to indicate what is at the point. | 144 | // Return a HitType value to indicate what is at the point. |
145 | private HitType SetHitType(Point point) | 145 | private HitType SetHitType(Point point) |
146 | { | 146 | { |
147 | if (shapeList.Count == 0) | 147 | if (shapeList.Count == 0) |
148 | { | 148 | { |
149 | currentShape = 0; | 149 | currentShape = 0; |
150 | return HitType.None; | 150 | return HitType.None; |
151 | } | 151 | } |
152 | for (int i = 0; i < shapeList.Count; i++) | 152 | for (int i = 0; i < shapeList.Count; i++) |
153 | { | 153 | { |
154 | Rectangle rect = shapeList[i]; | 154 | Rectangle rect = shapeList[i]; |
155 | double left = Canvas.GetLeft(rect); | 155 | double left = Canvas.GetLeft(rect); |
156 | double top = Canvas.GetTop(rect); | 156 | double top = Canvas.GetTop(rect); |
157 | double right = left + rect.Width; | 157 | double right = left + rect.Width; |
158 | double bottom = top + rect.Height; | 158 | double bottom = top + rect.Height; |
159 | if (point.X < left) continue; | 159 | if (point.X < left) continue; |
160 | if (point.X > right) continue; | 160 | if (point.X > right) continue; |
161 | if (point.Y < top) continue; | 161 | if (point.Y < top) continue; |
162 | if (point.Y > bottom) continue; | 162 | if (point.Y > bottom) continue; |
163 | currentShape = i; | 163 | currentShape = i; |
164 | 164 | ||
165 | const double GAP = 10; | 165 | const double GAP = 10; |
166 | if (point.X - left < GAP) | 166 | if (point.X - left < GAP) |
167 | { | 167 | { |
168 | // Left edge. | 168 | // Left edge. |
169 | if (point.Y - top < GAP) return HitType.UL; | 169 | if (point.Y - top < GAP) return HitType.UL; |
170 | if (bottom - point.Y < GAP) return HitType.LL; | 170 | if (bottom - point.Y < GAP) return HitType.LL; |
171 | return HitType.L; | 171 | return HitType.L; |
172 | } | 172 | } |
173 | if (right - point.X < GAP) | 173 | if (right - point.X < GAP) |
174 | { | 174 | { |
175 | // Right edge. | 175 | // Right edge. |
176 | if (point.Y - top < GAP) return HitType.UR; | 176 | if (point.Y - top < GAP) return HitType.UR; |
177 | if (bottom - point.Y < GAP) return HitType.LR; | 177 | if (bottom - point.Y < GAP) return HitType.LR; |
178 | return HitType.R; | 178 | return HitType.R; |
179 | } | 179 | } |
180 | if (point.Y - top < GAP) return HitType.T; | 180 | if (point.Y - top < GAP) return HitType.T; |
181 | if (bottom - point.Y < GAP) return HitType.B; | 181 | if (bottom - point.Y < GAP) return HitType.B; |
182 | return HitType.Body; | 182 | return HitType.Body; |
183 | } | 183 | } |
184 | currentShape = 0; | 184 | currentShape = 0; |
185 | return HitType.None; | 185 | return HitType.None; |
186 | } | 186 | } |
187 | 187 | ||
188 | // Set a mouse cursor appropriate for the current hit type. | 188 | // Set a mouse cursor appropriate for the current hit type. |
189 | private void SetMouseCursor() | 189 | private void SetMouseCursor() |
190 | { | 190 | { |
191 | // See what cursor we should display. | 191 | // See what cursor we should display. |
192 | Cursor desired_cursor = Cursors.Arrow; | 192 | Cursor desired_cursor = Cursors.Arrow; |
193 | switch (MouseHitType) | 193 | switch (MouseHitType) |
194 | { | 194 | { |
195 | case HitType.None: | 195 | case HitType.None: |
196 | desired_cursor = Cursors.Arrow; | 196 | desired_cursor = Cursors.Arrow; |
197 | break; | 197 | break; |
198 | case HitType.Body: | 198 | case HitType.Body: |
199 | desired_cursor = Cursors.ScrollAll; | 199 | desired_cursor = Cursors.ScrollAll; |
200 | break; | 200 | break; |
201 | case HitType.UL: | 201 | case HitType.UL: |
202 | case HitType.LR: | 202 | case HitType.LR: |
203 | desired_cursor = Cursors.SizeNWSE; | 203 | desired_cursor = Cursors.SizeNWSE; |
204 | break; | 204 | break; |
205 | case HitType.LL: | 205 | case HitType.LL: |
206 | case HitType.UR: | 206 | case HitType.UR: |
207 | desired_cursor = Cursors.SizeNESW; | 207 | desired_cursor = Cursors.SizeNESW; |
208 | break; | 208 | break; |
209 | case HitType.T: | 209 | case HitType.T: |
210 | case HitType.B: | 210 | case HitType.B: |
211 | desired_cursor = Cursors.SizeNS; | 211 | desired_cursor = Cursors.SizeNS; |
212 | break; | 212 | break; |
213 | case HitType.L: | 213 | case HitType.L: |
214 | case HitType.R: | 214 | case HitType.R: |
215 | desired_cursor = Cursors.SizeWE; | 215 | desired_cursor = Cursors.SizeWE; |
216 | break; | 216 | break; |
217 | } | 217 | } |
218 | 218 | ||
219 | // Display the desired cursor. | 219 | // Display the desired cursor. |
220 | if (Cursor != desired_cursor) Cursor = desired_cursor; | 220 | if (Cursor != desired_cursor) Cursor = desired_cursor; |
221 | } | 221 | } |
222 | 222 | ||
223 | // constance | 223 | // constance |
224 | int indicatorAligment = 2; | 224 | int indicatorAligment = 2; |
225 | 225 | ||
226 | /* | 226 | /* |
227 | private Point? dragStartPoint = null; | 227 | private Point? dragStartPoint = null; |
228 | 228 | ||
229 | */ | 229 | */ |
230 | public IEnumerable<DesignerItem> SelectedItems | 230 | public IEnumerable<DesignerItem> SelectedItems |
231 | { | 231 | { |
232 | get | 232 | get |
233 | { | 233 | { |
234 | var selectedItems = from item in this.Children.OfType<DesignerItem>() | 234 | var selectedItems = from item in this.Children.OfType<DesignerItem>() |
235 | where item.IsSelected == true | 235 | where item.IsSelected == true |
236 | select item; | 236 | select item; |
237 | 237 | ||
238 | return selectedItems; | 238 | return selectedItems; |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | public void DeselectAll() | 242 | public void DeselectAll() |
243 | { | 243 | { |
244 | /* | 244 | /* |
245 | foreach (DesignerItem item in this.SelectedItems) | 245 | foreach (DesignerItem item in this.SelectedItems) |
246 | { | 246 | { |
247 | item.IsSelected = false; | 247 | item.IsSelected = false; |
248 | }*/ | 248 | }*/ |
249 | } | 249 | } |
250 | 250 | ||
251 | protected override void OnMouseDown(MouseButtonEventArgs e) | 251 | protected override void OnMouseDown(MouseButtonEventArgs e) |
252 | { | 252 | { |
253 | base.OnMouseDown(e); | 253 | base.OnMouseDown(e); |
254 | 254 | ||
255 | MouseHitType = SetHitType(Mouse.GetPosition(this)); | 255 | MouseHitType = SetHitType(Mouse.GetPosition(this)); |
256 | SetMouseCursor(); | 256 | SetMouseCursor(); |
257 | 257 | ||
258 | if (Operation == OperationState.DrawRoute && isStartDrawRoute) | 258 | if (Operation == OperationState.DrawRoute && isStartDrawRoute) |
259 | { | 259 | { |
260 | if (isGoalDrawRoute) | 260 | if (isGoalDrawRoute) |
261 | { | 261 | { |
262 | return; | 262 | return; |
263 | } | 263 | } |
264 | 264 | ||
265 | // Check state draw | 265 | // Check state draw |
266 | if (MouseHitType == HitType.None) | 266 | if (MouseHitType == HitType.None) |
267 | { | 267 | { |
268 | if (gGrpLine.Children.Count == 1) | 268 | if (gGrpLine.Children.Count == 1) |
269 | { | 269 | { |
270 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[0]; | 270 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[0]; |
271 | lineGeometry.EndPoint = LastPoint; | 271 | lineGeometry.EndPoint = LastPoint; |
272 | 272 | ||
273 | // Check end route | 273 | // Check end route |
274 | if (IsEndRoute(_goalPoint, lineGeometry)) | 274 | if (IsEndRoute(_goalPoint, lineGeometry)) |
275 | { | 275 | { |
276 | isGoalDrawRoute = true; | 276 | isGoalDrawRoute = true; |
277 | ProcessEndRoute(); | 277 | ProcessEndRoute(); |
278 | return; | 278 | return; |
279 | } | 279 | } |
280 | } | 280 | } |
281 | else if (IsCurverNode((LineGeometry)gGrpLine.Children[currentLine - 1] | 281 | else if (IsCurverNode((LineGeometry)gGrpLine.Children[currentLine - 1] |
282 | , (LineGeometry)gGrpLine.Children[currentLine])) | 282 | , (LineGeometry)gGrpLine.Children[currentLine])) |
283 | { | 283 | { |
284 | // Set end point to finish draw line | 284 | // Set end point to finish draw line |
285 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine]; | 285 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine]; |
286 | lineGeometry.EndPoint = LastPoint; | 286 | lineGeometry.EndPoint = LastPoint; |
287 | 287 | ||
288 | // Add node to curver postion | 288 | // Add node to curver postion |
289 | AddNode(lineGeometry.StartPoint, gGrpRedNode); | 289 | AddNode(lineGeometry.StartPoint, gGrpRedNode); |
290 | 290 | ||
291 | // Check end route | 291 | // Check end route |
292 | if (IsEndRoute(_goalPoint, lineGeometry)) | 292 | if (IsEndRoute(_goalPoint, lineGeometry)) |
293 | { | 293 | { |
294 | isGoalDrawRoute = true; | 294 | isGoalDrawRoute = true; |
295 | ProcessEndRoute(); | 295 | ProcessEndRoute(); |
296 | return; | 296 | return; |
297 | } | 297 | } |
298 | } | 298 | } |
299 | else | 299 | else |
300 | { | 300 | { |
301 | // Remove current line | 301 | // Remove current line |
302 | gGrpLine.Children.RemoveAt(currentLine); | 302 | gGrpLine.Children.RemoveAt(currentLine); |
303 | 303 | ||
304 | // Set end point to finish draw line | 304 | // Set end point to finish draw line |
305 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine - 1]; | 305 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine - 1]; |
306 | lineGeometry.EndPoint = LastPoint; | 306 | lineGeometry.EndPoint = LastPoint; |
307 | 307 | ||
308 | // Check end route | 308 | // Check end route |
309 | if (IsEndRoute(_goalPoint, lineGeometry)) | 309 | if (IsEndRoute(_goalPoint, lineGeometry)) |
310 | { | 310 | { |
311 | isGoalDrawRoute = true; | 311 | isGoalDrawRoute = true; |
312 | ProcessEndRoute(); | 312 | ProcessEndRoute(); |
313 | return; | 313 | return; |
314 | } | 314 | } |
315 | } | 315 | } |
316 | 316 | ||
317 | // Draw new line | 317 | // Draw new line |
318 | DrawLine(LastPoint, LastPoint, gGrpLine); | 318 | DrawLine(LastPoint, LastPoint, gGrpLine); |
319 | // Setting start point for new line | 319 | // Setting start point for new line |
320 | StartDrawPoint = LastPoint; | 320 | StartDrawPoint = LastPoint; |
321 | 321 | ||
322 | mouseState = MouseState.Draw; | 322 | mouseState = MouseState.Draw; |
323 | currentLine = gGrpLine.Children.Count - 1; | 323 | currentLine = gGrpLine.Children.Count - 1; |
324 | return; | 324 | return; |
325 | } | 325 | } |
326 | } | 326 | } |
327 | else if (Operation == OperationState.DrawSetFreeNode) | 327 | else if (Operation == OperationState.DrawSetFreeNode) |
328 | { | 328 | { |
329 | bool RightClick = false; | 329 | bool RightClick = false; |
330 | if (IsStopDrawRoute(e)) | 330 | if (IsStopDrawRoute(e)) |
331 | RightClick = true; | 331 | RightClick = true; |
332 | 332 | ||
333 | StartDrawPoint = e.MouseDevice.GetPosition(this); | 333 | StartDrawPoint = e.MouseDevice.GetPosition(this); |
334 | 334 | ||
335 | SetFreeNodes(StartDrawPoint, RightClick); | 335 | SetFreeNodes(StartDrawPoint, RightClick); |
336 | } | 336 | } |
337 | //2017/03/04 NAM EDT START | 337 | //2017/03/04 NAM EDT START |
338 | else if (Operation == OperationState.NewDrawSetFreeNode) | 338 | else if (Operation == OperationState.NewDrawSetFreeNode) |
339 | { | 339 | { |
340 | bool RightClick = false; | 340 | bool RightClick = false; |
341 | bool LeftClick = false; | 341 | bool LeftClick = false; |
342 | if (IsStopDrawRoute(e)) | 342 | if (IsStopDrawRoute(e)) |
343 | RightClick = true; | 343 | RightClick = true; |
344 | 344 | ||
345 | StartDrawPoint = e.MouseDevice.GetPosition(this); | 345 | StartDrawPoint = e.MouseDevice.GetPosition(this); |
346 | CreateNode(StartDrawPoint,LeftClick, RightClick); | 346 | CreateNode(StartDrawPoint,LeftClick, RightClick); |
347 | //NewSetFreeNodes(StartDrawPoint, RightClick); | 347 | //NewSetFreeNodes(StartDrawPoint, RightClick); |
348 | } | 348 | } |
349 | //2017/03/04 NAM EDT END | 349 | //2017/03/04 NAM EDT END |
350 | 350 | ||
351 | else if (Operation == OperationState.EditNode) | 351 | else if (Operation == OperationState.EditNode) |
352 | { | 352 | { |
353 | Point node_edited = e.MouseDevice.GetPosition(this); | 353 | Point node_edited = e.MouseDevice.GetPosition(this); |
354 | 354 | ||
355 | // start Edit Node Infor | 355 | // start Edit Node Infor |
356 | EditNode(node_edited); | 356 | EditNode(node_edited); |
357 | 357 | ||
358 | } | 358 | } |
359 | else if (Operation == OperationState.DrawObstract) | 359 | else if (Operation == OperationState.DrawObstract) |
360 | { | 360 | { |
361 | if (MouseHitType == HitType.None) | 361 | if (MouseHitType == HitType.None) |
362 | { | 362 | { |
363 | Rectangle shape = new Rectangle(); | 363 | Rectangle shape = new Rectangle(); |
364 | shape.Width = 1; | 364 | shape.Width = 1; |
365 | shape.Height = 1; | 365 | shape.Height = 1; |
366 | // Create a SolidColorBrush and use it to | 366 | // Create a SolidColorBrush and use it to |
367 | // paint the rectangle. | 367 | // paint the rectangle. |
368 | shape.Stroke = Brushes.Blue; | 368 | shape.Stroke = Brushes.Blue; |
369 | shape.StrokeThickness = 1; | 369 | shape.StrokeThickness = 1; |
370 | shape.Fill = new SolidColorBrush(Colors.LightCyan); | 370 | shape.Fill = new SolidColorBrush(Colors.LightCyan); |
371 | StartDrawPoint = e.MouseDevice.GetPosition(this); | 371 | StartDrawPoint = e.MouseDevice.GetPosition(this); |
372 | shape.SetValue(Canvas.LeftProperty, StartDrawPoint.X); | 372 | shape.SetValue(Canvas.LeftProperty, StartDrawPoint.X); |
373 | shape.SetValue(Canvas.TopProperty, StartDrawPoint.Y); | 373 | shape.SetValue(Canvas.TopProperty, StartDrawPoint.Y); |
374 | this.Children.Add(shape); | 374 | this.Children.Add(shape); |
375 | shapeList.Add(shape); | 375 | shapeList.Add(shape); |
376 | 376 | ||
377 | mouseState = MouseState.Draw; | 377 | mouseState = MouseState.Draw; |
378 | currentShape = shapeList.Count() - 1; | 378 | currentShape = shapeList.Count() - 1; |
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 | return; | 396 | return; |
397 | } | 397 | } |
398 | else | 398 | else |
399 | { | 399 | { |
400 | if (shapeList.Count() != 0) | 400 | if (shapeList.Count() != 0) |
401 | shapeList[currentShape].Fill = new SolidColorBrush(Colors.LightCyan); | 401 | shapeList[currentShape].Fill = new SolidColorBrush(Colors.LightCyan); |
402 | 402 | ||
403 | double shapeX = Canvas.GetLeft(shapeList[currentShape]); | 403 | double shapeX = Canvas.GetLeft(shapeList[currentShape]); |
404 | double shapeY = Canvas.GetTop(shapeList[currentShape]); | 404 | double shapeY = Canvas.GetTop(shapeList[currentShape]); |
405 | shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; | 405 | shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; |
406 | shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); | 406 | shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); |
407 | shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); | 407 | shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); |
408 | 408 | ||
409 | double width = (int)shapeList[currentShape].Width; | 409 | double width = (int)shapeList[currentShape].Width; |
410 | double height = (int)shapeList[currentShape].Height; | 410 | double height = (int)shapeList[currentShape].Height; |
411 | shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; | 411 | shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; |
412 | shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); | 412 | shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); |
413 | shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); | 413 | shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); |
414 | 414 | ||
415 | this.Children.Add(shapePosIndicator); | 415 | this.Children.Add(shapePosIndicator); |
416 | this.Children.Add(shapeSizeIndicator); | 416 | this.Children.Add(shapeSizeIndicator); |
417 | } | 417 | } |
418 | 418 | ||
419 | LastPoint = Mouse.GetPosition(this); | 419 | LastPoint = Mouse.GetPosition(this); |
420 | mouseState = MouseState.Drag; | 420 | mouseState = MouseState.Drag; |
421 | } | 421 | } |
422 | e.Handled = true; | 422 | e.Handled = true; |
423 | } | 423 | } |
424 | 424 | ||
425 | protected override void OnMouseMove(MouseEventArgs e) | 425 | protected override void OnMouseMove(MouseEventArgs e) |
426 | { | 426 | { |
427 | base.OnMouseMove(e); | 427 | base.OnMouseMove(e); |
428 | 428 | ||
429 | if (mouseState == MouseState.None) | 429 | if (mouseState == MouseState.None) |
430 | { | 430 | { |
431 | MouseHitType = SetHitType(Mouse.GetPosition(this)); | 431 | MouseHitType = SetHitType(Mouse.GetPosition(this)); |
432 | SetMouseCursor(); | 432 | SetMouseCursor(); |
433 | } | 433 | } |
434 | else if (Operation == OperationState.DrawRoute && isStartDrawRoute) | 434 | else if (Operation == OperationState.DrawRoute && isStartDrawRoute) |
435 | { | 435 | { |
436 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine]; | 436 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[currentLine]; |
437 | 437 | ||
438 | // See how much the mouse has moved. | 438 | // See how much the mouse has moved. |
439 | Point point = Mouse.GetPosition(this); | 439 | Point point = Mouse.GetPosition(this); |
440 | double offset_x = point.X - StartDrawPoint.X; | 440 | double offset_x = point.X - StartDrawPoint.X; |
441 | double offset_y = point.Y - StartDrawPoint.Y; | 441 | double offset_y = point.Y - StartDrawPoint.Y; |
442 | 442 | ||
443 | // Get the line's current position. | 443 | // Get the line's current position. |
444 | double new_x = lineGeometry.StartPoint.X; | 444 | double new_x = lineGeometry.StartPoint.X; |
445 | double new_y = lineGeometry.StartPoint.Y; | 445 | double new_y = lineGeometry.StartPoint.Y; |
446 | 446 | ||
447 | if (offset_x != 0 || offset_y != 0) | 447 | if (offset_x != 0 || offset_y != 0) |
448 | { | 448 | { |
449 | if (Math.Abs(offset_x) >= Math.Abs(offset_y)) | 449 | if (Math.Abs(offset_x) >= Math.Abs(offset_y)) |
450 | { | 450 | { |
451 | new_x = point.X; | 451 | new_x = point.X; |
452 | } | 452 | } |
453 | else | 453 | else |
454 | { | 454 | { |
455 | new_y = point.Y; | 455 | new_y = point.Y; |
456 | } | 456 | } |
457 | } | 457 | } |
458 | 458 | ||
459 | // Set end point of current line | 459 | // Set end point of current line |
460 | LastPoint = new Point(new_x, new_y); | 460 | LastPoint = new Point(new_x, new_y); |
461 | lineGeometry.EndPoint = LastPoint; | 461 | lineGeometry.EndPoint = LastPoint; |
462 | DisplayCoordinate(LastPoint); | 462 | DisplayCoordinate(LastPoint); |
463 | } | 463 | } |
464 | else if (Operation == OperationState.DrawObstract) | 464 | else if (Operation == OperationState.DrawObstract) |
465 | { | 465 | { |
466 | if (mouseState == MouseState.Drag) | 466 | if (mouseState == MouseState.Drag) |
467 | { | 467 | { |
468 | // See how much the mouse has moved. | 468 | // See how much the mouse has moved. |
469 | Point point = Mouse.GetPosition(this); | 469 | Point point = Mouse.GetPosition(this); |
470 | double offset_x = point.X - LastPoint.X; | 470 | double offset_x = point.X - LastPoint.X; |
471 | double offset_y = point.Y - LastPoint.Y; | 471 | double offset_y = point.Y - LastPoint.Y; |
472 | 472 | ||
473 | // Get the rectangle's current position. | 473 | // Get the rectangle's current position. |
474 | double new_x = Canvas.GetLeft(shapeList[currentShape]); | 474 | double new_x = Canvas.GetLeft(shapeList[currentShape]); |
475 | double new_y = Canvas.GetTop(shapeList[currentShape]); | 475 | double new_y = Canvas.GetTop(shapeList[currentShape]); |
476 | double new_width = shapeList[currentShape].Width; | 476 | double new_width = shapeList[currentShape].Width; |
477 | double new_height = shapeList[currentShape].Height; | 477 | double new_height = shapeList[currentShape].Height; |
478 | 478 | ||
479 | // Update the rectangle. | 479 | // Update the rectangle. |
480 | switch (MouseHitType) | 480 | switch (MouseHitType) |
481 | { | 481 | { |
482 | case HitType.Body: | 482 | case HitType.Body: |
483 | new_x += offset_x; | 483 | new_x += offset_x; |
484 | new_y += offset_y; | 484 | new_y += offset_y; |
485 | break; | 485 | break; |
486 | case HitType.UL: | 486 | case HitType.UL: |
487 | new_x += offset_x; | 487 | new_x += offset_x; |
488 | new_y += offset_y; | 488 | new_y += offset_y; |
489 | new_width -= offset_x; | 489 | new_width -= offset_x; |
490 | new_height -= offset_y; | 490 | new_height -= offset_y; |
491 | break; | 491 | break; |
492 | case HitType.UR: | 492 | case HitType.UR: |
493 | new_y += offset_y; | 493 | new_y += offset_y; |
494 | new_width += offset_x; | 494 | new_width += offset_x; |
495 | new_height -= offset_y; | 495 | new_height -= offset_y; |
496 | break; | 496 | break; |
497 | case HitType.LR: | 497 | case HitType.LR: |
498 | new_width += offset_x; | 498 | new_width += offset_x; |
499 | new_height += offset_y; | 499 | new_height += offset_y; |
500 | break; | 500 | break; |
501 | case HitType.LL: | 501 | case HitType.LL: |
502 | new_x += offset_x; | 502 | new_x += offset_x; |
503 | new_width -= offset_x; | 503 | new_width -= offset_x; |
504 | new_height += offset_y; | 504 | new_height += offset_y; |
505 | break; | 505 | break; |
506 | case HitType.L: | 506 | case HitType.L: |
507 | new_x += offset_x; | 507 | new_x += offset_x; |
508 | new_width -= offset_x; | 508 | new_width -= offset_x; |
509 | break; | 509 | break; |
510 | case HitType.R: | 510 | case HitType.R: |
511 | new_width += offset_x; | 511 | new_width += offset_x; |
512 | break; | 512 | break; |
513 | case HitType.B: | 513 | case HitType.B: |
514 | new_height += offset_y; | 514 | new_height += offset_y; |
515 | break; | 515 | break; |
516 | case HitType.T: | 516 | case HitType.T: |
517 | new_y += offset_y; | 517 | new_y += offset_y; |
518 | new_height -= offset_y; | 518 | new_height -= offset_y; |
519 | break; | 519 | break; |
520 | } | 520 | } |
521 | // Don't use negative width or height. | 521 | // Don't use negative width or height. |
522 | if ((new_width > 0) && (new_height > 0)) | 522 | if ((new_width > 0) && (new_height > 0)) |
523 | { | 523 | { |
524 | // Update the rectangle. | 524 | // Update the rectangle. |
525 | Canvas.SetLeft(shapeList[currentShape], new_x); | 525 | Canvas.SetLeft(shapeList[currentShape], new_x); |
526 | Canvas.SetTop(shapeList[currentShape], new_y); | 526 | Canvas.SetTop(shapeList[currentShape], new_y); |
527 | shapeList[currentShape].Width = new_width; | 527 | shapeList[currentShape].Width = new_width; |
528 | shapeList[currentShape].Height = new_height; | 528 | shapeList[currentShape].Height = new_height; |
529 | 529 | ||
530 | // Save the mouse's new location. | 530 | // Save the mouse's new location. |
531 | LastPoint = point; | 531 | LastPoint = point; |
532 | 532 | ||
533 | } | 533 | } |
534 | } | 534 | } |
535 | else if (mouseState == MouseState.Draw) | 535 | else if (mouseState == MouseState.Draw) |
536 | { | 536 | { |
537 | 537 | ||
538 | // See how much the mouse has moved. | 538 | // See how much the mouse has moved. |
539 | Point point = Mouse.GetPosition(this); | 539 | Point point = Mouse.GetPosition(this); |
540 | 540 | ||
541 | 541 | ||
542 | double offset_x = point.X - StartDrawPoint.X; | 542 | double offset_x = point.X - StartDrawPoint.X; |
543 | double offset_y = point.Y - StartDrawPoint.Y; | 543 | double offset_y = point.Y - StartDrawPoint.Y; |
544 | 544 | ||
545 | // Get the rectangle's current position. | 545 | // Get the rectangle's current position. |
546 | double start_x = Canvas.GetLeft(shapeList[currentShape]); | 546 | double start_x = Canvas.GetLeft(shapeList[currentShape]); |
547 | double start_y = Canvas.GetTop(shapeList[currentShape]); | 547 | double start_y = Canvas.GetTop(shapeList[currentShape]); |
548 | double new_x = Canvas.GetLeft(shapeList[currentShape]); | 548 | double new_x = Canvas.GetLeft(shapeList[currentShape]); |
549 | double new_y = Canvas.GetTop(shapeList[currentShape]); | 549 | double new_y = Canvas.GetTop(shapeList[currentShape]); |
550 | double new_width = offset_x; | 550 | double new_width = offset_x; |
551 | double new_height = offset_y; | 551 | double new_height = offset_y; |
552 | if (offset_x < 0) | 552 | if (offset_x < 0) |
553 | { | 553 | { |
554 | new_x = point.X; | 554 | new_x = point.X; |
555 | new_width = -offset_x; | 555 | new_width = -offset_x; |
556 | } | 556 | } |
557 | if (offset_y < 0) | 557 | if (offset_y < 0) |
558 | { | 558 | { |
559 | new_y = point.Y; | 559 | new_y = point.Y; |
560 | new_height = -offset_y; | 560 | new_height = -offset_y; |
561 | } | 561 | } |
562 | Canvas.SetLeft(shapeList[currentShape], new_x); | 562 | Canvas.SetLeft(shapeList[currentShape], new_x); |
563 | Canvas.SetTop(shapeList[currentShape], new_y); | 563 | Canvas.SetTop(shapeList[currentShape], new_y); |
564 | shapeList[currentShape].Width = new_width; | 564 | shapeList[currentShape].Width = new_width; |
565 | shapeList[currentShape].Height = new_height; | 565 | shapeList[currentShape].Height = new_height; |
566 | 566 | ||
567 | } | 567 | } |
568 | 568 | ||
569 | double shapeX = Canvas.GetLeft(shapeList[currentShape]); | 569 | double shapeX = Canvas.GetLeft(shapeList[currentShape]); |
570 | double shapeY = Canvas.GetTop(shapeList[currentShape]); | 570 | double shapeY = Canvas.GetTop(shapeList[currentShape]); |
571 | shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; | 571 | shapePosIndicator.Text = "(" + Math.Round(shapeX, 0) + "," + Math.Round(shapeY, 0) + ")"; |
572 | shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); | 572 | shapePosIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment); |
573 | shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); | 573 | shapePosIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment); |
574 | 574 | ||
575 | double width = (int)shapeList[currentShape].Width; | 575 | double width = (int)shapeList[currentShape].Width; |
576 | double height = (int)shapeList[currentShape].Height; | 576 | double height = (int)shapeList[currentShape].Height; |
577 | shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; | 577 | shapeSizeIndicator.Text = "(" + Math.Round(width, 0) + "," + Math.Round(height, 0) + ")"; |
578 | shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); | 578 | shapeSizeIndicator.SetValue(Canvas.LeftProperty, shapeX + indicatorAligment + width); |
579 | shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); | 579 | shapeSizeIndicator.SetValue(Canvas.TopProperty, shapeY + indicatorAligment + height); |
580 | } | 580 | } |
581 | e.Handled = true; | 581 | e.Handled = true; |
582 | } | 582 | } |
583 | 583 | ||
584 | protected override void OnMouseUp(MouseButtonEventArgs e) | 584 | protected override void OnMouseUp(MouseButtonEventArgs e) |
585 | { | 585 | { |
586 | base.OnMouseUp(e); | 586 | base.OnMouseUp(e); |
587 | if (Operation == OperationState.DrawObstract) | 587 | if (Operation == OperationState.DrawObstract) |
588 | { | 588 | { |
589 | if (shapeList.Count() != 0) | 589 | if (shapeList.Count() != 0) |
590 | shapeList[currentShape].Fill = new SolidColorBrush(Colors.Blue); | 590 | shapeList[currentShape].Fill = new SolidColorBrush(Colors.Blue); |
591 | shapePosIndicator.Text = ""; | 591 | shapePosIndicator.Text = ""; |
592 | shapeSizeIndicator.Text = ""; | 592 | shapeSizeIndicator.Text = ""; |
593 | this.Children.Remove(shapePosIndicator); | 593 | this.Children.Remove(shapePosIndicator); |
594 | this.Children.Remove(shapeSizeIndicator); | 594 | this.Children.Remove(shapeSizeIndicator); |
595 | 595 | ||
596 | mouseState = MouseState.None; | 596 | mouseState = MouseState.None; |
597 | currentShape = 0; | 597 | currentShape = 0; |
598 | } | 598 | } |
599 | e.Handled = true; | 599 | e.Handled = true; |
600 | } | 600 | } |
601 | 601 | ||
602 | /// <summary> | 602 | /// <summary> |
603 | /// On Preview Mouse Down | 603 | /// On Preview Mouse Down |
604 | /// </summary> | 604 | /// </summary> |
605 | /// <param name="e"></param> | 605 | /// <param name="e"></param> |
606 | protected override void OnPreviewMouseDown(MouseButtonEventArgs e) | 606 | protected override void OnPreviewMouseDown(MouseButtonEventArgs e) |
607 | { | 607 | { |
608 | base.OnPreviewMouseDown(e); | 608 | base.OnPreviewMouseDown(e); |
609 | if (Operation != OperationState.NewDrawSetFreeNode) | 609 | if (Operation != OperationState.NewDrawSetFreeNode) |
610 | { | 610 | { |
611 | return; | 611 | return; |
612 | } | 612 | } |
613 | 613 | ||
614 | Point currentPoint = e.MouseDevice.GetPosition(this); | 614 | Point currentPoint = e.MouseDevice.GetPosition(this); |
615 | //bool _isStart = IsStartEndRoute(_startPoint, currentPoint); | 615 | //bool _isStart = IsStartEndRoute(_startPoint, currentPoint); |
616 | 616 | ||
617 | if (isDrawingNode == false) | 617 | if (isDrawingNode == false) |
618 | { | 618 | { |
619 | //double centerY = Canvas.GetTop(_startPoint); | 619 | //double centerY = Canvas.GetTop(_startPoint); |
620 | //double centerX = Canvas.GetLeft(_startPoint); | 620 | //double centerX = Canvas.GetLeft(_startPoint); |
621 | 621 | ||
622 | isDrawingNode = true; | 622 | isDrawingNode = true; |
623 | InitDrawRoute(); | 623 | InitDrawRoute(); |
624 | //DrawLine(new Point(centerX + 25, centerY + 25), new Point(centerX + 25, centerY + 25), gGrpLine); | 624 | //DrawLine(new Point(centerX + 25, centerY + 25), new Point(centerX + 25, centerY + 25), gGrpLine); |
625 | mouseState = MouseState.Draw; | 625 | mouseState = MouseState.Draw; |
626 | //currentLine = gGrpLine.Children.Count - 1; | 626 | //currentLine = gGrpLine.Children.Count - 1; |
627 | //StartDrawPoint = new Point(centerX + 25, centerY + 25); | 627 | //StartDrawPoint = new Point(centerX + 25, centerY + 25); |
628 | 628 | ||
629 | //this.Children.Remove(_startPoint); | 629 | //this.Children.Remove(_startPoint); |
630 | //this.Children.Add(_startPoint); | 630 | //this.Children.Add(_startPoint); |
631 | 631 | ||
632 | return; | 632 | return; |
633 | } | 633 | } |
634 | //2017/03/04 NAM EDT START | 634 | //2017/03/04 NAM EDT START |
635 | else | 635 | else |
636 | { | 636 | { |
637 | 637 | ||
638 | bool RightClick = false; | 638 | bool RightClick = false; |
639 | bool LeftClick = false; | 639 | bool LeftClick = false; |
640 | 640 | ||
641 | 641 | ||
642 | if (IsMouseLeftClick(e)) | 642 | if (IsMouseLeftClick(e)) |
643 | LeftClick = true; | 643 | LeftClick = true; |
644 | if (IsStopDrawRoute(e)) | 644 | if (IsStopDrawRoute(e)) |
645 | RightClick = true; | 645 | RightClick = true; |
646 | 646 | ||
647 | StartDrawPoint = e.MouseDevice.GetPosition(this); | 647 | StartDrawPoint = e.MouseDevice.GetPosition(this); |
648 | CreateNode(StartDrawPoint, LeftClick, RightClick); | 648 | CreateNode(StartDrawPoint, LeftClick, RightClick); |
649 | } | 649 | } |
650 | //2017/03/04 NAM EDT END | 650 | //2017/03/04 NAM EDT END |
651 | 651 | ||
652 | 652 | ||
653 | bool _isgoal = IsStartEndRoute(_goalPoint, LastPoint); | 653 | bool _isgoal = IsStartEndRoute(_goalPoint, LastPoint); |
654 | if (_isgoal && isGoalDrawRoute == false) | 654 | if (_isgoal && isGoalDrawRoute == false) |
655 | { | 655 | { |
656 | isGoalDrawRoute = true; | 656 | isGoalDrawRoute = true; |
657 | ProcessEndRoute(); | 657 | ProcessEndRoute(); |
658 | } | 658 | } |
659 | } | 659 | } |
660 | 660 | ||
661 | #region Functions for draw route | 661 | #region Functions for draw route |
662 | 662 | ||
663 | /// <summary> | 663 | /// <summary> |
664 | /// Check start or end draw route | 664 | /// Check start or end draw route |
665 | /// </summary> | 665 | /// </summary> |
666 | /// <param name="_ucStartEndButton">Button start</param> | 666 | /// <param name="_ucStartEndButton">Button start</param> |
667 | /// <param name="currentPoint">Position for check</param> | 667 | /// <param name="currentPoint">Position for check</param> |
668 | /// <returns>true: start, false: not start</returns> | 668 | /// <returns>true: start, false: not start</returns> |
669 | private bool IsStartEndRoute(ucStartEndButton _ucStartEndButton, Point currentPoint) | 669 | private bool IsStartEndRoute(ucStartEndButton _ucStartEndButton, Point currentPoint) |
670 | { | 670 | { |
671 | if(_ucStartEndButton == null) | 671 | if(_ucStartEndButton == null) |
672 | { | 672 | { |
673 | return false; | 673 | return false; |
674 | } | 674 | } |
675 | 675 | ||
676 | double centerX = Canvas.GetLeft(_ucStartEndButton); | 676 | double centerX = Canvas.GetLeft(_ucStartEndButton); |
677 | double centerY = Canvas.GetTop(_ucStartEndButton); | 677 | double centerY = Canvas.GetTop(_ucStartEndButton); |
678 | 678 | ||
679 | if (currentPoint.X < centerX + 50 && currentPoint.X > centerX | 679 | if (currentPoint.X < centerX + 50 && currentPoint.X > centerX |
680 | && currentPoint.Y < centerY + 50 && currentPoint.Y > centerY) | 680 | && currentPoint.Y < centerY + 50 && currentPoint.Y > centerY) |
681 | { | 681 | { |
682 | return true; | 682 | return true; |
683 | } | 683 | } |
684 | return false; | 684 | return false; |
685 | } | 685 | } |
686 | 686 | ||
687 | /// <summary> | 687 | /// <summary> |
688 | /// Process when end draw route | 688 | /// Process when end draw route |
689 | /// </summary> | 689 | /// </summary> |
690 | private void ProcessEndRoute() | 690 | private void ProcessEndRoute() |
691 | { | 691 | { |
692 | Operation = OperationState.None; | 692 | Operation = OperationState.None; |
693 | AutoEditLine(); | 693 | AutoEditLine(); |
694 | this.Children.Remove(_displayAxiPosition); | 694 | this.Children.Remove(_displayAxiPosition); |
695 | this.Children.Remove(_goalPoint); | 695 | this.Children.Remove(_goalPoint); |
696 | this.Children.Add(_goalPoint); | 696 | this.Children.Add(_goalPoint); |
697 | } | 697 | } |
698 | 698 | ||
699 | /// <summary> | 699 | /// <summary> |
700 | /// Check end draw route | 700 | /// Check end draw route |
701 | /// </summary> | 701 | /// </summary> |
702 | /// <param name="_ucStartEndButton">Button end</param> | 702 | /// <param name="_ucStartEndButton">Button end</param> |
703 | /// <param name="currentPoint">Position for check</param> | 703 | /// <param name="currentPoint">Position for check</param> |
704 | /// <returns>true: end, false: not end</returns> | 704 | /// <returns>true: end, false: not end</returns> |
705 | private bool IsEndRoute(ucStartEndButton _ucStartEndButton, LineGeometry lineGeometry) | 705 | private bool IsEndRoute(ucStartEndButton _ucStartEndButton, LineGeometry lineGeometry) |
706 | { | 706 | { |
707 | if (_ucStartEndButton == null) | 707 | if (_ucStartEndButton == null) |
708 | { | 708 | { |
709 | return false; | 709 | return false; |
710 | } | 710 | } |
711 | 711 | ||
712 | double centerX = Canvas.GetLeft(_ucStartEndButton); | 712 | double centerX = Canvas.GetLeft(_ucStartEndButton); |
713 | double centerY = Canvas.GetTop(_ucStartEndButton); | 713 | double centerY = Canvas.GetTop(_ucStartEndButton); |
714 | Point startPoint = lineGeometry.StartPoint; | 714 | Point startPoint = lineGeometry.StartPoint; |
715 | Point endPoint = lineGeometry.EndPoint; | 715 | Point endPoint = lineGeometry.EndPoint; |
716 | 716 | ||
717 | if(IsVerticalLine(lineGeometry)) | 717 | if(IsVerticalLine(lineGeometry)) |
718 | { | 718 | { |
719 | if(endPoint.X < centerX || endPoint.X > centerX + 50) | 719 | if(endPoint.X < centerX || endPoint.X > centerX + 50) |
720 | return false; | 720 | return false; |
721 | 721 | ||
722 | if (startPoint.Y > centerY + 50 && endPoint.Y > centerY + 50) | 722 | if (startPoint.Y > centerY + 50 && endPoint.Y > centerY + 50) |
723 | return false; | 723 | return false; |
724 | 724 | ||
725 | if (startPoint.Y < centerY && endPoint.Y < centerY) | 725 | if (startPoint.Y < centerY && endPoint.Y < centerY) |
726 | return false; | 726 | return false; |
727 | }else | 727 | }else |
728 | { | 728 | { |
729 | if (endPoint.Y < centerY || endPoint.Y > centerY + 50) | 729 | if (endPoint.Y < centerY || endPoint.Y > centerY + 50) |
730 | return false; | 730 | return false; |
731 | 731 | ||
732 | if (startPoint.X > centerX + 50 && endPoint.X > centerX + 50) | 732 | if (startPoint.X > centerX + 50 && endPoint.X > centerX + 50) |
733 | return false; | 733 | return false; |
734 | 734 | ||
735 | if (startPoint.X < centerX && endPoint.X < centerX) | 735 | if (startPoint.X < centerX && endPoint.X < centerX) |
736 | return false; | 736 | return false; |
737 | } | 737 | } |
738 | 738 | ||
739 | return true; | 739 | return true; |
740 | } | 740 | } |
741 | 741 | ||
742 | /// <summary> | 742 | /// <summary> |
743 | /// Make root | 743 | /// Make root |
744 | /// </summary> | 744 | /// </summary> |
745 | public void MakeRoot() | 745 | public void MakeRoot() |
746 | { | 746 | { |
747 | //LineGeometry lineGeometry; | 747 | //LineGeometry lineGeometry; |
748 | //EllipseGeometry ellipseGeometry; | 748 | //EllipseGeometry ellipseGeometry; |
749 | //Point startPoint; | 749 | //Point startPoint; |
750 | //Point endPoint; | 750 | //Point endPoint; |
751 | 751 | ||
752 | // If still not route | 752 | // If still not route |
753 | if (gGrpLine.Children.Count == 0) | 753 | if (gGrpLine.Children.Count == 0) |
754 | return; | 754 | return; |
755 | 755 | ||
756 | pLine.Stroke = new SolidColorBrush(Colors.Red); | 756 | pLine.Stroke = new SolidColorBrush(Colors.Red); |
757 | pLine.StrokeThickness = STROKE_ROOT_LINE; | 757 | pLine.StrokeThickness = STROKE_ROOT_LINE; |
758 | 758 | ||
759 | //// Setting for path line | 759 | //// Setting for path line |
760 | //pRootLine.Stroke = new SolidColorBrush(Colors.Red); | 760 | //pRootLine.Stroke = new SolidColorBrush(Colors.Red); |
761 | //pRootLine.StrokeThickness = STROKE_ROOT_LINE; | 761 | //pRootLine.StrokeThickness = STROKE_ROOT_LINE; |
762 | //pRootLine.Data = gGrpRootLine; | 762 | //pRootLine.Data = gGrpRootLine; |
763 | //this.Children.Add(pRootLine); | 763 | //this.Children.Add(pRootLine); |
764 | 764 | ||
765 | // Setting for path curver line | 765 | // Setting for path curver line |
766 | //pCurverLine.StrokeThickness = STROKE_ROOT_LINE; | 766 | //pCurverLine.StrokeThickness = STROKE_ROOT_LINE; |
767 | 767 | ||
768 | //// Get start point | 768 | //// Get start point |
769 | //lineGeometry = (LineGeometry)gGrpLine.Children[0]; | 769 | //lineGeometry = (LineGeometry)gGrpLine.Children[0]; |
770 | //startPoint = lineGeometry.StartPoint; | 770 | //startPoint = lineGeometry.StartPoint; |
771 | 771 | ||
772 | //for (int i = 0; i < gGrpYellowNode.Children.Count; i = i + 2) | 772 | //for (int i = 0; i < gGrpYellowNode.Children.Count; i = i + 2) |
773 | //{ | 773 | //{ |
774 | // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i]; | 774 | // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i]; |
775 | // endPoint = ellipseGeometry.Center; | 775 | // endPoint = ellipseGeometry.Center; |
776 | 776 | ||
777 | // DrawLine(startPoint, endPoint, gGrpRootLine); | 777 | // DrawLine(startPoint, endPoint, gGrpRootLine); |
778 | 778 | ||
779 | // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i + 1]; | 779 | // ellipseGeometry = (EllipseGeometry)gGrpYellowNode.Children[i + 1]; |
780 | // startPoint = ellipseGeometry.Center; | 780 | // startPoint = ellipseGeometry.Center; |
781 | //} | 781 | //} |
782 | 782 | ||
783 | //lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count - 1]; | 783 | //lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count - 1]; |
784 | //endPoint = lineGeometry.EndPoint; | 784 | //endPoint = lineGeometry.EndPoint; |
785 | 785 | ||
786 | //DrawLine(startPoint, endPoint, gGrpRootLine); | 786 | //DrawLine(startPoint, endPoint, gGrpRootLine); |
787 | 787 | ||
788 | //this.Children.Remove(pYellowNode); | 788 | //this.Children.Remove(pYellowNode); |
789 | //this.Children.Remove(pBlueNode); | 789 | //this.Children.Remove(pBlueNode); |
790 | //this.Children.Remove(_startPoint); | 790 | //this.Children.Remove(_startPoint); |
791 | //this.Children.Remove(_goalPoint); | 791 | //this.Children.Remove(_goalPoint); |
792 | //this.Children.Add(pYellowNode); | 792 | //this.Children.Add(pYellowNode); |
793 | //this.Children.Add(pBlueNode); | 793 | //this.Children.Add(pBlueNode); |
794 | //this.Children.Add(_startPoint); | 794 | //this.Children.Add(_startPoint); |
795 | //this.Children.Add(_goalPoint); | 795 | //this.Children.Add(_goalPoint); |
796 | } | 796 | } |
797 | 797 | ||
798 | /// <summary> | 798 | /// <summary> |
799 | /// Auto edit leght of line | 799 | /// Auto edit leght of line |
800 | /// </summary> | 800 | /// </summary> |
801 | private void AutoEditLine() | 801 | private void AutoEditLine() |
802 | { | 802 | { |
803 | double temp; | 803 | double temp; |
804 | int index = gGrpLine.Children.Count - 1; | 804 | int index = gGrpLine.Children.Count - 1; |
805 | double centerY = Canvas.GetTop(_goalPoint) + 25; | 805 | double centerY = Canvas.GetTop(_goalPoint) + 25; |
806 | double centerX = Canvas.GetLeft(_goalPoint) + 25; | 806 | double centerX = Canvas.GetLeft(_goalPoint) + 25; |
807 | LineGeometry lastLine = (LineGeometry)gGrpLine.Children[index]; | 807 | LineGeometry lastLine = (LineGeometry)gGrpLine.Children[index]; |
808 | LineGeometry beforeLastLine = (LineGeometry)gGrpLine.Children[index]; | 808 | LineGeometry beforeLastLine = (LineGeometry)gGrpLine.Children[index]; |
809 | 809 | ||
810 | if(gGrpLine.Children.Count > 1) | 810 | if(gGrpLine.Children.Count > 1) |
811 | { | 811 | { |
812 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; | 812 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; |
813 | 813 | ||
814 | if (!IsCurverNode(beforeLastLine, lastLine)) | 814 | if (!IsCurverNode(beforeLastLine, lastLine)) |
815 | { | 815 | { |
816 | beforeLastLine.EndPoint = lastLine.EndPoint; | 816 | beforeLastLine.EndPoint = lastLine.EndPoint; |
817 | gGrpLine.Children.RemoveAt(index); | 817 | gGrpLine.Children.RemoveAt(index); |
818 | //// Remove yellow node | 818 | //// Remove yellow node |
819 | //if (gGrpYellowNode.Children.Count > 0) | 819 | //if (gGrpYellowNode.Children.Count > 0) |
820 | //{ | 820 | //{ |
821 | // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); | 821 | // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); |
822 | // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); | 822 | // gGrpYellowNode.Children.RemoveAt(gGrpYellowNode.Children.Count - 1); |
823 | //} | 823 | //} |
824 | //// Remove curver line | 824 | //// Remove curver line |
825 | //if (gGrpCurverLine.Children.Count > 0) | 825 | //if (gGrpCurverLine.Children.Count > 0) |
826 | //{ | 826 | //{ |
827 | // gGrpCurverLine.Children.RemoveAt(gGrpCurverLine.Children.Count - 1); | 827 | // gGrpCurverLine.Children.RemoveAt(gGrpCurverLine.Children.Count - 1); |
828 | //} | 828 | //} |
829 | index = index - 1; | 829 | index = index - 1; |
830 | lastLine = (LineGeometry)gGrpLine.Children[index]; | 830 | lastLine = (LineGeometry)gGrpLine.Children[index]; |
831 | } | 831 | } |
832 | } | 832 | } |
833 | 833 | ||
834 | if (index == gGrpRedNode.Children.Count + 1) | 834 | if (index == gGrpRedNode.Children.Count + 1) |
835 | { | 835 | { |
836 | AddNode(lastLine.StartPoint, gGrpRedNode); | 836 | AddNode(lastLine.StartPoint, gGrpRedNode); |
837 | } | 837 | } |
838 | 838 | ||
839 | if (lastLine.EndPoint.X == centerX && lastLine.EndPoint.Y == centerY) | 839 | if (lastLine.EndPoint.X == centerX && lastLine.EndPoint.Y == centerY) |
840 | return; | 840 | return; |
841 | 841 | ||
842 | if(IsVerticalLine(lastLine)) | 842 | if(IsVerticalLine(lastLine)) |
843 | { | 843 | { |
844 | temp = lastLine.StartPoint.Y; | 844 | temp = lastLine.StartPoint.Y; |
845 | lastLine.StartPoint = new Point(centerX, temp); | 845 | lastLine.StartPoint = new Point(centerX, temp); |
846 | lastLine.EndPoint = new Point(centerX, centerY); | 846 | lastLine.EndPoint = new Point(centerX, centerY); |
847 | 847 | ||
848 | if(gGrpLine.Children.Count > 1){ | 848 | if(gGrpLine.Children.Count > 1){ |
849 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; | 849 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; |
850 | temp = beforeLastLine.EndPoint.Y; | 850 | temp = beforeLastLine.EndPoint.Y; |
851 | beforeLastLine.EndPoint = new Point(centerX, temp); | 851 | beforeLastLine.EndPoint = new Point(centerX, temp); |
852 | } | 852 | } |
853 | }else | 853 | }else |
854 | { | 854 | { |
855 | temp = lastLine.StartPoint.X; | 855 | temp = lastLine.StartPoint.X; |
856 | lastLine.StartPoint = new Point(temp, centerY); | 856 | lastLine.StartPoint = new Point(temp, centerY); |
857 | lastLine.EndPoint = new Point(centerX, centerY); | 857 | lastLine.EndPoint = new Point(centerX, centerY); |
858 | if (gGrpLine.Children.Count > 1) | 858 | if (gGrpLine.Children.Count > 1) |
859 | { | 859 | { |
860 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; | 860 | beforeLastLine = (LineGeometry)gGrpLine.Children[index - 1]; |
861 | temp = beforeLastLine.EndPoint.X; | 861 | temp = beforeLastLine.EndPoint.X; |
862 | beforeLastLine.EndPoint = new Point(temp, centerY); | 862 | beforeLastLine.EndPoint = new Point(temp, centerY); |
863 | } | 863 | } |
864 | } | 864 | } |
865 | 865 | ||
866 | // Draw curver line | 866 | // Draw curver line |
867 | if (IsCurverNode(beforeLastLine, lastLine)) | 867 | if (IsCurverNode(beforeLastLine, lastLine)) |
868 | { | 868 | { |
869 | EllipseGeometry ellipseGeometry = (EllipseGeometry)gGrpRedNode.Children[gGrpRedNode.Children.Count - 1]; | 869 | EllipseGeometry ellipseGeometry = (EllipseGeometry)gGrpRedNode.Children[gGrpRedNode.Children.Count - 1]; |
870 | ellipseGeometry.Center = lastLine.StartPoint; | 870 | ellipseGeometry.Center = lastLine.StartPoint; |
871 | // | 871 | // |
872 | //if (GetDistance(lastLine.StartPoint, lastLine.EndPoint) > RADIUS_CURVER_LINE + 25) | 872 | //if (GetDistance(lastLine.StartPoint, lastLine.EndPoint) > RADIUS_CURVER_LINE + 25) |
873 | //{ | 873 | //{ |
874 | //DrawCurver(beforeLastLine, lastLine); | 874 | //DrawCurver(beforeLastLine, lastLine); |
875 | //} | 875 | //} |
876 | } | 876 | } |
877 | } | 877 | } |
878 | 878 | ||
879 | /// <summary> | 879 | /// <summary> |
880 | /// Check draw curver node | 880 | /// Check draw curver node |
881 | /// </summary> | 881 | /// </summary> |
882 | /// <param name="oldLine">Old line</param> | 882 | /// <param name="oldLine">Old line</param> |
883 | /// <param name="newLine">New line</param> | 883 | /// <param name="newLine">New line</param> |
884 | /// <returns>true:is curver, fasle: not curver</returns> | 884 | /// <returns>true:is curver, fasle: not curver</returns> |
885 | private bool IsCurverNode(LineGeometry oldLine, LineGeometry newLine) | 885 | private bool IsCurverNode(LineGeometry oldLine, LineGeometry newLine) |
886 | { | 886 | { |
887 | if (oldLine.StartPoint.Y == oldLine.EndPoint.Y && oldLine.StartPoint.Y == newLine.EndPoint.Y) | 887 | if (oldLine.StartPoint.Y == oldLine.EndPoint.Y && oldLine.StartPoint.Y == newLine.EndPoint.Y) |
888 | { | 888 | { |
889 | return false; | 889 | return false; |
890 | } | 890 | } |
891 | 891 | ||
892 | if (oldLine.StartPoint.X == oldLine.EndPoint.X && oldLine.StartPoint.X == newLine.EndPoint.X) | 892 | if (oldLine.StartPoint.X == oldLine.EndPoint.X && oldLine.StartPoint.X == newLine.EndPoint.X) |
893 | { | 893 | { |
894 | return false; | 894 | return false; |
895 | } | 895 | } |
896 | 896 | ||
897 | return true; | 897 | return true; |
898 | } | 898 | } |
899 | 899 | ||
900 | /// <summary> | 900 | /// <summary> |
901 | /// Check timming to stop draw route | 901 | /// Check timming to stop draw route |
902 | /// </summary> | 902 | /// </summary> |
903 | /// <param name="e"></param> | 903 | /// <param name="e"></param> |
904 | /// <returns>true:stop; false:continue</returns> | 904 | /// <returns>true:stop; false:continue</returns> |
905 | private bool IsStopDrawRoute(MouseEventArgs e) | 905 | private bool IsStopDrawRoute(MouseEventArgs e) |
906 | { | 906 | { |
907 | if(e.RightButton == MouseButtonState.Pressed) | 907 | if(e.RightButton == MouseButtonState.Pressed) |
908 | { | 908 | { |
909 | return true; | 909 | return true; |
910 | } | 910 | } |
911 | 911 | ||
912 | return false; | 912 | return false; |
913 | } | 913 | } |
914 | 914 | ||
915 | //2017/03/05 NAM ADD START | 915 | //2017/03/05 NAM ADD START |
916 | private bool IsMouseLeftClick(MouseEventArgs e) | 916 | private bool IsMouseLeftClick(MouseEventArgs e) |
917 | { | 917 | { |
918 | if (e.LeftButton == MouseButtonState.Pressed) | 918 | if (e.LeftButton == MouseButtonState.Pressed) |
919 | { | 919 | { |
920 | return true; | 920 | return true; |
921 | } | 921 | } |
922 | 922 | ||
923 | return false; | 923 | return false; |
924 | } | 924 | } |
925 | //2017/03/05 NAM ADD END | 925 | //2017/03/05 NAM ADD END |
926 | 926 | ||
927 | /// <summary> | 927 | /// <summary> |
928 | /// Draw curver line and yellow node | 928 | /// Draw curver line and yellow node |
929 | /// </summary> | 929 | /// </summary> |
930 | /// <param name="oldLine">Old line</param> | 930 | /// <param name="oldLine">Old line</param> |
931 | /// <param name="newLine">New line</param> | 931 | /// <param name="newLine">New line</param> |
932 | private void DrawCurver(LineGeometry oldLine, LineGeometry newLine) | 932 | private void DrawCurver(LineGeometry oldLine, LineGeometry newLine) |
933 | { | 933 | { |
934 | double radius = RADIUS_CURVER_LINE; | 934 | double radius = RADIUS_CURVER_LINE; |
935 | 935 | ||
936 | Point startPoint ; | 936 | Point startPoint ; |
937 | Point endPoint ; | 937 | Point endPoint ; |
938 | 938 | ||
939 | // Get postion of yellow node on old line | 939 | // Get postion of yellow node on old line |
940 | if(IsVerticalLine(oldLine)) | 940 | if(IsVerticalLine(oldLine)) |
941 | { | 941 | { |
942 | if (oldLine.StartPoint.Y > oldLine.EndPoint.Y) | 942 | if (oldLine.StartPoint.Y > oldLine.EndPoint.Y) |
943 | startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y + radius); | 943 | startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y + radius); |
944 | else | 944 | else |
945 | startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y - radius); | 945 | startPoint = new Point(oldLine.EndPoint.X, oldLine.EndPoint.Y - radius); |
946 | }else | 946 | }else |
947 | { | 947 | { |
948 | if (oldLine.StartPoint.X > oldLine.EndPoint.X) | 948 | if (oldLine.StartPoint.X > oldLine.EndPoint.X) |
949 | startPoint = new Point(oldLine.EndPoint.X + radius, oldLine.EndPoint.Y); | 949 | startPoint = new Point(oldLine.EndPoint.X + radius, oldLine.EndPoint.Y); |
950 | else | 950 | else |
951 | startPoint = new Point(oldLine.EndPoint.X - radius, oldLine.EndPoint.Y); | 951 | startPoint = new Point(oldLine.EndPoint.X - radius, oldLine.EndPoint.Y); |
952 | } | 952 | } |
953 | 953 | ||
954 | // Get postion of yellow node on new line | 954 | // Get postion of yellow node on new line |
955 | if (IsVerticalLine(newLine)) | 955 | if (IsVerticalLine(newLine)) |
956 | { | 956 | { |
957 | if (newLine.StartPoint.Y > newLine.EndPoint.Y) | 957 | if (newLine.StartPoint.Y > newLine.EndPoint.Y) |
958 | endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y - radius); | 958 | endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y - radius); |
959 | else | 959 | else |
960 | endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y + radius); | 960 | endPoint = new Point(newLine.StartPoint.X, newLine.StartPoint.Y + radius); |
961 | } | 961 | } |
962 | else | 962 | else |
963 | { | 963 | { |
964 | if (newLine.StartPoint.X > newLine.EndPoint.X) | 964 | if (newLine.StartPoint.X > newLine.EndPoint.X) |
965 | endPoint = new Point(newLine.StartPoint.X - radius, newLine.StartPoint.Y); | 965 | endPoint = new Point(newLine.StartPoint.X - radius, newLine.StartPoint.Y); |
966 | else | 966 | else |
967 | endPoint = new Point(newLine.StartPoint.X + radius, newLine.StartPoint.Y); | 967 | endPoint = new Point(newLine.StartPoint.X + radius, newLine.StartPoint.Y); |
968 | } | 968 | } |
969 | 969 | ||
970 | //// Setting sweep direction | 970 | //// Setting sweep direction |
971 | //SweepDirection sweepDirection = SweepDirection.Clockwise; | 971 | //SweepDirection sweepDirection = SweepDirection.Clockwise; |
972 | //if (IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) > 0) | 972 | //if (IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) > 0) |
973 | //{ | 973 | //{ |
974 | // sweepDirection = SweepDirection.Counterclockwise; | 974 | // sweepDirection = SweepDirection.Counterclockwise; |
975 | //} | 975 | //} |
976 | 976 | ||
977 | //if (!IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) < 0) | 977 | //if (!IsVerticalLine(oldLine) && ((startPoint.Y - endPoint.Y) * (startPoint.X - endPoint.X)) < 0) |
978 | //{ | 978 | //{ |
979 | // sweepDirection = SweepDirection.Counterclockwise; | 979 | // sweepDirection = SweepDirection.Counterclockwise; |
980 | //} | 980 | //} |
981 | 981 | ||
982 | //// Add curver line | 982 | //// Add curver line |
983 | //DrawCurverLine(startPoint, endPoint, sweepDirection, gGrpCurverLine); | 983 | //DrawCurverLine(startPoint, endPoint, sweepDirection, gGrpCurverLine); |
984 | 984 | ||
985 | // Add node to postion distance 1300mm | 985 | // Add node to postion distance 1300mm |
986 | if (GetDistance(oldLine.StartPoint, oldLine.EndPoint) > RADIUS_CURVER_LINE) | 986 | if (GetDistance(oldLine.StartPoint, oldLine.EndPoint) > RADIUS_CURVER_LINE) |
987 | { | 987 | { |
988 | AddNode(startPoint, gGrpYellowNode); | 988 | AddNode(startPoint, gGrpYellowNode); |
989 | } | 989 | } |
990 | 990 | ||
991 | if (GetDistance(newLine.StartPoint, newLine.EndPoint) > RADIUS_CURVER_LINE) | 991 | if (GetDistance(newLine.StartPoint, newLine.EndPoint) > RADIUS_CURVER_LINE) |
992 | { | 992 | { |
993 | AddNode(endPoint, gGrpYellowNode); | 993 | AddNode(endPoint, gGrpYellowNode); |
994 | } | 994 | } |
995 | } | 995 | } |
996 | 996 | ||
997 | /// <summary> | 997 | /// <summary> |
998 | /// Init data for draw route | 998 | /// Init data for draw route |
999 | /// </summary> | 999 | /// </summary> |
1000 | private void InitDrawRoute() | 1000 | private void InitDrawRoute() |
1001 | { | 1001 | { |
1002 | //2017/03/04 NAM ADD START | 1002 | //2017/03/04 NAM ADD START |
1003 | pNewLine.Stroke = new SolidColorBrush(Colors.Red); | 1003 | pNewLine.Stroke = new SolidColorBrush(Colors.Red); |
1004 | pNewLine.StrokeThickness = STROKE_LINE; | 1004 | pNewLine.StrokeThickness = STROKE_LINE; |
1005 | pNewLine.Data = gGrpNewLine; | 1005 | pNewLine.Data = gGrpNewLine; |
1006 | //2017/03/04 NAM ADD END | 1006 | //2017/03/04 NAM ADD END |
1007 | 1007 | ||
1008 | pScheduleLine.Stroke = new SolidColorBrush(Colors.Red); | 1008 | pScheduleLine.Stroke = new SolidColorBrush(Colors.Red); |
1009 | pScheduleLine.StrokeThickness = STROKE_LINE; | 1009 | pScheduleLine.StrokeThickness = STROKE_LINE; |
1010 | pScheduleLine.Data = gGrpScheduleLine; | 1010 | pScheduleLine.Data = gGrpScheduleLine; |
1011 | 1011 | ||
1012 | // Setting for path line | 1012 | // Setting for path line |
1013 | pLine.Stroke = new SolidColorBrush(Colors.Blue); | 1013 | pLine.Stroke = new SolidColorBrush(Colors.Blue); |
1014 | pLine.StrokeThickness = STROKE_LINE; | 1014 | pLine.StrokeThickness = STROKE_LINE; |
1015 | pLine.Data = gGrpLine; | 1015 | pLine.Data = gGrpLine; |
1016 | 1016 | ||
1017 | // Setting for path of curver line | 1017 | // Setting for path of curver line |
1018 | pCurverLine.Stroke = Brushes.Red; | 1018 | pCurverLine.Stroke = Brushes.Red; |
1019 | pCurverLine.StrokeThickness = STROKE_LINE; | 1019 | pCurverLine.StrokeThickness = STROKE_LINE; |
1020 | pCurverLine.Data = gGrpCurverLine; | 1020 | pCurverLine.Data = gGrpCurverLine; |
1021 | 1021 | ||
1022 | // Setting for path of red node | 1022 | // Setting for path of red node |
1023 | pRedNode.Stroke = new SolidColorBrush(Colors.Blue); | 1023 | pRedNode.Stroke = new SolidColorBrush(Colors.Blue); |
1024 | pRedNode.Fill = new SolidColorBrush(Colors.Red); | 1024 | pRedNode.Fill = new SolidColorBrush(Colors.Red); |
1025 | pRedNode.StrokeThickness = STROKE_NODE; | 1025 | pRedNode.StrokeThickness = STROKE_NODE; |
1026 | pRedNode.Data = gGrpRedNode; | 1026 | pRedNode.Data = gGrpRedNode; |
1027 | 1027 | ||
1028 | // Setting for path of yellow node | 1028 | // Setting for path of yellow node |
1029 | pYellowNode.Stroke = new SolidColorBrush(Colors.Blue); | 1029 | pYellowNode.Stroke = new SolidColorBrush(Colors.Blue); |
1030 | pYellowNode.Fill = new SolidColorBrush(Colors.Yellow); | 1030 | pYellowNode.Fill = new SolidColorBrush(Colors.Yellow); |
1031 | pYellowNode.StrokeThickness = STROKE_NODE; | 1031 | pYellowNode.StrokeThickness = STROKE_NODE; |
1032 | pYellowNode.Data = gGrpYellowNode; | 1032 | pYellowNode.Data = gGrpYellowNode; |
1033 | 1033 | ||
1034 | // Setting for path of Blue node | 1034 | // Setting for path of Blue node |
1035 | pBlueNode.Stroke = new SolidColorBrush(Colors.Blue); | 1035 | pBlueNode.Stroke = new SolidColorBrush(Colors.Blue); |
1036 | pBlueNode.Fill = new SolidColorBrush(Colors.LightBlue); | 1036 | pBlueNode.Fill = new SolidColorBrush(Colors.LightBlue); |
1037 | pBlueNode.StrokeThickness = STROKE_NODE; | 1037 | pBlueNode.StrokeThickness = STROKE_NODE; |
1038 | pBlueNode.Data = gGrpBlueNode; | 1038 | pBlueNode.Data = gGrpBlueNode; |
1039 | 1039 | ||
1040 | // Setting for path of Free node | 1040 | // Setting for path of Free node |
1041 | //pFreeNode.Stroke = new SolidColorBrush(Colors.Blue); | 1041 | //pFreeNode.Stroke = new SolidColorBrush(Colors.Blue); |
1042 | //pFreeNode.Fill = new SolidColorBrush(Colors.LightBlue); | 1042 | //pFreeNode.Fill = new SolidColorBrush(Colors.LightBlue); |
1043 | //pFreeNode.StrokeThickness = STROKE_NODE; | 1043 | //pFreeNode.StrokeThickness = STROKE_NODE; |
1044 | //pFreeNode.Data = gGrpFreeNode; | 1044 | //pFreeNode.Data = gGrpFreeNode; |
1045 | 1045 | ||
1046 | // Add paths to canvas | 1046 | // Add paths to canvas |
1047 | this.Children.Add(pLine); | 1047 | this.Children.Add(pLine); |
1048 | this.Children.Add(pCurverLine); | 1048 | this.Children.Add(pCurverLine); |
1049 | this.Children.Add(pRedNode); | 1049 | this.Children.Add(pRedNode); |
1050 | this.Children.Add(pYellowNode); | 1050 | this.Children.Add(pYellowNode); |
1051 | 1051 | ||
1052 | //this.Children.Add(pBlueNode); | 1052 | //this.Children.Add(pBlueNode); |
1053 | //2017/03/04 NAM ADD START | 1053 | //2017/03/04 NAM ADD START |
1054 | this.Children.Add(pNewLine); | 1054 | this.Children.Add(pNewLine); |
1055 | //this.Children.Add(pScheduleLine); | 1055 | //this.Children.Add(pScheduleLine); |
1056 | scheduleCanvas.Children.Add(pScheduleLine); | 1056 | scheduleCanvas.Children.Add(pScheduleLine); |
1057 | //2017/03/04 NAM ADD END | 1057 | //2017/03/04 NAM ADD END |
1058 | } | 1058 | } |
1059 | 1059 | ||
1060 | /// <summary> | 1060 | /// <summary> |
1061 | /// Clear all route | 1061 | /// Clear all route |
1062 | /// </summary> | 1062 | /// </summary> |
1063 | public void ClearRoute() | 1063 | public void ClearRoute() |
1064 | { | 1064 | { |
1065 | isStartDrawRoute = false; | 1065 | isStartDrawRoute = false; |
1066 | isGoalDrawRoute = false; | 1066 | isGoalDrawRoute = false; |
1067 | 1067 | ||
1068 | gGrpLine.Children.Clear(); | 1068 | gGrpLine.Children.Clear(); |
1069 | gGrpRootLine.Children.Clear(); | 1069 | gGrpRootLine.Children.Clear(); |
1070 | gGrpCurverLine.Children.Clear(); | 1070 | gGrpCurverLine.Children.Clear(); |
1071 | gGrpRedNode.Children.Clear(); | 1071 | gGrpRedNode.Children.Clear(); |
1072 | gGrpYellowNode.Children.Clear(); | 1072 | gGrpYellowNode.Children.Clear(); |
1073 | gGrpBlueNode.Children.Clear(); | 1073 | gGrpBlueNode.Children.Clear(); |
1074 | 1074 | ||
1075 | this.Children.Remove(pLine); | 1075 | this.Children.Remove(pLine); |
1076 | this.Children.Remove(pRootLine); | 1076 | this.Children.Remove(pRootLine); |
1077 | this.Children.Remove(pCurverLine); | 1077 | this.Children.Remove(pCurverLine); |
1078 | this.Children.Remove(pRedNode); | 1078 | this.Children.Remove(pRedNode); |
1079 | this.Children.Remove(pYellowNode); | 1079 | this.Children.Remove(pYellowNode); |
1080 | this.Children.Remove(pBlueNode); | 1080 | this.Children.Remove(pBlueNode); |
1081 | } | 1081 | } |
1082 | 1082 | ||
1083 | /// <summary> | 1083 | /// <summary> |
1084 | /// Draw line for route | 1084 | /// Draw line for route |
1085 | /// </summary> | 1085 | /// </summary> |
1086 | /// <param name="startPoint">Start point</param> | 1086 | /// <param name="startPoint">Start point</param> |
1087 | /// <param name="endPoint">End point</param> | 1087 | /// <param name="endPoint">End point</param> |
1088 | /// <param name="geometryGroup">Geometry Group</param> | 1088 | /// <param name="geometryGroup">Geometry Group</param> |
1089 | private void DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup) | 1089 | private void DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup) |
1090 | { | 1090 | { |
1091 | LineGeometry lineGeometry = new LineGeometry(); | 1091 | LineGeometry lineGeometry = new LineGeometry(); |
1092 | lineGeometry.StartPoint = startPoint; | 1092 | lineGeometry.StartPoint = startPoint; |
1093 | lineGeometry.EndPoint = endPoint; | 1093 | lineGeometry.EndPoint = endPoint; |
1094 | geometryGroup.Children.Add(lineGeometry); | 1094 | geometryGroup.Children.Add(lineGeometry); |
1095 | } | 1095 | } |
1096 | 1096 | ||
1097 | /// <summary> | 1097 | /// <summary> |
1098 | /// Draw curver line | 1098 | /// Draw curver line |
1099 | /// </summary> | 1099 | /// </summary> |
1100 | /// <param name="startPoint">Point start curver line</param> | 1100 | /// <param name="startPoint">Point start curver line</param> |
1101 | /// <param name="endPoint">Point end curver line</param> | 1101 | /// <param name="endPoint">Point end curver line</param> |
1102 | /// <param name="radius">Radius</param> | 1102 | /// <param name="radius">Radius</param> |
1103 | /// <param name="geometryGroup">Geometry Group</param> | 1103 | /// <param name="geometryGroup">Geometry Group</param> |
1104 | private void DrawCurverLine(Point startPoint, Point endPoint, SweepDirection sweepDirection, GeometryGroup geometryGroup) | 1104 | private void DrawCurverLine(Point startPoint, Point endPoint, SweepDirection sweepDirection, GeometryGroup geometryGroup) |
1105 | { | 1105 | { |
1106 | PathGeometry pathGeometry = new PathGeometry(); | 1106 | PathGeometry pathGeometry = new PathGeometry(); |
1107 | PathFigure figure = new PathFigure(); | 1107 | PathFigure figure = new PathFigure(); |
1108 | figure.StartPoint = startPoint; | 1108 | figure.StartPoint = startPoint; |
1109 | figure.Segments.Add(new ArcSegment(endPoint, new Size(RADIUS_CURVER_LINE, RADIUS_CURVER_LINE), 90, false, sweepDirection, true)); | 1109 | figure.Segments.Add(new ArcSegment(endPoint, new Size(RADIUS_CURVER_LINE, RADIUS_CURVER_LINE), 90, false, sweepDirection, true)); |
1110 | pathGeometry.Figures.Add(figure); | 1110 | pathGeometry.Figures.Add(figure); |
1111 | geometryGroup.Children.Add(pathGeometry); | 1111 | geometryGroup.Children.Add(pathGeometry); |
1112 | } | 1112 | } |
1113 | 1113 | ||
1114 | /// <summary> | 1114 | /// <summary> |
1115 | /// Setting node | 1115 | /// Setting node |
1116 | /// </summary> | 1116 | /// </summary> |
1117 | /// <param name="centerPoit">Position of center node</param> | 1117 | /// <param name="centerPoit">Position of center node</param> |
1118 | /// <param name="geometryGroup">Geometry Group</param> | 1118 | /// <param name="geometryGroup">Geometry Group</param> |
1119 | private void AddNode(Point centerPoit, GeometryGroup geometryGroup) | 1119 | private void AddNode(Point centerPoit, GeometryGroup geometryGroup) |
1120 | { | 1120 | { |
1121 | double radius = RADIUS_NODE; | 1121 | double radius = RADIUS_NODE; |
1122 | geometryGroup.Children.Add(new EllipseGeometry(centerPoit, radius, radius)); | 1122 | geometryGroup.Children.Add(new EllipseGeometry(centerPoit, radius, radius)); |
1123 | } | 1123 | } |
1124 | 1124 | ||
1125 | /// <summary> | 1125 | /// <summary> |
1126 | /// Check line is vertical or horizontal | 1126 | /// Check line is vertical or horizontal |
1127 | /// </summary> | 1127 | /// </summary> |
1128 | /// <param name="line"></param> | 1128 | /// <param name="line"></param> |
1129 | /// <returns>true:Vertical, false:Horizontal</returns> | 1129 | /// <returns>true:Vertical, false:Horizontal</returns> |
1130 | private bool IsVerticalLine(LineGeometry line) | 1130 | private bool IsVerticalLine(LineGeometry line) |
1131 | { | 1131 | { |
1132 | if (line.StartPoint.X == line.EndPoint.X) | 1132 | if (line.StartPoint.X == line.EndPoint.X) |
1133 | { | 1133 | { |
1134 | // Vertical line | 1134 | // Vertical line |
1135 | return true; | 1135 | return true; |
1136 | } | 1136 | } |
1137 | 1137 | ||
1138 | // Horizontal line | 1138 | // Horizontal line |
1139 | return false; | 1139 | return false; |
1140 | } | 1140 | } |
1141 | 1141 | ||
1142 | /// <summary> | 1142 | /// <summary> |
1143 | /// Get distance between two point | 1143 | /// Get distance between two point |
1144 | /// </summary> | 1144 | /// </summary> |
1145 | /// <param name="point1">Point 1</param> | 1145 | /// <param name="point1">Point 1</param> |
1146 | /// <param name="point2">Point 2</param> | 1146 | /// <param name="point2">Point 2</param> |
1147 | /// <returns>Distance between two point</returns> | 1147 | /// <returns>Distance between two point</returns> |
1148 | private double GetDistance(Point point1, Point point2) | 1148 | private double GetDistance(Point point1, Point point2) |
1149 | { | 1149 | { |
1150 | //pythagorean theorem c^2 = a^2 + b^2 | 1150 | //pythagorean theorem c^2 = a^2 + b^2 |
1151 | //thus c = square root(a^2 + b^2) | 1151 | //thus c = square root(a^2 + b^2) |
1152 | double a = (double)(point2.X - point1.X); | 1152 | double a = (double)(point2.X - point1.X); |
1153 | double b = (double)(point2.Y - point1.Y); | 1153 | double b = (double)(point2.Y - point1.Y); |
1154 | 1154 | ||
1155 | return Math.Sqrt(a * a + b * b); | 1155 | return Math.Sqrt(a * a + b * b); |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | /// <summary> | 1158 | /// <summary> |
1159 | /// Check point is valid for draw | 1159 | /// Check point is valid for draw |
1160 | /// </summary> | 1160 | /// </summary> |
1161 | /// <param name="point">Poit need check</param> | 1161 | /// <param name="point">Poit need check</param> |
1162 | /// <returns>true:Valid, false:Invalid</returns> | 1162 | /// <returns>true:Valid, false:Invalid</returns> |
1163 | private bool IsValidPoint(Point point) | 1163 | private bool IsValidPoint(Point point) |
1164 | { | 1164 | { |
1165 | return true; | 1165 | return true; |
1166 | } | 1166 | } |
1167 | 1167 | ||
1168 | /// <summary> | 1168 | /// <summary> |
1169 | /// Display coordinate position | 1169 | /// Display coordinate position |
1170 | /// </summary> | 1170 | /// </summary> |
1171 | /// <param name="point">Position to display</param> | 1171 | /// <param name="point">Position to display</param> |
1172 | private void DisplayCoordinate(Point point) | 1172 | private void DisplayCoordinate(Point point) |
1173 | { | 1173 | { |
1174 | if (_displayAxiPosition == null) | 1174 | if (_displayAxiPosition == null) |
1175 | { | 1175 | { |
1176 | _displayAxiPosition = new ucDisplayCoordinate(); | 1176 | _displayAxiPosition = new ucDisplayCoordinate(); |
1177 | this.Children.Add(_displayAxiPosition); | 1177 | this.Children.Add(_displayAxiPosition); |
1178 | } | 1178 | } |
1179 | _displayAxiPosition.Display(point); | 1179 | _displayAxiPosition.Display(point); |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | #endregion | 1182 | #endregion |
1183 | 1183 | ||
1184 | #region Functions for Set Auto Nodes | 1184 | #region Functions for Set Auto Nodes |
1185 | 1185 | ||
1186 | /// <summary> | 1186 | /// <summary> |
1187 | /// SetAutoNodes | 1187 | /// SetAutoNodes |
1188 | /// </summary> | 1188 | /// </summary> |
1189 | public void SetAutoNodes() | 1189 | public void SetAutoNodes() |
1190 | { | 1190 | { |
1191 | double radiusStart = DISTANCE_START_NODES; | 1191 | double radiusStart = DISTANCE_START_NODES; |
1192 | double radiusEnd = DISTANCE_END_NODES; | 1192 | double radiusEnd = DISTANCE_END_NODES; |
1193 | double radiusCurver = RADIUS_CURVER_LINE; | 1193 | double radiusCurver = RADIUS_CURVER_LINE; |
1194 | 1194 | ||
1195 | Point startNode; | 1195 | Point startNode; |
1196 | Point endNode; | 1196 | Point endNode; |
1197 | 1197 | ||
1198 | gGrpBlueNode.Children.Clear(); | 1198 | gGrpBlueNode.Children.Clear(); |
1199 | 1199 | ||
1200 | if (gGrpLine.Children.Count == 1) | 1200 | if (gGrpLine.Children.Count == 1) |
1201 | radiusCurver = radiusEnd; | 1201 | radiusCurver = radiusEnd; |
1202 | 1202 | ||
1203 | if (gGrpLine.Children.Count > 0) | 1203 | if (gGrpLine.Children.Count > 0) |
1204 | { | 1204 | { |
1205 | for (int i = 0; i < gGrpLine.Children.Count; i++) | 1205 | for (int i = 0; i < gGrpLine.Children.Count; i++) |
1206 | { | 1206 | { |
1207 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i]; | 1207 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i]; |
1208 | if (i == 0) | 1208 | if (i == 0) |
1209 | { | 1209 | { |
1210 | startNode = lineGeometry.EndPoint; | 1210 | startNode = lineGeometry.EndPoint; |
1211 | endNode = lineGeometry.StartPoint; | 1211 | endNode = lineGeometry.StartPoint; |
1212 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusStart); | 1212 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusStart); |
1213 | } | 1213 | } |
1214 | else if (i == gGrpLine.Children.Count - 1 && i > 0) | 1214 | else if (i == gGrpLine.Children.Count - 1 && i > 0) |
1215 | { | 1215 | { |
1216 | startNode = lineGeometry.StartPoint; | 1216 | startNode = lineGeometry.StartPoint; |
1217 | endNode = lineGeometry.EndPoint; | 1217 | endNode = lineGeometry.EndPoint; |
1218 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusEnd); | 1218 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusEnd); |
1219 | } | 1219 | } |
1220 | else | 1220 | else |
1221 | { | 1221 | { |
1222 | startNode = lineGeometry.StartPoint; | 1222 | startNode = lineGeometry.StartPoint; |
1223 | endNode = lineGeometry.EndPoint; | 1223 | endNode = lineGeometry.EndPoint; |
1224 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusCurver); | 1224 | DrawAutoNodes(startNode, endNode, radiusCurver, radiusCurver); |
1225 | } | 1225 | } |
1226 | } | 1226 | } |
1227 | } | 1227 | } |
1228 | } | 1228 | } |
1229 | 1229 | ||
1230 | 1230 | ||
1231 | /// <summary> | 1231 | /// <summary> |
1232 | /// DrawAutoNodes | 1232 | /// DrawAutoNodes |
1233 | /// </summary> | 1233 | /// </summary> |
1234 | /// <param name="startNode"></param> | 1234 | /// <param name="startNode"></param> |
1235 | /// <param name="endNode"></param> | 1235 | /// <param name="endNode"></param> |
1236 | /// <param name="radiusStart"></param> | 1236 | /// <param name="radiusStart"></param> |
1237 | /// <param name="radiusEnd"></param> | 1237 | /// <param name="radiusEnd"></param> |
1238 | private void DrawAutoNodes(Point startNode, Point endNode, double radiusStart, double radiusEnd) | 1238 | private void DrawAutoNodes(Point startNode, Point endNode, double radiusStart, double radiusEnd) |
1239 | { | 1239 | { |
1240 | double distance = DISTANCE_AUTO_NODES; | 1240 | double distance = DISTANCE_AUTO_NODES; |
1241 | double i; | 1241 | double i; |
1242 | 1242 | ||
1243 | Point node; | 1243 | Point node; |
1244 | 1244 | ||
1245 | // Get postion of blue node on line | 1245 | // Get postion of blue node on line |
1246 | if (startNode.X == endNode.X) | 1246 | if (startNode.X == endNode.X) |
1247 | { | 1247 | { |
1248 | if (startNode.Y > endNode.Y) | 1248 | if (startNode.Y > endNode.Y) |
1249 | { | 1249 | { |
1250 | i = startNode.Y - radiusStart; | 1250 | i = startNode.Y - radiusStart; |
1251 | if (i - distance > endNode.Y + radiusEnd) | 1251 | if (i - distance > endNode.Y + radiusEnd) |
1252 | { | 1252 | { |
1253 | do | 1253 | do |
1254 | { | 1254 | { |
1255 | i = i - distance; | 1255 | i = i - distance; |
1256 | node = new Point(endNode.X, i); | 1256 | node = new Point(endNode.X, i); |
1257 | // Add node to postion distance 1000mm | 1257 | // Add node to postion distance 1000mm |
1258 | AddNode(node, gGrpBlueNode); | 1258 | AddNode(node, gGrpBlueNode); |
1259 | 1259 | ||
1260 | } while (i > endNode.Y + radiusEnd + distance); | 1260 | } while (i > endNode.Y + radiusEnd + distance); |
1261 | } | 1261 | } |
1262 | } | 1262 | } |
1263 | else | 1263 | else |
1264 | { | 1264 | { |
1265 | i = startNode.Y + radiusStart; | 1265 | i = startNode.Y + radiusStart; |
1266 | if (i + distance < endNode.Y - radiusEnd) | 1266 | if (i + distance < endNode.Y - radiusEnd) |
1267 | { | 1267 | { |
1268 | do | 1268 | do |
1269 | { | 1269 | { |
1270 | i = i + distance; | 1270 | i = i + distance; |
1271 | node = new Point(endNode.X, i); | 1271 | node = new Point(endNode.X, i); |
1272 | // Add node to postion distance 1000mm | 1272 | // Add node to postion distance 1000mm |
1273 | AddNode(node, gGrpBlueNode); | 1273 | AddNode(node, gGrpBlueNode); |
1274 | } while (i < endNode.Y - radiusEnd - distance); | 1274 | } while (i < endNode.Y - radiusEnd - distance); |
1275 | } | 1275 | } |
1276 | } | 1276 | } |
1277 | } | 1277 | } |
1278 | else | 1278 | else |
1279 | { | 1279 | { |
1280 | if (startNode.X > endNode.X) | 1280 | if (startNode.X > endNode.X) |
1281 | { | 1281 | { |
1282 | i = startNode.X - radiusStart; | 1282 | i = startNode.X - radiusStart; |
1283 | if (i - distance > endNode.X + radiusEnd) | 1283 | if (i - distance > endNode.X + radiusEnd) |
1284 | { | 1284 | { |
1285 | do | 1285 | do |
1286 | { | 1286 | { |
1287 | i = i - distance; | 1287 | i = i - distance; |
1288 | node = new Point(i, endNode.Y); | 1288 | node = new Point(i, endNode.Y); |
1289 | // Add node to postion distance 1000mm | 1289 | // Add node to postion distance 1000mm |
1290 | AddNode(node, gGrpBlueNode); | 1290 | AddNode(node, gGrpBlueNode); |
1291 | } while (i > endNode.X + radiusEnd + distance); | 1291 | } while (i > endNode.X + radiusEnd + distance); |
1292 | } | 1292 | } |
1293 | } | 1293 | } |
1294 | else | 1294 | else |
1295 | { | 1295 | { |
1296 | i = startNode.X + radiusStart; | 1296 | i = startNode.X + radiusStart; |
1297 | if (i + distance < endNode.X - radiusEnd) | 1297 | if (i + distance < endNode.X - radiusEnd) |
1298 | { | 1298 | { |
1299 | do | 1299 | do |
1300 | { | 1300 | { |
1301 | i = i + distance; | 1301 | i = i + distance; |
1302 | node = new Point(i, endNode.Y); | 1302 | node = new Point(i, endNode.Y); |
1303 | // Add node to postion distance 1000mm | 1303 | // Add node to postion distance 1000mm |
1304 | AddNode(node, gGrpBlueNode); | 1304 | AddNode(node, gGrpBlueNode); |
1305 | } while (i < endNode.X - radiusEnd - distance); | 1305 | } while (i < endNode.X - radiusEnd - distance); |
1306 | } | 1306 | } |
1307 | } | 1307 | } |
1308 | } | 1308 | } |
1309 | 1309 | ||
1310 | } | 1310 | } |
1311 | 1311 | ||
1312 | #endregion | 1312 | #endregion |
1313 | 1313 | ||
1314 | #region Functions for Set Free Nodes | 1314 | #region Functions for Set Free Nodes |
1315 | /// <summary> | 1315 | /// <summary> |
1316 | /// Draw Auto Blue node | 1316 | /// Draw Auto Blue node |
1317 | /// </summary> | 1317 | /// </summary> |
1318 | 1318 | ||
1319 | public void SetFreeNodes(Point FreeNode, bool RightClick) | 1319 | public void SetFreeNodes(Point FreeNode, bool RightClick) |
1320 | { | 1320 | { |
1321 | double radiusStart = DISTANCE_START_NODES; | 1321 | double radiusStart = DISTANCE_START_NODES; |
1322 | double radiusEnd = DISTANCE_END_NODES; | 1322 | double radiusEnd = DISTANCE_END_NODES; |
1323 | double radiusNode = RADIUS_NODE; | 1323 | double radiusNode = RADIUS_NODE; |
1324 | double radiusCurver = RADIUS_CURVER_LINE + RADIUS_NODE; | 1324 | double radiusCurver = RADIUS_CURVER_LINE + RADIUS_NODE; |
1325 | 1325 | ||
1326 | EllipseGeometry ellipseGeometry; | 1326 | EllipseGeometry ellipseGeometry; |
1327 | Point node; | 1327 | Point node; |
1328 | bool deleteFlag = false; | 1328 | bool deleteFlag = false; |
1329 | 1329 | ||
1330 | 1330 | ||
1331 | if (RightClick) | 1331 | if (RightClick) |
1332 | { | 1332 | { |
1333 | if (gGrpBlueNode.Children.Count > 0) | 1333 | if (gGrpBlueNode.Children.Count > 0) |
1334 | { | 1334 | { |
1335 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 1335 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
1336 | { | 1336 | { |
1337 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 1337 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
1338 | node = ellipseGeometry.Center; | 1338 | node = ellipseGeometry.Center; |
1339 | if (FreeNode.X == node.X) | 1339 | if (FreeNode.X == node.X) |
1340 | { | 1340 | { |
1341 | if (CheckIsNode(FreeNode, node, radiusNode)) | 1341 | if (CheckIsNode(FreeNode, node, radiusNode)) |
1342 | { | 1342 | { |
1343 | deleteFlag = true; | 1343 | deleteFlag = true; |
1344 | } | 1344 | } |
1345 | } | 1345 | } |
1346 | else | 1346 | else |
1347 | { | 1347 | { |
1348 | if (CheckIsNode(FreeNode, node, radiusNode)) | 1348 | if (CheckIsNode(FreeNode, node, radiusNode)) |
1349 | { | 1349 | { |
1350 | deleteFlag = true; | 1350 | deleteFlag = true; |
1351 | } | 1351 | } |
1352 | } | 1352 | } |
1353 | if (deleteFlag) | 1353 | if (deleteFlag) |
1354 | { | 1354 | { |
1355 | MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); | 1355 | MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); |
1356 | if (result == MessageBoxResult.OK) | 1356 | if (result == MessageBoxResult.OK) |
1357 | { | 1357 | { |
1358 | gGrpBlueNode.Children.RemoveAt(i); | 1358 | gGrpBlueNode.Children.RemoveAt(i); |
1359 | 1359 | ||
1360 | this.Children.Remove(NodeNo[i]); | 1360 | this.Children.Remove(NodeNo[i]); |
1361 | return; | 1361 | return; |
1362 | } | 1362 | } |
1363 | else | 1363 | else |
1364 | { | 1364 | { |
1365 | return; | 1365 | return; |
1366 | } | 1366 | } |
1367 | } | 1367 | } |
1368 | } | 1368 | } |
1369 | } | 1369 | } |
1370 | } | 1370 | } |
1371 | else | 1371 | else |
1372 | { | 1372 | { |
1373 | 1373 | ||
1374 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 1374 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
1375 | { | 1375 | { |
1376 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 1376 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
1377 | node = ellipseGeometry.Center; | 1377 | node = ellipseGeometry.Center; |
1378 | bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE); | 1378 | bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE); |
1379 | 1379 | ||
1380 | if (isEditNode) | 1380 | if (isEditNode) |
1381 | { | 1381 | { |
1382 | EditNode(node); | 1382 | EditNode(node); |
1383 | return; | 1383 | return; |
1384 | } | 1384 | } |
1385 | } | 1385 | } |
1386 | 1386 | ||
1387 | 1387 | ||
1388 | MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel); | 1388 | MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel); |
1389 | if (result == MessageBoxResult.OK) | 1389 | if (result == MessageBoxResult.OK) |
1390 | { | 1390 | { |
1391 | AddNode(FreeNode, gGrpBlueNode); | 1391 | AddNode(FreeNode, gGrpBlueNode); |
1392 | 1392 | ||
1393 | TextBlock textBlock = new TextBlock(); | 1393 | TextBlock textBlock = new TextBlock(); |
1394 | textBlock.Text = stt.ToString(); | 1394 | textBlock.Text = stt.ToString(); |
1395 | textBlock.FontSize = 17; | 1395 | textBlock.FontSize = 17; |
1396 | textBlock.Foreground = new SolidColorBrush(Colors.Red); | 1396 | textBlock.Foreground = new SolidColorBrush(Colors.Red); |
1397 | Canvas.SetLeft(textBlock, FreeNode.X - RADIUS_NODE / 2); | 1397 | Canvas.SetLeft(textBlock, FreeNode.X - RADIUS_NODE / 2); |
1398 | Canvas.SetTop(textBlock, FreeNode.Y - 1.5 * RADIUS_NODE); | 1398 | Canvas.SetTop(textBlock, FreeNode.Y - 1.5 * RADIUS_NODE); |
1399 | 1399 | ||
1400 | this.Children.Add(textBlock); | 1400 | this.Children.Add(textBlock); |
1401 | NodeNo.Add(textBlock); | 1401 | NodeNo.Add(textBlock); |
1402 | 1402 | ||
1403 | if (stt > 1) | 1403 | if (stt > 1) |
1404 | { | 1404 | { |
1405 | int tmp = gGrpBlueNode.Children.Count; | 1405 | int tmp = gGrpBlueNode.Children.Count; |
1406 | 1406 | ||
1407 | EllipseGeometry elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2]; | 1407 | EllipseGeometry elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2]; |
1408 | Point node1 = elip.Center; | 1408 | Point node1 = elip.Center; |
1409 | elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1]; | 1409 | elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1]; |
1410 | Point node2 = elip.Center; | 1410 | Point node2 = elip.Center; |
1411 | DrawLine(node1, node2, gGrpCurverLine); | 1411 | DrawLine(node1, node2, gGrpCurverLine); |
1412 | } | 1412 | } |
1413 | 1413 | ||
1414 | 1414 | ||
1415 | stt++; | 1415 | stt++; |
1416 | } | 1416 | } |
1417 | } | 1417 | } |
1418 | 1418 | ||
1419 | if (gGrpLine.Children.Count > 0) | 1419 | if (gGrpLine.Children.Count > 0) |
1420 | { | 1420 | { |
1421 | for (int i = 0; i < gGrpLine.Children.Count; i++) | 1421 | for (int i = 0; i < gGrpLine.Children.Count; i++) |
1422 | { | 1422 | { |
1423 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i]; | 1423 | LineGeometry lineGeometry = (LineGeometry)gGrpLine.Children[i]; |
1424 | 1424 | ||
1425 | // Get postion of node on line | 1425 | // Get postion of node on line |
1426 | if (IsVerticalLine(lineGeometry)) | 1426 | if (IsVerticalLine(lineGeometry)) |
1427 | { | 1427 | { |
1428 | if (FreeNode.X < lineGeometry.EndPoint.X + radiusNode && FreeNode.X > lineGeometry.EndPoint.X - radiusNode) | 1428 | if (FreeNode.X < lineGeometry.EndPoint.X + radiusNode && FreeNode.X > lineGeometry.EndPoint.X - radiusNode) |
1429 | { | 1429 | { |
1430 | FreeNode.X = lineGeometry.EndPoint.X; | 1430 | FreeNode.X = lineGeometry.EndPoint.X; |
1431 | 1431 | ||
1432 | if (i == 0) | 1432 | if (i == 0) |
1433 | { | 1433 | { |
1434 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver)) | 1434 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver)) |
1435 | { | 1435 | { |
1436 | 1436 | ||
1437 | AddNode(FreeNode, gGrpBlueNode); | 1437 | AddNode(FreeNode, gGrpBlueNode); |
1438 | } | 1438 | } |
1439 | } | 1439 | } |
1440 | else if (i == gGrpLine.Children.Count - 1 && i > 0) | 1440 | else if (i == gGrpLine.Children.Count - 1 && i > 0) |
1441 | { | 1441 | { |
1442 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd)) | 1442 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd)) |
1443 | { | 1443 | { |
1444 | 1444 | ||
1445 | AddNode(FreeNode, gGrpBlueNode); | 1445 | AddNode(FreeNode, gGrpBlueNode); |
1446 | } | 1446 | } |
1447 | } | 1447 | } |
1448 | else | 1448 | else |
1449 | { | 1449 | { |
1450 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver)) | 1450 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver)) |
1451 | { | 1451 | { |
1452 | 1452 | ||
1453 | AddNode(FreeNode, gGrpBlueNode); | 1453 | AddNode(FreeNode, gGrpBlueNode); |
1454 | } | 1454 | } |
1455 | } | 1455 | } |
1456 | 1456 | ||
1457 | } | 1457 | } |
1458 | } | 1458 | } |
1459 | else | 1459 | else |
1460 | { | 1460 | { |
1461 | if (FreeNode.Y < lineGeometry.EndPoint.Y + radiusNode && FreeNode.Y > lineGeometry.EndPoint.Y - radiusNode) | 1461 | if (FreeNode.Y < lineGeometry.EndPoint.Y + radiusNode && FreeNode.Y > lineGeometry.EndPoint.Y - radiusNode) |
1462 | { | 1462 | { |
1463 | FreeNode.Y = lineGeometry.EndPoint.Y; | 1463 | FreeNode.Y = lineGeometry.EndPoint.Y; |
1464 | if (i == 0) | 1464 | if (i == 0) |
1465 | { | 1465 | { |
1466 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver)) | 1466 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusStart, radiusCurver)) |
1467 | { | 1467 | { |
1468 | 1468 | ||
1469 | AddNode(FreeNode, gGrpBlueNode); | 1469 | AddNode(FreeNode, gGrpBlueNode); |
1470 | } | 1470 | } |
1471 | } | 1471 | } |
1472 | else if (i == gGrpLine.Children.Count - 1 && i > 0) | 1472 | else if (i == gGrpLine.Children.Count - 1 && i > 0) |
1473 | { | 1473 | { |
1474 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd)) | 1474 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusEnd)) |
1475 | { | 1475 | { |
1476 | 1476 | ||
1477 | AddNode(FreeNode, gGrpBlueNode); | 1477 | AddNode(FreeNode, gGrpBlueNode); |
1478 | } | 1478 | } |
1479 | } | 1479 | } |
1480 | else | 1480 | else |
1481 | { | 1481 | { |
1482 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver)) | 1482 | if (CheckFreeNodes(lineGeometry, FreeNode, radiusCurver, radiusCurver)) |
1483 | { | 1483 | { |
1484 | 1484 | ||
1485 | AddNode(FreeNode, gGrpBlueNode); | 1485 | AddNode(FreeNode, gGrpBlueNode); |
1486 | } | 1486 | } |
1487 | } | 1487 | } |
1488 | 1488 | ||
1489 | } | 1489 | } |
1490 | } | 1490 | } |
1491 | } | 1491 | } |
1492 | } | 1492 | } |
1493 | } | 1493 | } |
1494 | 1494 | ||
1495 | 1495 | ||
1496 | public bool CheckFreeNodes(LineGeometry lineNode, Point Freenode, double radiusStart, double radiusEnd) | 1496 | public bool CheckFreeNodes(LineGeometry lineNode, Point Freenode, double radiusStart, double radiusEnd) |
1497 | { | 1497 | { |
1498 | 1498 | ||
1499 | double distanceFreeNode = DISTANCE_FREE_NODES; | 1499 | double distanceFreeNode = DISTANCE_FREE_NODES; |
1500 | double radiusNode = RADIUS_NODE; | 1500 | double radiusNode = RADIUS_NODE; |
1501 | EllipseGeometry ellipseGeometry; | 1501 | EllipseGeometry ellipseGeometry; |
1502 | Point node; | 1502 | Point node; |
1503 | 1503 | ||
1504 | if (IsVerticalLine(lineNode)) | 1504 | if (IsVerticalLine(lineNode)) |
1505 | { | 1505 | { |
1506 | if (lineNode.StartPoint.Y < lineNode.EndPoint.Y) | 1506 | if (lineNode.StartPoint.Y < lineNode.EndPoint.Y) |
1507 | { | 1507 | { |
1508 | if (Freenode.Y < lineNode.StartPoint.Y + radiusStart || Freenode.Y > lineNode.EndPoint.Y - radiusEnd) | 1508 | if (Freenode.Y < lineNode.StartPoint.Y + radiusStart || Freenode.Y > lineNode.EndPoint.Y - radiusEnd) |
1509 | { | 1509 | { |
1510 | return false; | 1510 | return false; |
1511 | } | 1511 | } |
1512 | } | 1512 | } |
1513 | else | 1513 | else |
1514 | { | 1514 | { |
1515 | if (Freenode.Y > lineNode.StartPoint.Y - radiusStart || Freenode.Y < lineNode.EndPoint.Y + radiusEnd) | 1515 | if (Freenode.Y > lineNode.StartPoint.Y - radiusStart || Freenode.Y < lineNode.EndPoint.Y + radiusEnd) |
1516 | { | 1516 | { |
1517 | return false; | 1517 | return false; |
1518 | } | 1518 | } |
1519 | } | 1519 | } |
1520 | } | 1520 | } |
1521 | else | 1521 | else |
1522 | { | 1522 | { |
1523 | if (lineNode.StartPoint.X < lineNode.EndPoint.X) | 1523 | if (lineNode.StartPoint.X < lineNode.EndPoint.X) |
1524 | { | 1524 | { |
1525 | if (Freenode.X < lineNode.StartPoint.X + radiusStart || Freenode.X > lineNode.EndPoint.X - radiusEnd) | 1525 | if (Freenode.X < lineNode.StartPoint.X + radiusStart || Freenode.X > lineNode.EndPoint.X - radiusEnd) |
1526 | { | 1526 | { |
1527 | return false; | 1527 | return false; |
1528 | } | 1528 | } |
1529 | } | 1529 | } |
1530 | else | 1530 | else |
1531 | { | 1531 | { |
1532 | if (Freenode.X > lineNode.StartPoint.X - radiusStart || Freenode.X < lineNode.EndPoint.X + radiusEnd) | 1532 | if (Freenode.X > lineNode.StartPoint.X - radiusStart || Freenode.X < lineNode.EndPoint.X + radiusEnd) |
1533 | { | 1533 | { |
1534 | return false; | 1534 | return false; |
1535 | } | 1535 | } |
1536 | } | 1536 | } |
1537 | } | 1537 | } |
1538 | 1538 | ||
1539 | if (gGrpBlueNode.Children.Count > 0) | 1539 | if (gGrpBlueNode.Children.Count > 0) |
1540 | { | 1540 | { |
1541 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 1541 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
1542 | { | 1542 | { |
1543 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 1543 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
1544 | node = ellipseGeometry.Center; | 1544 | node = ellipseGeometry.Center; |
1545 | if (Freenode.X == node.X) | 1545 | if (Freenode.X == node.X) |
1546 | { | 1546 | { |
1547 | if (CheckIsNode(Freenode, node, radiusNode)) | 1547 | if (CheckIsNode(Freenode, node, radiusNode)) |
1548 | { | 1548 | { |
1549 | return false; | 1549 | return false; |
1550 | } | 1550 | } |
1551 | else if (Freenode.Y < node.Y + distanceFreeNode && Freenode.Y > node.Y - distanceFreeNode) | 1551 | else if (Freenode.Y < node.Y + distanceFreeNode && Freenode.Y > node.Y - distanceFreeNode) |
1552 | { | 1552 | { |
1553 | return false; | 1553 | return false; |
1554 | } | 1554 | } |
1555 | } | 1555 | } |
1556 | else if (Freenode.Y == node.Y) | 1556 | else if (Freenode.Y == node.Y) |
1557 | { | 1557 | { |
1558 | if (CheckIsNode(Freenode, node, radiusNode)) | 1558 | if (CheckIsNode(Freenode, node, radiusNode)) |
1559 | { | 1559 | { |
1560 | return false; | 1560 | return false; |
1561 | } | 1561 | } |
1562 | else if (Freenode.X < node.X + distanceFreeNode && Freenode.X > node.X - distanceFreeNode) | 1562 | else if (Freenode.X < node.X + distanceFreeNode && Freenode.X > node.X - distanceFreeNode) |
1563 | { | 1563 | { |
1564 | return false; | 1564 | return false; |
1565 | } | 1565 | } |
1566 | } | 1566 | } |
1567 | } | 1567 | } |
1568 | } | 1568 | } |
1569 | 1569 | ||
1570 | return true; | 1570 | return true; |
1571 | } | 1571 | } |
1572 | 1572 | ||
1573 | public bool CheckIsNode(Point FreeNode, Point Node, double radiusNode) | 1573 | public bool CheckIsNode(Point FreeNode, Point Node, double radiusNode) |
1574 | { | 1574 | { |
1575 | if (FreeNode.X < Node.X + radiusNode && FreeNode.X > Node.X - radiusNode && FreeNode.Y < Node.Y + radiusNode && FreeNode.Y > Node.Y - radiusNode) | 1575 | if (FreeNode.X < Node.X + radiusNode && FreeNode.X > Node.X - radiusNode && FreeNode.Y < Node.Y + radiusNode && FreeNode.Y > Node.Y - radiusNode) |
1576 | { | 1576 | { |
1577 | return true; | 1577 | return true; |
1578 | } | 1578 | } |
1579 | return false; | 1579 | return false; |
1580 | } | 1580 | } |
1581 | 1581 | ||
1582 | #endregion | 1582 | #endregion |
1583 | 1583 | ||
1584 | #region Edit Node | 1584 | #region Edit Node |
1585 | public void InitNodeInfo_List() | 1585 | public void InitNodeInfo_List() |
1586 | { | 1586 | { |
1587 | //Reset List | 1587 | //Reset List |
1588 | NodeInfo_List = new List<NodeInfo>(); | 1588 | NodeInfo_List = new List<NodeInfo>(); |
1589 | 1589 | ||
1590 | if (gGrpBlueNode.Children.Count > 0) | 1590 | if (gGrpBlueNode.Children.Count > 0) |
1591 | { | 1591 | { |
1592 | // Get start point | 1592 | // Get start point |
1593 | LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[0]; | 1593 | LineGeometry lineGeometry = (LineGeometry)gGrpNewLine.Children[0]; |
1594 | Point startPoint = lineGeometry.StartPoint; | 1594 | Point startPoint = lineGeometry.StartPoint; |
1595 | 1595 | ||
1596 | NodeInfo n1 = new NodeInfo(); | 1596 | NodeInfo n1 = new NodeInfo(); |
1597 | n1.X = startPoint.X; | 1597 | n1.X = startPoint.X; |
1598 | n1.Y = startPoint.Y; | 1598 | n1.Y = startPoint.Y; |
1599 | n1.Mode1 = ""; | 1599 | n1.Mode1 = ""; |
1600 | n1.Mode2 = ""; | 1600 | n1.Mode2 = ""; |
1601 | n1.Mode3 = ""; | 1601 | n1.Mode3 = ""; |
1602 | NodeInfo_List.Add(n1); | 1602 | NodeInfo_List.Add(n1); |
1603 | 1603 | ||
1604 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 1604 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
1605 | { | 1605 | { |
1606 | Point point; | 1606 | Point point; |
1607 | EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 1607 | EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
1608 | point = eGeometry.Center; | 1608 | point = eGeometry.Center; |
1609 | 1609 | ||
1610 | NodeInfo Ninfo = new NodeInfo(); | 1610 | NodeInfo Ninfo = new NodeInfo(); |
1611 | Ninfo.X = point.X; | 1611 | Ninfo.X = point.X; |
1612 | Ninfo.Y = point.Y; | 1612 | Ninfo.Y = point.Y; |
1613 | 1613 | ||
1614 | Ninfo.Mode1 = ""; | 1614 | Ninfo.Mode1 = ""; |
1615 | Ninfo.Mode2 = ""; | 1615 | Ninfo.Mode2 = ""; |
1616 | Ninfo.Mode3 = ""; | 1616 | Ninfo.Mode3 = ""; |
1617 | 1617 | ||
1618 | NodeInfo_List.Add(Ninfo); | 1618 | NodeInfo_List.Add(Ninfo); |
1619 | } | 1619 | } |
1620 | 1620 | ||
1621 | // Get end point | 1621 | // Get end point |
1622 | lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count -1]; | 1622 | lineGeometry = (LineGeometry)gGrpLine.Children[gGrpLine.Children.Count -1]; |
1623 | Point endPoint = lineGeometry.EndPoint; | 1623 | Point endPoint = lineGeometry.EndPoint; |
1624 | 1624 | ||
1625 | NodeInfo n2 = new NodeInfo(); | 1625 | NodeInfo n2 = new NodeInfo(); |
1626 | n2.X = startPoint.X; | 1626 | n2.X = startPoint.X; |
1627 | n2.Y = startPoint.Y; | 1627 | n2.Y = startPoint.Y; |
1628 | n2.Mode1 = ""; | 1628 | n2.Mode1 = ""; |
1629 | n2.Mode2 = ""; | 1629 | n2.Mode2 = ""; |
1630 | n2.Mode3 = ""; | 1630 | n2.Mode3 = ""; |
1631 | NodeInfo_List.Add(n2); | 1631 | NodeInfo_List.Add(n2); |
1632 | 1632 | ||
1633 | //Resort NodeInfo_List From Start to Goal | 1633 | //Resort NodeInfo_List From Start to Goal |
1634 | LineGeometry firstLine = (LineGeometry)gGrpLine.Children[0]; | 1634 | LineGeometry firstLine = (LineGeometry)gGrpLine.Children[0]; |
1635 | Point startNode = firstLine.StartPoint; | 1635 | Point startNode = firstLine.StartPoint; |
1636 | Point endNode = firstLine.EndPoint; | 1636 | Point endNode = firstLine.EndPoint; |
1637 | 1637 | ||
1638 | 1638 | ||
1639 | List<NodeInfo> tmpLst = new List<NodeInfo>(); | 1639 | List<NodeInfo> tmpLst = new List<NodeInfo>(); |
1640 | 1640 | ||
1641 | // Create temp List | 1641 | // Create temp List |
1642 | if(startNode.X == endNode.X) | 1642 | if(startNode.X == endNode.X) |
1643 | { | 1643 | { |
1644 | for (int i = 1; i < NodeInfo_List.Count; i++) | 1644 | for (int i = 1; i < NodeInfo_List.Count; i++) |
1645 | { | 1645 | { |
1646 | if (NodeInfo_List[i].X != endNode.X) | 1646 | if (NodeInfo_List[i].X != endNode.X) |
1647 | { | 1647 | { |
1648 | break; | 1648 | break; |
1649 | } | 1649 | } |
1650 | else | 1650 | else |
1651 | { | 1651 | { |
1652 | tmpLst.Add(NodeInfo_List[i]); | 1652 | tmpLst.Add(NodeInfo_List[i]); |
1653 | } | 1653 | } |
1654 | } | 1654 | } |
1655 | } | 1655 | } |
1656 | 1656 | ||
1657 | if (startNode.Y == endNode.Y) | 1657 | if (startNode.Y == endNode.Y) |
1658 | { | 1658 | { |
1659 | for (int i = 1; i < NodeInfo_List.Count; i++) | 1659 | for (int i = 1; i < NodeInfo_List.Count; i++) |
1660 | { | 1660 | { |
1661 | if (NodeInfo_List[i].Y != endNode.Y) | 1661 | if (NodeInfo_List[i].Y != endNode.Y) |
1662 | { | 1662 | { |
1663 | break; | 1663 | break; |
1664 | } | 1664 | } |
1665 | else | 1665 | else |
1666 | { | 1666 | { |
1667 | tmpLst.Add(NodeInfo_List[i]); | 1667 | tmpLst.Add(NodeInfo_List[i]); |
1668 | } | 1668 | } |
1669 | } | 1669 | } |
1670 | } | 1670 | } |
1671 | 1671 | ||
1672 | // Sort NodeInfo_List | 1672 | // Sort NodeInfo_List |
1673 | for (int i = 0; i < tmpLst.Count; i++) | 1673 | for (int i = 0; i < tmpLst.Count; i++) |
1674 | { | 1674 | { |
1675 | NodeInfo_List[i + 1] = tmpLst[tmpLst.Count -1 - i]; | 1675 | NodeInfo_List[i + 1] = tmpLst[tmpLst.Count -1 - i]; |
1676 | } | 1676 | } |
1677 | 1677 | ||
1678 | } | 1678 | } |
1679 | } | 1679 | } |
1680 | 1680 | ||
1681 | 1681 | ||
1682 | public void EditNode(Point node_edited) | 1682 | public void EditNode(Point node_edited) |
1683 | { | 1683 | { |
1684 | EllipseGeometry ellipseGeometry; | 1684 | EllipseGeometry ellipseGeometry; |
1685 | Point node; | 1685 | Point node; |
1686 | double radiusNode = RADIUS_NODE; | 1686 | double radiusNode = RADIUS_NODE; |
1687 | 1687 | ||
1688 | bool flag = false; | 1688 | bool flag = false; |
1689 | 1689 | ||
1690 | if (gGrpBlueNode.Children.Count > 0) | 1690 | if (gGrpBlueNode.Children.Count > 0) |
1691 | { | 1691 | { |
1692 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 1692 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
1693 | { | 1693 | { |
1694 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 1694 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
1695 | node = ellipseGeometry.Center; | 1695 | node = ellipseGeometry.Center; |
1696 | 1696 | ||
1697 | if (CheckIsNode(node_edited, node, radiusNode)) | 1697 | if (CheckIsNode(node_edited, node, radiusNode)) |
1698 | { | 1698 | { |
1699 | flag = true; | 1699 | flag = true; |
1700 | } | 1700 | } |
1701 | 1701 | ||
1702 | if (flag) | 1702 | if (flag) |
1703 | { | 1703 | { |
1704 | node_edited.X = node.X; | 1704 | node_edited.X = node.X; |
1705 | node_edited.Y = node.Y; | 1705 | node_edited.Y = node.Y; |
1706 | 1706 | ||
1707 | // show form edit node | 1707 | // show form edit node |
1708 | EditNodeWindow edtNodeWindow = new EditNodeWindow(); | 1708 | EditNodeWindow edtNodeWindow = new EditNodeWindow(); |
1709 | edtNodeWindow.ShowDialog(); | 1709 | edtNodeWindow.ShowDialog(); |
1710 | 1710 | ||
1711 | string result1 = edtNodeWindow._txtMode1; | 1711 | string result1 = edtNodeWindow._txtMode1; |
1712 | string result2 = edtNodeWindow._txtMode2; | 1712 | string result2 = edtNodeWindow._txtMode2; |
1713 | string result3 = edtNodeWindow._txtMode3; | 1713 | string result3 = edtNodeWindow._txtMode3; |
1714 | bool exit = edtNodeWindow._ExitFlg; | 1714 | bool exit = edtNodeWindow._ExitFlg; |
1715 | 1715 | ||
1716 | if (!exit) { | 1716 | if (!exit) { |
1717 | SaveChanged(node_edited.X, node_edited.Y, result1, result2, result3); | 1717 | SaveChanged(node_edited.X, node_edited.Y, result1, result2, result3); |
1718 | } | 1718 | } |
1719 | 1719 | ||
1720 | return; | 1720 | return; |
1721 | } | 1721 | } |
1722 | } | 1722 | } |
1723 | } | 1723 | } |
1724 | } | 1724 | } |
1725 | 1725 | ||
1726 | public void SaveChanged(double x, double y, string st1, string st2, string st3) | 1726 | public void SaveChanged(double x, double y, string st1, string st2, string st3) |
1727 | { | 1727 | { |
1728 | for (int i = 0; i < NodeInfo_List.Count; i++) | 1728 | for (int i = 0; i < NodeInfo_List.Count; i++) |
1729 | { | 1729 | { |
1730 | NodeInfo ni = new NodeInfo(); | 1730 | NodeInfo ni = new NodeInfo(); |
1731 | ni = NodeInfo_List[i]; | 1731 | ni = NodeInfo_List[i]; |
1732 | 1732 | ||
1733 | if (ni.X == x && ni.Y == y) | 1733 | if (ni.X == x && ni.Y == y) |
1734 | { | 1734 | { |
1735 | 1735 | ||
1736 | ni.Mode1 = st1; | 1736 | ni.Mode1 = st1; |
1737 | ni.Mode2 = st2; | 1737 | ni.Mode2 = st2; |
1738 | ni.Mode3 = st3; | 1738 | ni.Mode3 = st3; |
1739 | 1739 | ||
1740 | NodeInfo_List[i] = ni; | 1740 | NodeInfo_List[i] = ni; |
1741 | return; | 1741 | return; |
1742 | } | 1742 | } |
1743 | } | 1743 | } |
1744 | } | 1744 | } |
1745 | 1745 | ||
1746 | 1746 | ||
1747 | #endregion | 1747 | #endregion |
1748 | 1748 | ||
1749 | #region Display RouteInfo | 1749 | #region Display RouteInfo |
1750 | 1750 | ||
1751 | public void DspRouteInfo() | 1751 | public void DspRouteInfo() |
1752 | { | 1752 | { |
1753 | //Clear Route Info Table | 1753 | //Clear Route Info Table |
1754 | ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear(); | 1754 | ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear(); |
1755 | 1755 | ||
1756 | if (NodeInfo_List.Count != 0) | 1756 | if (NodeInfo_List.Count != 0) |
1757 | { | 1757 | { |
1758 | int _RowIdx = 0; | 1758 | int _RowIdx = 0; |
1759 | string _Content = ""; | 1759 | string _Content = ""; |
1760 | 1760 | ||
1761 | for (int i = 0; i < NodeInfo_List.Count; i++) | 1761 | for (int i = 0; i < NodeInfo_List.Count; i++) |
1762 | { | 1762 | { |
1763 | 1763 | ||
1764 | NodeInfo ni = new NodeInfo(); | 1764 | NodeInfo ni = new NodeInfo(); |
1765 | ni = NodeInfo_List[i]; | 1765 | ni = NodeInfo_List[i]; |
1766 | 1766 | ||
1767 | //column 1 | 1767 | //column 1 |
1768 | if (i == 0) | 1768 | if (i == 0) |
1769 | { | 1769 | { |
1770 | _Content = "S"; | 1770 | _Content = "S"; |
1771 | } | 1771 | } |
1772 | else if (i == NodeInfo_List.Count - 1) | 1772 | else if (i == NodeInfo_List.Count - 1) |
1773 | { | 1773 | { |
1774 | _Content = "G"; | 1774 | _Content = "G"; |
1775 | } | 1775 | } |
1776 | else | 1776 | else |
1777 | { | 1777 | { |
1778 | _Content = i.ToString(); | 1778 | _Content = i.ToString(); |
1779 | } | 1779 | } |
1780 | AddLabeltoGrid(_RowIdx, 0, _Content); | 1780 | AddLabeltoGrid(_RowIdx, 0, _Content); |
1781 | 1781 | ||
1782 | //column 2 | 1782 | //column 2 |
1783 | // Display Node's Position | 1783 | // Display Node's Position |
1784 | _Content = ni.X + ", " + ni.Y; | 1784 | _Content = ni.X + ", " + ni.Y; |
1785 | AddLabeltoGrid(_RowIdx, 1, _Content); | 1785 | AddLabeltoGrid(_RowIdx, 1, _Content); |
1786 | 1786 | ||
1787 | // Display Node's Field | 1787 | // Display Node's Field |
1788 | if (ni.Mode1 != "" && ni.Mode1 != null) | 1788 | if (ni.Mode1 != "" && ni.Mode1 != null) |
1789 | { | 1789 | { |
1790 | char delimiterChars = '_'; | 1790 | char delimiterChars = '_'; |
1791 | string[] tmp = ni.Mode1.Split(delimiterChars); | 1791 | string[] tmp = ni.Mode1.Split(delimiterChars); |
1792 | foreach (string s in tmp) | 1792 | foreach (string s in tmp) |
1793 | { | 1793 | { |
1794 | _RowIdx++; | 1794 | _RowIdx++; |
1795 | delimiterChars = ':'; | 1795 | delimiterChars = ':'; |
1796 | 1796 | ||
1797 | if (s.Split(delimiterChars)[0] == "Mode") | 1797 | if (s.Split(delimiterChars)[0] == "Mode") |
1798 | { | 1798 | { |
1799 | double distance = 0; | 1799 | double distance = 0; |
1800 | if (i == NodeInfo_List.Count - 1) | 1800 | if (i == NodeInfo_List.Count - 1) |
1801 | { | 1801 | { |
1802 | distance = 0; | 1802 | distance = 0; |
1803 | } | 1803 | } |
1804 | else | 1804 | else |
1805 | { | 1805 | { |
1806 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); | 1806 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); |
1807 | } | 1807 | } |
1808 | _Content = "MOVE " + distance.ToString() + "mm"; | 1808 | _Content = "MOVE " + distance.ToString() + "mm"; |
1809 | } | 1809 | } |
1810 | else | 1810 | else |
1811 | { | 1811 | { |
1812 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; | 1812 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; |
1813 | } | 1813 | } |
1814 | 1814 | ||
1815 | AddLabeltoGrid(_RowIdx, 1, _Content); | 1815 | AddLabeltoGrid(_RowIdx, 1, _Content); |
1816 | } | 1816 | } |
1817 | } | 1817 | } |
1818 | 1818 | ||
1819 | if (ni.Mode2 != "" && ni.Mode2 != null) | 1819 | if (ni.Mode2 != "" && ni.Mode2 != null) |
1820 | { | 1820 | { |
1821 | char delimiterChars = '_'; | 1821 | char delimiterChars = '_'; |
1822 | string[] tmp = ni.Mode2.Split(delimiterChars); | 1822 | string[] tmp = ni.Mode2.Split(delimiterChars); |
1823 | foreach (string s in tmp) | 1823 | foreach (string s in tmp) |
1824 | { | 1824 | { |
1825 | _RowIdx++; | 1825 | _RowIdx++; |
1826 | delimiterChars = ':'; | 1826 | delimiterChars = ':'; |
1827 | 1827 | ||
1828 | if (s.Split(delimiterChars)[0] == "Mode") | 1828 | if (s.Split(delimiterChars)[0] == "Mode") |
1829 | { | 1829 | { |
1830 | double distance = 0; | 1830 | double distance = 0; |
1831 | if (i == NodeInfo_List.Count - 1) | 1831 | if (i == NodeInfo_List.Count - 1) |
1832 | { | 1832 | { |
1833 | distance = 0; | 1833 | distance = 0; |
1834 | } | 1834 | } |
1835 | else | 1835 | else |
1836 | { | 1836 | { |
1837 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); | 1837 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); |
1838 | } | 1838 | } |
1839 | _Content = "MOVE " + distance.ToString() + "mm"; | 1839 | _Content = "MOVE " + distance.ToString() + "mm"; |
1840 | } | 1840 | } |
1841 | else | 1841 | else |
1842 | { | 1842 | { |
1843 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; | 1843 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; |
1844 | } | 1844 | } |
1845 | 1845 | ||
1846 | AddLabeltoGrid(_RowIdx, 1, _Content); | 1846 | AddLabeltoGrid(_RowIdx, 1, _Content); |
1847 | } | 1847 | } |
1848 | } | 1848 | } |
1849 | 1849 | ||
1850 | if (ni.Mode3 != "" && ni.Mode3 != null) | 1850 | if (ni.Mode3 != "" && ni.Mode3 != null) |
1851 | { | 1851 | { |
1852 | char delimiterChars = '_'; | 1852 | char delimiterChars = '_'; |
1853 | string[] tmp = ni.Mode3.Split(delimiterChars); | 1853 | string[] tmp = ni.Mode3.Split(delimiterChars); |
1854 | foreach (string s in tmp) | 1854 | foreach (string s in tmp) |
1855 | { | 1855 | { |
1856 | _RowIdx++; | 1856 | _RowIdx++; |
1857 | delimiterChars = ':'; | 1857 | delimiterChars = ':'; |
1858 | 1858 | ||
1859 | if (s.Split(delimiterChars)[0] == "Mode") | 1859 | if (s.Split(delimiterChars)[0] == "Mode") |
1860 | { | 1860 | { |
1861 | double distance = 0; | 1861 | double distance = 0; |
1862 | if (i == NodeInfo_List.Count - 1) | 1862 | if (i == NodeInfo_List.Count - 1) |
1863 | { | 1863 | { |
1864 | distance = 0; | 1864 | distance = 0; |
1865 | } | 1865 | } |
1866 | else | 1866 | else |
1867 | { | 1867 | { |
1868 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); | 1868 | distance = DistanceCalculate(NodeInfo_List[i].X, NodeInfo_List[i].Y, NodeInfo_List[i + 1].X, NodeInfo_List[i + 1].Y); |
1869 | } | 1869 | } |
1870 | _Content = "MOVE " + distance.ToString() + "mm"; | 1870 | _Content = "MOVE " + distance.ToString() + "mm"; |
1871 | } | 1871 | } |
1872 | else | 1872 | else |
1873 | { | 1873 | { |
1874 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; | 1874 | _Content = s.Split(delimiterChars)[0] + " " + s.Split(delimiterChars)[1]; |
1875 | } | 1875 | } |
1876 | 1876 | ||
1877 | AddLabeltoGrid(_RowIdx, 1, _Content); | 1877 | AddLabeltoGrid(_RowIdx, 1, _Content); |
1878 | } | 1878 | } |
1879 | } | 1879 | } |
1880 | _RowIdx++; | 1880 | _RowIdx++; |
1881 | } | 1881 | } |
1882 | } | 1882 | } |
1883 | } | 1883 | } |
1884 | 1884 | ||
1885 | public double DistanceCalculate(double _X1, double _Y1, double _X2, double _Y2) | 1885 | public double DistanceCalculate(double _X1, double _Y1, double _X2, double _Y2) |
1886 | { | 1886 | { |
1887 | double dist = 0; | 1887 | double dist = 0; |
1888 | 1888 | ||
1889 | if (_X1 == _X2) | 1889 | if (_X1 == _X2) |
1890 | { | 1890 | { |
1891 | dist = System.Math.Abs(_Y1 - _Y2) * DISTANCE_RATIO; | 1891 | dist = System.Math.Abs(_Y1 - _Y2) * DISTANCE_RATIO; |
1892 | } | 1892 | } |
1893 | else if (_Y1 == _Y2) | 1893 | else if (_Y1 == _Y2) |
1894 | { | 1894 | { |
1895 | dist = System.Math.Abs(_X1 - _X2) * DISTANCE_RATIO; | 1895 | dist = System.Math.Abs(_X1 - _X2) * DISTANCE_RATIO; |
1896 | } | 1896 | } |
1897 | return dist; | 1897 | return dist; |
1898 | } | 1898 | } |
1899 | 1899 | ||
1900 | public void AddLabeltoGrid(int RowIdx, int ColIdx, string Content) | 1900 | public void AddLabeltoGrid(int RowIdx, int ColIdx, string Content) |
1901 | { | 1901 | { |
1902 | //Add Row to Grid | 1902 | //Add Row to Grid |
1903 | RowDefinition _rd = new RowDefinition(); | 1903 | RowDefinition _rd = new RowDefinition(); |
1904 | ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.RowDefinitions.Add(_rd); | 1904 | ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.RowDefinitions.Add(_rd); |
1905 | 1905 | ||
1906 | // Add data to Grid | 1906 | // Add data to Grid |
1907 | Label dynamicLabel = new Label(); | 1907 | Label dynamicLabel = new Label(); |
1908 | 1908 | ||
1909 | dynamicLabel.Content = Content; | 1909 | dynamicLabel.Content = Content; |
1910 | dynamicLabel.Margin = new Thickness(0, 0, 0, 0); | 1910 | dynamicLabel.Margin = new Thickness(0, 0, 0, 0); |
1911 | dynamicLabel.Foreground = new SolidColorBrush(Colors.Black); | 1911 | dynamicLabel.Foreground = new SolidColorBrush(Colors.Black); |
1912 | dynamicLabel.Background = new SolidColorBrush(Colors.White); | 1912 | dynamicLabel.Background = new SolidColorBrush(Colors.White); |
1913 | dynamicLabel.BorderBrush = new SolidColorBrush(Colors.LightGray); | 1913 | dynamicLabel.BorderBrush = new SolidColorBrush(Colors.LightGray); |
1914 | dynamicLabel.BorderThickness = new Thickness(1); | 1914 | dynamicLabel.BorderThickness = new Thickness(1); |
1915 | 1915 | ||
1916 | Grid.SetRow(dynamicLabel, RowIdx); | 1916 | Grid.SetRow(dynamicLabel, RowIdx); |
1917 | Grid.SetColumn(dynamicLabel, ColIdx); | 1917 | Grid.SetColumn(dynamicLabel, ColIdx); |
1918 | ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Add(dynamicLabel); | 1918 | ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Add(dynamicLabel); |
1919 | } | 1919 | } |
1920 | #endregion | 1920 | #endregion |
1921 | 1921 | ||
1922 | 1922 | ||
1923 | public void CreateGoalPoint() | 1923 | public void CreateGoalPoint() |
1924 | { | 1924 | { |
1925 | if (isGoalDrawRoute) | 1925 | if (isGoalDrawRoute) |
1926 | { | 1926 | { |
1927 | return; | 1927 | return; |
1928 | } | 1928 | } |
1929 | 1929 | ||
1930 | isStartDrawRoute = false; | 1930 | isStartDrawRoute = false; |
1931 | if (_goalPoint == null) | 1931 | if (_goalPoint == null) |
1932 | { | 1932 | { |
1933 | _goalPoint = new ucStartEndButton(); | 1933 | _goalPoint = new ucStartEndButton(); |
1934 | _goalPoint.btnWidth = 50.0; | 1934 | _goalPoint.btnWidth = 50.0; |
1935 | _goalPoint.btnHeight = 50.0; | 1935 | _goalPoint.btnHeight = 50.0; |
1936 | _goalPoint.buttText = "G"; | 1936 | _goalPoint.buttText = "G"; |
1937 | Canvas.SetLeft(_goalPoint, 675); | 1937 | Canvas.SetLeft(_goalPoint, 675); |
1938 | Canvas.SetTop(_goalPoint, 75); | 1938 | Canvas.SetTop(_goalPoint, 75); |
1939 | this.Children.Add(_goalPoint); | 1939 | this.Children.Add(_goalPoint); |
1940 | } | 1940 | } |
1941 | } | 1941 | } |
1942 | 1942 | ||
1943 | public void CreateStartPoint() | 1943 | public void CreateStartPoint() |
1944 | { | 1944 | { |
1945 | if (isGoalDrawRoute) | 1945 | if (isGoalDrawRoute) |
1946 | { | 1946 | { |
1947 | return; | 1947 | return; |
1948 | } | 1948 | } |
1949 | 1949 | ||
1950 | isStartDrawRoute = false; | 1950 | isStartDrawRoute = false; |
1951 | if (_startPoint == null) | 1951 | if (_startPoint == null) |
1952 | { | 1952 | { |
1953 | _startPoint = new ucStartEndButton(); | 1953 | _startPoint = new ucStartEndButton(); |
1954 | _startPoint.btnWidth = 50.0; | 1954 | _startPoint.btnWidth = 50.0; |
1955 | _startPoint.btnHeight = 50.0; | 1955 | _startPoint.btnHeight = 50.0; |
1956 | _startPoint.buttText = "S"; | 1956 | _startPoint.buttText = "S"; |
1957 | Canvas.SetLeft(_startPoint, 75); | 1957 | Canvas.SetLeft(_startPoint, 75); |
1958 | Canvas.SetTop(_startPoint, 675); | 1958 | Canvas.SetTop(_startPoint, 675); |
1959 | this.Children.Add(_startPoint); | 1959 | this.Children.Add(_startPoint); |
1960 | } | 1960 | } |
1961 | } | 1961 | } |
1962 | 1962 | ||
1963 | 1963 | ||
1964 | #region Draw New FreeNode | 1964 | #region Draw New FreeNode |
1965 | 1965 | ||
1966 | /// <summary> | 1966 | /// <summary> |
1967 | /// Draw Auto Blue node | 1967 | /// Draw Auto Blue node |
1968 | /// </summary> | 1968 | /// </summary> |
1969 | 1969 | ||
1970 | 1970 | ||
1971 | public void NewSetFreeNodes(Point FreeNode, bool RightClick) | 1971 | public void NewSetFreeNodes(Point FreeNode, bool RightClick) |
1972 | { | 1972 | { |
1973 | double radiusNode = RADIUS_NODE; | 1973 | double radiusNode = RADIUS_NODE; |
1974 | 1974 | ||
1975 | EllipseGeometry ellipseGeometry; | 1975 | EllipseGeometry ellipseGeometry; |
1976 | Point node; | 1976 | Point node; |
1977 | bool deleteFlag = false; | 1977 | bool deleteFlag = false; |
1978 | 1978 | ||
1979 | 1979 | ||
1980 | if (RightClick) | 1980 | if (RightClick) |
1981 | { | 1981 | { |
1982 | if (gGrpBlueNode.Children.Count > 0) | 1982 | if (gGrpBlueNode.Children.Count > 0) |
1983 | { | 1983 | { |
1984 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 1984 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
1985 | { | 1985 | { |
1986 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 1986 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
1987 | node = ellipseGeometry.Center; | 1987 | node = ellipseGeometry.Center; |
1988 | if (FreeNode.X == node.X) | 1988 | if (FreeNode.X == node.X) |
1989 | { | 1989 | { |
1990 | if (CheckIsNode(FreeNode, node, radiusNode)) | 1990 | if (CheckIsNode(FreeNode, node, radiusNode)) |
1991 | { | 1991 | { |
1992 | deleteFlag = true; | 1992 | deleteFlag = true; |
1993 | } | 1993 | } |
1994 | } | 1994 | } |
1995 | else | 1995 | else |
1996 | { | 1996 | { |
1997 | if (CheckIsNode(FreeNode, node, radiusNode)) | 1997 | if (CheckIsNode(FreeNode, node, radiusNode)) |
1998 | { | 1998 | { |
1999 | deleteFlag = true; | 1999 | deleteFlag = true; |
2000 | } | 2000 | } |
2001 | } | 2001 | } |
2002 | if (deleteFlag) | 2002 | if (deleteFlag) |
2003 | { | 2003 | { |
2004 | MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); | 2004 | MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); |
2005 | if (result == MessageBoxResult.OK) | 2005 | if (result == MessageBoxResult.OK) |
2006 | { | 2006 | { |
2007 | 2007 | ||
2008 | //Call Function Delete Node | 2008 | //Call Function Delete Node |
2009 | DeleteNode(i); | 2009 | DeleteNode(i); |
2010 | 2010 | ||
2011 | //gGrpBlueNode.Children.RemoveAt(i); | 2011 | //gGrpBlueNode.Children.RemoveAt(i); |
2012 | 2012 | ||
2013 | //this.Children.Remove(NodeNo[i]); | 2013 | //this.Children.Remove(NodeNo[i]); |
2014 | return; | 2014 | return; |
2015 | } | 2015 | } |
2016 | else | 2016 | else |
2017 | { | 2017 | { |
2018 | return; | 2018 | return; |
2019 | } | 2019 | } |
2020 | } | 2020 | } |
2021 | } | 2021 | } |
2022 | } | 2022 | } |
2023 | } | 2023 | } |
2024 | else | 2024 | else |
2025 | { | 2025 | { |
2026 | //Check EditNode State | 2026 | //Check EditNode State |
2027 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 2027 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
2028 | { | 2028 | { |
2029 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 2029 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
2030 | node = ellipseGeometry.Center; | 2030 | node = ellipseGeometry.Center; |
2031 | bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE); | 2031 | bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE); |
2032 | 2032 | ||
2033 | if (isEditNode) | 2033 | if (isEditNode) |
2034 | { | 2034 | { |
2035 | NewEditNode(node); | 2035 | NewEditNode(node); |
2036 | NewDspRouteInfo(); | 2036 | NewDspRouteInfo(); |
2037 | return; | 2037 | return; |
2038 | } | 2038 | } |
2039 | } | 2039 | } |
2040 | 2040 | ||
2041 | 2041 | ||
2042 | MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel); | 2042 | MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel); |
2043 | if (result == MessageBoxResult.OK) | 2043 | if (result == MessageBoxResult.OK) |
2044 | { | 2044 | { |
2045 | AddNode(FreeNode, gGrpBlueNode); | 2045 | AddNode(FreeNode, gGrpBlueNode); |
2046 | 2046 | ||
2047 | TextBlock textBlock = new TextBlock(); | 2047 | TextBlock textBlock = new TextBlock(); |
2048 | textBlock.Text = stt.ToString(); | 2048 | textBlock.Text = stt.ToString(); |
2049 | textBlock.FontSize = 35; | 2049 | textBlock.FontSize = 35; |
2050 | textBlock.VerticalAlignment = VerticalAlignment.Center; | 2050 | textBlock.VerticalAlignment = VerticalAlignment.Center; |
2051 | textBlock.HorizontalAlignment = HorizontalAlignment.Center; | 2051 | textBlock.HorizontalAlignment = HorizontalAlignment.Center; |
2052 | textBlock.Foreground = new SolidColorBrush(Colors.Red); | 2052 | textBlock.Foreground = new SolidColorBrush(Colors.Red); |
2053 | 2053 | ||
2054 | Canvas.SetLeft(textBlock, FreeNode.X - RADIUS_NODE / 2); | 2054 | Canvas.SetLeft(textBlock, FreeNode.X - RADIUS_NODE / 2); |
2055 | Canvas.SetTop(textBlock, FreeNode.Y - 1.5 * RADIUS_NODE); | 2055 | Canvas.SetTop(textBlock, FreeNode.Y - 1.5 * RADIUS_NODE); |
2056 | 2056 | ||
2057 | 2057 | ||
2058 | this.Children.Add(textBlock); | 2058 | this.Children.Add(textBlock); |
2059 | NodeNo.Add(textBlock); | 2059 | NodeNo.Add(textBlock); |
2060 | 2060 | ||
2061 | if (stt > 1) | 2061 | if (stt > 1) |
2062 | { | 2062 | { |
2063 | int tmp = gGrpBlueNode.Children.Count; | 2063 | int tmp = gGrpBlueNode.Children.Count; |
2064 | 2064 | ||
2065 | EllipseGeometry elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2]; | 2065 | EllipseGeometry elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2]; |
2066 | Point node1 = elip.Center; | 2066 | Point node1 = elip.Center; |
2067 | elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1]; | 2067 | elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1]; |
2068 | Point node2 = elip.Center; | 2068 | Point node2 = elip.Center; |
2069 | DrawLine(node1, node2, gGrpNewLine); | 2069 | DrawLine(node1, node2, gGrpNewLine); |
2070 | 2070 | ||
2071 | 2071 | ||
2072 | this.Children.Remove(pBlueNode); | 2072 | this.Children.Remove(pBlueNode); |
2073 | for (int i = 0; i < tmp; i++) | 2073 | for (int i = 0; i < tmp; i++) |
2074 | { | 2074 | { |
2075 | this.Children.Remove(NodeNo[i]); | 2075 | this.Children.Remove(NodeNo[i]); |
2076 | } | 2076 | } |
2077 | 2077 | ||
2078 | this.Children.Add(pBlueNode); | 2078 | this.Children.Add(pBlueNode); |
2079 | for (int i = 0; i < tmp; i++) | 2079 | for (int i = 0; i < tmp; i++) |
2080 | { | 2080 | { |
2081 | this.Children.Add(NodeNo[i]); | 2081 | this.Children.Add(NodeNo[i]); |
2082 | } | 2082 | } |
2083 | } | 2083 | } |
2084 | 2084 | ||
2085 | stt++; | 2085 | stt++; |
2086 | NewInitNodeInfo_List(); | 2086 | NewInitNodeInfo_List(); |
2087 | NewDspRouteInfo(); | 2087 | NewDspRouteInfo(); |
2088 | } | 2088 | } |
2089 | } | 2089 | } |
2090 | } | 2090 | } |
2091 | 2091 | ||
2092 | public void DeleteNode(int i) | 2092 | public void DeleteNode(int i) |
2093 | { | 2093 | { |
2094 | //DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup) | 2094 | //DrawLine(Point startPoint, Point endPoint, GeometryGroup geometryGroup) |
2095 | 2095 | ||
2096 | LineGeometry lineGeometry = new LineGeometry(); | 2096 | LineGeometry lineGeometry = new LineGeometry(); |
2097 | EllipseGeometry ellip; | 2097 | EllipseGeometry ellip; |
2098 | 2098 | ||
2099 | 2099 | ||
2100 | if (i == gGrpBlueNode.Children.Count - 1) | 2100 | if (i == gGrpBlueNode.Children.Count - 1) |
2101 | { | 2101 | { |
2102 | // delete line | 2102 | // delete line |
2103 | if (gGrpNewLine.Children.Count > 0) | 2103 | if (gGrpNewLine.Children.Count > 0) |
2104 | { | 2104 | { |
2105 | gGrpNewLine.Children.RemoveAt(i - 1); | 2105 | gGrpNewLine.Children.RemoveAt(i - 1); |
2106 | } | 2106 | } |
2107 | 2107 | ||
2108 | // delete ucNode | 2108 | // delete ucNode |
2109 | ucNode _ucNode = new ucNode(); | 2109 | ucNode _ucNode = new ucNode(); |
2110 | _ucNode = ucNode_Lst[i]; | 2110 | _ucNode = ucNode_Lst[i]; |
2111 | this.Children.Remove(_ucNode); | 2111 | this.Children.Remove(_ucNode); |
2112 | ucNode_Lst.RemoveAt(i); | 2112 | ucNode_Lst.RemoveAt(i); |
2113 | 2113 | ||
2114 | // delete node | 2114 | // delete node |
2115 | gGrpBlueNode.Children.RemoveAt(i); | 2115 | gGrpBlueNode.Children.RemoveAt(i); |
2116 | NewNodeInfo_List.RemoveAt(i); | 2116 | NewNodeInfo_List.RemoveAt(i); |
2117 | 2117 | ||
2118 | } | 2118 | } |
2119 | else | 2119 | else |
2120 | { | 2120 | { |
2121 | // remove last Node | 2121 | // remove last Node |
2122 | int lastIdx = gGrpBlueNode.Children.Count - 1; | 2122 | int lastIdx = gGrpBlueNode.Children.Count - 1; |
2123 | 2123 | ||
2124 | NewNodeInfo_List.RemoveAt(lastIdx); | 2124 | NewNodeInfo_List.RemoveAt(lastIdx); |
2125 | gGrpBlueNode.Children.RemoveAt(lastIdx); | 2125 | gGrpBlueNode.Children.RemoveAt(lastIdx); |
2126 | gGrpNewLine.Children.RemoveAt(lastIdx - 1); | 2126 | gGrpNewLine.Children.RemoveAt(lastIdx - 1); |
2127 | 2127 | ||
2128 | ucNode _ucNode = new ucNode(); | 2128 | ucNode _ucNode = new ucNode(); |
2129 | _ucNode = ucNode_Lst[lastIdx]; | 2129 | _ucNode = ucNode_Lst[lastIdx]; |
2130 | this.Children.Remove(_ucNode); | 2130 | this.Children.Remove(_ucNode); |
2131 | 2131 | ||
2132 | ucNode_Lst.RemoveAt(lastIdx); | 2132 | ucNode_Lst.RemoveAt(lastIdx); |
2133 | 2133 | ||
2134 | 2134 | ||
2135 | 2135 | ||
2136 | 2136 | ||
2137 | // ellip = (EllipseGeometry)gGrpBlueNode.Children[i - 1]; | 2137 | // ellip = (EllipseGeometry)gGrpBlueNode.Children[i - 1]; |
2138 | //Point p1 = ellip.Center; | 2138 | //Point p1 = ellip.Center; |
2139 | //ellip = (EllipseGeometry)gGrpBlueNode.Children[i + 1]; | 2139 | //ellip = (EllipseGeometry)gGrpBlueNode.Children[i + 1]; |
2140 | //Point p2 = ellip.Center; | 2140 | //Point p2 = ellip.Center; |
2141 | 2141 | ||
2142 | //gGrpNewLine.Children.RemoveAt(i); | 2142 | //gGrpNewLine.Children.RemoveAt(i); |
2143 | //gGrpNewLine.Children.RemoveAt(i - 1); | 2143 | //gGrpNewLine.Children.RemoveAt(i - 1); |
2144 | 2144 | ||
2145 | 2145 | ||
2146 | //lineGeometry.StartPoint = p1; | 2146 | //lineGeometry.StartPoint = p1; |
2147 | //lineGeometry.EndPoint = p2; | 2147 | //lineGeometry.EndPoint = p2; |
2148 | //gGrpNewLine.Children.Add(lineGeometry); | 2148 | //gGrpNewLine.Children.Add(lineGeometry); |
2149 | 2149 | ||
2150 | ////gGrpNewLine.Children.Clear(); | 2150 | ////gGrpNewLine.Children.Clear(); |
2151 | 2151 | ||
2152 | //this.Children.Remove(pNewLine); | 2152 | //this.Children.Remove(pNewLine); |
2153 | //this.Children.Add(pNewLine); | 2153 | //this.Children.Add(pNewLine); |
2154 | 2154 | ||
2155 | //gGrpBlueNode.Children.RemoveAt(i); | 2155 | //gGrpBlueNode.Children.RemoveAt(i); |
2156 | } | 2156 | } |
2157 | 2157 | ||
2158 | 2158 | ||
2159 | 2159 | ||
2160 | //NewInitNodeInfo_List(); | 2160 | //NewInitNodeInfo_List(); |
2161 | 2161 | ||
2162 | 2162 | ||
2163 | NewDspRouteInfo(); | 2163 | NewDspRouteInfo(); |
2164 | stt--; | 2164 | stt--; |
2165 | 2165 | ||
2166 | 2166 | ||
2167 | } | 2167 | } |
2168 | 2168 | ||
2169 | 2169 | ||
2170 | 2170 | ||
2171 | 2171 | ||
2172 | public void NewInitNodeInfo_List() | 2172 | public void NewInitNodeInfo_List() |
2173 | { | 2173 | { |
2174 | //Reset List | 2174 | //Reset List |
2175 | //NewNodeInfo_List = new List<NewNodeInfo>(); | 2175 | //NewNodeInfo_List = new List<NewNodeInfo>(); |
2176 | 2176 | ||
2177 | if (gGrpBlueNode.Children.Count > 0) | 2177 | if (gGrpBlueNode.Children.Count > 0) |
2178 | { | 2178 | { |
2179 | //for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 2179 | //for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
2180 | //{ | 2180 | //{ |
2181 | int i = gGrpBlueNode.Children.Count - 1; | 2181 | int i = gGrpBlueNode.Children.Count - 1; |
2182 | Point point; | 2182 | Point point; |
2183 | EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 2183 | EllipseGeometry eGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
2184 | point = eGeometry.Center; | 2184 | point = eGeometry.Center; |
2185 | 2185 | ||
2186 | NewNodeInfo Ninfo = new NewNodeInfo(); | 2186 | NewNodeInfo Ninfo = new NewNodeInfo(); |
2187 | Ninfo.X = point.X; | 2187 | Ninfo.X = point.X; |
2188 | Ninfo.Y = point.Y; | 2188 | Ninfo.Y = point.Y; |
2189 | 2189 | ||
2190 | Ninfo.Mode = ""; | 2190 | Ninfo.Mode = ""; |
2191 | 2191 | ||
2192 | NewNodeInfo_List.Add(Ninfo); | 2192 | NewNodeInfo_List.Add(Ninfo); |
2193 | //} | 2193 | //} |
2194 | 2194 | ||
2195 | } | 2195 | } |
2196 | } | 2196 | } |
2197 | 2197 | ||
2198 | public void NewEditNode(Point node_edited) | 2198 | public void NewEditNode(Point node_edited) |
2199 | { | 2199 | { |
2200 | EllipseGeometry ellipseGeometry; | 2200 | EllipseGeometry ellipseGeometry; |
2201 | Point node; | 2201 | Point node; |
2202 | double radiusNode = RADIUS_NODE; | 2202 | double radiusNode = RADIUS_NODE; |
2203 | 2203 | ||
2204 | bool flag = false; | 2204 | bool flag = false; |
2205 | 2205 | ||
2206 | if (gGrpBlueNode.Children.Count > 0) | 2206 | if (gGrpBlueNode.Children.Count > 0) |
2207 | { | 2207 | { |
2208 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 2208 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
2209 | { | 2209 | { |
2210 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 2210 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
2211 | node = ellipseGeometry.Center; | 2211 | node = ellipseGeometry.Center; |
2212 | 2212 | ||
2213 | if (CheckIsNode(node_edited, node, radiusNode)) | 2213 | if (CheckIsNode(node_edited, node, radiusNode)) |
2214 | { | 2214 | { |
2215 | flag = true; | 2215 | flag = true; |
2216 | } | 2216 | } |
2217 | 2217 | ||
2218 | if (flag) | 2218 | if (flag) |
2219 | { | 2219 | { |
2220 | node_edited.X = node.X; | 2220 | node_edited.X = node.X; |
2221 | node_edited.Y = node.Y; | 2221 | node_edited.Y = node.Y; |
2222 | 2222 | ||
2223 | // show form edit node | 2223 | // show form edit node |
2224 | EditNodeWindow edtNodeWindow = new EditNodeWindow(); | 2224 | EditNodeWindow edtNodeWindow = new EditNodeWindow(); |
2225 | edtNodeWindow.ShowDialog(); | 2225 | edtNodeWindow.ShowDialog(); |
2226 | 2226 | ||
2227 | string result = edtNodeWindow._txtMode; | 2227 | string result = edtNodeWindow._txtMode; |
2228 | bool exit = edtNodeWindow._ExitFlg; | 2228 | bool exit = edtNodeWindow._ExitFlg; |
2229 | 2229 | ||
2230 | if (!exit) | 2230 | if (!exit) |
2231 | { | 2231 | { |
2232 | NewSaveChanged(node_edited.X, node_edited.Y, result); | 2232 | NewSaveChanged(node_edited.X, node_edited.Y, result); |
2233 | } | 2233 | } |
2234 | 2234 | ||
2235 | return; | 2235 | return; |
2236 | } | 2236 | } |
2237 | } | 2237 | } |
2238 | } | 2238 | } |
2239 | } | 2239 | } |
2240 | 2240 | ||
2241 | //Save Node's Data Edited | 2241 | //Save Node's Data Edited |
2242 | public void NewSaveChanged(double x, double y, string st) | 2242 | public void NewSaveChanged(double x, double y, string st) |
2243 | { | 2243 | { |
2244 | for (int i = 0; i < NewNodeInfo_List.Count; i++) | 2244 | for (int i = 0; i < NewNodeInfo_List.Count; i++) |
2245 | { | 2245 | { |
2246 | NewNodeInfo ni = new NewNodeInfo(); | 2246 | NewNodeInfo ni = new NewNodeInfo(); |
2247 | ni = NewNodeInfo_List[i]; | 2247 | ni = NewNodeInfo_List[i]; |
2248 | 2248 | ||
2249 | if (ni.X == x && ni.Y == y) | 2249 | if (ni.X == x && ni.Y == y) |
2250 | { | 2250 | { |
2251 | ni.Mode = st; | 2251 | ni.Mode = st; |
2252 | 2252 | ||
2253 | NewNodeInfo_List[i] = ni; | 2253 | NewNodeInfo_List[i] = ni; |
2254 | return; | 2254 | return; |
2255 | } | 2255 | } |
2256 | } | 2256 | } |
2257 | } | 2257 | } |
2258 | 2258 | ||
2259 | public void NewDspRouteInfo() | 2259 | public void NewDspRouteInfo() |
2260 | { | 2260 | { |
2261 | //Clear Route Info Table | 2261 | //Clear Route Info Table |
2262 | ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear(); | 2262 | ((RoboforkMenu)System.Windows.Application.Current.MainWindow).grdRouteInfo.Children.Clear(); |
2263 | 2263 | ||
2264 | if (NewNodeInfo_List.Count != 0) | 2264 | if (NewNodeInfo_List.Count != 0) |
2265 | { | 2265 | { |
2266 | int _RowIdx = 0; | 2266 | int _RowIdx = 0; |
2267 | string _Content = ""; | 2267 | string _Content = ""; |
2268 | 2268 | ||
2269 | for (int i = 0; i < NewNodeInfo_List.Count; i++) | 2269 | for (int i = 0; i < NewNodeInfo_List.Count; i++) |
2270 | { | 2270 | { |
2271 | 2271 | ||
2272 | NewNodeInfo ni = new NewNodeInfo(); | 2272 | NewNodeInfo ni = new NewNodeInfo(); |
2273 | ni = NewNodeInfo_List[i]; | 2273 | ni = NewNodeInfo_List[i]; |
2274 | 2274 | ||
2275 | //column 1 | 2275 | //column 1 |
2276 | _Content = (i +1).ToString(); | 2276 | _Content = (i +1).ToString(); |
2277 | AddLabeltoGrid(_RowIdx, 0, _Content); | 2277 | AddLabeltoGrid(_RowIdx, 0, _Content); |
2278 | 2278 | ||
2279 | //column 2 | 2279 | //column 2 |
2280 | // Display Node's Position | 2280 | // Display Node's Position |
2281 | _Content = "LAT " + ni.X; | 2281 | _Content = "LAT " + ni.X; |
2282 | AddLabeltoGrid(_RowIdx, 1, _Content); | 2282 | AddLabeltoGrid(_RowIdx, 1, _Content); |
2283 | _RowIdx++; | 2283 | _RowIdx++; |
2284 | 2284 | ||
2285 | _Content = "LOC " + ni.Y; | 2285 | _Content = "LOC " + ni.Y; |
2286 | AddLabeltoGrid(_RowIdx, 1, _Content); | 2286 | AddLabeltoGrid(_RowIdx, 1, _Content); |
2287 | 2287 | ||
2288 | // Display Node's Field | 2288 | // Display Node's Field |
2289 | if (ni.Mode != "" && ni.Mode != null) | 2289 | if (ni.Mode != "" && ni.Mode != null) |
2290 | { | 2290 | { |
2291 | char delimiterChars = '_'; | 2291 | char delimiterChars = '_'; |
2292 | string[] tmp = ni.Mode.Split(delimiterChars); | 2292 | string[] tmp = ni.Mode.Split(delimiterChars); |
2293 | foreach (string s in tmp) | 2293 | foreach (string s in tmp) |
2294 | { | 2294 | { |
2295 | _RowIdx++; | 2295 | _RowIdx++; |
2296 | delimiterChars = ':'; | 2296 | delimiterChars = ':'; |
2297 | 2297 | ||
2298 | if (s.Split(delimiterChars)[0] == "Speed") | 2298 | if (s.Split(delimiterChars)[0] == "Speed") |
2299 | { | 2299 | { |
2300 | _Content = "SPD " + s.Split(delimiterChars)[1]; | 2300 | _Content = "SPD " + s.Split(delimiterChars)[1]; |
2301 | AddLabeltoGrid(_RowIdx, 1, _Content); | 2301 | AddLabeltoGrid(_RowIdx, 1, _Content); |
2302 | } | 2302 | } |
2303 | } | 2303 | } |
2304 | } | 2304 | } |
2305 | _RowIdx++; | 2305 | _RowIdx++; |
2306 | } | 2306 | } |
2307 | } | 2307 | } |
2308 | } | 2308 | } |
2309 | 2309 | ||
2310 | 2310 | ||
2311 | private void CreateNode(Point FreeNode, bool LeftClick, bool RightClick) | 2311 | private void CreateNode(Point FreeNode, bool LeftClick, bool RightClick) |
2312 | { | 2312 | { |
2313 | double radiusNode = RADIUS_NODE; | 2313 | double radiusNode = RADIUS_NODE; |
2314 | 2314 | ||
2315 | EllipseGeometry ellipseGeometry; | 2315 | EllipseGeometry ellipseGeometry; |
2316 | Point node; | 2316 | Point node; |
2317 | bool deleteFlag = false; | 2317 | bool deleteFlag = false; |
2318 | 2318 | ||
2319 | //Su kien bam chuot phai | 2319 | //Su kien bam chuot phai |
2320 | if (RightClick) | 2320 | if (RightClick) |
2321 | { | 2321 | { |
2322 | if (gGrpBlueNode.Children.Count > 0) | 2322 | if (gGrpBlueNode.Children.Count > 0) |
2323 | { | 2323 | { |
2324 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 2324 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
2325 | { | 2325 | { |
2326 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 2326 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
2327 | node = ellipseGeometry.Center; | 2327 | node = ellipseGeometry.Center; |
2328 | if (FreeNode.X == node.X) | 2328 | if (FreeNode.X == node.X) |
2329 | { | 2329 | { |
2330 | if (CheckIsNode(FreeNode, node, radiusNode)) | 2330 | if (CheckIsNode(FreeNode, node, radiusNode)) |
2331 | { | 2331 | { |
2332 | deleteFlag = true; | 2332 | deleteFlag = true; |
2333 | } | 2333 | } |
2334 | } | 2334 | } |
2335 | else | 2335 | else |
2336 | { | 2336 | { |
2337 | if (CheckIsNode(FreeNode, node, radiusNode)) | 2337 | if (CheckIsNode(FreeNode, node, radiusNode)) |
2338 | { | 2338 | { |
2339 | deleteFlag = true; | 2339 | deleteFlag = true; |
2340 | } | 2340 | } |
2341 | } | 2341 | } |
2342 | if (deleteFlag) | 2342 | if (deleteFlag) |
2343 | { | 2343 | { |
2344 | MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); | 2344 | MessageBoxResult result = MessageBox.Show("Do You Delete This Node?", "Delete Node", MessageBoxButton.OKCancel); |
2345 | if (result == MessageBoxResult.OK) | 2345 | if (result == MessageBoxResult.OK) |
2346 | { | 2346 | { |
2347 | 2347 | ||
2348 | DeleteNode(i); | 2348 | DeleteNode(i); |
2349 | 2349 | ||
2350 | SetScheduleRoute(); | 2350 | SetScheduleRoute(); |
2351 | 2351 | ||
2352 | return; | 2352 | return; |
2353 | } | 2353 | } |
2354 | else | 2354 | else |
2355 | { | 2355 | { |
2356 | return; | 2356 | return; |
2357 | } | 2357 | } |
2358 | } | 2358 | } |
2359 | } | 2359 | } |
2360 | } | 2360 | } |
2361 | } | 2361 | } |
2362 | 2362 | ||
2363 | // them nut | 2363 | // them nut |
2364 | else | 2364 | else |
2365 | { | 2365 | { |
2366 | //Check EditNode State | 2366 | //Check EditNode State |
2367 | if(LeftClick) | 2367 | if(LeftClick) |
2368 | { | 2368 | { |
2369 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 2369 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
2370 | { | 2370 | { |
2371 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; | 2371 | ellipseGeometry = (EllipseGeometry)gGrpBlueNode.Children[i]; |
2372 | node = ellipseGeometry.Center; | 2372 | node = ellipseGeometry.Center; |
2373 | bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE); | 2373 | bool isEditNode = CheckIsNode(FreeNode, node, RADIUS_NODE); |
2374 | 2374 | ||
2375 | if (isEditNode) | 2375 | if (isEditNode) |
2376 | { | 2376 | { |
2377 | NewEditNode(node); | 2377 | NewEditNode(node); |
2378 | NewDspRouteInfo(); | 2378 | NewDspRouteInfo(); |
2379 | return; | 2379 | return; |
2380 | } | 2380 | } |
2381 | } | 2381 | } |
2382 | } | 2382 | } |
2383 | 2383 | ||
2384 | 2384 | ||
2385 | // them nut | 2385 | // them nut |
2386 | MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel); | 2386 | MessageBoxResult result = MessageBox.Show("Do You Want To Add This Node?", "Add Node", MessageBoxButton.OKCancel); |
2387 | if (result == MessageBoxResult.OK) | 2387 | if (result == MessageBoxResult.OK) |
2388 | { | 2388 | { |
2389 | ucNode _ucNode = new ucNode(); | 2389 | ucNode _ucNode = new ucNode(); |
2390 | _ucNode.btnWidth = 50.0; | 2390 | _ucNode.btnWidth = 50.0; |
2391 | _ucNode.btnHeight = 50.0; | 2391 | _ucNode.btnHeight = 50.0; |
2392 | _ucNode.txtNode = stt.ToString(); | 2392 | _ucNode.txtNode = stt.ToString(); |
2393 | Canvas.SetLeft(_ucNode, FreeNode.X); | 2393 | Canvas.SetLeft(_ucNode, FreeNode.X -25); |
2394 | Canvas.SetTop(_ucNode, FreeNode.Y); | 2394 | Canvas.SetTop(_ucNode, FreeNode.Y - 25); |
2395 | this.Children.Add(_ucNode); | 2395 | this.Children.Add(_ucNode); |
2396 | ucNode_Lst.Add(_ucNode); | 2396 | ucNode_Lst.Add(_ucNode); |
2397 | 2397 | ||
2398 | double XXX = FreeNode.X + _ucNode.btnWidth / 2; | ||
2399 | double YYY = FreeNode.Y + _ucNode.btnWidth / 2; | ||
2400 | FreeNode.X = XXX; | ||
2401 | FreeNode.Y = YYY; | ||
2402 | AddNode(FreeNode, gGrpBlueNode); | 2398 | AddNode(FreeNode, gGrpBlueNode); |
2403 | 2399 | ||
2404 | SetScheduleRoute(); | 2400 | SetScheduleRoute(); |
2405 | 2401 | ||
2406 | //ve line | 2402 | //ve line |
2407 | if (stt > 1) | 2403 | if (stt > 1) |
2408 | { | 2404 | { |
2409 | int tmp = ucNode_Lst.Count; | 2405 | int tmp = ucNode_Lst.Count; |
2410 | 2406 | ||
2411 | EllipseGeometry elip = new EllipseGeometry(); | 2407 | EllipseGeometry elip = new EllipseGeometry(); |
2412 | 2408 | ||
2413 | elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2]; | 2409 | elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 2]; |
2414 | Point node1 = elip.Center; | 2410 | Point node1 = elip.Center; |
2415 | elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1]; | 2411 | elip = (EllipseGeometry)gGrpBlueNode.Children[tmp - 1]; |
2416 | Point node2 = elip.Center; | 2412 | Point node2 = elip.Center; |
2417 | DrawLine(node1, node2, gGrpNewLine); | 2413 | DrawLine(node1, node2, gGrpNewLine); |
2418 | 2414 | ||
2419 | } | 2415 | } |
2420 | 2416 | ||
2421 | stt++; | 2417 | stt++; |
2422 | NewInitNodeInfo_List(); | 2418 | NewInitNodeInfo_List(); |
2423 | NewDspRouteInfo(); | 2419 | NewDspRouteInfo(); |
2424 | } | 2420 | } |
2425 | } | 2421 | } |
2426 | 2422 | ||
2427 | } | 2423 | } |
2428 | #endregion | 2424 | #endregion |
2429 | 2425 | ||
2430 | #region Schedule | 2426 | #region Schedule |
2431 | 2427 | ||
2432 | public void SetScheduleRoute() | 2428 | public void SetScheduleRoute() |
2433 | { | 2429 | { |
2434 | 2430 | ||
2435 | EllipseGeometry ellipseGeometry_1; | 2431 | EllipseGeometry ellipseGeometry_1; |
2436 | EllipseGeometry ellipseGeometry_2; | 2432 | EllipseGeometry ellipseGeometry_2; |
2437 | Point node_1; | 2433 | Point node_1; |
2438 | Point node_2; | 2434 | Point node_2; |
2439 | Point node_Schedule = new Point(); | 2435 | Point node_Schedule = new Point(); |
2440 | double x_1 = 50; | 2436 | double x_1 = 50; |
2441 | double y_1 = 80; | 2437 | double y_1 = 80; |
2442 | double Totaldistance = 1270; | 2438 | double Totaldistance = 1270; |
2443 | 2439 | ||
2444 | 2440 | ||
2445 | if (ucScheduleNode_Lst.Count > 0) | 2441 | if (ucScheduleNode_Lst.Count > 0) |
2446 | { | 2442 | { |
2447 | for (int i = 0; i < ucScheduleNode_Lst.Count; i++) | 2443 | for (int i = 0; i < ucScheduleNode_Lst.Count; i++) |
2448 | { | 2444 | { |
2449 | ucNode _ucNode = new ucNode(); | 2445 | ucNode _ucNode = new ucNode(); |
2450 | _ucNode = ucScheduleNode_Lst[i]; | 2446 | _ucNode = ucScheduleNode_Lst[i]; |
2451 | scheduleCanvas.Children.Remove(_ucNode); | 2447 | scheduleCanvas.Children.Remove(_ucNode); |
2452 | 2448 | ||
2453 | } | 2449 | } |
2454 | ucScheduleNode_Lst.Clear(); | 2450 | ucScheduleNode_Lst.Clear(); |
2455 | } | 2451 | } |
2456 | 2452 | ||
2457 | gGrpScheduleNode.Children.Clear(); | 2453 | gGrpScheduleNode.Children.Clear(); |
2458 | gGrpScheduleLine.Children.Clear(); | 2454 | gGrpScheduleLine.Children.Clear(); |
2459 | 2455 | ||
2460 | 2456 | ||
2461 | List<double> distance = new List<double>(); | 2457 | List<double> distance = new List<double>(); |
2462 | double addDistance; | 2458 | double addDistance; |
2463 | 2459 | ||
2464 | if (gGrpBlueNode.Children.Count > 0) | 2460 | if (gGrpBlueNode.Children.Count > 0) |
2465 | { | 2461 | { |
2466 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) | 2462 | for (int i = 0; i < gGrpBlueNode.Children.Count; i++) |
2467 | { | 2463 | { |
2468 | ellipseGeometry_2 = (EllipseGeometry)gGrpBlueNode.Children[i]; | 2464 | ellipseGeometry_2 = (EllipseGeometry)gGrpBlueNode.Children[i]; |
2469 | node_2 = ellipseGeometry_2.Center; | 2465 | node_2 = ellipseGeometry_2.Center; |
2470 | 2466 | ||
2471 | if (i >= 1) | 2467 | if (i >= 1) |
2472 | { | 2468 | { |
2473 | ellipseGeometry_1 = (EllipseGeometry)gGrpBlueNode.Children[i - 1]; | 2469 | ellipseGeometry_1 = (EllipseGeometry)gGrpBlueNode.Children[i - 1]; |
2474 | node_1 = ellipseGeometry_1.Center; | 2470 | node_1 = ellipseGeometry_1.Center; |
2475 | if (node_1.X == node_2.X) | 2471 | if (node_1.X == node_2.X) |
2476 | { | 2472 | { |
2477 | addDistance = Math.Abs(node_1.Y - node_2.Y); | 2473 | addDistance = Math.Abs(node_1.Y - node_2.Y); |
2478 | distance.Add(addDistance); | 2474 | distance.Add(addDistance); |
2479 | } | 2475 | } |
2480 | else if (node_1.Y == node_2.Y) | 2476 | else if (node_1.Y == node_2.Y) |
2481 | { | 2477 | { |
2482 | addDistance = Math.Abs(node_1.X - node_2.X); | 2478 | addDistance = Math.Abs(node_1.X - node_2.X); |
2483 | distance.Add(addDistance); | 2479 | distance.Add(addDistance); |
2484 | } | 2480 | } |
2485 | else | 2481 | else |
2486 | { | 2482 | { |
2487 | var a = (double)(node_2.X - node_1.X); | 2483 | var a = (double)(node_2.X - node_1.X); |
2488 | var b = (double)(node_2.Y - node_1.Y); | 2484 | var b = (double)(node_2.Y - node_1.Y); |
2489 | addDistance = Math.Sqrt(a * a + b * b); | 2485 | addDistance = Math.Sqrt(a * a + b * b); |
2490 | distance.Add(addDistance); | 2486 | distance.Add(addDistance); |
2491 | } | 2487 | } |
2492 | } | 2488 | } |
2493 | } | 2489 | } |
2494 | } | 2490 | } |
2495 | if (distance.Count > 0) | 2491 | if (distance.Count > 0) |
2496 | { | 2492 | { |
2497 | double total = 0; | 2493 | double total = 0; |
2498 | double distance_i; | 2494 | double distance_i; |
2499 | 2495 | ||
2500 | for (int i = 0; i < distance.Count; i++) | 2496 | for (int i = 0; i < distance.Count; i++) |
2501 | { | 2497 | { |
2502 | total = total + distance[i]; | 2498 | total = total + distance[i]; |
2503 | } | 2499 | } |
2504 | 2500 | ||
2505 | for (int i = 0; i < distance.Count; i++) | 2501 | for (int i = 0; i < distance.Count; i++) |
2506 | { | 2502 | { |
2507 | distance_i = distance[i] * (Totaldistance / total); | 2503 | distance_i = distance[i] * (Totaldistance / total); |
2508 | distance[i] = distance_i; | 2504 | distance[i] = distance_i; |
2509 | } | 2505 | } |
2510 | } | 2506 | } |
2511 | 2507 | ||
2512 | node_Schedule.X = x_1; | 2508 | node_Schedule.X = x_1; |
2513 | node_Schedule.Y = y_1; | 2509 | node_Schedule.Y = y_1; |
2514 | AddNode(node_Schedule, gGrpScheduleNode); | 2510 | AddNode(node_Schedule, gGrpScheduleNode); |
2515 | 2511 | ||
2516 | addDistance = 0; | 2512 | addDistance = 0; |
2517 | for (int i = 0; i < distance.Count; i++) | 2513 | for (int i = 0; i < distance.Count; i++) |
2518 | { | 2514 | { |
2519 | 2515 | ||
2520 | node_Schedule.Y = y_1; | 2516 | node_Schedule.Y = y_1; |
2521 | addDistance = addDistance + distance[i]; | 2517 | addDistance = addDistance + distance[i]; |
2522 | node_Schedule.X = addDistance; | 2518 | node_Schedule.X = addDistance; |
2523 | AddNode(node_Schedule, gGrpScheduleNode); | 2519 | AddNode(node_Schedule, gGrpScheduleNode); |
2524 | } | 2520 | } |
2525 | 2521 | ||
2526 | if (gGrpScheduleNode.Children.Count > 0) | 2522 | if (gGrpScheduleNode.Children.Count > 0) |
2527 | { | 2523 | { |
2528 | for (int i = 0; i < gGrpScheduleNode.Children.Count; i++) | 2524 | for (int i = 0; i < gGrpScheduleNode.Children.Count; i++) |
2529 | { | 2525 | { |
2530 | ellipseGeometry_1 = (EllipseGeometry)gGrpScheduleNode.Children[i]; | 2526 | ellipseGeometry_1 = (EllipseGeometry)gGrpScheduleNode.Children[i]; |
2531 | node_1 = ellipseGeometry_1.Center; | 2527 | node_1 = ellipseGeometry_1.Center; |
2532 | if (i > 0) | 2528 | if (i > 0) |
2533 | { | 2529 | { |
2534 | ellipseGeometry_2 = (EllipseGeometry)gGrpScheduleNode.Children[i -1]; | 2530 | ellipseGeometry_2 = (EllipseGeometry)gGrpScheduleNode.Children[i -1]; |
2535 | node_2 = ellipseGeometry_2.Center; | 2531 | node_2 = ellipseGeometry_2.Center; |
2536 | DrawLine(node_1, node_2, gGrpScheduleLine); | 2532 | DrawLine(node_1, node_2, gGrpScheduleLine); |
2537 | } | 2533 | } |
2538 | CreateScheduleNode(node_1, i + 1); | 2534 | CreateScheduleNode(node_1, i + 1); |
2539 | } | 2535 | } |
2540 | } | 2536 | } |
2541 | } | 2537 | } |
2542 | 2538 | ||
2543 | 2539 | ||
2544 | private void CreateNode(Point point, int indexNode) | 2540 | private void CreateNode(Point point, int indexNode) |
2545 | { | 2541 | { |
2546 | ucNode _ucNode = new ucNode(); | 2542 | ucNode _ucNode = new ucNode(); |
2547 | _ucNode.btnWidth = 20.0; | 2543 | _ucNode.btnWidth = 20.0; |
2548 | _ucNode.btnHeight = 20.0; | 2544 | _ucNode.btnHeight = 20.0; |
2549 | _ucNode.txtNode = indexNode.ToString(); | 2545 | _ucNode.txtNode = indexNode.ToString(); |
2550 | Canvas.SetLeft(_ucNode, point.X); | 2546 | Canvas.SetLeft(_ucNode, point.X); |
2551 | Canvas.SetTop(_ucNode, point.Y); | 2547 | Canvas.SetTop(_ucNode, point.Y); |
2552 | this.Children.Add(_ucNode); | 2548 | this.Children.Add(_ucNode); |
2553 | } | 2549 | } |
2554 | 2550 | ||
2555 | private void CreateScheduleNode(Point point, int indexNode) | 2551 | private void CreateScheduleNode(Point point, int indexNode) |
2556 | { | 2552 | { |
2557 | ucNode _ucNode = new ucNode(); | 2553 | ucNode _ucNode = new ucNode(); |
2558 | _ucNode.btnWidth = 20.0; | 2554 | _ucNode.btnWidth = 20.0; |
2559 | _ucNode.btnHeight = 20.0; | 2555 | _ucNode.btnHeight = 20.0; |
2560 | _ucNode.txtNode = indexNode.ToString(); | 2556 | _ucNode.txtNode = indexNode.ToString(); |
2561 | Canvas.SetLeft(_ucNode, point.X - 25); | 2557 | Canvas.SetLeft(_ucNode, point.X - 25); |
2562 | Canvas.SetTop(_ucNode, point.Y - 25); | 2558 | Canvas.SetTop(_ucNode, point.Y - 25); |
2563 | scheduleCanvas.Children.Add(_ucNode); | 2559 | scheduleCanvas.Children.Add(_ucNode); |
2564 | ucScheduleNode_Lst.Add(_ucNode); | 2560 | ucScheduleNode_Lst.Add(_ucNode); |
2565 | } | 2561 | } |
2566 | 2562 | ||
2567 | #endregion | 2563 | #endregion |
2568 | 2564 | ||
2569 | } | 2565 | } |
2570 | } | 2566 | } |
2571 | 2567 |