public override object Clone() { PipeInfo d = (PipeInfo)base.Clone(); d.Level = this.Level; d.Max = this.Max; d.Current = this.Current; return(d); }
// test explicit layout, insertion of new PipeInfo, modifying existing PipeInfo private void Grid_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.L) // layout the diagram again { myDiagram.LayoutDiagram(); } else if (e.Key == Key.I) // insert a pipe { int id = 21; while (myDiagram.Model.FindNodeByKey(id.ToString()) != null) { id++; } PipeInfo pi = new PipeInfo() { Key = id.ToString(), ParentKey = "2", Level = "New", Current = id }; var pipes = myDiagram.Model.NodesSource as ObservableCollection <PipeInfo>; if (pipes != null) { // need StartTransaction/CommitTransaction if supporting undo/redo myDiagram.StartTransaction("add node"); pipes.Add(pi); myDiagram.CommitTransaction("add node"); } } else if (e.Key == Key.M) // modify a particular pipe { PipeInfo pi = myDiagram.Model.FindNodeByKey("11") as PipeInfo; if (pi != null) { // need StartTransaction/CommitTransaction if supporting undo/redo myDiagram.StartTransaction("incrementing Current"); pi.Current++; myDiagram.CommitTransaction("incrementing Current"); } } }
protected override void AssignTreeVertexValues(TreeVertex v) { base.AssignTreeVertexValues(v); // Manually rotate the TextBlock and resize the background Rectangle // based on the level/depth in the tree so that the node/vertex is approximately // the correct (minimum) size, including the TextBlock and some space around it. // This is kludgy but will work both in WPF and in Silverlight // (there's no FrameworkElement.LayoutTransform in Silverlight). Node node = v.Node; FrameworkElement back = node.FindNamedDescendant("Background"); FrameworkElement tb = node.FindNamedDescendant("TextBlock"); // find how big the TextBlock is Size tsize = new Size(tb.ActualWidth, tb.ActualHeight); // length includes some space at both ends double textlen = tsize.Width + 20; PipeInfo pi = node.Data as PipeInfo; // the thickness of the "pipe" Rectangle double boxthickness = Math.Max(pi.Current, 20); if (v.Angle == 0 || v.Angle == 180) // if tree is growing sideways // the Background Rectangle is sized according to PipeInfo.Current // and is long enough to hold the text { back.Width = boxthickness; back.Height = textlen; node.SetAngle(tb, 90); // and the text is turned to 90 degrees } else { back.Width = textlen; back.Height = boxthickness; node.SetAngle(tb, 0); // normal upright text } // update the vertex with the new size v.Bounds = new Rect(0, 0, back.Width, back.Height); }