/// <summary> /// 拷贝构造函数 /// </summary> public PartitionLine(PartitionLine line) { if (line == null) { return; } IsSelected = line.IsSelected; IsLocked = line.IsLocked; Start = line.Start; End = line.End; Position = line.Position; IsRow = line.IsRow; if (line.ChildLines != null)///拷贝孩子 { ChildLines = new SDLinkedList <PartitionLine>(); foreach (PartitionLine childLine in line.ChildLines) { ChildLines.AddLast(new PartitionLine(childLine)); } } if (line.FatherLine != null) { FatherLine = line.FatherLine; } }
/// <summary> /// 根据位置来分割线段 /// </summary> /// <param name="position"></param> public void PartitionByPos(int position) { Point point; if (IsRow) { point = new Point(position, Position); } else { point = new Point(Position, position); } ///如果没有孩子线段 if (this.ChildLines == null) { ChildLines = new SDLinkedList <PartitionLine>(); PartitionLine preLine = new PartitionLine(this.Start, position, this.Position, this.IsRow); PartitionLine aftLine = new PartitionLine(position, this.End, this.Position, this.IsRow); preLine.FatherLine = this; aftLine.FatherLine = this; ChildLines.AddFirst(preLine); ChildLines.AddLast(aftLine); } else { ///找到被切割的线段 FindLineByPoint findByPoint = new FindLineByPoint(point); LinkedListNode <PartitionLine> resultNode = ChildLines.Find(findByPoint.PredicatePointIn); ///在被切割的线段前后添加一线段,同时删除原线段 if (resultNode != null) { PartitionLine preLine = new PartitionLine(resultNode.Value.Start, position, resultNode.Value.Position, this.IsRow); PartitionLine aftLine = new PartitionLine(position, resultNode.Value.End, resultNode.Value.Position, this.IsRow); preLine.FatherLine = this; aftLine.FatherLine = this; ChildLines.AddBefore(resultNode, preLine); ChildLines.AddAfter(resultNode, aftLine); ChildLines.Remove(resultNode); } } }
public CommandList() { Commands = new SDLinkedList <BaseCommand>(); }