/// <summary> /// Generates fast lookup class which allows to find elements in O(1) time by given key /// </summary> /// <param name="root">Root node of tree</param> /// <param name="keysSelector">function that returns keys by which to search fast</param> public FastLookup(EquipmentTreeNode root, Func <EquipmentTreeNode, IEnumerable <TKey> > keysSelector) { this.root = root; this.keysSelector = keysSelector; UpdateNodeDictionary(); }
public void SetElectricity(EquipmentTreeNode node, bool value, bool isRoot = false) { if (!isRoot) { node.IsClickable = value; } node.TurnedOn = value; }
private void UpdateTransfomerList(EquipmentTreeNode root) { var fastNodeLookupByItemType = new FastLookupByItemType(root); var transformers = fastNodeLookupByItemType .Find(typeof(TransformerModel)) .Select((node) => node.Item as TransformerModel) .ToList(); Transformers = new ObservableCollection <TransformerModel>(transformers); }
public void Update(object sender, ModelUpdateEvent e) { EquipmentTreeNode root = EquipmentTreeFactory.CreateFrom(e); var fastNodeLookupByMrid = new FastLookupByMrid(root); App.Current.Dispatcher.Invoke((System.Action) delegate { measurementUpdater = new MeasurementUpdater(fastNodeLookupByMrid); DisplayTree(root); UpdateTransfomerList(root); }); }
private static IEnumerable <string> MridSelector(EquipmentTreeNode node) { if (node.Item is TransformerModel transformer) { return(new[] { transformer?.MRID, transformer?.PowerTransformer?.MRID, transformer?.RatioTapChanger?.MRID }); } return(new[] { node.Item?.MRID }); }
private void UpdateNodeDictionary(EquipmentTreeNode currentNode) { foreach (var key in keysSelector(currentNode)) { if (key != null) { nodeDict[key] = currentNode; } } foreach (var child in currentNode.Children) { UpdateNodeDictionary(child); } }
private void UpdateNodeDictionary(EquipmentTreeNode currentNode) { var itemType = currentNode.Item.GetType(); if (nodesByItemType.TryGetValue(itemType, out var nodes)) { nodes.Add(currentNode); } else { nodesByItemType[itemType] = new List <EquipmentTreeNode> { currentNode }; } foreach (var child in currentNode.Children) { UpdateNodeDictionary(child); } }
public OpenTransformerFormCommand(EquipmentTreeNode node) { this.node = node; }
/// <summary> /// Generates fast lookup class which allows to find elements in O(1) time by type /// </summary> /// <param name="root">Root node of tree</param> public FastLookupByItemType(EquipmentTreeNode root) { this.root = root; UpdateNodeDictionary(); }
private void DisplayTree(EquipmentTreeNode root) { Nodes = new ObservableCollection <EquipmentTreeNode>(new[] { root }); }
public FastLookupByMrid(EquipmentTreeNode root) : base(root, keysSelector: MridSelector) { }
public ToggleElectricityCommand(EquipmentTreeNode node) { _node = node; }