public static void DrawLines(List <Model.LineEntity> lines, Canvas canvas) { Model.Point startNode = new Model.Point(); Model.Point EndNode = new Model.Point(); Model.Point currPoint = new Model.Point(); Model.Point prevPoint = new Model.Point(); foreach (var item in lines) { if (!collectionOfNodes.ContainsKey(item.FirstEnd) || !collectionOfNodes.ContainsKey(item.SecondEnd)) { continue; } startNode = collectionOfNodes[item.FirstEnd]; EndNode = collectionOfNodes[item.SecondEnd]; prevPoint.X = currPoint.X = startNode.X; prevPoint.Y = currPoint.Y = startNode.Y; int step = (currPoint.X > EndNode.X) ? -10 : 10; // razmak izmedju dva x-a na gridu je 10, zbog toga i korak -10 ili +10 while (currPoint.X != EndNode.X) //crtamo po x { currPoint.X += step; if (!horizontalLineOnPoint.ContainsKey(new Point(currPoint.X, currPoint.Y)) || currPoint.X == EndNode.X) { Line l1 = createLine(prevPoint, currPoint); l1.ToolTip = "\tLINE \nID: " + item.Id.ToString() + "\nName: " + item.Name + "\nFirstEnd: " + item.FirstEnd.ToString() + "\nSecondEnd: " + item.SecondEnd.ToString(); canvas.Children.Add(l1); horizontalLineOnPoint[new Point(currPoint.X, currPoint.Y)] = LineType.Horizontal; } prevPoint.X = currPoint.X; } step = (currPoint.Y > EndNode.Y) ? -10 : 10; // razmak izmedju dva y-a na gridu je 10, zbog toga i korak -10 ili +10 while (currPoint.Y != EndNode.Y) //crtamo po y { currPoint.Y += step; if (!verticalLineOnPoint.ContainsKey(new Point(currPoint.X, currPoint.Y)) || currPoint.Y == EndNode.Y) { Line l1 = createLine(prevPoint, currPoint); l1.ToolTip = "\tLINE \nID: " + item.Id.ToString() + "\nName: " + item.Name + "\nFirstEnd: " + item.FirstEnd.ToString() + "\nSecondEnd: " + item.SecondEnd.ToString(); canvas.Children.Add(l1); verticalLineOnPoint[new Point(currPoint.X, currPoint.Y)] = LineType.Verical; } prevPoint.Y = currPoint.Y; } } }
private static Line createLine(Model.Point point1, Model.Point point2) { Line line = new Line(); line.Stroke = new SolidColorBrush(Color.FromRgb(71, 252, 58)); line.X1 = point1.X + 4.5; line.Y1 = point1.Y + 4.5; line.X2 = point2.X + 4.5; line.Y2 = point2.Y + 4.5; line.StrokeThickness = 1.5; return(line); }