public RecloserState(RecloserLayout recloser) { Recloser = recloser; First = new Stack <NodeLayout>(); Second = new Stack <NodeLayout>(); NodeLayout n1 = recloser.Node1; NodeLayout n2 = recloser.Node2; if (n1.Y < n2.Y) { NodeLayout t = n1; n1 = n2; n2 = t; } while (n1.Y > n2.Y) { First.Push(n1); n1 = n1.Parent; } while (n1 != n2) { First.Push(n1); Second.Push(n2); n1 = n1.Parent; n2 = n2.Parent; } Parent = n1; Depth = recloser.Node1.Y - n1.Y; }
void Layout() { if (!networkModelChanged || networkModel == null) { return; } networkModelChanged = false; Tuple <List <Node>, List <RecloserNode> > model = networkModel.GetTreesAndReclosers(); Dictionary <Node, NodeLayout> recloserConNodes = new Dictionary <Node, NodeLayout>(model.Item2.Count * 2); foreach (RecloserNode rn in model.Item2) { recloserConNodes[rn.node1] = null; recloserConNodes[rn.node2] = null; } NodeLayout root = new NodeLayout(null, null); foreach (Node tree in model.Item1) { NodeLayout treeRoot = new NodeLayout(root, tree); NodeLayout node = treeRoot; uint y = 0; do { node.Y = y; if (recloserConNodes.ContainsKey(node.Node)) { recloserConNodes[node.Node] = node; } if (node.Children.Count < node.Node.children.Count) { node = new NodeLayout(node, node.Node.children[node.Children.Count]); ++y; continue; } node.Parent.Children.Add(node); node = node.Parent; --y; }while(node != root); } List <RecloserLayout> reclosers = new List <RecloserLayout>(model.Item2.Count); List <RecloserState> recloserStates = new List <RecloserState>(model.Item2.Count); foreach (RecloserNode rn in model.Item2) { RecloserLayout r = new RecloserLayout(rn, recloserConNodes[rn.node1], recloserConNodes[rn.node2]); reclosers.Add(r); recloserStates.Add(new RecloserState(r)); } recloserStates.Sort(); { NodeLayout node = root; Stack <int> stack = new Stack <int>(); stack.Push(0); uint x = 0; do { int i = stack.Pop(); if (i == 0) { ReorderChildren(node, recloserStates); } if (i < node.Children.Count) { node = node.Children[i]; stack.Push(i + 1); stack.Push(0); continue; } if (node.Children.Count > 0) { foreach (NodeLayout child in node.Children) { node.X += child.X; } node.X /= (uint)node.Children.Count; } else { node.X = x += (node.IO != null && ModelCodeHelper.GetTypeFromGID(node.IO.GID) == DMSType.EnergyConsumer) ? 2 : 1; } node = node.Parent; }while(node != null); } this.root = root; this.reclosers = reclosers; topologyChanged = true; }