bool ISpaceManager.TryAddLevel <T>(Dimension <T> dimension) { if (dimension.HeadDimPoint == null || dimension.HeadDimPoint.TailLink == null) { return(false); } var topLeft = dimension.HeadDimPoint.TailLink; if (topLeft.CountConnectionsRight() == 0) { return(false); } var left = new DimensionLink <T>((byte)(topLeft.Level + 1)); topLeft.AssignUpper(left); var topRight = dimension.TailDimPoint.TailLink; var right = new DimensionLink <T>((byte)(topRight.Level + 1)); topRight.AssignUpper(right); left.AssignNext(right); dimension.HeadDimPoint.TailLink = left; dimension.TailDimPoint.TailLink = right; return(true); }
private static bool HasTopLevelNeighbourToTheRight <T>(DimensionLink <T> tail) { return(tail.Level > 1 && tail.Next != null && tail.Next.Lower.Prev != tail.Lower && tail.Next.Lower.Prev.Prev != tail.Lower); }
private void DrawLink(DimensionLink <int> link) { var x = (double)link.DimPoint.Position; var y = link.Level * ypad + ypad * 4; const int containerPad = 7; var p = new Polygon { Stroke = Brushes.Black, Fill = Brushes.LightBlue, StrokeThickness = 0.5, Points = new PointCollection { new Point(x, y - containerPad), new Point(x + containerPad, y), new Point(x, y + containerPad), new Point(x - containerPad, y) } }; _canvas.Children.Add(p); var tb = Text(link.Level.ToString(CultureInfo.InvariantCulture), x, y); _canvas.Children.Add(tb); if (link.Level == 0) { var el = new Ellipse { Tag = link.DimPoint, Width = containerPad * 2, Height = containerPad * 2, Fill = Brushes.Moccasin, Stroke = Brushes.Gray }; el.SetValue(Canvas.LeftProperty, x - containerPad); el.SetValue(Canvas.TopProperty, y - ypad - containerPad); _canvas.Children.Add(el); y = ypad * 2; foreach (var sp in link.DimPoint.SpaPoints) { _canvas.Children.Add(new Rectangle { Width = containerPad * 5, Height = containerPad * 2, Fill = sp.IsFastMover ? Brushes.LawnGreen : Brushes.LightSkyBlue, Stroke = Brushes.Black, StrokeThickness = 0.5, Tag = sp } .Do(r => r.SetValue(Canvas.LeftProperty, x - containerPad * 2.5)) .Do(r => r.SetValue(Canvas.TopProperty, y - containerPad))); tb = Text(sp.Value.ToString(CultureInfo.InvariantCulture), x, y); _canvas.Children.Add(tb); y -= containerPad * 2; } } }
public static dynamic GetTSObject(DimensionLink dynObject) { if (dynObject is null) { return(null); } return(dynObject.teklaObject); }
private static void ProcessTwoColumns <T>(DimensionLink <T> a, DimensionLink <T> b, Action <DimensionLink <T>, DimensionLink <T> > func) { while (a != null && b != null) { func(a, b); a = a.Upper; b = b.Upper; } }
private static bool HasBottomLevelNeighbourToTheRight <T>(DimensionLink <T> head) { var next = head.Next; return(next != null && next.Upper == null && next.Next != null && next.Next.Upper == null); }
private static bool HasBottomLevelNeighbourToTheLeft <T>(DimensionLink <T> head) { var prev = head.Prev; return(prev != null && prev.Upper == null && prev.Prev != null && prev.Prev.Upper == null); }
private static void DeleteColumn <T>(DimensionLink <T> head) { var toSrink = head.Upper; // make sure we are not removing edge column if (toSrink != null && toSrink.Prev != null && toSrink.Next != null) { ShrinkColumn(toSrink); } head.AssignUpper(null); head.DimPoint.TailLink = head.DimPoint.HeadLink; }
private void DrawVerticalLines(DimensionLink <int> dpl0) { const double ySpacePoints = ypad * 2; const double yLevel0 = ypad * 2 + ypad * 2; const int linePad = 10; var x = (double)dpl0.DimPoint.Position; _canvas.Children.Add(new Line { X1 = x, Y1 = ySpacePoints + linePad, X2 = x, Y2 = ySpacePoints + ypad - linePad, Stroke = new SolidColorBrush(Colors.DarkBlue) }); _canvas.Children.Add(new Line { X1 = x, Y1 = ySpacePoints + ypad + linePad, X2 = x, Y2 = yLevel0 - linePad, Stroke = new SolidColorBrush(Colors.DarkBlue) }); DrawHeadPointer(x, yLevel0, linePad / 2); DrawTailPointer(x, yLevel0 + dpl0.DimPoint.TailLink.Level * ypad, linePad / 2); DrawLink(dpl0); if (dpl0.Next != null) { var nextX = dpl0.Next.DimPoint.Position; _canvas.Children.Add(new Line { X1 = x + linePad, Y1 = yLevel0, X2 = nextX - linePad, Y2 = yLevel0, Stroke = new SolidColorBrush(Colors.DarkGreen) }); } var upper = dpl0.Upper; var prevYLevel = yLevel0; while (upper != null) { DrawLink(upper); var yLevel = prevYLevel + ypad; _canvas.Children.Add(new Line { X1 = x, Y1 = prevYLevel + linePad, X2 = x, Y2 = yLevel - linePad, Stroke = new SolidColorBrush(Colors.DarkBlue) }); prevYLevel = yLevel; if (upper.Next != null) { var nextX = upper.Next.DimPoint.Position; _canvas.Children.Add(new Line { X1 = x + linePad, Y1 = yLevel, X2 = nextX - linePad, Y2 = yLevel, Stroke = new SolidColorBrush(Colors.DarkGreen) }); } upper = upper.Upper; } }
private static bool RowHasLinkNotConnectedToUpper <T>(DimensionLink <T> left) { var link = left; while (link != null) { if (link.Upper == null) { return(true); } link = link.Next; } return(false); }
private static void ShrinkColumn <T>(DimensionLink <T> link) { while (link != null) { if (link.Prev != null) { link.Prev.AssignNext(link.Next); } else if (link.Next != null) { link.Next.AssignPrev(link.Prev); } link = link.Upper; } }
bool ISpaceManager.TryExtendUp <T>(DimensionLink <T> toExtendUp, out DimensionLink <T> nextUpExtension) { nextUpExtension = null; if (toExtendUp == null || // nothing to extend toExtendUp.Upper != null || // alrady extended toExtendUp.Next == null || // cannot extend up right edge toExtendUp.Prev == null || // cannot extend up left edge toExtendUp.Next.Upper != null || // no need to extend up if neighbours are extended up toExtendUp.Prev.Upper != null) { return(false); } var leftCorner = toExtendUp.PrevUntil((n, i) => n.Upper != null); var rightCorner = toExtendUp.NextUntil((n, i) => n.Upper != null); if (leftCorner == null || rightCorner == null) { return(false); } var left = leftCorner.Upper; var right = rightCorner.Upper; var upper = new DimensionLink <T>((byte)(toExtendUp.Level + 1)); toExtendUp.AssignUpper(upper); left.AssignNext(upper); upper.AssignNext(right); toExtendUp.DimPoint.TailLink = upper; nextUpExtension = upper.GetSiblingExtensionCandidate(); return(true); }
bool ISpaceManager.AddPoint <T>(Dimension <T> dimension, SpacePoint <T> sp, float position) { if (dimension == null || sp == null) { return(false); } MustBe.Null(sp.Dimensions[dimension.Index], () => "space point already has assigned the dimension with index=" + dimension.Index); if (dimension.HeadDimPoint == null) { var dp = new DimensionPoint <T>(dimension) { Position = position }; dp.HeadLink = dp.TailLink = new DimensionLink <T>(0, dp); dp.AddPoint(sp); dimension.HeadDimPoint = dimension.TailDimPoint = dp; dimension.Count = 1; return(true); } // try to find existing dimension point DimensionPoint <T> left; DimensionPoint <T> right; if (_spaceManager.TryFindDimensionPoint(dimension, position, out left, out right)) { // if found add the space point to it return(left.AddPoint(sp)); } // new head if (left == null) { AppendNewHead(dimension, sp, position); dimension.Count++; return(true); } // new tail if (right == null) { AppendNewTail(dimension, sp, position); dimension.Count++; return(true); } // new in between var newPoint = new DimensionPoint <T>(dimension) { Position = position }; newPoint.AddPoint(sp); var newLink = new DimensionLink <T>(0, newPoint); newPoint.HeadLink = newLink; newPoint.TailLink = newLink; left.HeadLink.AssignNext(newLink); newLink.AssignNext(right.HeadLink); // for fast movers do not normalize the tree if (!sp.IsFastMover) { _spaceManager.TryAddLevel(dimension); var toExtendUp = newLink.GetSiblingExtensionCandidate(); while (_spaceManager.TryExtendUp(toExtendUp, out toExtendUp)) { _spaceManager.TryAddLevel(dimension); } } dimension.Count++; return(true); }
private bool PopulateDimension <T>(Dimension <T> dimension, List <SpacePointSource <T> > points) { if (points.Count == 0) { return(false); } points.Sort(new SpacePointComparer <T>(dimension.Index)); //points.Sort((a, b) => a.InitialPositions[dimension.Index].CompareTo(b.InitialPositions[dimension.Index])); DimensionPoint <T> head = null; DimensionPoint <T> curr = null; DimensionPoint <T> prev = null; for (var i = 0; i < points.Count; ++i) { var sp = points[i]; if (sp == null) { continue; } var position = sp.InitialPositions[dimension.Index]; if (prev != null) { if (dimension.Eq(prev.Position, position)) { prev.AddPoint(sp); continue; } } curr = new DimensionPoint <T>(dimension) { Position = position }; curr.HeadLink = new DimensionLink <T>(0, curr); curr.TailLink = curr.HeadLink; curr.AddPoint(sp); if (prev != null) { prev.HeadLink.AssignNext(curr.HeadLink); } else { head = curr; } prev = curr; } dimension.HeadDimPoint = head; dimension.TailDimPoint = curr; dimension.Count += points.Count; // ReSharper disable PossibleNullReferenceException DimensionLink <T> link = dimension.HeadDimPoint.HeadLink; // ReSharper restore PossibleNullReferenceException // if this is the top level if (link.Next == null || link.Next.Next == null) { return(true); } DimensionLink <T> prevUpper = null; DimensionLink <T> firstUpper = null; while (link != null) { var upper = new DimensionLink <T>((byte)(link.Level + 1)); if (firstUpper == null) { firstUpper = upper; } link.AssignUpper(upper); link.DimPoint.TailLink = upper; if (prevUpper != null) { prevUpper.AssignNext(upper); } // if this is the end if (link.Next == null) { link = firstUpper; firstUpper = null; prevUpper = null; // if this is the top level if (link.Next == null || link.Next.Next == null) { return(true); } continue; } link = link.Next.Next; // the next is the end and it is two links away if (link.Next != null && link.Next.Next == null) { link = link.Next; } prevUpper = upper; } return(true); }
private void DrawVerticalLines(DimensionLink<int> dpl0) { const double ySpacePoints = ypad * 2; const double yLevel0 = ypad * 2 + ypad * 2; const int linePad = 10; var x = (double)dpl0.DimPoint.Position; _canvas.Children.Add(new Line { X1 = x, Y1 = ySpacePoints + linePad, X2 = x, Y2 = ySpacePoints + ypad - linePad, Stroke = new SolidColorBrush(Colors.DarkBlue) }); _canvas.Children.Add(new Line { X1 = x, Y1 = ySpacePoints + ypad + linePad, X2 = x, Y2 = yLevel0 - linePad, Stroke = new SolidColorBrush(Colors.DarkBlue) }); DrawHeadPointer(x, yLevel0, linePad / 2); DrawTailPointer(x, yLevel0 + dpl0.DimPoint.TailLink.Level * ypad, linePad / 2); DrawLink(dpl0); if (dpl0.Next != null) { var nextX = dpl0.Next.DimPoint.Position; _canvas.Children.Add(new Line { X1 = x + linePad, Y1 = yLevel0, X2 = nextX - linePad, Y2 = yLevel0, Stroke = new SolidColorBrush(Colors.DarkGreen) }); } var upper = dpl0.Upper; var prevYLevel = yLevel0; while (upper != null) { DrawLink(upper); var yLevel = prevYLevel + ypad; _canvas.Children.Add(new Line { X1 = x, Y1 = prevYLevel + linePad, X2 = x, Y2 = yLevel - linePad, Stroke = new SolidColorBrush(Colors.DarkBlue) }); prevYLevel = yLevel; if (upper.Next != null) { var nextX = upper.Next.DimPoint.Position; _canvas.Children.Add(new Line { X1 = x + linePad, Y1 = yLevel, X2 = nextX - linePad, Y2 = yLevel, Stroke = new SolidColorBrush(Colors.DarkGreen) }); } upper = upper.Upper; } }
private void DrawLink(DimensionLink<int> link) { var x = (double)link.DimPoint.Position; var y = link.Level * ypad + ypad * 4; const int containerPad = 7; var p = new Polygon { Stroke = Brushes.Black, Fill = Brushes.LightBlue, StrokeThickness = 0.5, Points = new PointCollection { new Point(x, y - containerPad), new Point(x + containerPad, y), new Point(x, y + containerPad), new Point(x - containerPad, y) } }; _canvas.Children.Add(p); var tb = Text(link.Level.ToString(CultureInfo.InvariantCulture), x, y); _canvas.Children.Add(tb); if (link.Level == 0) { var el = new Ellipse { Tag = link.DimPoint, Width = containerPad * 2, Height = containerPad * 2, Fill = Brushes.Moccasin, Stroke = Brushes.Gray }; el.SetValue(Canvas.LeftProperty, x - containerPad); el.SetValue(Canvas.TopProperty, y - ypad - containerPad); _canvas.Children.Add(el); y = ypad * 2; foreach (var sp in link.DimPoint.SpaPoints) { _canvas.Children.Add(new Rectangle { Width = containerPad * 5, Height = containerPad * 2, Fill = sp.IsFastMover ? Brushes.LawnGreen : Brushes.LightSkyBlue, Stroke = Brushes.Black, StrokeThickness = 0.5, Tag = sp } .Do(r => r.SetValue(Canvas.LeftProperty, x - containerPad * 2.5)) .Do(r => r.SetValue(Canvas.TopProperty, y - containerPad))); tb = Text(sp.Value.ToString(CultureInfo.InvariantCulture), x, y); _canvas.Children.Add(tb); y -= containerPad * 2; } } }