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